import React, { FunctionComponent, useContext ,useState} from 'react' import { View, Text } from 'react-native'; import { DataContext } from '../steps/UserContext' import Icon from '../icon/index' import { IComponent, ComponentDefaults } from '../utils/typings' import pt from '../utils/pt' import { useConfig } from '../configprovider'; import stepStyles from './styles'; export interface StepProps extends IComponent { title: string content: string activeIndex: number icon: string iconColor: string size: string className: string, isStart:boolean, isEnd:boolean, style: React.CSSProperties renderContent: () => React.ReactNode } const defaultProps = { ...ComponentDefaults, title: '', content: '', activeIndex: 0, icon: '', iconColor: '', size: '12px', isStart:false, isEnd:false, } as StepProps export const Step: FunctionComponent< Partial & React.HTMLAttributes > = (props) => { const { children, title, content, activeIndex, icon, iconColor, size, className, renderContent, iconClassPrefix, iconFontClassName, isStart, isEnd, ...restProps } = { ...defaultProps, ...props, } const { theme } = useConfig(); const mStyles = stepStyles(theme); const parent: any = useContext(DataContext) const [itemWidth, setItemWidth] = useState(0) const dot = parent.propSteps.progressDot const getCurrentStatus = () => { const index = activeIndex if (index < +parent.propSteps.current) return 'finish' return index === +parent.propSteps.current ? 'process' : 'wait' } const handleClickStep = () => { parent.propSteps?.onClickStep && parent.propSteps?.onClickStep(activeIndex) parent.propSteps?.clickStep && parent.propSteps?.clickStep(activeIndex) } const renderIconClass = () => { if (!dot && icon) { return 'nut-step-icon is-icon' } if (!dot && !icon) { return 'nut-step-icon is-text' } return 'nut-step-icon' } const getDotStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': style = { backgroundColor:'#fff', borderWidth:0.5, borderColor:'#ff2f2c' } break; case 'process': style = { backgroundColor:'#ff2f2c' } break; case 'wait': style = { backgroundColor:'#959fb1' } break; default: style = {} break; } return style; } const getDotTxStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': style = { color:'#ff2f2c', } break; case 'process': style = { color:'#fff' } break; case 'wait': style = { color:'rgba(0,0,0,0)' } break; default: style = {} break; } return style; } const getLeftLineStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': if(isStart){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#ff2f2c' } } break; case 'process': if(isStart){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#ff2f2c' } } break; case 'wait': if(isStart){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#959fb1' } } break; default: style = {} break; } return style; } const getRightLineStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': if(isEnd){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#ff2f2c' } } break; case 'process': if(isEnd){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#959fb1' } } break; case 'wait': if(isEnd){ style = { backgroundColor:'rgba(0,0,0,0)' } }else{ style = { backgroundColor:'#959fb1' } } break; default: style = {} break; } return style; } const getTitleTxStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': case 'process': style = { color:'#ff2f2c' } break; case 'wait': style = { color:'#959fb1' } break; default: style = {} break; } return style; } const getContentTxStyle = ()=>{ let style; switch(getCurrentStatus()){ case 'finish': case 'process': style = { color:'#000' } break; case 'wait': style = { color:'#959fb1' } break; default: style = {} break; } return style; } const getDotView=()=>{ let dotView; switch(getCurrentStatus()){ case 'finish': dotView = break; case 'process': dotView = break; case 'wait': dotView = break; default: dotView = null; break; } return dotView; } if(parent.propSteps.direction === 'horizontal'){ return ( { const contentWidth = e.nativeEvent.layout.width; if(itemWidth===0){ setItemWidth(contentWidth); } }} {...restProps} onClick={handleClickStep}> {icon ? ( ) : ( !dot ? {activeIndex} : getDotView() )} {title} {content ? {content} : null} {renderContent && renderContent()} ) }else { return ( {icon ? ( ) : ( !dot ? {activeIndex} : getDotView() )} {title} {content ? {content} : null} {renderContent && renderContent()} ) } } Step.defaultProps = defaultProps Step.displayName = 'NutStep'