import { Steps as AntdSteps, StepsProps, ConfigProvider } from 'antd'; import React, { createContext, ReactNode, useContext, useEffect, useState, } from 'react'; import './index.less'; import classNames from 'classnames'; import { AOP } from '../utils/AOP'; import StepItem from './components/StepItem'; import style from './index.less'; interface StepsExtraProps { type?: 'default' | 'navigation' | 'arrow'; } const StepInfo = createContext & StepsExtraProps>({}); const StepIndex = createContext(0); const Steps = (props: Omit & StepsExtraProps) => { // 为了与 antd 的生态保持兼容性,我们要求必须要使用 `.@{ant-prefix}` 变量来生成类名 const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const prefixCls = getPrefixCls('btri-steps'); const { type = 'default' } = props; const [_current, setCurrent] = useState(props.current); const _onChange = new AOP(props.onChange) .before(cur => { setCurrent(cur); }) .getFunction(); const StepsNode = { default: ( {props.children} ), navigation: ( {props.children} ), arrow: (
{(props.children as any)?.map ? ( (props.children as any).map((item, index) => { return ( {item} ); }) ) : ( {props.children} )}
), }; return ( {StepsNode[type]} ); }; type StepProps = { description?: React.ReactNode; disabled?: boolean; icons?: React.ReactNode; status?: string; subTitle?: React.ReactNode; title?: React.ReactNode; className?: string; }; const Step = (props: StepProps) => { const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const prefixCls = getPrefixCls('btri-step'); const { type = 'default', ...res } = useContext(StepInfo); const stepIndex = useContext(StepIndex); const StepNodes = { default: ( ), navigation: ( ), arrow: ( ), }; return StepNodes[type] || <>; }; Steps.Step = Step; export { Steps };