import React from 'react' import styles from './_progress-bar.module.scss' import FormLabel from '../FormLabel/FormLabel' import Icon from '../Icons/Icon' import Spinner from '../Spinner/Spinner' import { c } from '../../translations/LibraryTranslationService' type ProgressBarBaseProps = { /** Current progress that should be shown. Range from 0 - 100 */ percentage: number /** Optional text below the ProgressBar */ helperText?: string /** Optionally style the ProgressBar as an error */ error?: boolean /** Optional prop to add a test id to the ProgressBar for QA testing */ qaTestId?: string } type FormLabelProps = React.ComponentProps type ProgressBarWithLabel = ProgressBarBaseProps & { /** Optional label above the ProgressBar */ formLabelProps?: Omit & { showRightLabel?: boolean } } type ProgressBarWithoutLabel = ProgressBarBaseProps & { formLabelProps?: never showPercentageText?: never } export type ProgressBarProps = ProgressBarWithLabel | ProgressBarWithoutLabel const ProgressBar = ({ percentage = 0, formLabelProps, helperText, error, qaTestId = 'progress-bar', }: ProgressBarProps): React.JSX.Element => { if (percentage < 0 || percentage > 100) { throw new Error(c('errorProgressBar')) } return (
{formLabelProps ? ( {!error ? ( {percentage} {c('percentageSymbol')} ) : null} {error ? ( ) : percentage < 100 ? ( ) : ( )}
), } : {})} /> ) : null}
{helperText ? (
{helperText}
) : null}
) } export default ProgressBar