diff --git a/frontend/src/components/SeedlotRegistrationProgress/SparProgressIndicator.tsx b/frontend/src/components/SeedlotRegistrationProgress/SparProgressIndicator.tsx new file mode 100644 index 000000000..082255602 --- /dev/null +++ b/frontend/src/components/SeedlotRegistrationProgress/SparProgressIndicator.tsx @@ -0,0 +1,85 @@ +import React, { useState } from 'react'; +import prefix from '../../styles/classPrefix'; +import { SparProgressStepProps } from './SparProgressStep'; + +export interface SparProgressIndicatorProps + extends Omit, 'onChange'> { + children?: React.ReactNode; + className?: string; + currentIndex?: number; + onChange?: (data: number) => void; + spaceEqually?: boolean; + vertical?: boolean; +} + +/** + * Create a progress bar modified with custom icons. + * + * @param {SparProgressIndicatorProps} param0 Progress bar indicator parameters. + * @returns {JSX.Element} custom element + */ +function SparProgressIndicator({ + children, + className: customClassName, + currentIndex: controlledIndex = 0, + onChange, + spaceEqually, + vertical +}: SparProgressIndicatorProps): JSX.Element { + const [currentIndex, setCurrentIndex] = useState(controlledIndex); + const [prevControlledIndex, setPrevControlledIndex] = useState(controlledIndex); + + const getClassName = (): string => { + let classNames = `${prefix}--progress `; + if (vertical) { + classNames += `${prefix}--progress--vertical `; + } + if (spaceEqually && !vertical) { + classNames += `${prefix}--progress--space-equal `; + } + if (customClassName) { + classNames += customClassName; + } + return classNames; + }; + + if (controlledIndex !== prevControlledIndex) { + setCurrentIndex(controlledIndex); + setPrevControlledIndex(controlledIndex); + } + + return ( + + ); +} + +export { SparProgressIndicator }; diff --git a/frontend/src/components/SeedlotRegistrationProgress/SparProgressStep.tsx b/frontend/src/components/SeedlotRegistrationProgress/SparProgressStep.tsx new file mode 100644 index 000000000..d20ca140b --- /dev/null +++ b/frontend/src/components/SeedlotRegistrationProgress/SparProgressStep.tsx @@ -0,0 +1,113 @@ +import React from 'react'; +import prefix from '../../styles/classPrefix'; +import { SparSVGIcon } from './SparSVGIcon'; + +export interface SparProgressStepProps { + className?: string; + complete?: boolean; + current?: boolean; + description?: string; + disabled?: boolean; + invalid?: boolean; + label: string; + onClick?: ( + event: + | React.KeyboardEvent + | React.MouseEvent + ) => void; + secondaryLabel?: string; +} + +/** + * Create a custom progress step. + * + * @param {SparProgressStepProps} props parameters of the component. + * @returns {JSX.Element} custom element + */ +const SparProgressStep = ({ + className, + complete, + current, + description, + disabled, + invalid, + label, + onClick, + secondaryLabel +}: SparProgressStepProps): JSX.Element => { + const getClassName = (): string => { + const classNames: Array = [`${prefix}--progress-step`]; + classNames.push(current ? `${prefix}--progress-step--current` : ''); + classNames.push(complete ? `${prefix}--progress-step--complete` : ''); + classNames.push(!complete && !current ? `${prefix}--progress-step--incomplete` : ''); + classNames.push(disabled ? `${prefix}--progress-step--disabled` : ''); + if (className) { + classNames.push(className); + } + return classNames.join(' '); + }; + + const getButtonClassName = (): string => { + const classNames: Array = [`${prefix}--progress-step-button`]; + classNames.push(!onClick || current ? `${prefix}--progress-step-button--unclickable` : ''); + return classNames.join(' '); + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if ((e.key === 'Enter' || e.key === 'Space') && onClick) { + onClick(e); + } + }; + + let message = 'Incomplete'; + + if (current) { + message = 'Current'; + } + + if (complete) { + message = 'Complete'; + } + + if (invalid) { + message = 'Invalid'; + } + + return ( +
  • + +
  • + ); +}; + +export { SparProgressStep }; diff --git a/frontend/src/components/SeedlotRegistrationProgress/SparSVGIcon.tsx b/frontend/src/components/SeedlotRegistrationProgress/SparSVGIcon.tsx new file mode 100644 index 000000000..b0213d5b7 --- /dev/null +++ b/frontend/src/components/SeedlotRegistrationProgress/SparSVGIcon.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { + CheckmarkFilled, + Warning, + CircleDash, + Incomplete, + CircleFilled +} from '@carbon/icons-react'; + +export interface SparSVGIconProps { + complete?: boolean; + current?: boolean; + description?: string; + invalid?: boolean; + svgPrefix: string; +} + +const SparSVGIcon = ({ + complete, + current, + description, + invalid, + svgPrefix +}: SparSVGIconProps): JSX.Element => { + if (invalid) { + return ( + + {description} + + ); + } + if (current && !complete) { + return ( + + {description} + + ); + } + if (current && complete) { + return ( + + {description} + + ); + } + if (complete && !current) { + return ( + + {description} + + ); + } + return ( + + {description} + + ); +}; + +export { SparSVGIcon }; diff --git a/frontend/src/components/SeedlotRegistrationProgress/index.tsx b/frontend/src/components/SeedlotRegistrationProgress/index.tsx index 9f3e22890..97d7e971c 100644 --- a/frontend/src/components/SeedlotRegistrationProgress/index.tsx +++ b/frontend/src/components/SeedlotRegistrationProgress/index.tsx @@ -1,10 +1,7 @@ import React from 'react'; -import { - ProgressIndicator, - ProgressStep -} from '@carbon/react'; - +import { SparProgressIndicator } from './SparProgressIndicator'; +import { SparProgressStep } from './SparProgressStep'; import { ProgressIndicatorConfig } from '../../views/Seedlot/ContextContainerClassA/definitions'; import { MEDIUM_SCREEN_WIDTH } from '../../shared-constants/shared-constants'; import useWindowSize from '../../hooks/UseWindowSize'; @@ -13,7 +10,7 @@ import './styles.scss'; interface SeedlotRegistrationProgressProps { progressStatus: ProgressIndicatorConfig; - interactFunction?: Function; + interactFunction?: (data: number) => void; } const SeedlotRegistrationProgress = ({ @@ -22,57 +19,57 @@ const SeedlotRegistrationProgress = ({ }: SeedlotRegistrationProgressProps) => { const widowSize = useWindowSize(); return ( - - - - - - - - + ); }; diff --git a/frontend/src/components/SeedlotRegistrationProgress/styles.scss b/frontend/src/components/SeedlotRegistrationProgress/styles.scss index f4ac89305..6cdc7d54c 100644 --- a/frontend/src/components/SeedlotRegistrationProgress/styles.scss +++ b/frontend/src/components/SeedlotRegistrationProgress/styles.scss @@ -4,4 +4,8 @@ .#{vars.$bcgov-prefix}--progress-step { min-inline-size: unset; } + + .#{vars.$bcgov-prefix}--progress-step-button--unclickable .#{vars.$bcgov-prefix}--progress-label { + font-weight: 700; + } }