Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Steppers] Add example for breadcrumbs using Steppers #13333

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions docs/src/pages/demos/steppers/Breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Button from '@material-ui/core/Button';
import ButtonBase from '@material-ui/core/ButtonBase';
import Icon from '@material-ui/core/Icon';
import ChevronRight from '@material-ui/icons/ChevronRight';
import Home from '@material-ui/icons/Home';
import Dashboard from '@material-ui/icons/Dashboard';
import Message from '@material-ui/icons/Message';
import Stepper from '@material-ui/core/Stepper';
import Typography from '@material-ui/core/Typography';

const styles = theme => ({
root: {
flexGrow: 1,
},
button: {
margin: theme.spacing.unit,
'&:hover': {
backgroundColor: 'inherit',
},
},
icon: {
color: 'black',
marginRight: theme.spacing.unit,
},
step: {
alignItems: 'center',
display: 'flex',
},
reset: {
marginTop: theme.spacing.unit * 2,
},
});

const initialSteps = [
{ icon: Home, label: 'Home', displayed: true },
{ icon: Dashboard, label: 'Dashboard', displayed: true },
{ icon: Message, label: 'Messages', displayed: true },
];

class Breadcrumbs extends React.Component {
state = {
steps: initialSteps,
};

handleClick = e => {
const { textContent } = e.target;
this.setState(state => {
const { steps } = state;
const selectedStepIndex = steps.map(step => step.label).indexOf(textContent);
const updatedSteps = steps.map((step, index) => {
if (index > selectedStepIndex && index !== 0) {
return { ...step, ...{ displayed: false } };
}
return step;
});

return { steps: updatedSteps };
});
};

handleResetState = () => {
this.setState({ steps: initialSteps });
};

render() {
const { classes } = this.props;
const { steps } = this.state;
const lastStep = steps.filter(step => step.displayed === true).length - 1;
return (
<div className={classes.root}>
<AppBar color="default" position="static">
<Stepper connector={<ChevronRight />}>
{steps.filter(step => step.displayed === true).map((step, index) => {
const { icon, label } = step;
const isDisabled = index === lastStep;
const buttonProps = {
className: classes.button,
disabled: isDisabled,
disableRipple: true,
disableFocusRipple: true,
onMouseDown: this.handleClick,
size: 'small',
};
const typographyProps = {
disabled: isDisabled,
color: isDisabled ? 'default' : 'primary',
variant: 'h6',
};
return (
<div className={classes.step} key={label}>
<ButtonBase {...buttonProps}>
<Icon className={classes.icon} component={icon} />
<Typography {...typographyProps}>{label}</Typography>
</ButtonBase>
</div>
);
})}
</Stepper>
</AppBar>
<Button
className={classes.reset}
onClick={this.handleResetState}
color="primary"
variant="contained"
>
Reset
</Button>
</div>
);
}
}

Breadcrumbs.propTypes = {
classes: PropTypes.object,
};

export default withStyles(styles)(Breadcrumbs);
6 changes: 6 additions & 0 deletions docs/src/pages/demos/steppers/steppers.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ This component uses a customized `StepConnector` element that changes border col

{{"demo": "pages/demos/steppers/CustomizedStepper.js"}}

## Breadcrumbs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a description here along the lines of: "The stepper components can be repurposed to create navigation breadcrumbs."

Trivia - breadcrumbs were one of the first web-server plugin components I ever created (back in 1998), but I didn't know they were called that then, so it was called "clickable path".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

I did some digging to try to find the origin and also found another alias: "Cookie crumbs" (https://en.wikipedia.org/wiki/Breadcrumb_(navigation)).

Copy link
Member

@mbrookes mbrookes Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also did some digging, and would you believe, it's still out there!

http://source.riverweb.com/modules/modinfo.html?id=37

This was for Roxen, a web server that was so far ahead of its time. You could add plugins ("modules"), and their configuration page would show up in the web server's web GUI. It supported "RXML" which allowed you to embed tags in your html pages, that would then be converted by the respective module to HTML, images, etc. when the page was requested.

Sadly Apache won out at the time, and Roxen went on to become a niche CMS.

The `Stepper` can be repurposed to implement navigation breadcrumbs.

{{"demo": "pages/demos/steppers/Breadcrumbs.js"}}

## Mobile Stepper

This component implements a compact stepper suitable for a mobile device. See [mobile steps](https://material.io/archive/guidelines/components/steppers.html#steppers-types-of-steps) for its inspiration.
Expand Down
7 changes: 7 additions & 0 deletions pages/demos/steppers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/steppers/VerticalLinearStepper'), 'utf8')
`,
},
'pages/demos/steppers/Breadcrumbs.js': {
js: require('docs/src/pages/demos/steppers/Breadcrumbs').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/steppers/Breadcrumbs'), 'utf8')
`,
},
'pages/demos/steppers/HorizontalNonLinearStepperWithError.js': {
Expand Down