Skip to content

Commit

Permalink
[Stepper] Refactor Stepper to address mui#3725
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarks committed Apr 8, 2016
1 parent 887297d commit 3348130
Show file tree
Hide file tree
Showing 22 changed files with 1,152 additions and 1,102 deletions.
Original file line number Diff line number Diff line change
@@ -1,138 +1,82 @@
import React from 'react';
import Stepper from 'material-ui/Stepper';
import Step from 'material-ui/Stepper/HorizontalStep';
import Paper from 'material-ui/Paper';
import FontIcon from 'material-ui/FontIcon';
import {
Step,
Stepper,
StepButton,
StepLabel,
} from 'material-ui/Stepper';
// import FontIcon from 'material-ui/FontIcon';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';

const HorizontalStepper = React.createClass({
getInitialState() {
return {
activeStep: -1,
lastActiveStep: 0,
};
},
class HorizontalLinearStepper extends React.Component {

handleStepHeaderTouch(currentStep) {
const {
lastActiveStep,
activeStep,
state = {
stepIndex: 1,
};

} = this.state;

if (currentStep > lastActiveStep) {
return;
handleNext = () => {
const {stepIndex} = this.state;
if (stepIndex < 2) {
this.setState({stepIndex: stepIndex + 1});
}
};

this.setState({
activeStep: currentStep,
lastActiveStep: Math.max(lastActiveStep, activeStep),
});
},

updateCompletedSteps(currentStep) {
return currentStep < this.state.lastActiveStep;
},

createIcon(step) {
if (step.props.isCompleted) {
return (
<FontIcon className="material-icons" style={{fontSize: 14}}>
done
</FontIcon>
);
handlePrev = () => {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};

return <span>{step.props.orderStepLabel}</span>;
},

handleTouchTap() {
const {
activeStep,
lastActiveStep,
} = this.state;

this.setState({
activeStep: activeStep + 1,
lastActiveStep: Math.max(lastActiveStep, activeStep + 1),
});
},
getStepContent(stepIndex) {
switch (stepIndex) {
case 0:
return 'Select campaign settings...';
case 1:
return 'What is an ad group anyways?';
case 2:
return 'This is the bit I really care about!';
default:
return 'You\'re a long way from home sonny jim!';
}
}

render() {
const {stepIndex} = this.state;
const contentStyle = {margin: '0 16px'};

return (
<Paper style={{width: 500, margin: 'auto'}}>
<div style={{
textAlign: 'center',
padding: 10,
fontSize: 20,
}}
>
Material-UI User Group Registration
</div>
<Stepper
horizontal={true}
activeStep={this.state.activeStep}
onStepHeaderTouch={this.handleStepHeaderTouch}
updateCompletedStatus={this.updateCompletedSteps}
createIcon={this.createIcon}
>
<Step
orderStepLabel="1"
stepLabel="User account"
actions={[
<RaisedButton
key={0}
label="Continue"
primary={true}
onTouchTap={this.handleTouchTap}
/>,
<FlatButton key={1} label="Cancel" />,
]}
>
<div style={{padding: 20}}>
Please create an account, or login with your account details.
</div>
<div>
<Stepper activeStep={stepIndex}>
<Step>
<StepButton>Select campaign settings</StepButton>
</Step>
<Step
orderStepLabel="2"
stepLabel="Event registration"
actions={[
<RaisedButton
key={0}
label="Continue"
primary={true}
onTouchTap={this.handleTouchTap}
/>,
<FlatButton key={1} label="Cancel" />,
]}
>
<div style={{padding: 20}}>
Please sign up for the event you wish to attend.
</div>
<Step>
<StepLabel>Create an ad group</StepLabel>
</Step>

<Step
orderStepLabel="3"
stepLabel="Payment"
actions={[
<RaisedButton
key={0}
label="Finish"
primary={true}
onTouchTap={this.handleTouchTap}
/>,
<FlatButton key={1} label="Cancel" />,
]}
>
<div style={{padding: 20}}>
Please provide your credit card details.
</div>
<Step>
<StepButton>Create an ad</StepButton>
</Step>
</Stepper>
</Paper>
<div style={contentStyle}>
{this.getStepContent(stepIndex)}
<div style={{marginTop: 12}}>
<FlatButton
label="Back"
onTouchTap={this.handlePrev}
style={{marginRight: 12}}
/>
<RaisedButton
label="Next"
primary={true}
onTouchTap={this.handleNext}
/>
</div>
</div>
</div>
);
},
});
}
}

export default HorizontalStepper;
export default HorizontalLinearStepper;
61 changes: 18 additions & 43 deletions docs/src/app/components/pages/components/Stepper/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@ import PropTypeDescription from '../../../PropTypeDescription';
import MarkdownElement from '../../../MarkdownElement';

import stepperReadmeText from './README';
import VerticalLinearStepper from './VerticalLinearStepper';
import VerticalNonLinearStepper from './VerticalNonLinearStepper';
import VerticalLinearStepperWithOptionalStep from './VerticalLinearStepperWithOptionalStep';
import VerticalLinearStepperCode from '!raw!./VerticalLinearStepper';
import VerticalLinearStepperWithOptionalStepCode from '!raw!./VerticalLinearStepperWithOptionalStep';
import VerticalNonLinearStepperCode from '!raw!./VerticalNonLinearStepper';
import HorizontalLinearStepper from './HorizontalLinearStepper';
import HorizontalLinearStepperCode from '!raw!./HorizontalLinearStepper';
import VerticalLinearStepper from './VerticalLinearStepper';
import VerticalLinearStepperCode from '!raw!./VerticalLinearStepper';

import stepCode from '!raw!material-ui/lib/Stepper/Step';
import stepperCode from '!raw!material-ui/lib/Stepper/Stepper';
import verticalStepCode from '!raw!material-ui/lib/Stepper/VerticalStep';
import horizontalStepCode from '!raw!material-ui/lib/Stepper/HorizontalStep';


const descriptions = {
verticalLinearStepper: 'The vertical linear stepper requires steps be completed in a specific order.',
verticalLinearStepperWithOptionalStep: 'Set the `optional` property to `true` for optional steps.' +
'Pass a custom label view through `stepLabel` property to indicate an optional step.',
verticalNonLinearStepper: 'For the vertical non-linear stepper, steps can be completed in any order.',
horizontalLinearStepper: 'The horizontal linear stepper acts the same as the vertical linear stepper. ' +
'The horizontal stepper does not support optional or non-linear steps at this time.',
horizontalLinearStepper:
'Horizontal steppers are ideal when the contents of one step depend ' +
' on an earlier step. Avoid using long step names in horizontal steppers.' +
'\n\n' +
'Linear steppers require users to complete one step in order to move on to the next.',
verticalLinearStepper: '',
};


Expand All @@ -38,49 +33,29 @@ const styles = {
const StepperPage = () => (
<div>
<MarkdownElement text={stepperReadmeText} />
<CodeExample
title="Vertical linear step example"
description={descriptions.verticalLinearStepper}
code={VerticalLinearStepperCode}
>
<div style={styles.stepperWrapper}>
<VerticalLinearStepper />
</div>
</CodeExample>

<CodeExample
title="Optional step example"
description={descriptions.verticalLinearStepperWithOptionalStep}
code={VerticalLinearStepperWithOptionalStepCode}
>
<div style={styles.stepperWrapper}>
<VerticalLinearStepperWithOptionalStep />
</div>
</CodeExample>

<CodeExample
title="Non linear example"
description={descriptions.verticalNonLinearStepper}
code={VerticalNonLinearStepperCode}
title="Horizontal linear stepper"
description={descriptions.horizontalLinearStepper}
code={HorizontalLinearStepperCode}
>
<div style={styles.stepperWrapper}>
<VerticalNonLinearStepper />
<HorizontalLinearStepper />
</div>
</CodeExample>

<CodeExample
title="Horizontal linear step example"
description={descriptions.horizontalLinearStepper}
code={HorizontalLinearStepperCode}
title="Vertical linear stepper"
description={descriptions.verticalLinearStepper}
code={VerticalLinearStepperCode}
>
<div style={styles.stepperWrapper}>
<HorizontalLinearStepper />
<VerticalLinearStepper />
</div>
</CodeExample>

<PropTypeDescription code={stepCode} header="### Step properties" />
<PropTypeDescription code={stepperCode} header="### Stepper properties" />
<PropTypeDescription code={verticalStepCode} header="### VerticalStep properties" />
<PropTypeDescription code={horizontalStepCode} header="### HorizontalStep properties" />
</div>
);

Expand Down
7 changes: 4 additions & 3 deletions docs/src/app/components/pages/components/Stepper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A [stepper](https://www.google.com/design/spec/components/steppers.html)
is an interface for users to show numbered steps or for navigation. It just provides
views, not handling logic (when the step is active, or when the step is completed, or how to move
to the next step). We delegate that to the parent component. We just pass `activeStepIndex`
to show which step is active.
### Examples
to the next step).

There are two versions of this component.

Loading

0 comments on commit 3348130

Please sign in to comment.