Skip to content

Commit

Permalink
[Stepper] Mobile version (#7043)
Browse files Browse the repository at this point in the history
* [Stepper] Mobile version - fixes #7033

* Change classes.mobileStepper for classes.root

* Use theme.spacing.unit rather than hard coded padding and dot width/height

* Optimise use of classNames for dotClassName

* Fixed classes.root tests

* Added props backButtonText and nextButtonText

* Added position prop making MobileStepper not fixed by default.

* Fixed linting issues

* [MobileStepper] Second iteration
  • Loading branch information
alexhayes authored and oliviertassinari committed Jun 5, 2017
1 parent d200ce2 commit de4c31b
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/src/pages/component-api/MobileStepper/MobileStepper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# MobileStepper



## Props
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| activeStep | number | 0 | Set the active step (zero based index). This will enable `Step` control helpers. |
| backButtonText | node | 'Back' | Set the text that appears for the back button. |
| classes | object | | Useful to extend the style applied to components. |
| disableBack | bool | false | Set to true to disable the back button. |
| disableNext | bool | false | Set to true to disable the next button. |
| nextButtonText | node | 'Next' | Set the text that appears for the next button. |
| <span style="color: #31a148">onBack *</span> | function | | Passed into the onTouchTap prop of the Back button. |
| <span style="color: #31a148">onNext *</span> | function | | Passed into the onTouchTap prop of the Next button. |
| position | enum:&nbsp;'bottom'<br>&nbsp;'top'<br>&nbsp;'static'<br> | 'bottom' | Set the text that appears for the next button. |
| <span style="color: #31a148">steps *</span> | number | | The total steps. |
| type | enum:&nbsp;'text'<br>&nbsp;'dots'<br>&nbsp;'progress'<br> | 'dots' | The type of mobile stepper to use. |

Any other properties supplied will be spread to the root element.
## Classes

You can overrides all the class names injected by Material-UI thanks to the `classes` property.
This property accepts the following keys:
- `root`
- `position-bottom`
- `positon-top`
- `position-static`
- `button`
- `dots`
- `dot`
- `dotActive`
- `progress`

Have a look at [overriding with class names](/customization/overrides#overriding-with-class-names)
section for more detail.

If using the `overrides` key of the theme as documented
[here](/customization/themes#customizing-all-instances-of-a-component-type),
you need to use the following style sheet name: `MuiMobileStepper`.
54 changes: 54 additions & 0 deletions docs/src/pages/component-demos/stepper/DotsMobileStepper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @flow

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyleSheet } from 'material-ui/styles';
import MobileStepper from 'material-ui/MobileStepper';

const styleSheet = createStyleSheet('DotsMobileStepper', {
root: {
maxWidth: 400,
flexGrow: 1,
},
});

class DotsMobileStepper extends Component {
state = {
activeStep: 0,
};

handleNext = () => {
this.setState({
activeStep: this.state.activeStep + 1,
});
};

handleBack = () => {
this.setState({
activeStep: this.state.activeStep - 1,
});
};

render() {
const classes = this.props.classes;
return (
<MobileStepper
type="dots"
steps={6}
position="static"
activeStep={this.state.activeStep}
className={classes.root}
onBack={this.handleBack}
onNext={this.handleNext}
disableBack={this.state.activeStep === 0}
disableNext={this.state.activeStep === 5}
/>
);
}
}

DotsMobileStepper.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styleSheet)(DotsMobileStepper);
54 changes: 54 additions & 0 deletions docs/src/pages/component-demos/stepper/ProgressMobileStepper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @flow

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyleSheet } from 'material-ui/styles';
import MobileStepper from 'material-ui/MobileStepper';

const styleSheet = createStyleSheet('ProgressMobileStepper', {
root: {
maxWidth: 400,
flexGrow: 1,
},
});

