1- /** @jsx jsx */
2- import { jsx } from '@emotion/react' ;
1+ import React from 'react' ;
32import { FooterLink } from '#app/models/types/serviceConfig' ;
43import { ReactElement } from 'react' ;
54import Link from '../Link' ;
6- import styles , { gridTemplateRows } from './index.styles' ;
5+
6+ const getRowCount = ( {
7+ itemCount,
8+ columns,
9+ trustProjectLink,
10+ } : {
11+ itemCount : number ;
12+ columns : number ;
13+ trustProjectLink ?: FooterLink ;
14+ } ) =>
15+ trustProjectLink
16+ ? Math . ceil ( itemCount / columns ) + 1
17+ : Math . ceil ( itemCount / columns ) ;
718
819export default ( {
920 elements = [ ] ,
@@ -14,32 +25,55 @@ export default ({
1425 trustProjectLink ?: FooterLink ;
1526 extraLinks ?: boolean ;
1627} ) => {
28+ const itemCount = elements . length ;
29+
30+ const getGridRows = ( columns : number ) =>
31+ `repeat(${ getRowCount ( { itemCount, columns, trustProjectLink } ) } , auto)` ;
32+
1733 return (
1834 < ul
1935 role = "list"
20- css = { [
21- styles . list ,
22- trustProjectLink
23- ? [
24- styles . listPaddingWithTrustProjectLink ,
25- styles . listItemWithBottomBorder ,
26- ]
27- : styles . listPaddingWithoutTrustProjectLink ,
28- gridTemplateRows ( {
29- itemCount : elements . length ,
30- trustProjectLink,
31- } ) ,
32- extraLinks && styles . listExtraLinks ,
33- ] }
36+ className = { `
37+ border-b border-gel-shadow
38+ columns-4
39+ m-0
40+ list-none
41+ supports-[display:grid]:grid
42+ supports-[display:grid]:grid-flow-col
43+ group-0:grid-flow-row
44+ group-0:columns-1
45+ group-1:gap-x-4 group-1:grid-cols-2 group-1:columns-2
46+ group-2:gap-x-4 group-2:grid-cols-2 group-2:columns-2
47+ group-3:gap-x-8 group-3:grid-cols-3 group-3:columns-3
48+ group-4:gap-x-8 group-4:grid-cols-4 group-4:columns-4
49+ group-5:gap-x-8 group-5:grid-cols-5 group-5:columns-5
50+ ${ trustProjectLink ? 'pb-4' : 'py-4' }
51+ ${ trustProjectLink ?
52+ `[&>li:first-child]:border-b [&>li:first-child]:border-gel-shadow
53+ [&>li:first-child]:py-4 [&>li:first-child]:mb-4
54+ [&>li:first-child]:col-span-full [&>li:first-child]:w-full
55+ [&>li:first-child]:column-span-all` : '' }
56+ ${ extraLinks ? 'group-2:grid-cols-1 group-2:columns-1 group-2:grid-flow-row' : '' }
57+ ` }
58+ style = { {
59+ gridTemplateRows : window . CSS ?. supports ( 'display: grid' ) ?
60+ `
61+ ${ getGridRows ( 2 ) } /* group-1 and group-2 */
62+ ` : undefined
63+ } }
3464 >
3565 { trustProjectLink && (
36- < li css = { styles . listItem } >
66+ < li className = "min-w-[50%] gap-x-8 break-inside-avoid" >
3767 < Link text = { trustProjectLink . text } href = { trustProjectLink . href } />
3868 </ li >
3969 ) }
4070 { elements . map ( ( elem , index ) => (
41- // eslint-disable-next-line react/no-array-index-key
42- < li key = { index } > { elem } </ li >
71+ < li
72+ key = { index }
73+ className = "min-w-[50%] gap-x-8 break-inside-avoid"
74+ >
75+ { elem }
76+ </ li >
4377 ) ) }
4478 </ ul >
4579 ) ;
0 commit comments