File size: 1,117 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import clsx from 'clsx'
import { forwardRef, ReactNode } from 'react'
import * as FontSizes from '../../styles/fontStyles.css'
import { descriptiveList, list } from './List.css'

export interface ListProps {
  tag?: keyof Pick<React.JSX.IntrinsicElements, 'ul' | 'ol'>
  fontStyle?: keyof FontSizes.FontSizes
  className?: string
  children?: ReactNode
}

export const List = forwardRef<HTMLUListElement | HTMLOListElement, ListProps>(
  ({ tag = 'ul', fontStyle = 'XS', className, children }, ref) => {
    const Element = tag

    return (
      <Element
        className={clsx(FontSizes[fontStyle], list, className)}
        // @ts-expect-error - TODO: polymorphic refs, woo.
        ref={ref}
      >
        {children}
      </Element>
    )
  }
)

interface DescriptiveListProps {
  data: [title: string, item: ReactNode][]
}

export const DescriptiveList = ({ data }: DescriptiveListProps) => {
  return (
    <dl className={descriptiveList}>
      {data.map(datum => (
        <div key={datum[0]}>
          <dt>{`${datum[0]} –`}</dt>
          <dd>{datum[1]}</dd>
        </div>
      ))}
    </dl>
  )
}