UNPKG

@wordpress/components

Version:
127 lines (125 loc) 4.73 kB
"use strict"; 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 __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/components/src/circular-option-picker/circular-option-picker-option.tsx var circular_option_picker_option_exports = {}; __export(circular_option_picker_option_exports, { Option: () => Option }); module.exports = __toCommonJS(circular_option_picker_option_exports); var import_clsx = __toESM(require("clsx")); var import_compose = require("@wordpress/compose"); var import_element = require("@wordpress/element"); var import_icons = require("@wordpress/icons"); var import_circular_option_picker_context = require("./circular-option-picker-context"); var import_button = __toESM(require("../button")); var import_composite = require("../composite"); var import_jsx_runtime = require("react/jsx-runtime"); function UnforwardedOptionAsButton(props, forwardedRef) { const { isPressed, label, ...additionalProps } = props; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.default, { ...additionalProps, "aria-pressed": isPressed, ref: forwardedRef, label }); } var OptionAsButton = (0, import_element.forwardRef)(UnforwardedOptionAsButton); function UnforwardedOptionAsOption(props, forwardedRef) { const { id, isSelected, label, ...additionalProps } = props; const { setActiveId, activeId } = (0, import_element.useContext)(import_circular_option_picker_context.CircularOptionPickerContext); (0, import_element.useEffect)(() => { if (isSelected && !activeId) { window.setTimeout(() => setActiveId?.(id), 0); } }, [isSelected, setActiveId, activeId, id]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_composite.Composite.Item, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.default, { ...additionalProps, role: "option", "aria-selected": !!isSelected, ref: forwardedRef, label }), id }); } var OptionAsOption = (0, import_element.forwardRef)(UnforwardedOptionAsOption); function Option({ className, isSelected, selectedIconProps = {}, tooltipText, ...additionalProps }) { const { baseId, setActiveId } = (0, import_element.useContext)(import_circular_option_picker_context.CircularOptionPickerContext); const id = (0, import_compose.useInstanceId)(Option, baseId || "components-circular-option-picker__option"); const commonProps = { id, className: "components-circular-option-picker__option", __next40pxDefaultSize: true, ...additionalProps }; const isListbox = setActiveId !== void 0; const optionControl = isListbox ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OptionAsOption, { ...commonProps, label: tooltipText, isSelected }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OptionAsButton, { ...commonProps, label: tooltipText, isPressed: isSelected }); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_clsx.default)(className, "components-circular-option-picker__option-wrapper"), children: [optionControl, isSelected && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: import_icons.check, ...selectedIconProps })] }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Option }); //# sourceMappingURL=circular-option-picker-option.js.map