import * as Nerv from 'nervjs' import classnames from 'classnames' import {styleStr2Obj} from '../util/util' type StatusType = 'wait' | 'process' | 'finish' | 'error' export interface StepProps { className?: string, type?: string, title?: string, description?: string, icon?: string, status?: StatusType, current?: number, index?: number } class Step extends Nerv.Component { constructor (props) { super(props) } renderStepClassNames (props: StepProps) { let statusClass: string = '' const current = props.current || 0 const index = props.index || 0 if (current === index) { statusClass = props.status ? `at-step--${props.status}` : 'at-step--process' } else if (current > index) { statusClass = 'at-step--finish' } else if (current < index) { statusClass = 'at-step--wait' } return classnames('at-step', [ statusClass ], props.className) } render () { const props = this.props const { style, onDragLeave, onDragOver, onDrop, onMouseOver, onMouseEnter, onMouseOut, onMouseLeave, onClick, children } = props const needProps = { children, onDragLeave, onDragOver, onDrop, onMouseOver, onMouseOut, onMouseEnter, onMouseLeave, onClick } const classNames = this.renderStepClassNames(props) const current = props.current || 0 const index = props.index || 0 let icon: any = null // console.log(props.index) if (current <= index) { let classname = '' if (props.icon) { classname = `icon ${props.icon}` icon = (
) } else { icon = (
{~index ? index + 1 : 0}
) if (props.status && (current === index)) { if (props.status === 'error') { icon = (
) } else if (props.status === 'finish') { icon = (
) } else if (props.status === 'wait' || props.status === 'process') { icon = (
{~index ? index + 1 : 0}
) } } } } else if (current > index) { if (!props.icon) { icon = (
) } else { const classname = `icon ${props.icon}` icon = (
) } } let line: any = null if (!props.last) { line =
} const widthStyle = {width: `${(1 / (props.length) || 3) * 100}%`} let styleComputed: any = {} if (typeof style === 'string' || style instanceof String) { styleComputed = Object.assign(styleStr2Obj(style), widthStyle) } else { styleComputed = { ...style, ...widthStyle} } // console.log('here', style, styleComputed) return (
{line}
{icon}
{props.title}
{props.description}
) } componentDidMount () { } componentWillReceiveProps (nextProps) { } } export default Step