# All files / Progress Progress.tsx

0% Statements 0/19
0% Branches 0/7
0% Functions 0/1
0% Lines 0/18

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

     import * as React from 'react'
    import classNames from 'classnames'
    import { createUseStyles } from '@fluent-ui/styles'
    import { styles } from './Progress.styled'
    import { Theme } from '../styles'
    import { ProgressClassProps, ProgressProps, ProgressPropTypes } from './Progress.type'

    export const name = 'Progress'

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

    const Progress: React.FC<ProgressProps> = React.forwardRef<HTMLDivElement, ProgressProps>(
      (props, ref): React.ReactElement => {
        const { as: Component = 'div', className: classNameProp, value, ...rest } = props

        const isIndeterminate = !(typeof value === 'number')
        const transform = !isIndeterminate && value ? value - 100 : false

        const classes = useStyles(props)
        const className = classNames(classes.root, classNameProp)
        const progressClassName = classNames(classes.progress, {
          [classes.isIndeterminate]: isIndeterminate
        })

        return (
          <Component className={className} ref={ref} {...rest}>
            <div
              className={progressClassName}
              style={transform ? { transform: `translateX(${transform}%)` } : {}}
            />
          </Component>
        )
      }
    )

    Progress.displayName = `F${name}`

    Progress.propTypes = ProgressPropTypes

    export default Progress