Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | 1x 2x 2x 2x 2x 1x | // @flow import React, { Component } from 'react'; import { Stepper as MuiStepper } from 'material-ui/Stepper'; import RaisedButton from 'material-ui/RaisedButton'; import FlatButton from 'material-ui/FlatButton'; import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; type Props = { /** Set the active step (zero based index). This will enable Step control helpers */ activeStep?: number, /** The style for the back button */ backButtonStyle?: Object, /** Should be two or more <Step /> components */ children?: Node, /** CSS class name of the root element */ className?: string, finishedButtonStyle?: Object, /** The text to display on the final button when all steps have been completed */ finishedText?: string, /** Dash event handler for click events */ fireEvent?: () => void, /** Dash ID */ id: string, /** If set to true, the Stepper will assist in controlling steps for linear flow */ linear?: boolean, /** The style for the next button */ nextButtonStyle?: Object, /** The stepper orientation (layout flow direction) */ orientation?: 'horizontal' | 'vertical', /** Dash callback to update props on the server */ setProps?: (props: {stepIndex?: number}) => void, /** Override the inline-style of the root element */ style?: Object, }; type State = { finished: boolean, stepIndex: number, }; const defaultProps = { activeStep: 0, backButtonStyle: {marginRight: 12}, children: [], className: '', finishedButtonStyle: {}, finishedText: 'Click here to view again', fireEvent: () => {}, linear: true, nextButtonStyle: {}, orientation: 'horizontal', setProps: () => {}, style: {}, }; export default class Stepper extends Component<Props, State> { constructor(props: Props) { super(props); this.state = { stepIndex: props.activeStep, finished: false, }; } handleNext = () => { const {stepIndex} = this.state; const increased = stepIndex + 1; this.setState({ stepIndex: increased, finished: increased >= this.props.children.length, }); if (this.props.setProps) this.props.setProps({activeStep: increased}); if (this.props.fireEvent) this.props.fireEvent({event: 'click'}); }; handlePrev = () => { const {stepIndex} = this.state; const decreased = stepIndex - 1; if (stepIndex > 0) { this.setState({stepIndex: decreased}); if (this.props.setProps) this.props.setProps({activeStep: decreased}); if (this.props.fireEvent) this.props.fireEvent({event: 'click'}); } }; resetSteps = () => { this.setState({stepIndex: 0, finished: false}); if (this.props.setProps) this.props.setProps({activeStep: 0}); if (this.props.fireEvent) this.props.fireEvent({event: 'click'}); }; render() { const { id, backButtonStyle, className, finishedButtonStyle, finishedText, linear, nextButtonStyle, orientation, style } = this.props; return ( <div id={id} className={className} style={style}> <MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}> <div> <MuiStepper activeStep={this.state.stepIndex} linear={linear} orientation={orientation} > {this.props.children} </MuiStepper> {this.state.finished ? ( <RaisedButton label={finishedText} onClick={this.resetSteps} style={finishedButtonStyle} /> ) : ( <div> <div style={{marginTop: 14}}> <FlatButton label="Back" disabled={this.state.stepIndex === 0} onClick={this.handlePrev} style={backButtonStyle} /> <RaisedButton label={this.state.stepIndex >= this.props.children.length - 1 ? 'Finish' : 'Next'} primary={true} onClick={this.handleNext} style={nextButtonStyle} /> </div> </div> )} </div> </MuiThemeProvider> </div> ); } } Stepper.defaultProps = defaultProps; |