UNPKG

mui-tiptap

Version:

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

79 lines (78 loc) 4.45 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.default = FieldContainer; const jsx_runtime_1 = require("react/jsx-runtime"); const Box_1 = __importDefault(require("@mui/material/Box")); const styles_1 = require("@mui/material/styles"); const clsx_1 = require("clsx"); const FieldContainer_classes_1 = require("./FieldContainer.classes"); const styles_2 = require("./styles"); const componentName = (0, styles_2.getUtilityComponentName)("FieldContainer"); const FieldContainerRoot = (0, styles_1.styled)(Box_1.default, { name: componentName, slot: "root", overridesResolver: (props, styles) => [ styles.root, props.ownerState.variant === "outlined" && styles.outlined, props.ownerState.variant === "standard" && styles.standard, props.ownerState.focused && styles.focused, props.ownerState.disabled && styles.disabled, ], })(({ theme, ownerState }) => (Object.assign({}, (ownerState.variant === "outlined" && Object.assign({ borderRadius: theme.shape.borderRadius, padding: 1, position: "relative" }, (!ownerState.focused && !ownerState.disabled && { [`&:hover .${FieldContainer_classes_1.fieldContainerClasses.notchedOutline}`]: { borderColor: theme.palette.text.primary, }, })))))); const FieldContainerNotchedOutline = (0, styles_1.styled)("div", { name: componentName, slot: "notchedOutline", overridesResolver: (props, styles) => styles.notchedOutline, })(({ theme, ownerState }) => (Object.assign(Object.assign({ position: "absolute", inset: 0, borderRadius: "inherit", borderColor: theme.palette.mode === "light" ? "rgba(0, 0, 0, 0.23)" : "rgba(255, 255, 255, 0.23)", borderStyle: "solid", borderWidth: 1, pointerEvents: "none", overflow: "hidden", zIndex: styles_2.Z_INDEXES.NOTCHED_OUTLINE }, (ownerState.focused && { borderColor: theme.palette.primary.main, borderWidth: 2, })), (ownerState.disabled && { borderColor: theme.palette.action.disabled, })))); /** * Renders an element with classes and styles that correspond to the state and * style-variant of a user-input field, the content of which should be passed in as * `children`. */ function FieldContainer(inProps) { const props = (0, styles_1.useThemeProps)({ props: inProps, name: componentName }); const { variant = "outlined", children, focused, disabled, classes = {}, className, sx } = props, boxProps = __rest(props, ["variant", "children", "focused", "disabled", "classes", "className", "sx"]); const ownerState = { variant, focused, disabled }; return ((0, jsx_runtime_1.jsxs)(FieldContainerRoot, Object.assign({}, boxProps, { className: (0, clsx_1.clsx)([ FieldContainer_classes_1.fieldContainerClasses.root, className, classes.root, variant === "outlined" ? [FieldContainer_classes_1.fieldContainerClasses.outlined, classes.outlined] : [FieldContainer_classes_1.fieldContainerClasses.standard, classes.standard], // Note that we want focused and disabled styles of equal specificity to // trump default root/outlined/standard styles, so they should be defined // in this order focused && [FieldContainer_classes_1.fieldContainerClasses.focused, classes.focused], disabled && [FieldContainer_classes_1.fieldContainerClasses.disabled, classes.disabled], ]), sx: sx, ownerState: ownerState, children: [children, variant === "outlined" && ((0, jsx_runtime_1.jsx)(FieldContainerNotchedOutline, { ownerState: ownerState, className: (0, clsx_1.clsx)([ FieldContainer_classes_1.fieldContainerClasses.notchedOutline, classes.notchedOutline, ]), "aria-hidden": true }))] }))); }