Skip to content

Commit

Permalink
feat: add Chip component
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Shepherd <[email protected]>
  • Loading branch information
Christopher Shepherd committed Jul 29, 2019
1 parent f77e015 commit ed12622
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions package/src/components/Chip/Chip.js
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;
1 change: 1 addition & 0 deletions package/src/components/Chip/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Chip";

0 comments on commit ed12622

Please sign in to comment.