* @param {Array} [props.options=CSS_UNITS] Available units to select from.
* @param {Function} [props.onChange=noop] A callback function invoked when the value is changed.
* @param {string} [props.size="default"] Size of the control option. Supports "default" and "small".
* @param {string} [props.value="px"] Current unit.
function UnitSelectControl(_ref) {
var className = _ref.className,
_ref$isTabbable = _ref.isTabbable,
isTabbable = _ref$isTabbable === void 0 ? true : _ref$isTabbable,
_ref$options = _ref.options,
options = _ref$options === void 0 ? CSS_UNITS : _ref$options,
_ref$onChange = _ref.onChange,
onChange = _ref$onChange === void 0 ? external_lodash_["noop"] : _ref$onChange,
size = _ref$size === void 0 ? 'default' : _ref$size,
value = _ref$value === void 0 ? 'px' : _ref$value,
props = Object(objectWithoutProperties["a" /* default */])(_ref, ["className", "isTabbable", "options", "onChange", "size", "value"]);
if (!utils_hasUnits(options)) {
return Object(external_wp_element_["createElement"])(UnitLabel, {
className: "components-unit-control__unit-label",
var handleOnChange = function handleOnChange(event) {
var unitValue = event.target.value;
var data = options.find(function (option) {
return option.value === unitValue;
var classes = classnames_default()('components-unit-control__select', className);
return Object(external_wp_element_["createElement"])(UnitSelect, Object(esm_extends["a" /* default */])({
onChange: handleOnChange,
tabIndex: isTabbable ? null : '-1',
}, props), options.map(function (option) {
return Object(external_wp_element_["createElement"])("option", {
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/utils/hooks/use-controlled-state.js
function use_controlled_state_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function use_controlled_state_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { use_controlled_state_ownKeys(Object(source), true).forEach(function (key) { Object(esm_defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { use_controlled_state_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
* @property {T | undefined} initial Initial value
* @property {T | ""} fallback Fallback value
/** @type {Readonly<{ initial: undefined, fallback: '' }>} */
* Defaults to empty string, as that is preferred for usage with
* <input />, <textarea />, and <select /> form elements.
* Custom hooks for "controlled" components to track and consolidate internal
* state and incoming values. This is useful for components that render
* `input`, `textarea`, or `select` HTML elements.
* https://reactjs.org/docs/forms.html#controlled-components
* At first, a component using useControlledState receives an initial prop
* value, which is used as initial internal state.
* This internal state can be maintained and updated without
* relying on new incoming prop values.
* Unlike the basic useState hook, useControlledState's state can
* be updated if a new incoming prop value is changed.
* @param {T | undefined} currentState The current value.
* @param {Options<T>} [options=defaultOptions] Additional options for the hook.
* @return {[T | "", (nextState: T) => void]} The controlled value and the value setter.
function useControlledState(currentState) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
var _defaultOptions$optio = use_controlled_state_objectSpread(use_controlled_state_objectSpread({}, defaultOptions), options),
initial = _defaultOptions$optio.initial,
fallback = _defaultOptions$optio.fallback;
var _useState = Object(external_wp_element_["useState"])(currentState),
_useState2 = Object(slicedToArray["a" /* default */])(_useState, 2),
internalState = _useState2[0],
setInternalState = _useState2[1];
var hasCurrentState = isValueDefined(currentState);
* Resets internal state if value every changes from uncontrolled <-> controlled.
Object(external_wp_element_["useEffect"])(function () {
if (hasCurrentState && internalState) {
setInternalState(undefined);
}, [hasCurrentState, internalState]);
var state = getDefinedValue([currentState, internalState, initial], fallback);
/* eslint-disable jsdoc/no-undefined-types */
/** @type {(nextState: T) => void} */
var setState = function setState(nextState) {
setInternalState(nextState);
/* eslint-enable jsdoc/no-undefined-types */
return [state, setState];
/* harmony default export */ var use_controlled_state = (useControlledState);
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/unit-control/index.js
function UnitControl(_ref, ref) {
var _ref$__unstableStateR = _ref.__unstableStateReducer,
stateReducer = _ref$__unstableStateR === void 0 ? function (state) {
} : _ref$__unstableStateR,
_ref$autoComplete = _ref.autoComplete,
autoComplete = _ref$autoComplete === void 0 ? 'off' : _ref$autoComplete,
className = _ref.className,
_ref$disabled = _ref.disabled,
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
_ref$disableUnits = _ref.disableUnits,
disableUnits = _ref$disableUnits === void 0 ? false : _ref$disableUnits,
_ref$isPressEnterToCh = _ref.isPressEnterToChange,
isPressEnterToChange = _ref$isPressEnterToCh === void 0 ? false : _ref$isPressEnterToCh,
_ref$isResetValueOnUn = _ref.isResetValueOnUnitChange,
isResetValueOnUnitChange = _ref$isResetValueOnUn === void 0 ? false : _ref$isResetValueOnUn,
_ref$isUnitSelectTabb = _ref.isUnitSelectTabbable,
isUnitSelectTabbable = _ref$isUnitSelectTabb === void 0 ? true : _ref$isUnitSelectTabb,
_ref$onChange = _ref.onChange,
onChange = _ref$onChange === void 0 ? external_lodash_["noop"] : _ref$onChange,
_ref$onUnitChange = _ref.onUnitChange,
onUnitChange = _ref$onUnitChange === void 0 ? external_lodash_["noop"] : _ref$onUnitChange,
size = _ref$size === void 0 ? 'default' : _ref$size,
units = _ref$units === void 0 ? CSS_UNITS : _ref$units,
props = Object(objectWithoutProperties["a" /* default */])(_ref, ["__unstableStateReducer", "autoComplete", "className", "disabled", "disableUnits", "isPressEnterToChange", "isResetValueOnUnitChange", "isUnitSelectTabbable", "label", "onChange", "onUnitChange", "size", "style", "unit", "units", "value"]);
var _getParsedValue = getParsedValue(valueProp, unitProp, units),
_getParsedValue2 = Object(slicedToArray["a" /* default */])(_getParsedValue, 2),
value = _getParsedValue2[0],
initialUnit = _getParsedValue2[1];
var _useControlledState = use_controlled_state(unitProp, {
_useControlledState2 = Object(slicedToArray["a" /* default */])(_useControlledState, 2),
unit = _useControlledState2[0],
setUnit = _useControlledState2[1]; // Stores parsed value for hand-off in state reducer
var refParsedValue = Object(external_wp_element_["useRef"])(null);
var classes = classnames_default()('components-unit-control', className);
var handleOnChange = function handleOnChange(next, changeProps) {
onChange('', changeProps);
* Customizing the onChange callback.
* This allows as to broadcast a combined value+unit to onChange.
next = getValidParsedUnit(next, units, value, unit).join('');
onChange(next, changeProps);
var handleOnUnitChange = function handleOnUnitChange(next, changeProps) {
var data = changeProps.data;
var nextValue = "".concat(value).concat(next);
if (isResetValueOnUnitChange && (data === null || data === void 0 ? void 0 : data.default) !== undefined) {
nextValue = "".concat(data.default).concat(next);
onChange(nextValue, changeProps);
onUnitChange(next, changeProps);
var mayUpdateUnit = function mayUpdateUnit(event) {
if (!isNaN(event.target.value)) {
refParsedValue.current = null;
var _getValidParsedUnit = getValidParsedUnit(event.target.value, units, value, unit),
_getValidParsedUnit2 = Object(slicedToArray["a" /* default */])(_getValidParsedUnit, 2),
parsedValue = _getValidParsedUnit2[0],
parsedUnit = _getValidParsedUnit2[1];
refParsedValue.current = parsedValue;
if (isPressEnterToChange && parsedUnit !== unit) {
var data = units.find(function (option) {
return option.value === parsedUnit;
onChange("".concat(parsedValue).concat(parsedUnit), changeProps);
onUnitChange(parsedUnit, changeProps);
var handleOnBlur = mayUpdateUnit;
var handleOnKeyDown = function handleOnKeyDown(event) {
var keyCode = event.keyCode;
if (keyCode === external_wp_keycodes_["ENTER"]) {
* "Middleware" function that intercepts updates from InputControl.
* This allows us to tap into actions to transform the (next) state for
* @param {Object} state State from InputControl
* @param {Object} action Action triggering state change
* @return {Object} The updated state to apply to InputControl
var unitControlStateReducer = function unitControlStateReducer(state, action) {
* On commits (when pressing ENTER and on blur if
* isPressEnterToChange is true), if a parse has been performed
* then use that result to update the state.
if (action.type === inputControlActionTypes.COMMIT) {
if (refParsedValue.current !== null) {
state.value = refParsedValue.current;
refParsedValue.current = null;
var inputSuffix = !disableUnits ? Object(external_wp_element_["createElement"])(UnitSelectControl, {
"aria-label": Object(external_wp_i18n_["__"])('Select unit'),
isTabbable: isUnitSelectTabbable,
onChange: handleOnUnitChange,
return Object(external_wp_element_["createElement"])(unit_control_styles_Root, {
className: "components-unit-control-wrapper",
}, Object(external_wp_element_["createElement"])(ValueInput, Object(esm_extends["a" /* default */])({
type: isPressEnterToChange ? 'text' : 'number'
}, Object(external_lodash_["omit"])(props, ['children']), {
autoComplete: autoComplete,
disableUnits: disableUnits,
isPressEnterToChange: isPressEnterToChange,
onKeyDown: handleOnKeyDown,
onChange: handleOnChange,
__unstableStateReducer: state_composeStateReducers(unitControlStateReducer, stateReducer)
var ForwardedUnitControl = Object(external_wp_element_["forwardRef"])(UnitControl);
/* harmony default export */ var unit_control = (ForwardedUnitControl);
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/box-control/styles/box-control-styles.js
function box_control_styles_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
var box_control_styles_Root = styled_base_browser_esm("div", {
styles: "box-sizing:border-box;max-width:235px;padding-bottom:12px;width:100%;"
var Header = /*#__PURE__*/styled_base_browser_esm(flex_Flex, {
})("color:", colors_color('ui.label'), ";padding-bottom:8px;" + ( true ? "" : undefined));
var HeaderControlWrapper = /*#__PURE__*/styled_base_browser_esm(flex_Flex, {
label: "HeaderControlWrapper"
styles: "min-height:30px;"
var UnitControlWrapper = styled_base_browser_esm("div", {
label: "UnitControlWrapper"
styles: "box-sizing:border-box;max-width:80px;"
var LayoutContainer = /*#__PURE__*/styled_base_browser_esm(flex_Flex, {
styles: "justify-content:center;padding-top:8px;"
var Layout = /*#__PURE__*/styled_base_browser_esm(flex_Flex, {
styles: "position:relative;height:100%;width:100%;"
var box_control_styles_ref = true ? {
styles: "border-radius:2px;"
var box_control_styles_ref2 = true ? {
styles: "border-radius:0;"
var box_control_styles_unitControlBorderRadiusStyles = function unitControlBorderRadiusStyles(_ref3) {
var isFirst = _ref3.isFirst,
borderBottomRightRadius: 0
borderBottomLeftRadius: 0
return box_control_styles_ref;
return box_control_styles_ref2;
var box_control_styles_unitControlMarginStyles = function unitControlMarginStyles(_ref4) {
var isFirst = _ref4.isFirst;
var marginLeft = isFirst ? 0 : -1;
var box_control_styles_UnitControl = /*#__PURE__*/styled_base_browser_esm(unit_control, {
})("max-width:60px;", box_control_styles_unitControlBorderRadiusStyles, ";", box_control_styles_unitControlMarginStyles, ";" + ( true ? "" : undefined));
// CONCATENATED MODULE: ./node_modules/@wordpress/components/build-module/box-control/unit-control.js
function BoxUnitControl(_ref) {
var isFirst = _ref.isFirst,
_ref$onHoverOn = _ref.onHoverOn,
onHoverOn = _ref$onHoverOn === void 0 ? external_lodash_["noop"] : _ref$onHoverOn,
_ref$onHoverOff = _ref.onHoverOff,
onHoverOff = _ref$onHoverOff === void 0 ? external_lodash_["noop"] : _ref$onHoverOff,
props = Object(objectWithoutProperties["a" /* default */])(_ref, ["isFirst", "isLast", "isOnly", "onHoverOn", "onHoverOff", "label", "value"]);
var bindHoverGesture = useHover(function (_ref2) {
state = Object(objectWithoutProperties["a" /* default */])(_ref2, ["event"]);
onHoverOff(event, state);
return Object(external_wp_element_["createElement"])(UnitControlWrapper, bindHoverGesture(), Object(external_wp_element_["createElement"])(Tooltip, {