@wordpress/block-library
Version:
Block library for the WordPress editor.
183 lines (182 loc) • 5.32 kB
JavaScript
// packages/block-library/src/list/ordered-list-settings.js
import { __ } from "@wordpress/i18n";
import { InspectorControls } from "@wordpress/block-editor";
import {
TextControl,
PanelBody,
ToggleControl,
SelectControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem
} from "@wordpress/components";
import { Platform } from "@wordpress/element";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks";
import { jsx, jsxs } from "react/jsx-runtime";
var LIST_STYLE_OPTIONS = [
{
label: __("Numbers"),
value: "decimal"
},
{
label: __("Uppercase letters"),
value: "upper-alpha"
},
{
label: __("Lowercase letters"),
value: "lower-alpha"
},
{
label: __("Uppercase Roman numerals"),
value: "upper-roman"
},
{
label: __("Lowercase Roman numerals"),
value: "lower-roman"
}
];
var OrderedListSettings = ({ setAttributes, reversed, start, type }) => {
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
return /* @__PURE__ */ jsx(InspectorControls, { children: Platform.isNative ? /* @__PURE__ */ jsxs(PanelBody, { title: __("Settings"), children: [
/* @__PURE__ */ jsx(
SelectControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: __("List style"),
options: LIST_STYLE_OPTIONS,
value: type,
onChange: (newValue) => setAttributes({ type: newValue })
}
),
/* @__PURE__ */ jsx(
TextControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: __("Start value"),
type: "number",
onChange: (value) => {
const int = parseInt(value, 10);
setAttributes({
// It should be possible to unset the value,
// e.g. with an empty string.
start: isNaN(int) ? void 0 : int
});
},
value: Number.isInteger(start) ? start.toString(10) : "",
step: "1"
}
),
/* @__PURE__ */ jsx(
ToggleControl,
{
__nextHasNoMarginBottom: true,
label: __("Reverse order"),
checked: reversed || false,
onChange: (value) => {
setAttributes({
// Unset the attribute if not reversed.
reversed: value || void 0
});
}
}
)
] }) : /* @__PURE__ */ jsxs(
ToolsPanel,
{
label: __("Settings"),
resetAll: () => {
setAttributes({
type: void 0,
start: void 0,
reversed: void 0
});
},
dropdownMenuProps,
children: [
/* @__PURE__ */ jsx(
ToolsPanelItem,
{
label: __("List style"),
isShownByDefault: true,
hasValue: () => !!type,
onDeselect: () => setAttributes({
type: void 0
}),
children: /* @__PURE__ */ jsx(
SelectControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: __("List style"),
options: LIST_STYLE_OPTIONS,
value: type || "decimal",
onChange: (newValue) => setAttributes({ type: newValue })
}
)
}
),
/* @__PURE__ */ jsx(
ToolsPanelItem,
{
label: __("Start value"),
isShownByDefault: true,
hasValue: () => !!start,
onDeselect: () => setAttributes({
start: void 0
}),
children: /* @__PURE__ */ jsx(
TextControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: __("Start value"),
type: "number",
onChange: (value) => {
const int = parseInt(value, 10);
setAttributes({
// It should be possible to unset the value,
// e.g. with an empty string.
start: isNaN(int) ? void 0 : int
});
},
value: Number.isInteger(start) ? start.toString(10) : "",
step: "1"
}
)
}
),
/* @__PURE__ */ jsx(
ToolsPanelItem,
{
label: __("Reverse order"),
isShownByDefault: true,
hasValue: () => !!reversed,
onDeselect: () => setAttributes({
reversed: void 0
}),
children: /* @__PURE__ */ jsx(
ToggleControl,
{
__nextHasNoMarginBottom: true,
label: __("Reverse order"),
checked: reversed || false,
onChange: (value) => {
setAttributes({
// Unset the attribute if not reversed.
reversed: value || void 0
});
}
}
)
}
)
]
}
) });
};
var ordered_list_settings_default = OrderedListSettings;
export {
ordered_list_settings_default as default
};
//# sourceMappingURL=ordered-list-settings.js.map