UNPKG

@wordpress/block-editor

Version:
88 lines (87 loc) 2.55 kB
// packages/block-editor/src/components/duotone-control/index.js import { ColorIndicator, Dropdown, DuotonePicker, DuotoneSwatch, MenuGroup, ToolbarButton } from "@wordpress/components"; import { __ } from "@wordpress/i18n"; import { DOWN } from "@wordpress/keycodes"; import { Icon, filter } from "@wordpress/icons"; import { useInstanceId } from "@wordpress/compose"; import { jsx, jsxs } from "react/jsx-runtime"; function DuotoneControl({ id: idProp, colorPalette, duotonePalette, disableCustomColors, disableCustomDuotone, value, onChange }) { let toolbarIcon; if (value === "unset") { toolbarIcon = /* @__PURE__ */ jsx(ColorIndicator, { className: "block-editor-duotone-control__unset-indicator" }); } else if (value) { toolbarIcon = /* @__PURE__ */ jsx(DuotoneSwatch, { values: value }); } else { toolbarIcon = /* @__PURE__ */ jsx(Icon, { icon: filter }); } const actionLabel = __("Apply duotone filter"); const id = useInstanceId(DuotoneControl, "duotone-control", idProp); const descriptionId = `${id}__description`; return /* @__PURE__ */ jsx( Dropdown, { popoverProps: { className: "block-editor-duotone-control__popover", headerTitle: __("Duotone") }, renderToggle: ({ isOpen, onToggle }) => { const openOnArrowDown = (event) => { if (!isOpen && event.keyCode === DOWN) { event.preventDefault(); onToggle(); } }; return /* @__PURE__ */ jsx( ToolbarButton, { showTooltip: true, onClick: onToggle, "aria-haspopup": "true", "aria-expanded": isOpen, onKeyDown: openOnArrowDown, label: actionLabel, icon: toolbarIcon } ); }, renderContent: () => /* @__PURE__ */ jsxs(MenuGroup, { label: __("Duotone"), children: [ /* @__PURE__ */ jsx("p", { children: __( "Create a two-tone color effect without losing your original image." ) }), /* @__PURE__ */ jsx( DuotonePicker, { "aria-label": actionLabel, "aria-describedby": descriptionId, colorPalette, duotonePalette, disableCustomColors, disableCustomDuotone, value, onChange } ) ] }) } ); } var duotone_control_default = DuotoneControl; export { duotone_control_default as default }; //# sourceMappingURL=index.js.map