@wordpress/block-editor
Version:
65 lines (60 loc) • 1.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = AllInputControl;
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _utils = require("./utils");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function AllInputControl({
onChange,
selectedUnits,
setSelectedUnits,
values,
...props
}) {
let allValue = (0, _utils.getAllValue)(values);
if (allValue === undefined) {
// If we don't have any value set the unit to any current selection
// or the most common unit from the individual radii values.
allValue = (0, _utils.getAllUnit)(selectedUnits);
}
const hasValues = (0, _utils.hasDefinedValues)(values);
const isMixed = hasValues && (0, _utils.hasMixedValues)(values);
const allPlaceholder = isMixed ? (0, _i18n.__)('Mixed') : null;
// Filter out CSS-unit-only values to prevent invalid styles.
const handleOnChange = next => {
const isNumeric = !isNaN(parseFloat(next));
const nextValue = isNumeric ? next : undefined;
onChange(nextValue);
};
// Store current unit selection for use as fallback for individual
// radii controls.
const handleOnUnitChange = unit => {
setSelectedUnits({
topLeft: unit,
topRight: unit,
bottomLeft: unit,
bottomRight: unit
});
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalUnitControl, {
...props,
"aria-label": (0, _i18n.__)('Border radius'),
disableUnits: isMixed,
isOnly: true,
value: allValue,
onChange: handleOnChange,
onUnitChange: handleOnUnitChange,
placeholder: allPlaceholder,
size: "__unstable-large"
});
}
//# sourceMappingURL=all-input-control.js.map
;