UNPKG

@ariakit/react-core

Version:

Ariakit React core

118 lines (94 loc) 3.83 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _YTEJF6TYcjs = require('./YTEJF6TY.cjs'); var _W5V6HX7Hcjs = require('./W5V6HX7H.cjs'); var _FCZ3IGUBcjs = require('./FCZ3IGUB.cjs'); var _D6FV6EYScjs = require('./D6FV6EYS.cjs'); var _25BPIGZHcjs = require('./25BPIGZH.cjs'); var _WULEED4Qcjs = require('./WULEED4Q.cjs'); var _OZM4QA2Vcjs = require('./OZM4QA2V.cjs'); var _7EQBAZ46cjs = require('./7EQBAZ46.cjs'); // src/composite/composite-item-offscreen.tsx var _dom = require('@ariakit/core/utils/dom'); var _jsxruntime = require('react/jsx-runtime'); var TagName = "button"; function useCompositeItemOffscreen(_a) { var _b = _a, { store, offscreenBehavior = "active", disabled, value } = _b, props = _7EQBAZ46cjs.__objRest.call(void 0, _b, ["store", "offscreenBehavior", "disabled", "value"]); const context = _D6FV6EYScjs.useCompositeContext.call(void 0, ); store = store || context; const id = _OZM4QA2Vcjs.useId.call(void 0, props.id); const { storeId, active, listElement, offscreenRoot } = _25BPIGZHcjs.useStoreStateObject.call(void 0, store, { storeId: "id", active(state) { if (!state) return; if (!("selectedValue" in state) && "value" in state) { if (state.value === value) return true; } return !!id && state.activeId === id; }, listElement(state) { if (!state) return; if (!("listElement" in state)) return; return state.listElement; }, offscreenRoot(state) { if (props.offscreenRoot) return props.offscreenRoot; if (!state) return; if (!("contentElement" in state)) return; return state.contentElement || null; } } ); const offscreenProps = _W5V6HX7Hcjs.useCollectionItemOffscreen.call(void 0, _7EQBAZ46cjs.__spreadProps.call(void 0, _7EQBAZ46cjs.__spreadValues.call(void 0, { id, store, offscreenBehavior: active ? "active" : offscreenBehavior }, props), { offscreenRoot })); if (!offscreenProps.active) { return _7EQBAZ46cjs.__spreadProps.call(void 0, _7EQBAZ46cjs.__spreadValues.call(void 0, {}, offscreenProps), { children: value, role: _dom.getPopupItemRole.call(void 0, listElement), "aria-disabled": disabled || void 0, "data-offscreen-id": storeId }); } return offscreenProps; } var CompositeItem2 = _WULEED4Qcjs.forwardRef.call(void 0, function CompositeItem3(_a) { var _b = _a, { offscreenBehavior, offscreenRoot } = _b, props = _7EQBAZ46cjs.__objRest.call(void 0, _b, [ "offscreenBehavior", "offscreenRoot" ]); const _a2 = useCompositeItemOffscreen(_7EQBAZ46cjs.__spreadValues.call(void 0, { offscreenBehavior, offscreenRoot }, props)), { active, ref } = _a2, rest = _7EQBAZ46cjs.__objRest.call(void 0, _a2, ["active", "ref"]); const allProps = _7EQBAZ46cjs.__spreadProps.call(void 0, _7EQBAZ46cjs.__spreadValues.call(void 0, _7EQBAZ46cjs.__spreadValues.call(void 0, {}, rest), props), { ref: _OZM4QA2Vcjs.useMergeRefs.call(void 0, ref, props.ref) }); if (active) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _YTEJF6TYcjs.CompositeItem, _7EQBAZ46cjs.__spreadValues.call(void 0, {}, allProps)); } const _b2 = allProps, { store, rowId, preventScrollOnKeyDown, moveOnKeyPress, tabbable, getItem } = _b2, htmlProps = _7EQBAZ46cjs.__objRest.call(void 0, _b2, [ "store", "rowId", "preventScrollOnKeyDown", "moveOnKeyPress", "tabbable", "getItem" ]); const Component = _FCZ3IGUBcjs.Role[TagName]; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, _7EQBAZ46cjs.__spreadValues.call(void 0, {}, htmlProps)); }); exports.useCompositeItemOffscreen = useCompositeItemOffscreen; exports.CompositeItem = CompositeItem2;