@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
38 lines (37 loc) • 1.46 kB
JavaScript
import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import Chip from '@mui/material/Chip';
import classNames from 'classnames';
import { styled } from '@mui/material/styles';
const PREFIX = 'SCTagChip';
const classes = {
ellipsis: `${PREFIX}-ellipsis`
};
const Root = styled(Chip, {
name: PREFIX,
slot: 'Root',
overridesResolver: (props, styles) => [styles.root]
})(({ theme }) => ({
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
height: 25,
[`&.${classes.ellipsis}`]: {
maxWidth: 120
}
}));
export default function TagChip(props) {
// PROPS
const { tag, clickable = true, disposable = true, label = null, ellipsis = false, onClick = null, onDelete = null, className = null } = props, rest = __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 (_jsx(Root, Object.assign({ className: classNames(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)));
}