@b2bfinance/products-embed
Version:
products-embed React component
85 lines (68 loc) • 2.02 kB
JavaScript
;
exports.__esModule = true;
var _core = require("@material-ui/core");
var _colors = require("@material-ui/core/colors");
var _colorManipulator = require("@material-ui/core/styles/colorManipulator");
var _styles = require("@material-ui/styles");
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var colors = {
blue: _colors.blue,
blueGrey: _colors.blueGrey,
red: _colors.red,
orange: _colors.orange,
yellow: _colors.yellow,
teal: _colors.teal
};
var useStyles = (0, _styles.makeStyles)(function (theme) {
return {
productLabelWrapper: {
borderRadius: theme.spacing(4),
padding: theme.spacing(0.5, 1.5),
border: "1px solid",
borderColor: function borderColor(props) {
return props.colorGroup[500];
},
marginRight: theme.spacing(1),
"&:last-child": {
marginRight: 0
}
},
productLabelText: {
fontWeight: theme.typography.fontWeightBold,
color: function color(props) {
return props.colorGroup[500];
}
}
};
});
var getLabel = function getLabel(label) {
if (label.startsWith("#")) {
var firstSpaceIndex = label.indexOf(" ");
return [label.slice(1, firstSpaceIndex), label.slice(firstSpaceIndex + 1)];
}
return ["blueGrey", label];
};
var ProductLabel = function ProductLabel(_ref) {
var label = _ref.label;
var _getLabel = getLabel(label),
color = _getLabel[0],
text = _getLabel[1];
var classes = useStyles({ colorGroup: colors[color] || colors.blueGrey });
return _react2.default.createElement(
"div",
{ className: classes.productLabelWrapper },
_react2.default.createElement(
_core.Typography,
{
className: classes.productLabelText,
color: "inherit",
variant: "caption"
},
text
)
);
};
exports.default = ProductLabel;
module.exports = exports["default"];