Skip to content

Commit

Permalink
Added position prop making MobileStepper not fixed by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhayes committed Jun 4, 2017
1 parent c9b9011 commit 65c70e3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| nextButtonText | string | Next | Set the text that will appear within the next button. |
| onBack | function | | Supplied to the onClick attribute of the back button. |
| onNext | function | | Supplied to the onClick attribute of the next button. |
| position | `bottom` or `top` | | Set to fix to either the bottom or the top of the viewport. |
| steps | number | | The total amount of steps. |
| buttonClassName | string | | Specify an extra class to be put on back/next buttons |
| className | string | | Specify an extra class to be put on the root element |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const styleSheet = createStyleSheet('DotsMobileStepper', {
marginTop: 30,
width: '100%',
},
mobileStepper: {
position: 'relative',
},
});

class DotsMobileStepper extends Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const styleSheet = createStyleSheet('ProgressMobileStepper', {
marginTop: 30,
width: '100%',
},
mobileStepper: {
position: 'relative',
},
});

class ProgressMobileStepper extends Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const styleSheet = createStyleSheet('TextMobileStepper', {
marginTop: 30,
width: '100%',
},
mobileStepper: {
position: 'relative',
},
textualDescription: {
display: 'flex',
flexDirection: 'row',
Expand Down
26 changes: 23 additions & 3 deletions src/MobileStepper/MobileStepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ export const styleSheet = createStyleSheet('MuiMobileStepper', theme => ({
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
backgroundColor: theme.palette.background.paper,
padding: theme.spacing.unit,
},
fixedBottom: {
position: 'fixed',
bottom: 0,
left: 0,
zIndex: theme.zIndex.mobileStepper,
backgroundColor: theme.palette.background.paper,
padding: theme.spacing.unit,
},
fixedTop: {
position: 'fixed',
top: 0,
left: 0,
zIndex: theme.zIndex.mobileStepper,
},
button: {},
dots: {
Expand Down Expand Up @@ -56,6 +64,7 @@ function MobileStepper(props) {
disableNext,
dotClassName: dotClassNameProp,
dotsClassName: dotsClassNameProp,
position,
kind,
nextButtonText,
onBack,
Expand All @@ -65,7 +74,14 @@ function MobileStepper(props) {
...other
} = props;

const className = classNames(classes.root, classNameProp);
const className = classNames(
{
[classes.fixedBottom]: position === 'bottom',
[classes.fixedTop]: position === 'top',
},
classes.root,
classNameProp,
);
const dotsClassName = classNames(classes.dots, dotsClassNameProp);
const buttonClassName = classNames(classes.button, buttonClassNameProp);
const progressClassName = classNames(classes.progress, progressClassNameProp);
Expand Down Expand Up @@ -155,6 +171,10 @@ MobileStepper.propTypes = {
* Passed into the onTouchTap prop of the Next button.
*/
onNext: PropTypes.func.isRequired,
/**
* Set the text that appears for the next button.
*/
position: PropTypes.oneOf(['bottom', 'top']),
/**
* @ignore
*/
Expand Down
22 changes: 15 additions & 7 deletions src/MobileStepper/MobileStepper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,27 @@ describe('<MobileStepper />', () => {
});
it('should render with the root class', () => {
const wrapper = shallow(<MobileStepper {...defaultProps} />);
assert.strictEqual(
wrapper.hasClass(classes.root),
true,
'should have the root class',
);
assert.strictEqual(wrapper.hasClass(classes.root), true, 'should have the root class');
});
it('should render the custom className and the root class', () => {
const wrapper = shallow(<MobileStepper className="test-class-name" {...defaultProps} />);
assert.strictEqual(wrapper.is('.test-class-name'), true, 'should pass the test className');
assert.strictEqual(wrapper.hasClass(classes.root), true, 'should have the mobileStepper class');
});
it('should render with the fixedBottom class if position prop is set to bottom', () => {
const wrapper = shallow(<MobileStepper position="bottom" {...defaultProps} />);
assert.strictEqual(
wrapper.hasClass(classes.fixedBottom),
true,
'should have the fixedBottom class',
);
});
it('should render with the fixedTop class if position prop is set to top', () => {
const wrapper = shallow(<MobileStepper position="top" {...defaultProps} />);
assert.strictEqual(
wrapper.hasClass(classes.root),
wrapper.hasClass(classes.fixedTop),
true,
'should have the mobileStepper class',
'should have the fixedTop class',
);
});
it('should render two buttons', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/styles/zIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Needed as the zIndex works with absolute values.
export default {
mobileStepper: 900,
menu: 1000,
appBar: 1100,
drawerOverlay: 1200,
Expand All @@ -12,5 +13,4 @@ export default {
popover: 2100,
snackbar: 2900,
tooltip: 3000,
mobileStepper: 1100,
};

0 comments on commit 65c70e3

Please sign in to comment.