import React from 'react'; import { isFunction } from 'lodash-es'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { stepsClasses as css } from '@douyinfe/semi-foundation/steps/constants'; import { IconTickCircle, IconAlertCircle, IconAlertTriangle } from '@douyinfe/semi-icons'; export type Status = 'wait' | 'process' | 'finish' | 'error' | 'warning'; export type Size = 'default' | 'small'; export interface BasicStepProps { description?: React.ReactNode; icon?: React.ReactNode; status?: Status; title?: React.ReactNode; className?: string; style?: React.CSSProperties; active?: boolean; prefixCls?: string; stepNumber?: string; size?: Size; done?: boolean; onChange?: () => void; onClick?: React.MouseEventHandler; } export enum stepSizeMapIconSize { small = 'large', default = 'extra-large' } const BasicStep = (props: BasicStepProps) => { const { prefixCls, className, size, title, description, status, style, active, done, icon, stepNumber, onClick, onChange, ...restProps } = props; const renderIcon = () => { let inner, progress; if ('icon' in props) { if (React.isValidElement(icon)) { inner = icon; } } else if ('status' in props) { switch (status) { case 'error': inner = ; break; case 'wait': inner = {stepNumber}; break; case 'process': inner = {stepNumber}; progress = true; break; case 'finish': inner = ; break; case 'warning': inner = ; break; default: inner = null; break; } } const cls = classnames({ [`${prefixCls}-icon`]: true, [`${prefixCls}-custom-icon`]: 'icon' in props, [`${prefixCls}-icon-process`]: progress, }); return inner ? {inner} : null; }; const classString = classnames(prefixCls, className, `${prefixCls}-${status}`, { [`${prefixCls}-active`]: active, [`${prefixCls}-done`]: done }); const handleClick = (e: React.MouseEvent) => { if (isFunction(onClick)) { onClick(e); } onChange(); }; return (
handleClick(e)}>
{renderIcon()}
{title}
{description &&
{description}
}
); }; BasicStep.propTypes = { prefixCls: PropTypes.string, description: PropTypes.node, icon: PropTypes.node, status: PropTypes.oneOf(['wait', 'process', 'finish', 'error', 'warning']), title: PropTypes.node, className: PropTypes.string, style: PropTypes.object, onClick: PropTypes.func, active: PropTypes.bool, done: PropTypes.bool, }; BasicStep.defaultProps = { prefixCls: css.ITEM, active: false, done: false, status: 'wait', className: '', }; export default BasicStep;