UNPKG

@wordpress/components

Version:
99 lines (98 loc) • 4.24 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 clsx = require("clsx"); clsx = __toESM(clsx); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_element = require("@wordpress/element"); let _wordpress_icons = require("@wordpress/icons"); let __circular_option_picker_context_tsx = require("./circular-option-picker-context.cjs"); let ___button_index_tsx = require("../button/index.cjs"); ___button_index_tsx = __toESM(___button_index_tsx); let ___composite_index_tsx = require("../composite/index.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/components/src/circular-option-picker/circular-option-picker-option.tsx function UnforwardedOptionAsButton(props, forwardedRef) { const { isPressed, label, ...additionalProps } = props; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___button_index_tsx.default, { __next40pxDefaultSize: true, ...additionalProps, "aria-pressed": isPressed, ref: forwardedRef, label }); } const OptionAsButton = (0, _wordpress_element.forwardRef)(UnforwardedOptionAsButton); function UnforwardedOptionAsOption(props, forwardedRef) { const { id, isSelected, label, ...additionalProps } = props; const { setActiveId, activeId } = (0, _wordpress_element.useContext)(__circular_option_picker_context_tsx.CircularOptionPickerContext); (0, _wordpress_element.useEffect)(() => { if (isSelected && !activeId) window.setTimeout(() => setActiveId?.(id), 0); }, [ isSelected, setActiveId, activeId, id ]); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___composite_index_tsx.Composite.Item, { render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___button_index_tsx.default, { __next40pxDefaultSize: true, ...additionalProps, role: "option", "aria-selected": !!isSelected, ref: forwardedRef, label }), id }); } const OptionAsOption = (0, _wordpress_element.forwardRef)(UnforwardedOptionAsOption); function Option({ className, isSelected, selectedIconProps = {}, tooltipText, ...additionalProps }) { const { baseId, presentation = "toggle-buttons" } = (0, _wordpress_element.useContext)(__circular_option_picker_context_tsx.CircularOptionPickerContext); const commonProps = { id: (0, _wordpress_compose.useInstanceId)(Option, baseId || "components-circular-option-picker__option"), className: "components-circular-option-picker__option", ...additionalProps }; const optionControl = presentation === "listbox" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OptionAsOption, { ...commonProps, label: tooltipText, isSelected }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OptionAsButton, { ...commonProps, label: tooltipText, isPressed: presentation === "toggle-buttons" ? !!isSelected : void 0 }); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: (0, clsx.default)(className, "components-circular-option-picker__option-wrapper"), children: [optionControl, presentation !== "command-buttons" && isSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_icons.Icon, { icon: _wordpress_icons.check, ...selectedIconProps })] }); } exports.Option = Option; //# sourceMappingURL=circular-option-picker-option.cjs.map