@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
41 lines (40 loc) • 1.69 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const Chip_1 = tslib_1.__importDefault(require("@mui/material/Chip"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const styles_1 = require("@mui/material/styles");
const PREFIX = 'SCTagChip';
const classes = {
ellipsis: `${PREFIX}-ellipsis`
};
const Root = (0, styles_1.styled)(Chip_1.default, {
name: PREFIX,
slot: 'Root',
overridesResolver: (props, styles) => [styles.root]
})(({ theme }) => ({
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
height: 25,
[`&.${classes.ellipsis}`]: {
maxWidth: 120
}
}));
function TagChip(props) {
// PROPS
const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null } = props, rest = tslib_1.__rest(props, ["tag", "clickable", "disposable", "label", "ellipsis", "onClick", "onDelete", "className"]);
// HANDLERS
const handleClick = () => {
onClick && onClick(tag.id);
};
const handleDelete = () => {
onDelete && onDelete(tag.id);
};
/**
* Renders root object
*/
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(className, { [classes.ellipsis]: ellipsis }), sx: { backgroundColor: `${tag.color}`, color: (theme) => theme.palette.getContrastText(tag.color) } }, (clickable && { onClick: handleClick }), (disposable && { onDelete: handleDelete }), { label: label ? label : tag.name }, rest)));
}
exports.default = TagChip;
;