UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

102 lines (101 loc) 2.35 kB
import cx from 'classnames'; import * as React from 'react'; import { Tooltip } from '../Tooltip/Tooltip.js'; import { Box } from '../../utils/index.js'; export const StepperStep = React.forwardRef((props, forwardedRef) => { let { title, index, currentStepNumber, totalSteps, type, onClick, description, className, style, stepProps, trackContentProps, circleProps, nameProps, stepContent, ...rest } = props; let isPast = currentStepNumber > index; let isActive = currentStepNumber === index; let isClickable = isPast && !!onClick; let onCompletedClick = () => { if (isClickable) onClick?.(index); }; let onKeyDown = (e) => { if (e.altKey) return; if (!isClickable) return; if ('Enter' === e.key || 'Space' === e.key || ' ' === e.key) onCompletedClick(); }; let stepShape = React.createElement( Box, { as: 'li', ...stepProps, className: cx( 'iui-stepper-step', { 'iui-current': isActive, 'iui-clickable': isClickable, }, className, stepProps?.className, ), style: { inlineSize: 'default' === type ? `${100 / totalSteps}%` : void 0, ...style, ...stepProps?.style, }, onClick: onCompletedClick, onKeyDown: onKeyDown, 'aria-current': isActive ? 'step' : void 0, tabIndex: isClickable ? 0 : void 0, ref: forwardedRef, ...rest, }, React.createElement( Box, { as: 'div', ...trackContentProps, className: cx( 'iui-stepper-track-content', trackContentProps?.className, ), }, React.createElement( Box, { as: 'span', ...circleProps, className: cx('iui-stepper-circle', circleProps?.className), }, stepContent ? stepContent() : index + 1, ), ), 'default' === type && React.createElement( Box, { as: 'span', ...nameProps, className: cx('iui-stepper-step-name', nameProps?.className), }, title, ), ); return description ? React.createElement( Tooltip, { content: description, }, stepShape, ) : stepShape; });