@ariakit/react-core
Version:
Ariakit React core
105 lines (85 loc) • 2.9 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _DX5OUXRCcjs = require('./DX5OUXRC.cjs');
var _GLYXYN6Ccjs = require('./GLYXYN6C.cjs');
var _4IRVZ6J3cjs = require('./4IRVZ6J3.cjs');
var _EOGOO37Xcjs = require('./EOGOO37X.cjs');
var _RDNUVX4Vcjs = require('./RDNUVX4V.cjs');
var _SQLDFLTEcjs = require('./SQLDFLTE.cjs');
var _4KGS3DOWcjs = require('./4KGS3DOW.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, offscreenMode = "active", disabled, value, ...props }) {
const context = _EOGOO37Xcjs.useCompositeContext.call(void 0, );
store = store || context;
const id = _4KGS3DOWcjs.useId.call(void 0, props.id);
const { storeId, active, listElement, offscreenRoot } = _RDNUVX4Vcjs.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 = _GLYXYN6Ccjs.useCollectionItemOffscreen.call(void 0, {
id,
store,
offscreenMode: active ? "active" : offscreenMode,
...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 = _SQLDFLTEcjs.forwardRef.call(void 0, function CompositeItem3({
offscreenMode,
offscreenRoot,
...props
}) {
const { active, ref, ...rest } = useCompositeItemOffscreen({
offscreenMode,
offscreenRoot,
...props
});
const allProps = { ...rest, ...props, ref: _4KGS3DOWcjs.useMergeRefs.call(void 0, ref, props.ref) };
if (active) {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _DX5OUXRCcjs.CompositeItem, { ...allProps });
}
const {
store,
rowId,
preventScrollOnKeyDown,
moveOnKeyPress,
tabbable,
getItem,
...htmlProps
} = allProps;
const Component = _4IRVZ6J3cjs.Role[TagName];
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, { ...htmlProps });
});
exports.useCompositeItemOffscreen = useCompositeItemOffscreen; exports.CompositeItem = CompositeItem2;