@ariakit/react-core
Version:
Ariakit React core
105 lines (85 loc) • 2.92 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _DYMTSYDCcjs = require('./DYMTSYDC.cjs');
var _4VSOKENIcjs = require('./4VSOKENI.cjs');
var _DMTXWFDQcjs = require('./DMTXWFDQ.cjs');
var _GCJBB4ZTcjs = require('./GCJBB4ZT.cjs');
var _EMYYI4CZcjs = require('./EMYYI4CZ.cjs');
var _WBFXWJUHcjs = require('./WBFXWJUH.cjs');
var _MZ2HG624cjs = require('./MZ2HG624.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({ store, offscreenBehavior = "active", disabled, value, ...props }) {
const context = _GCJBB4ZTcjs.useCompositeContext.call(void 0, );
store = store || context;
const id = _MZ2HG624cjs.useId.call(void 0, props.id);
const { storeId, active, listElement, offscreenRoot } = _EMYYI4CZcjs.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 = _4VSOKENIcjs.useCollectionItemOffscreen.call(void 0, {
id,
store,
offscreenBehavior: active ? "active" : offscreenBehavior,
...props,
offscreenRoot
});
if (!offscreenProps.active) {
return {
...offscreenProps,
children: value,
role: _dom.getPopupItemRole.call(void 0, listElement),
"aria-disabled": disabled || void 0,
"data-offscreen-id": storeId
};
}
return offscreenProps;
}
var CompositeItem2 = _WBFXWJUHcjs.forwardRef.call(void 0, function CompositeItem3({
offscreenBehavior,
offscreenRoot,
...props
}) {
const { active, ref, ...rest } = useCompositeItemOffscreen({
offscreenBehavior,
offscreenRoot,
...props
});
const allProps = { ...rest, ...props, ref: _MZ2HG624cjs.useMergeRefs.call(void 0, ref, props.ref) };
if (active) {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _DYMTSYDCcjs.CompositeItem, { ...allProps });
}
const {
store,
rowId,
preventScrollOnKeyDown,
moveOnKeyPress,
tabbable,
getItem,
...htmlProps
} = allProps;
const Component = _DMTXWFDQcjs.Role[TagName];
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, { ...htmlProps });
});
exports.useCompositeItemOffscreen = useCompositeItemOffscreen; exports.CompositeItem = CompositeItem2;