UNPKG

@wordpress/components

Version:
144 lines (143 loc) • 7.83 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_i18n = require("@wordpress/i18n"); let ___border_control_style_picker_index_ts = require("../border-control-style-picker/index.cjs"); ___border_control_style_picker_index_ts = __toESM(___border_control_style_picker_index_ts); let ______button_index_tsx = require("../../button/index.cjs"); ______button_index_tsx = __toESM(______button_index_tsx); let ______color_indicator_index_tsx = require("../../color-indicator/index.cjs"); ______color_indicator_index_tsx = __toESM(______color_indicator_index_tsx); let ______color_palette_index_tsx = require("../../color-palette/index.cjs"); ______color_palette_index_tsx = __toESM(______color_palette_index_tsx); let ______dropdown_index_tsx = require("../../dropdown/index.cjs"); ______dropdown_index_tsx = __toESM(______dropdown_index_tsx); let ______v_stack_index_ts = require("../../v-stack/index.cjs"); let ______context_index_ts = require("../../context/index.cjs"); let __hook_ts = require("./hook.cjs"); let ______dropdown_dropdown_content_wrapper_tsx = require("../../dropdown/dropdown-content-wrapper.cjs"); ______dropdown_dropdown_content_wrapper_tsx = __toESM(______dropdown_dropdown_content_wrapper_tsx); let ______color_palette_utils_ts = require("../../color-palette/utils.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/components/src/border-control/border-control-dropdown/component.tsx const getAriaLabelColorValue = (colorValue) => { return colorValue.replace(/^var\((.+)\)$/, "$1"); }; const getColorObject = (colorValue, colors) => { if (!colorValue || !colors) return; if ((0, ______color_palette_utils_ts.isMultiplePaletteArray)(colors)) { let matchedColor; colors.some((origin) => origin.colors.some((color) => { if (color.color === colorValue) { matchedColor = color; return true; } return false; })); return matchedColor; } return colors.find((color) => color.color === colorValue); }; const getToggleAriaLabel = (colorValue, colorObject, style, isStyleEnabled) => { if (isStyleEnabled) { if (colorObject) { const ariaLabelValue = getAriaLabelColorValue(colorObject.color); return style ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color and style picker. The currently selected color is called \"%1$s\" and has a value of \"%2$s\". The currently selected style is \"%3$s\"."), colorObject.name, ariaLabelValue, style) : (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color and style picker. The currently selected color is called \"%1$s\" and has a value of \"%2$s\"."), colorObject.name, ariaLabelValue); } if (colorValue) { const ariaLabelValue = getAriaLabelColorValue(colorValue); return style ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color and style picker. The currently selected color has a value of \"%1$s\". The currently selected style is \"%2$s\"."), ariaLabelValue, style) : (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color and style picker. The currently selected color has a value of \"%s\"."), ariaLabelValue); } return (0, _wordpress_i18n.__)("Border color and style picker."); } if (colorObject) return (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color picker. The currently selected color is called \"%1$s\" and has a value of \"%2$s\"."), colorObject.name, getAriaLabelColorValue(colorObject.color)); if (colorValue) return (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Border color picker. The currently selected color has a value of \"%s\"."), getAriaLabelColorValue(colorValue)); return (0, _wordpress_i18n.__)("Border color picker."); }; const BorderControlDropdown = (props, forwardedRef) => { const { __experimentalIsRenderedInSidebar, border, colors, disableCustomColors, enableAlpha, enableStyle, indicatorWrapperClassName, indicatorWrapperStyle, isStyleSettable, onReset, onColorChange, onStyleChange, popoverControlsClassName, resetButtonWrapperClassName, __unstablePopoverProps, onToggle: onToggleProp, ...otherProps } = (0, __hook_ts.useBorderControlDropdown)(props); const { color, style } = border || {}; const colorObject = getColorObject(color, colors); const toggleAriaLabel = getToggleAriaLabel(color, colorObject, style, enableStyle); const enableResetButton = color || style && style !== "none"; const dropdownPosition = __experimentalIsRenderedInSidebar ? "bottom left" : void 0; const renderToggle = ({ onToggle }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______button_index_tsx.default, { onClick: onToggle, variant: "tertiary", "aria-label": toggleAriaLabel, tooltipPosition: dropdownPosition, label: (0, _wordpress_i18n.__)("Border color and style picker"), showTooltip: true, __next40pxDefaultSize: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: indicatorWrapperClassName, style: indicatorWrapperStyle, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______color_indicator_index_tsx.default, { colorValue: color }) }) }); const renderContent = () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(______dropdown_dropdown_content_wrapper_tsx.default, { paddingSize: "medium", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(______v_stack_index_ts.VStack, { className: popoverControlsClassName, spacing: 6, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(______color_palette_index_tsx.default, { value: color, onChange: onColorChange, colors, disableCustomColors, __experimentalIsRenderedInSidebar, clearable: false, enableAlpha }), enableStyle && isStyleSettable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___border_control_style_picker_index_ts.default, { label: (0, _wordpress_i18n.__)("Style"), value: style, onChange: onStyleChange })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: resetButtonWrapperClassName, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______button_index_tsx.default, { variant: "tertiary", onClick: () => { onReset(); }, disabled: !enableResetButton, accessibleWhenDisabled: true, __next40pxDefaultSize: true, children: (0, _wordpress_i18n.__)("Reset") }) })] }) }); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______dropdown_index_tsx.default, { renderToggle, renderContent, popoverProps: { ...__unstablePopoverProps }, ...otherProps, ref: forwardedRef }); }; const ConnectedBorderControlDropdown = (0, ______context_index_ts.contextConnect)(BorderControlDropdown, "BorderControlDropdown"); exports.default = ConnectedBorderControlDropdown; //# sourceMappingURL=component.cjs.map