-
-
Save Om4ar/047b83d775a6a25bd55d34e79c28d8a4 to your computer and use it in GitHub Desktop.
example of function component with full settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| import Chip from "material-ui/Chip"; | |
| import { withStyles } from "material-ui/styles"; | |
| const styles = theme => ({ | |
| root: { | |
| display: "flex", | |
| flexWrap: "wrap" | |
| }, | |
| chip: { | |
| margin: ".2em" | |
| } | |
| }); | |
| const TagsFormatter = props => { | |
| const { classes } = props; | |
| const renderTags = props.value.map(t => ( | |
| <Chip key={t} label={t} className={classes.chip} /> | |
| )); | |
| return ( | |
| <div className={classes.root}> | |
| {renderTags.length > 0 && renderTags} | |
| {renderTags.length === 0 && <span>-----</span>} | |
| </div> | |
| ); | |
| }; | |
| TagsFormatter.propTypes = { | |
| value: PropTypes.array.isRequired, | |
| classes: PropTypes.object.isRequired | |
| }; | |
| export default withStyles(styles)(TagsFormatter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment