Skip to content

Commit ed12622

Browse files
author
Christopher Shepherd
committed
feat: add Chip component
Signed-off-by: Christopher Shepherd <[email protected]>
1 parent f77e015 commit ed12622

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import MuiChip from "@material-ui/core/Chip";
4+
import makeStyles from "@material-ui/core/styles/makeStyles";
5+
6+
const useStyles = makeStyles((theme) => ({
7+
containedPrimary: {
8+
color: theme.palette.primary.contrastText,
9+
backgroundColor: theme.palette.colors.red
10+
},
11+
outlinedPrimary: {
12+
color: theme.palette.colors.red,
13+
border: `1px solid ${theme.palette.colors.red}`
14+
}
15+
}));
16+
17+
/**
18+
* @name Chip
19+
* @param {Object} props Component props
20+
* @returns {React.Component} returns a React component
21+
*/
22+
const Chip = React.forwardRef(function Chip(props, ref) {
23+
const {
24+
color,
25+
...otherProps
26+
} = props;
27+
28+
const classes = useStyles();
29+
30+
if (color === "error") {
31+
return (
32+
<MuiChip
33+
classes={{
34+
containedPrimary: classes.containedPrimary,
35+
outlinedPrimary: classes.outlinedPrimary
36+
}}
37+
color="primary"
38+
ref={ref}
39+
{...otherProps}
40+
/>
41+
);
42+
}
43+
44+
return (
45+
<MuiChip
46+
color={color}
47+
ref={ref}
48+
{...otherProps}
49+
/>
50+
);
51+
});
52+
53+
Chip.propTypes = {
54+
/**
55+
* CSS Classes
56+
*/
57+
classes: PropTypes.object,
58+
/**
59+
* The color of the component
60+
*/
61+
color: PropTypes.oneOf(["default", "primary", "secondary", "error"]),
62+
/**
63+
* The variant to use
64+
*/
65+
variant: PropTypes.oneOf(["default", "outlined"])
66+
};
67+
68+
Chip.defaultProps = {
69+
color: "primary",
70+
variant: "outlined"
71+
};
72+
73+
export default Chip;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./Chip";

0 commit comments

Comments
 (0)