aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/icons.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/icons.tsx')
-rw-r--r--src/components/icons.tsx76
1 files changed, 58 insertions, 18 deletions
diff --git a/src/components/icons.tsx b/src/components/icons.tsx
index 402b622..1411218 100644
--- a/src/components/icons.tsx
+++ b/src/components/icons.tsx
@@ -1,15 +1,37 @@
1/* 1/*
2 * SPDX-FileCopyrightText: 2023 Kristóf Marussy 2 * SPDX-FileCopyrightText: 2023-2024 Kristóf Marussy
3 * 3 *
4 * SPDX-License-Identifier: MIT 4 * SPDX-License-Identifier: MIT
5 */ 5 */
6 6
7import { useId } from 'react'; 7import { useId } from 'react';
8import { siGithub, siGooglescholar, siLinkedin, siOrcid } from 'simple-icons'; 8import {
9 siCreativecommons,
10 siDblp,
11 siGithub,
12 siGooglescholar,
13 siLinkedin,
14 siOrcid,
15 siScopus,
16} from 'simple-icons';
9 17
10import fediverse from './icons/fediverse'; 18import fediverse from './icons/fediverse';
19import mtmt from './icons/mtmt';
11 20
12export function Icon({ path, alt }: { path: string; alt: string }) { 21export interface IconProps {
22 hidden?: boolean;
23 className?: string;
24 alt?: string;
25}
26
27export function Icon({
28 path,
29 alt,
30 hidden,
31 className,
32}: IconProps & {
33 path: string;
34}) {
13 const titleId = useId(); 35 const titleId = useId();
14 36
15 return ( 37 return (
@@ -18,37 +40,55 @@ export function Icon({ path, alt }: { path: string; alt: string }) {
18 version="1.1" 40 version="1.1"
19 xmlns="http://www.w3.org/2000/svg" 41 xmlns="http://www.w3.org/2000/svg"
20 role="img" 42 role="img"
21 aria-labelledby={titleId} 43 {...(hidden ? { 'aria-hidden': true } : { 'aria-labelledby': titleId })}
22 viewBox="0 0 24 24" 44 viewBox="0 0 24 24"
23 width="24" 45 width="24"
24 height="24" 46 height="24"
47 {...(className ? { className } : {})}
25 > 48 >
26 <path fill="currentColor" d={path} /> 49 <path fill="currentColor" d={path} />
27 </svg> 50 </svg>
28 <span className="sr-only" id={titleId}> 51 {!hidden && (
29 {alt} 52 <span className="sr-only" id={titleId}>
30 </span> 53 {alt}
54 </span>
55 )}
31 </> 56 </>
32 ); 57 );
33} 58}
34 59
60export interface SimpleIcon {
61 path: string;
62 title: string;
63}
64
35export function SimpleIcon({ 65export function SimpleIcon({
36 icon: { path, title }, 66 icon: { path, title },
37}: { 67 ...props
38 icon: { 68}: IconProps & {
39 path: string; 69 icon: SimpleIcon;
40 title: string;
41 };
42}) { 70}) {
43 return <Icon path={path} alt={title} />; 71 return <Icon path={path} {...{ ...props, alt: props.alt ?? title }} />;
44} 72}
45 73
46export const FediverseIcon = () => <SimpleIcon icon={fediverse} />; 74function makeSimpleIcon(icon: SimpleIcon): (props: IconProps) => JSX.Element {
75 return (props) => <SimpleIcon icon={icon} {...props} />;
76}
77
78export const CreativeCommonsIcon = makeSimpleIcon(siCreativecommons);
79
80export const DBLPIcon = makeSimpleIcon(siDblp);
81
82export const FediverseIcon = makeSimpleIcon(fediverse);
83
84export const GithubIcon = makeSimpleIcon(siGithub);
85
86export const GoogleScholarIcon = makeSimpleIcon(siGooglescholar);
47 87
48export const GithubIcon = () => <SimpleIcon icon={siGithub} />; 88export const LinkedInIcon = makeSimpleIcon(siLinkedin);
49 89
50export const GoogleScholarIcon = () => <SimpleIcon icon={siGooglescholar} />; 90export const MTMTIcon = makeSimpleIcon(mtmt);
51 91
52export const LinkedInIcon = () => <SimpleIcon icon={siLinkedin} />; 92export const OrcidIcon = makeSimpleIcon(siOrcid);
53 93
54export const OrcidIcon = () => <SimpleIcon icon={siOrcid} />; 94export const ScopusIcon = makeSimpleIcon(siScopus);