@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 9.23 kB
Source Map (JSON)
{"version":3,"file":"StepperStep.cjs","names":["factory","useProps","useStepperContext","useMantineTheme","UnstyledButton","getThemeColor","Transition","Loader","CheckIcon","classes"],"sources":["../../../../src/components/Stepper/StepperStep/StepperStep.tsx"],"sourcesContent":["import {\n BoxProps,\n CompoundStylesApiProps,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n useMantineTheme,\n useProps,\n} from '../../../core';\nimport { CheckIcon } from '../../Checkbox';\nimport { Loader } from '../../Loader';\nimport { Transition } from '../../Transition';\nimport { UnstyledButton } from '../../UnstyledButton';\nimport type { StepFragmentComponent } from '../Stepper';\nimport { useStepperContext } from '../Stepper.context';\nimport classes from '../Stepper.module.css';\n\nconst getStepFragment = (\n Fragment: StepFragmentComponent | React.ReactNode,\n step: number | undefined\n) => {\n if (typeof Fragment === 'function') {\n return <Fragment step={step || 0} />;\n }\n\n return Fragment;\n};\n\nexport type StepperStepStylesNames =\n | 'step'\n | 'stepLoader'\n | 'verticalSeparator'\n | 'stepWrapper'\n | 'stepIcon'\n | 'stepCompletedIcon'\n | 'stepIconContent'\n | 'stepBody'\n | 'stepLabel'\n | 'stepDescription';\n\nexport interface StepperStepProps\n extends BoxProps, CompoundStylesApiProps<StepperStepFactory>, ElementProps<'button'> {\n /** 0-based step index, automatically set by Stepper component */\n step?: number;\n\n /** Step state, automatically set by Stepper component based on active prop. stepInactive: not reached, stepProgress: current, stepCompleted: passed */\n state?: 'stepInactive' | 'stepProgress' | 'stepCompleted';\n\n /** Key of `theme.colors`, by default controlled by Stepper component */\n color?: MantineColor;\n\n /** When false, hides the step icon. Useful for creating compact steppers with only labels @default true */\n withIcon?: boolean;\n\n /** Step icon, defaults to `step index + 1` when rendered within Stepper */\n icon?: React.ReactNode | StepFragmentComponent;\n\n /** Step icon displayed when step is completed */\n completedIcon?: React.ReactNode | StepFragmentComponent;\n\n /** Step icon displayed when step is in progress */\n progressIcon?: React.ReactNode | StepFragmentComponent;\n\n /** Step label, render after icon */\n label?: React.ReactNode | StepFragmentComponent;\n\n /** Step description */\n description?: React.ReactNode | StepFragmentComponent;\n\n /** Icon wrapper size */\n iconSize?: string | number;\n\n /** Icon position relative to step body, controlled by Stepper component */\n iconPosition?: 'right' | 'left';\n\n /** Indicates loading state of the step */\n loading?: boolean;\n\n /** Set to false to disable clicks on step */\n allowStepClick?: boolean;\n\n /** Should step selection be allowed */\n allowStepSelect?: boolean;\n\n /** Static selector base */\n __staticSelector?: string;\n\n /** Component orientation */\n orientation?: 'vertical' | 'horizontal';\n}\n\nexport type StepperStepFactory = Factory<{\n props: StepperStepProps;\n ref: HTMLButtonElement;\n stylesNames: StepperStepStylesNames;\n compound: true;\n}>;\n\nconst defaultProps = {\n withIcon: true,\n allowStepClick: true,\n iconPosition: 'left',\n} satisfies Partial<StepperStepProps>;\n\nexport const StepperStep = factory<StepperStepFactory>((props) => {\n const {\n classNames,\n className,\n style,\n styles,\n vars,\n step,\n state,\n color,\n icon,\n completedIcon,\n progressIcon,\n label,\n description,\n withIcon,\n iconSize,\n loading,\n allowStepClick,\n allowStepSelect,\n iconPosition,\n orientation,\n mod,\n ...others\n } = useProps('StepperStep', defaultProps, props);\n\n const ctx = useStepperContext();\n const theme = useMantineTheme();\n const stylesApi = { classNames, styles };\n\n const _icon = state === 'stepCompleted' ? null : state === 'stepProgress' ? progressIcon : icon;\n const dataAttributes = {\n 'data-progress': state === 'stepProgress' || undefined,\n 'data-completed': state === 'stepCompleted' || undefined,\n };\n\n return (\n <UnstyledButton\n {...ctx.getStyles('step', { className, style, variant: ctx.orientation, ...stylesApi })}\n mod={[\n { 'icon-position': iconPosition || ctx.iconPosition, 'allow-click': allowStepClick },\n mod,\n ]}\n {...dataAttributes}\n {...others}\n __vars={{ '--step-color': color ? getThemeColor(color, theme) : undefined }}\n tabIndex={allowStepClick ? 0 : -1}\n >\n {withIcon && (\n <span {...ctx.getStyles('stepWrapper', stylesApi)}>\n <span {...ctx.getStyles('stepIcon', stylesApi)} {...dataAttributes}>\n <Transition mounted={state === 'stepCompleted'} transition=\"pop\" duration={200}>\n {(transitionStyles) => (\n <span\n {...ctx.getStyles('stepCompletedIcon', { style: transitionStyles, ...stylesApi })}\n >\n {loading ? (\n <Loader\n color=\"var(--mantine-color-white)\"\n size=\"calc(var(--stepper-icon-size) / 2)\"\n {...ctx.getStyles('stepLoader', stylesApi)}\n />\n ) : (\n getStepFragment(completedIcon, step) || <CheckIcon size=\"60%\" />\n )}\n </span>\n )}\n </Transition>\n\n {state !== 'stepCompleted' ? (\n <span {...ctx.getStyles('stepIconContent', stylesApi)}>\n {loading ? (\n <Loader\n {...ctx.getStyles('stepLoader', stylesApi)}\n size=\"calc(var(--stepper-icon-size) / 2)\"\n color={color}\n />\n ) : (\n getStepFragment(_icon || icon, step)\n )}\n </span>\n ) : null}\n </span>\n {orientation === 'vertical' && (\n <span\n {...ctx.getStyles('verticalSeparator', stylesApi)}\n data-active={state === 'stepCompleted' || undefined}\n />\n )}\n </span>\n )}\n\n {(label || description) && (\n <span\n {...ctx.getStyles('stepBody', stylesApi)}\n data-orientation={ctx.orientation}\n data-icon-position={iconPosition || ctx.iconPosition}\n >\n {label && (\n <span {...ctx.getStyles('stepLabel', stylesApi)}>{getStepFragment(label, step)}</span>\n )}\n {description && (\n <span {...ctx.getStyles('stepDescription', stylesApi)}>\n {getStepFragment(description, step)}\n </span>\n )}\n </span>\n )}\n </UnstyledButton>\n );\n});\n\nStepperStep.classes = classes;\nStepperStep.displayName = '@mantine/core/StepperStep';\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAM,mBACJ,UACA,SACG;AACH,KAAI,OAAO,aAAa,WACtB,QAAO,iBAAA,GAAA,kBAAA,KAAC,UAAD,EAAU,MAAM,QAAQ,GAAK,CAAA;AAGtC,QAAO;;AAyET,MAAM,eAAe;CACnB,UAAU;CACV,gBAAgB;CAChB,cAAc;CACf;AAED,MAAa,cAAcA,gB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