-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christopher Shepherd <[email protected]>
- Loading branch information
Christopher Shepherd
committed
Jul 29, 2019
1 parent
f77e015
commit ed12622
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import MuiChip from "@material-ui/core/Chip"; | ||
import makeStyles from "@material-ui/core/styles/makeStyles"; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
containedPrimary: { | ||
color: theme.palette.primary.contrastText, | ||
backgroundColor: theme.palette.colors.red | ||
}, | ||
outlinedPrimary: { | ||
color: theme.palette.colors.red, | ||
border: `1px solid ${theme.palette.colors.red}` | ||
} | ||
})); | ||
|
||
/** | ||
* @name Chip | ||
* @param {Object} props Component props | ||
* @returns {React.Component} returns a React component | ||
*/ | ||
const Chip = React.forwardRef(function Chip(props, ref) { | ||
const { | ||
color, | ||
...otherProps | ||
} = props; | ||
|
||
const classes = useStyles(); | ||
|
||
if (color === "error") { | ||
return ( | ||
<MuiChip | ||
classes={{ | ||
containedPrimary: classes.containedPrimary, | ||
outlinedPrimary: classes.outlinedPrimary | ||
}} | ||
color="primary" | ||
ref={ref} | ||
{...otherProps} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<MuiChip | ||
color={color} | ||
ref={ref} | ||
{...otherProps} | ||
/> | ||
); | ||
}); | ||
|
||
Chip.propTypes = { | ||
/** | ||
* CSS Classes | ||
*/ | ||
classes: PropTypes.object, | ||
/** | ||
* The color of the component | ||
*/ | ||
color: PropTypes.oneOf(["default", "primary", "secondary", "error"]), | ||
/** | ||
* The variant to use | ||
*/ | ||
variant: PropTypes.oneOf(["default", "outlined"]) | ||
}; | ||
|
||
Chip.defaultProps = { | ||
color: "primary", | ||
variant: "outlined" | ||
}; | ||
|
||
export default Chip; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./Chip"; |