UNPKG

@ariakit/react-core

Version:

Ariakit React core

115 lines (113 loc) 3.12 kB
"use client"; import { useCompositeItemOffscreen } from "../__chunks/XOT33MS6.js"; import { ComboboxItem } from "../__chunks/D7FSM5GC.js"; import "../__chunks/IABE5EV2.js"; import "../__chunks/SBSPVDDI.js"; import "../__chunks/5VQZOHHZ.js"; import "../__chunks/OQDUQELZ.js"; import { Role } from "../__chunks/QJ4LGO2N.js"; import "../__chunks/Y62RTBST.js"; import { ComboboxListRoleContext, useComboboxScopedContext } from "../__chunks/OLVWQA7U.js"; import "../__chunks/Y67KZUMI.js"; import "../__chunks/T2AZQXQU.js"; import "../__chunks/ABN76PSX.js"; import "../__chunks/APTFW6PT.js"; import "../__chunks/2W3RN7C5.js"; import "../__chunks/OE2EFRVA.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/RTNCFSKZ.js"; import "../__chunks/5CPL3B7G.js"; import { forwardRef } from "../__chunks/VOQWLFSQ.js"; import { useMergeRefs } from "../__chunks/5GGHRIN3.js"; import "../__chunks/SK3NAZA3.js"; import { __objRest, __spreadProps, __spreadValues } from "../__chunks/3YLGPPWQ.js"; // src/combobox/combobox-item-offscreen.tsx import { useContext } from "react"; import { jsx } from "react/jsx-runtime"; var TagName = "div"; var itemRoleByPopupRole = { menu: "menuitem", listbox: "option", tree: "treeitem" }; function getItemRole(popupRole) { var _a; const key = popupRole; return (_a = itemRoleByPopupRole[key]) != null ? _a : "option"; } function useComboboxItemOffscreen(_a) { var _b = _a, { store, value } = _b, props = __objRest(_b, ["store", "value"]); const context = useComboboxScopedContext(); store = store || context; const offscreenProps = useCompositeItemOffscreen(__spreadValues({ store, value }, props)); const popupRole = useContext(ComboboxListRoleContext); if (!offscreenProps.active) { return __spreadProps(__spreadValues({}, offscreenProps), { role: getItemRole(popupRole) }); } return offscreenProps; } var ComboboxItem2 = forwardRef(function ComboboxItem3(_a) { var _b = _a, { offscreenBehavior, offscreenRoot } = _b, props = __objRest(_b, [ "offscreenBehavior", "offscreenRoot" ]); const _a2 = useComboboxItemOffscreen(__spreadValues({ offscreenBehavior, offscreenRoot }, props)), { active, ref } = _a2, rest = __objRest(_a2, ["active", "ref"]); const allProps = __spreadProps(__spreadValues(__spreadValues({}, rest), props), { ref: useMergeRefs(ref, props.ref) }); if (active) { return /* @__PURE__ */ jsx(ComboboxItem, __spreadValues({}, allProps)); } const _b2 = allProps, { store, value, hideOnClick, setValueOnClick, selectValueOnClick, resetValueOnSelect, focusOnHover, blurOnHoverEnd, moveOnKeyPress, getItem } = _b2, htmlProps = __objRest(_b2, [ "store", "value", "hideOnClick", "setValueOnClick", "selectValueOnClick", "resetValueOnSelect", "focusOnHover", "blurOnHoverEnd", "moveOnKeyPress", "getItem" ]); const Component = Role[TagName]; return /* @__PURE__ */ jsx(Component, __spreadValues({}, htmlProps)); }); export { ComboboxItem2 as ComboboxItem, useComboboxItemOffscreen };