import React from 'react'; import { isFunction } from 'lodash'; 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 interface FillStepProps { description?: React.ReactNode; icon?: React.ReactNode; status?: Status; title?: React.ReactNode; className?: string; style?: React.CSSProperties; prefixCls?: string; stepNumber?: string; onChange?: () => void; onClick?: React.MouseEventHandler; onKeyDown?: React.KeyboardEventHandler; "role"?: React.AriaRole; "aria-label"?: React.AriaAttributes["aria-label"] } const FillStep = (props: FillStepProps) => { const { prefixCls, className, title, description, status, style, onClick, icon, onChange, stepNumber, onKeyDown } = props; const renderIcon = () => { let inner, progress; if ('icon' in props) { 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}-left`]: true, [`${prefixCls}-icon`]: 'icon' in props, [`${prefixCls}-plain`]: !('icon' in props), [`${prefixCls}-icon-process`]: progress, [`${prefixCls}-hover`]: onChange || onClick, }); return inner ?
{inner}
: null; }; const handleClick = (e: React.MouseEvent) => { onClick?.(e); onChange?.(); }; const handleKeyDown = (e) => { if (e.key === 'Enter') { onKeyDown?.(e); onChange?.(); } }; return (
{ handleClick(e); }} onKeyDown={handleKeyDown} > {renderIcon()}
{title}
{description}
); }; FillStep.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, }; FillStep.defaultProps = { prefixCls: css.ITEM, status: 'wait', className: '', }; export default FillStep;