Skip to content

Commit 5d95b11

Browse files
Progress Indicator: Add working example
This maintains state and shows how to manipulate the component for devs
1 parent 0eb641f commit 5d95b11

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

components/progress-indicator/__docs__/storybook-stories.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ storiesOf(PROGRESS_INDICATOR, module)
9494
.add('Completed Progress', () => (
9595
<ExampleProgressIndicator
9696
steps={steps}
97-
selectedStep={steps[steps.length - 1]}
98-
completedSteps={steps.slice(0, steps.length - 1)}
97+
selectedStep={steps[steps.length - 2]}
98+
completedSteps={steps.slice(0, steps.length - 2)}
9999
assistiveText={{
100-
completedStep: "Finished this step.",
101-
disabledStep: "Unable to proceed on this step."
100+
completedStep: 'Finished this step.',
101+
disabledStep: 'Unable to proceed on this step.',
102102
}}
103103
/>
104104
));
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import createReactClass from 'create-react-class';
32
import IconSettings from '~/components/icon-settings';
43
import ProgressIndicator from '~/components/progress-indicator'; // `~` is replaced with design-system-react at runtime
54

@@ -15,33 +14,53 @@ const steps = [
1514
{ id: 4, label: 'tooltip label #5' },
1615
];
1716

18-
const handleStepEvent = function (event, data) {
19-
console.log(data);
20-
};
17+
/*
18+
* This example allows you to select the next step and only the next step. Typically, Progress Indicator should be paired with a modal and form errors should be explained outside of this component.
19+
*/
20+
class Example extends React.Component {
21+
constructor (props) {
22+
super(props);
23+
this.state = {
24+
steps,
25+
completedSteps: [],
26+
disabledSteps: steps.slice(2, steps.length),
27+
selectedStep: steps[0],
28+
};
29+
}
2130

22-
const Example = createReactClass({
23-
displayName: 'ProgressIndicatorDefault',
31+
handleStepEvent = (event, data) => {
32+
this.setState({
33+
completedSteps: steps.slice(0, data.step.id),
34+
disabledSteps: data.step.id < steps.length
35+
? steps.slice(data.step.id + 2, steps.length) : [],
36+
selectedStep: data.step,
37+
});
38+
};
2439

2540
render () {
2641
return (
2742
<IconSettings iconPath="/assets/icons">
2843
<div
2944
style={{
30-
padding: '2rem 1rem 0px',
45+
padding: '4rem 1rem 0px',
3146
background:
32-
this.props.variant === 'modal' ? 'rgb(244, 246, 249)' : '',
47+
this.props.variant === 'modal' ? 'rgb(244, 246, 249)' : undefined,
3348
}}
3449
>
3550
<ProgressIndicator
36-
steps={steps}
37-
selectedStep={steps[0]}
38-
onStepClick={handleStepEvent}
51+
completedSteps={this.state.completedSteps}
52+
disabledSteps={this.state.disabledSteps}
53+
onStepClick={this.handleStepEvent}
54+
steps={this.state.steps}
55+
selectedStep={this.state.selectedStep}
3956
// tooltipIsOpenSteps={stepsBasic.slice(0, 2)}
4057
/>
4158
</div>
4259
</IconSettings>
4360
);
44-
},
45-
});
61+
}
62+
}
63+
64+
Example.displayName = 'ProgressIndicatorDefault';
4665

4766
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime

0 commit comments

Comments
 (0)