UNPKG

@ariakit/react-core

Version:

Ariakit React core

115 lines (113 loc) 3.12 kB
"use client"; import { useCompositeItemOffscreen } from "../__chunks/JRLOXMGX.js"; import { ComboboxItem } from "../__chunks/JMHAJKUZ.js"; import "../__chunks/UQQRIHDV.js"; import "../__chunks/6VRAQV3D.js"; import "../__chunks/5VQZOHHZ.js"; import "../__chunks/3NAWWYOJ.js"; import { Role } from "../__chunks/XL7CSKGW.js"; import "../__chunks/RZ4GPYOB.js"; import { ComboboxListRoleContext, useComboboxScopedContext } from "../__chunks/S43UC3DV.js"; import "../__chunks/MTZPJQMC.js"; import "../__chunks/RS7LB2H4.js"; import "../__chunks/S6EF7IVO.js"; import "../__chunks/P7GR5CS5.js"; import "../__chunks/2RSXSRCN.js"; import "../__chunks/PFRGBC2K.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/YV4JVR4I.js"; import "../__chunks/VDHZ5F7K.js"; import { forwardRef } from "../__chunks/LMDWO4NN.js"; import { useMergeRefs } from "../__chunks/ABQUS43J.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 };