import React, { ReactNode, CSSProperties, useContext, HTMLAttributes } from 'react' import classNames from 'classnames' import { usePrefix } from '../ConfigProvider' import { concat } from '../utils' import { CheckIcon, CloseIcon } from '../icons' import { stepsContext, StepStatus } from '.' import { WithRef } from '../utils/type' export type StepProps = { /** * 步骤项标题 */ title?: ReactNode /** * 步骤项描述 */ description?: ReactNode /** * 步骤项图标 */ icon?: ReactNode /** * 步骤项序号,从 0 开始计数 */ number?: number className?: string style?: CSSProperties /** * 根元素的 html 属性 */ rootHtmlProps?: WithRef, HTMLDivElement> } function IconRenderer(props: {status: StepStatus, number: number }) { const { status, number } = props if (status === 'finish') { return } if (status === 'error') { return } return <>{number} } function calcStepStatus(status: StepStatus, current: number, number: number): StepStatus { if (number === current) { return status } if (number < current) { return 'finish' } return 'wait' } export default function Item(props: StepProps) { const { className, style, title, description, icon, number = 0, rootHtmlProps } = props const prefix = usePrefix('steps-item') const { status, current, onChange } = useContext(stepsContext) const stepStatus = calcStepStatus(status, current, number) const stepIcon = icon || const handleClick = (e: React.MouseEvent) => { rootHtmlProps?.onClick?.(e) if (e.defaultPrevented) return if (onChange) onChange(number) } return (
{stepIcon}
{title}
{description}
) }