# All files / src/List List.tsx

85.19% Statements 23/27
33.33% Branches 3/9
33.33% Functions 1/3
85.19% Lines 23/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    817x
    7x
    7x
    7x

    7x
    7x

    7x
    7x

    7x

    7x

    7x

    7x

    2x
    2x

    2x
    2x

    2x

    2x
    2x
    2x

    7x

    7x

    7x
     import * as React from 'react'
    import classNames from 'classnames'
    import { createUseStyles } from '@fluent-ui/styles'
    import { styles } from './List.styled'
    import { Theme } from '../styles'
    import { ListClassProps, ListProps, ListPropTypes } from './List.type'
    import { useReveal } from '@fluent-ui/hooks'

    import Box from '../Box'
    import Typography from '../Typography'

    export const ListContext = React.createContext<{
      reveal: boolean
      acrylic: boolean
    }>({
      reveal: false,
      acrylic: false
    })

    export const name = 'List'

    const useStyles = createUseStyles<Theme, ListClassProps>(styles, { name })

    const List: React.FC<ListProps> = React.forwardRef<HTMLDivElement, ListProps>(
      (props, ref): React.ReactElement => {
        const {
          as = 'div',
          className: classNameProp,
          children,
          title,
          acrylic,
          reveal,
          ...rest
        } = props

        // handle Reveal Effects
        const [RevealWrapper] = useReveal(66)
        const theChildren = reveal
          ? React.useMemo(
              (): React.ReactElement[] =>
                React.Children.map(
                  children,
                  (child: React.ReactElement, i): React.ReactElement => {
                    if (child.type && (child as any).type.displayName === 'FItem') {
                      return <RevealWrapper key={i}>{child}</RevealWrapper>
                    }
                    return child
                  }
                ),
              [children]
            )
          : children

        const contextValue = {
          reveal: reveal as boolean,
          acrylic: acrylic as boolean
        }

        const classes = useStyles(props)
        const className = classNames(classes.root, classNameProp)
        return (
          <ListContext.Provider value={contextValue}>
            <Box className={className} ref={ref} as={as} acrylic={acrylic} {...rest}>
              {title && (
                <Typography className={classes.title} variant="subtitle2">
                  {title}
                </Typography>
              )}
              {theChildren}
            </Box>
          </ListContext.Provider>
        )
      }
    )

    List.displayName = `F${name}`

    List.propTypes = ListPropTypes

    export default List