class ProgressMobileStepper extends Component {
state = {
activeStep: 0,
};

handleNext = () => {
this.setState({
activeStep: this.state.activeStep + 1,
});
};

handleBack = () => {
this.setState({
activeStep: this.state.activeStep - 1,
});
};

render() {
const classes = this.props.classes;
return (
<MobileStepper
type="progress"
steps={6}
position="static"
activeStep={this.state.activeStep}
className={classes.root}
onBack={this.handleBack}
onNext={this.handleNext}
disableBack={this.state.activeStep === 0}
disableNext={this.state.activeStep === 5}
/>
);
}
}

ProgressMobileStepper.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styleSheet)(ProgressMobileStepper);
71 changes: 71 additions & 0 deletions docs/src/pages/component-demos/stepper/TextMobileStepper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// @flow

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyleSheet } from 'material-ui/styles';
import MobileStepper from 'material-ui/MobileStepper';
import Paper from 'material-ui/Paper';
import Typography from 'material-ui/Typography';

const styleSheet = createStyleSheet('TextMobileStepper', theme => ({
root: {
maxWidth: 400,
flexGrow: 1,
},
header: {
display: 'flex',
alignItems: 'center',
height: 50,
paddingLeft: theme.spacing.unit * 5,
marginBottom: 20,
background: theme.palette.background.default,
},
}));

class TextMobileStepper extends Component {
state = {
activeStep: 0,
};

handleNext = () => {
this.setState({
activeStep: this.state.activeStep + 1,
});
};

handleBack = () => {
this.setState({
activeStep: this.state.activeStep - 1,
});
};

render() {
const classes = this.props.classes;
return (
<div className={classes.root}>
<Paper square elevation={0} className={classes.header}>
<Typography>
Step {this.state.activeStep + 1} of 6
</Typography>
</Paper>
<MobileStepper
type="text"
steps={6}
position="static"
activeStep={this.state.activeStep}
className={classes.mobileStepper}
onBack={this.handleBack}
onNext={this.handleNext}
disableBack={this.state.activeStep === 0}
disableNext={this.state.activeStep === 5}
/>
</div>
);
}
}

TextMobileStepper.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styleSheet)(TextMobileStepper);
31 changes: 31 additions & 0 deletions docs/src/pages/component-demos/stepper/stepper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
components: MobileStepper
---

# Stepper

[Steppers](https://material.io/guidelines/components/steppers.html) convey progress through numbered steps.

## Mobile Stepper

The [mobile steps](https://material.io/guidelines/components/steppers.html#steppers-types-of-steps) implements a compact stepper suitable for a mobile device.

### Mobile Stepper - Text

This is essentially a back/next button positioned correctly.
You must implement the textual description yourself however an example is provided below for reference.

{{demo='pages/component-demos/stepper/TextMobileStepper.js'}}

### Mobile Stepper - Dots

Use dots when the number of steps isn’t large.

{{demo='pages/component-demos/stepper/DotsMobileStepper.js'}}

### Mobile Stepper - Progress

Use a progress bar when there are many steps, or if there are steps that need to be inserted during the process (based on responses to earlier steps).

{{demo='pages/component-demos/stepper/ProgressMobileStepper.js'}}

1 change: 1 addition & 0 deletions docs/src/pages/getting-started/supported-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ to discuss the approach before submitting a PR.
- [Steppers](https://www.google.com/design/spec/components/steppers.html)
- [Horizontal](https://www.google.com/design/spec/components/steppers.html#steppers-types-of-steppers)
- [Vertical](https://www.google.com/design/spec/components/steppers.html#steppers-types-of-steppers)
- **[Mobile steps](https://material.io/guidelines/components/steppers.html#steppers-types-of-steps)**
- **[Tabs](https://www.google.com/design/spec/components/tabs.html)**
- Usage
- **[Mobile (Full width)](https://www.google.com/design/spec/components/tabs.html#tabs-usage)**
Expand Down
Loading

0 comments on commit de4c31b

Please sign in to comment.