UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

40 lines (39 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const material_1 = require("@mui/material"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const PREFIX = 'SCTagChip'; const classes = { ellipsis: `${PREFIX}-ellipsis` }; const Root = (0, material_1.styled)(material_1.Chip, { 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;