UNPKG

mui-tiptap

Version:

A Material-UI (MUI) styled WYSIWYG rich text editor, using Tiptap

83 lines (82 loc) 4.28 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ColorSwatchButton = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const Check_1 = __importDefault(require("@mui/icons-material/Check")); const styles_1 = require("@mui/material/styles"); const clsx_1 = require("clsx"); const react_1 = require("react"); const styles_2 = require("../styles"); const ColorSwatchButton_classes_1 = require("./ColorSwatchButton.classes"); const componentName = (0, styles_2.getUtilityComponentName)("ColorSwatchButton"); const ColorSwatchButtonRoot = (0, styles_1.styled)("button", { name: componentName, slot: "root", overridesResolver: (props, styles) => [styles.root, props.ownerState.colorNotSet && styles.colorNotSet], })(({ theme, ownerState }) => (Object.assign({ height: theme.spacing(2.5), width: theme.spacing(2.5), minWidth: theme.spacing(2.5), borderRadius: theme.shape.borderRadius, borderColor: theme.palette.mode === "dark" ? theme.palette.grey[700] : theme.palette.grey[400], borderStyle: "solid", borderWidth: 1, cursor: "pointer", // Use background-clip with content-box so that if a `padding` is specified by the // user, it adds a gap between the color and the border. padding: 0, backgroundClip: "content-box" }, (ownerState.colorNotSet && { // To indicate that a color hasn't been chosen, we'll use a checkerboard pattern // (https://stackoverflow.com/a/65129916/4543977) background: `repeating-conic-gradient( ${theme.palette.grey[400]} 0% 25%, ${theme.palette.common.white} 0% 50%) 50% / 12px 12px`, backgroundClip: "content-box", })))); const ColorSwatchButtonActiveIcon = (0, styles_1.styled)(Check_1.default, { name: componentName, slot: "activeIcon", overridesResolver: (props, styles) => styles.activeIcon, })(() => ({ height: "100%", width: "80%", verticalAlign: "middle", })); /** * Renders a button in the given color `value`, useful for showing and allowing * selecting a color preset. */ exports.ColorSwatchButton = (0, react_1.forwardRef)((inProps, ref) => { const props = (0, styles_1.useThemeProps)({ props: inProps, name: componentName }); const { value: colorValue, label, padding, active, className, classes = {}, sx } = props, buttonProps = __rest(props, ["value", "label", "padding", "active", "className", "classes", "sx"]); const theme = (0, styles_1.useTheme)(); const colorNotSet = !colorValue; const ownerState = { active, colorNotSet, }; return ((0, jsx_runtime_1.jsx)(ColorSwatchButtonRoot, Object.assign({ ref: ref, type: "button", style: { backgroundColor: colorValue, padding }, "aria-label": label !== null && label !== void 0 ? label : colorValue, value: colorValue }, buttonProps, { className: (0, clsx_1.clsx)([ ColorSwatchButton_classes_1.colorSwatchButtonClasses.root, colorNotSet && [ ColorSwatchButton_classes_1.colorSwatchButtonClasses.colorNotSet, classes.colorNotSet, ], classes.root, className, ]), sx: sx, ownerState: ownerState, children: active && ((0, jsx_runtime_1.jsx)(ColorSwatchButtonActiveIcon, { fontSize: "small", className: (0, clsx_1.clsx)([ ColorSwatchButton_classes_1.colorSwatchButtonClasses.activeIcon, classes.activeIcon, ]), style: { color: colorValue ? theme.palette.getContrastText(colorValue) : undefined, } })) }))); }); exports.ColorSwatchButton.displayName = "ColorSwatchButton";