@@ -15,24 +15,75 @@ import '@primer/brand-primitives/lib/design-tokens/css/tokens/functional/compone
15
15
*/
16
16
import styles from './MinimalFooter.module.css'
17
17
18
- export const MinimalFooterSocialLinks = [
19
- 'x' ,
20
- 'github' ,
21
- 'linkedin' ,
22
- 'youtube' ,
23
- 'facebook' ,
24
- 'twitch' ,
25
- 'tiktok' ,
26
- 'instagram' ,
27
- ] as const
18
+ const socialLinkData = {
19
+ x : {
20
+ fullName : 'X' ,
21
+ url : 'https://x.com/github' ,
22
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/x.svg' ,
23
+ iconWidth : 20 ,
24
+ iconHeight : 16 ,
25
+ } ,
26
+ github : {
27
+ fullName : 'GitHub' ,
28
+ url : 'https://github.com/github' ,
29
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/github-mark.svg' ,
30
+ iconWidth : 20 ,
31
+ iconHeight : 20 ,
32
+ } ,
33
+ linkedin : {
34
+ fullName : 'LinkedIn' ,
35
+ url : 'https://www.linkedin.com/company/github' ,
36
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/linkedin.svg' ,
37
+ iconWidth : 19 ,
38
+ iconHeight : 18 ,
39
+ } ,
40
+ youtube : {
41
+ fullName : 'YouTube' ,
42
+ url : 'https://www.youtube.com/github' ,
43
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/youtube.svg' ,
44
+ iconWidth : 23 ,
45
+ iconHeight : 16 ,
46
+ } ,
47
+ facebook : {
48
+ fullName : 'Facebook' ,
49
+ url : 'https://www.facebook.com/GitHub' ,
50
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/facebook.svg' ,
51
+ iconWidth : 18 ,
52
+ iconHeight : 18 ,
53
+ } ,
54
+ twitch : {
55
+ fullName : 'Twitch' ,
56
+ url : 'https://www.twitch.tv/github' ,
57
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/twitch.svg' ,
58
+ iconWidth : 18 ,
59
+ iconHeight : 18 ,
60
+ } ,
61
+ tiktok : {
62
+ fullName : 'TikTok' ,
63
+ url : 'https://www.tiktok.com/@github' ,
64
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/tiktok.svg' ,
65
+ iconWidth : 18 ,
66
+ iconHeight : 18 ,
67
+ } ,
68
+ instagram : {
69
+ fullName : 'Instagram' ,
70
+ url : 'https://www.instagram.com/github/' ,
71
+ icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/instagram.svg' ,
72
+ iconWidth : 24 ,
73
+ iconHeight : 24 ,
74
+ } ,
75
+ } as const
28
76
29
- type SocialLinks = ( typeof MinimalFooterSocialLinks ) [ number ]
77
+ type SocialLinkName = keyof typeof socialLinkData
78
+ type SocialLink = ( typeof socialLinkData ) [ SocialLinkName ]
79
+
80
+ const socialLinkNames = Object . keys ( socialLinkData ) as SocialLinkName [ ]
30
81
31
82
export type MinimalFooterProps = {
32
83
/**
33
84
* An array of social links to be displayed in the footer.
34
85
*/
35
- socialLinks ?: SocialLinks [ ] | false
86
+ socialLinks ?: SocialLinkName [ ] | false
36
87
/**
37
88
* The href for the GitHub logo.
38
89
*/
@@ -149,104 +200,40 @@ function Footnotes({children, className}: PropsWithChildren<FootnoteProps>) {
149
200
)
150
201
}
151
202
203
+ type SocialLinkProps = { name : SocialLinkName }
204
+
205
+ const SocialLink = ( { name} : SocialLinkProps ) => {
206
+ const link = socialLinkData [ name ]
207
+ return (
208
+ < li key = { name } >
209
+ < a
210
+ href = { link . url }
211
+ className = { styles [ 'Footer__social-link' ] }
212
+ data-analytics-event = { `{"category":"Footer","action":"go to ${ link . fullName } ","label":"text:${ name } "}` }
213
+ >
214
+ < img
215
+ className = { styles [ 'Footer__social-icon' ] }
216
+ src = { link . icon }
217
+ height = { link . iconHeight }
218
+ width = { link . iconWidth }
219
+ loading = "lazy"
220
+ decoding = "async"
221
+ alt = ""
222
+ />
223
+ < span className = "visually-hidden" > GitHub on { link . fullName } </ span >
224
+ </ a >
225
+ </ li >
226
+ )
227
+ }
228
+
152
229
type SocialLogomarksProps = {
153
- socialLinks ?: SocialLinks [ ] | false
230
+ socialLinks ?: SocialLinkName [ ] | false
154
231
logoHref ?: string
155
232
}
156
233
157
- function SocialLogomarks ( { socialLinks, logoHref} : SocialLogomarksProps ) {
234
+ function SocialLogomarks ( { socialLinks = socialLinkNames , logoHref} : SocialLogomarksProps ) {
158
235
const { colorMode} = useTheme ( )
159
236
160
- const socialLinkData = [
161
- {
162
- name : 'x' ,
163
- fullName : 'X' ,
164
- url : 'https://x.com/github' ,
165
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/x.svg' ,
166
- iconWidth : 20 ,
167
- iconHeight : 16 ,
168
- } ,
169
- {
170
- name : 'github' ,
171
- fullName : 'GitHub' ,
172
- url : 'https://github.com/github' ,
173
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/github-mark.svg' ,
174
- iconWidth : 20 ,
175
- iconHeight : 20 ,
176
- } ,
177
- {
178
- name : 'linkedin' ,
179
- fullName : 'LinkedIn' ,
180
- url : 'https://www.linkedin.com/company/github' ,
181
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/linkedin.svg' ,
182
- iconWidth : 19 ,
183
- iconHeight : 18 ,
184
- } ,
185
- {
186
- name : 'youtube' ,
187
- fullName : 'YouTube' ,
188
- url : 'https://www.youtube.com/github' ,
189
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/youtube.svg' ,
190
- iconWidth : 23 ,
191
- iconHeight : 16 ,
192
- } ,
193
- {
194
- name : 'facebook' ,
195
- fullName : 'Facebook' ,
196
- url : 'https://www.facebook.com/GitHub' ,
197
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/facebook.svg' ,
198
- iconWidth : 18 ,
199
- iconHeight : 18 ,
200
- } ,
201
- {
202
- name : 'twitch' ,
203
- fullName : 'Twitch' ,
204
- url : 'https://www.twitch.tv/github' ,
205
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/twitch.svg' ,
206
- iconWidth : 18 ,
207
- iconHeight : 18 ,
208
- } ,
209
- {
210
- name : 'tiktok' ,
211
- fullName : 'TikTok' ,
212
- url : 'https://www.tiktok.com/@github' ,
213
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/tiktok.svg' ,
214
- iconWidth : 18 ,
215
- iconHeight : 18 ,
216
- } ,
217
- {
218
- name : 'instagram' ,
219
- fullName : 'Instagram' ,
220
- url : 'https://www.instagram.com/github/' ,
221
- icon : 'https://static-gh.moeloli.ml/images/modules/site/icons/footer/instagram.svg' ,
222
- iconWidth : 24 ,
223
- iconHeight : 24 ,
224
- } ,
225
- ]
226
-
227
- const renderLink = ( link : ( typeof socialLinkData ) [ number ] ) => {
228
- return (
229
- < li key = { link . name } >
230
- < a
231
- href = { link . url }
232
- className = { styles [ 'Footer__social-link' ] }
233
- data-analytics-event = { `{"category":"Footer","action":"go to ${ link . fullName } ","label":"text:${ link . name } "}` }
234
- >
235
- < img
236
- className = { styles [ 'Footer__social-icon' ] }
237
- src = { link . icon }
238
- height = { link . iconHeight }
239
- width = { link . iconWidth }
240
- loading = "lazy"
241
- decoding = "async"
242
- alt = ""
243
- />
244
- < span className = "visually-hidden" > GitHub on { link . fullName } </ span >
245
- </ a >
246
- </ li >
247
- )
248
- }
249
-
250
237
return (
251
238
< section className = { clsx ( styles [ 'Footer__logomarks' ] ) } >
252
239
< div className = { styles [ 'Footer__container' ] } >
@@ -266,18 +253,13 @@ function SocialLogomarks({socialLinks, logoHref}: SocialLogomarksProps) {
266
253
< LogoGithubIcon fill = { colorMode === ColorModesEnum . DARK ? 'white' : 'black' } size = "medium" />
267
254
</ a >
268
255
</ div >
269
- { socialLinks !== false ? (
256
+ { socialLinks ? (
270
257
< ul className = { styles [ 'Footer__social-links' ] } >
271
- { socialLinkData . map ( ( link : ( typeof socialLinkData ) [ number ] ) => {
272
- if ( socialLinks && ! socialLinks . includes ( link . name as SocialLinks ) ) {
273
- return null
274
- }
275
- return renderLink ( link )
276
- } ) }
258
+ { socialLinks . map ( name => (
259
+ < SocialLink key = { name } name = { name } />
260
+ ) ) }
277
261
</ ul >
278
- ) : (
279
- < > </ >
280
- ) }
262
+ ) : null }
281
263
</ Stack >
282
264
</ div >
283
265
</ section >
0 commit comments