materialuiupgraded
Version:
Material-UI's workspace package
175 lines (167 loc) • 5.66 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import ListItemText from '@material-ui/core/ListItemText';
import Avatar from '@material-ui/core/Avatar';
import IconButton from '@material-ui/core/IconButton';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Checkbox from '@material-ui/core/Checkbox';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import FolderIcon from '@material-ui/icons/Folder';
import DeleteIcon from '@material-ui/icons/Delete';
const styles = theme => ({
root: {
flexGrow: 1,
maxWidth: 752,
},
demo: {
backgroundColor: theme.palette.background.paper,
},
title: {
margin: `${theme.spacing.unit * 4}px 0 ${theme.spacing.unit * 2}px`,
},
});
function generate(element) {
return [0, 1, 2].map(value =>
React.cloneElement(element, {
key: value,
}),
);
}
class InteractiveList extends React.Component {
state = {
dense: false,
secondary: false,
};
render() {
const { classes } = this.props;
const { dense, secondary } = this.state;
return (
<div className={classes.root}>
<FormGroup row>
<FormControlLabel
control={
<Checkbox
checked={dense}
onChange={event => this.setState({ dense: event.target.checked })}
value="dense"
/>
}
label="Enable dense"
/>
<FormControlLabel
control={
<Checkbox
checked={secondary}
onChange={event => this.setState({ secondary: event.target.checked })}
value="secondary"
/>
}
label="Enable secondary text"
/>
</FormGroup>
<Grid container spacing={16}>
<Grid item xs={12} md={6}>
<Typography variant="h6" className={classes.title}>
Text only
</Typography>
<div className={classes.demo}>
<List dense={dense}>
{generate(
<ListItem>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
/>
</ListItem>,
)}
</List>
</div>
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="h6" className={classes.title}>
Icon with text
</Typography>
<div className={classes.demo}>
<List dense={dense}>
{generate(
<ListItem>
<ListItemIcon>
<FolderIcon />
</ListItemIcon>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
/>
</ListItem>,
)}
</List>
</div>
</Grid>
</Grid>
<Grid container spacing={16}>
<Grid item xs={12} md={6}>
<Typography variant="h6" className={classes.title}>
Avatar with text
</Typography>
<div className={classes.demo}>
<List dense={dense}>
{generate(
<ListItem>
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
</ListItemAvatar>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
/>
</ListItem>,
)}
</List>
</div>
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="h6" className={classes.title}>
Avatar with text and icon
</Typography>
<div className={classes.demo}>
<List dense={dense}>
{generate(
<ListItem>
<ListItemAvatar>
<Avatar>
<FolderIcon />
</Avatar>
</ListItemAvatar>
<ListItemText
primary="Single-line item"
secondary={secondary ? 'Secondary text' : null}
/>
<ListItemSecondaryAction>
<IconButton aria-label="Delete">
<DeleteIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItem>,
)}
</List>
</div>
</Grid>
</Grid>
</div>
);
}
}
InteractiveList.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(InteractiveList);