diff options
Diffstat (limited to 'src/components/icons.tsx')
-rw-r--r-- | src/components/icons.tsx | 76 |
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 | ||
7 | import { useId } from 'react'; | 7 | import { useId } from 'react'; |
8 | import { siGithub, siGooglescholar, siLinkedin, siOrcid } from 'simple-icons'; | 8 | import { |
9 | siCreativecommons, | ||
10 | siDblp, | ||
11 | siGithub, | ||
12 | siGooglescholar, | ||
13 | siLinkedin, | ||
14 | siOrcid, | ||
15 | siScopus, | ||
16 | } from 'simple-icons'; | ||
9 | 17 | ||
10 | import fediverse from './icons/fediverse'; | 18 | import fediverse from './icons/fediverse'; |
19 | import mtmt from './icons/mtmt'; | ||
11 | 20 | ||
12 | export function Icon({ path, alt }: { path: string; alt: string }) { | 21 | export interface IconProps { |
22 | hidden?: boolean; | ||
23 | className?: string; | ||
24 | alt?: string; | ||
25 | } | ||
26 | |||
27 | export 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 | ||
60 | export interface SimpleIcon { | ||
61 | path: string; | ||
62 | title: string; | ||
63 | } | ||
64 | |||
35 | export function SimpleIcon({ | 65 | export 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 | ||
46 | export const FediverseIcon = () => <SimpleIcon icon={fediverse} />; | 74 | function makeSimpleIcon(icon: SimpleIcon): (props: IconProps) => JSX.Element { |
75 | return (props) => <SimpleIcon icon={icon} {...props} />; | ||
76 | } | ||
77 | |||
78 | export const CreativeCommonsIcon = makeSimpleIcon(siCreativecommons); | ||
79 | |||
80 | export const DBLPIcon = makeSimpleIcon(siDblp); | ||
81 | |||
82 | export const FediverseIcon = makeSimpleIcon(fediverse); | ||
83 | |||
84 | export const GithubIcon = makeSimpleIcon(siGithub); | ||
85 | |||
86 | export const GoogleScholarIcon = makeSimpleIcon(siGooglescholar); | ||
47 | 87 | ||
48 | export const GithubIcon = () => <SimpleIcon icon={siGithub} />; | 88 | export const LinkedInIcon = makeSimpleIcon(siLinkedin); |
49 | 89 | ||
50 | export const GoogleScholarIcon = () => <SimpleIcon icon={siGooglescholar} />; | 90 | export const MTMTIcon = makeSimpleIcon(mtmt); |
51 | 91 | ||
52 | export const LinkedInIcon = () => <SimpleIcon icon={siLinkedin} />; | 92 | export const OrcidIcon = makeSimpleIcon(siOrcid); |
53 | 93 | ||
54 | export const OrcidIcon = () => <SimpleIcon icon={siOrcid} />; | 94 | export const ScopusIcon = makeSimpleIcon(siScopus); |