UNPKG

@wordpress/block-editor

Version:
82 lines (77 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = BoxInputControls; var _components = require("@wordpress/components"); var _i18n = require("@wordpress/i18n"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ const CORNERS = { topLeft: (0, _i18n.__)('Top left'), topRight: (0, _i18n.__)('Top right'), bottomLeft: (0, _i18n.__)('Bottom left'), bottomRight: (0, _i18n.__)('Bottom right') }; function BoxInputControls({ onChange, selectedUnits, setSelectedUnits, values: valuesProp, ...props }) { const createHandleOnChange = corner => next => { if (!onChange) { return; } // Filter out CSS-unit-only values to prevent invalid styles. const isNumeric = !isNaN(parseFloat(next)); const nextValue = isNumeric ? next : undefined; onChange({ ...values, [corner]: nextValue }); }; const createHandleOnUnitChange = side => next => { const newUnits = { ...selectedUnits }; newUnits[side] = next; setSelectedUnits(newUnits); }; // For shorthand style & backwards compatibility, handle flat string value. const values = typeof valuesProp !== 'string' ? valuesProp : { topLeft: valuesProp, topRight: valuesProp, bottomLeft: valuesProp, bottomRight: valuesProp }; // Controls are wrapped in tooltips as visible labels aren't desired here. // Tooltip rendering also requires the UnitControl to be wrapped. See: // https://github.com/WordPress/gutenberg/pull/24966#issuecomment-685875026 return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "components-border-radius-control__input-controls-wrapper", children: Object.entries(CORNERS).map(([corner, label]) => { const [parsedQuantity, parsedUnit] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values[corner]); const computedUnit = values[corner] ? parsedUnit : selectedUnits[corner] || selectedUnits.flat; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Tooltip, { text: label, placement: "top", children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "components-border-radius-control__tooltip-wrapper", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalUnitControl, { ...props, "aria-label": label, value: [parsedQuantity, computedUnit].join(''), onChange: createHandleOnChange(corner), onUnitChange: createHandleOnUnitChange(corner), size: "__unstable-large" }) }) }, corner); }) }); } //# sourceMappingURL=input-controls.js.map