@wordpress/block-editor
Version:
94 lines (92 loc) • 3.06 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/dimensions-tool/aspect-ratio-tool.js
var aspect_ratio_tool_exports = {};
__export(aspect_ratio_tool_exports, {
default: () => AspectRatioTool
});
module.exports = __toCommonJS(aspect_ratio_tool_exports);
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_use_settings = require("../use-settings");
var import_jsx_runtime = require("react/jsx-runtime");
function AspectRatioTool({
panelId,
value,
onChange = () => {
},
options,
defaultValue = "auto",
hasValue,
isShownByDefault = true
}) {
const displayValue = value ?? "auto";
const [defaultRatios, themeRatios, showDefaultRatios] = (0, import_use_settings.useSettings)(
"dimensions.aspectRatios.default",
"dimensions.aspectRatios.theme",
"dimensions.defaultAspectRatios"
);
const themeOptions = themeRatios?.map(({ name, ratio }) => ({
label: name,
value: ratio
}));
const defaultOptions = defaultRatios?.map(({ name, ratio }) => ({
label: name,
value: ratio
}));
const aspectRatioOptions = [
{
label: (0, import_i18n._x)(
"Original",
"Aspect ratio option for dimensions control"
),
value: "auto"
},
...showDefaultRatios ? defaultOptions : [],
...themeOptions ? themeOptions : [],
{
label: (0, import_i18n._x)("Custom", "Aspect ratio option for dimensions control"),
value: "custom",
disabled: true,
hidden: true
}
];
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToolsPanelItem,
{
hasValue: hasValue ? hasValue : () => displayValue !== defaultValue,
label: (0, import_i18n.__)("Aspect ratio"),
onDeselect: () => onChange(void 0),
isShownByDefault,
panelId,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.SelectControl,
{
label: (0, import_i18n.__)("Aspect ratio"),
value: displayValue,
options: options ?? aspectRatioOptions,
onChange,
size: "__unstable-large",
__nextHasNoMarginBottom: true
}
)
}
);
}
//# sourceMappingURL=aspect-ratio-tool.js.map