UNPKG

@wordpress/block-library

Version:
101 lines (100 loc) • 4.08 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_compose = require("@wordpress/compose"); let ___lock_unlock_ts = require("../lock-unlock.cjs"); let __constants_js = require("./constants.cjs"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/spacer/controls.jsx const { useSpacingSizes } = (0, ___lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis); function DimensionInput({ label, onChange, isResizing, value = "" }) { const inputId = (0, _wordpress_compose.useInstanceId)(_wordpress_components.__experimentalUnitControl, "block-spacer-height-input"); const spacingSizes = useSpacingSizes(); const [spacingUnits] = (0, _wordpress_block_editor.useSettings)("spacing.units"); const availableUnits = spacingUnits ? spacingUnits.filter((unit) => unit !== "%") : [ "px", "em", "rem", "vw", "vh" ]; const units = (0, _wordpress_components.__experimentalUseCustomUnits)({ availableUnits, defaultValues: { px: 100, em: 10, rem: 10, vw: 10, vh: 25 } }); const [parsedQuantity, parsedUnit] = (0, _wordpress_components.__experimentalParseQuantityAndUnitFromRawValue)(value); const computedValue = (0, _wordpress_block_editor.isValueSpacingPreset)(value) ? value : [parsedQuantity, isResizing ? "px" : parsedUnit].join(""); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: spacingSizes?.length < 2 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalUnitControl, { id: inputId, isResetValueOnUnitChange: true, min: __constants_js.MIN_SPACER_SIZE, onChange, value: computedValue, units, label }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "tools-panel-item-spacing", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.__experimentalSpacingSizesControl, { values: { all: computedValue }, onChange: ({ all }) => { onChange(all); }, label, sides: ["all"], units, allowReset: false, splitOnAxis: false, showSideInLabel: false }) }) }); } function SpacerControls({ setAttributes, orientation, height, width, isResizing }) { const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToolsPanel, { label: (0, _wordpress_i18n.__)("Settings"), resetAll: () => { setAttributes({ width: void 0, height: "100px" }); }, dropdownMenuProps, children: [orientation === "horizontal" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Width"), isShownByDefault: true, hasValue: () => width !== void 0, onDeselect: () => setAttributes({ width: void 0 }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DimensionInput, { label: (0, _wordpress_i18n.__)("Width"), value: width, onChange: (nextWidth) => setAttributes({ width: nextWidth }), isResizing }) }), orientation !== "horizontal" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Height"), isShownByDefault: true, hasValue: () => height !== "100px", onDeselect: () => setAttributes({ height: "100px" }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DimensionInput, { label: (0, _wordpress_i18n.__)("Height"), value: height, onChange: (nextHeight) => setAttributes({ height: nextHeight }), isResizing }) })] }) }); } exports.default = SpacerControls; //# sourceMappingURL=controls.cjs.map