UNPKG

@ariakit/react

Version:

Toolkit for building accessible web apps with React

146 lines (113 loc) 4.98 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _JGG73QWScjs = require('./JGG73QWS.cjs'); var _G2NDLMHVcjs = require('./G2NDLMHV.cjs'); var _YAZY4X3Pcjs = require('./YAZY4X3P.cjs'); var _S64IPIO4cjs = require('./S64IPIO4.cjs'); var _5FQZLBJ7cjs = require('./5FQZLBJ7.cjs'); var _LZ6L3ECGcjs = require('./LZ6L3ECG.cjs'); // ../ariakit-react-components/dist/hovercard/hovercard-arrow.js var TagName = "div"; var useHovercardArrow = _LZ6L3ECGcjs.createHook.call(void 0, function useHovercardArrow2({ store, ...props }) { const context = _JGG73QWScjs.useHovercardContext.call(void 0, ); store = store || context; props = _G2NDLMHVcjs.usePopoverArrow.call(void 0, { store, ...props }); return props; }); var HovercardArrow = _LZ6L3ECGcjs.forwardRef.call(void 0, function HovercardArrow2(props) { return _LZ6L3ECGcjs.createElement.call(void 0, TagName, useHovercardArrow(props)); }); // ../ariakit-react-components/dist/hovercard/hovercard-disclosure.js var _react = require('react'); var _jsxruntime = require('react/jsx-runtime'); var TagName2 = "button"; var useHovercardDisclosure = _LZ6L3ECGcjs.createHook.call(void 0, function useHovercardDisclosure2({ store, ...props }) { const context = _JGG73QWScjs.useHovercardProviderContext.call(void 0, ); store = store || context; _LZ6L3ECGcjs.invariant.call(void 0, store, process.env.NODE_ENV !== "production" && "HovercardDisclosure must receive a `store` prop or be wrapped in a HovercardProvider component."); const [visible, setVisible] = _react.useState.call(void 0, false); _react.useEffect.call(void 0, () => { if (!visible) return; const onBlur = (event) => { if (!store) return; const nextActiveElement = event.relatedTarget; if (_LZ6L3ECGcjs.isNode.call(void 0, nextActiveElement)) { const { anchorElement: anchor, popoverElement: popover, disclosureElement: disclosure } = store.getState(); if (anchor && _LZ6L3ECGcjs.contains.call(void 0, anchor, nextActiveElement)) return; if (popover && _LZ6L3ECGcjs.contains.call(void 0, popover, nextActiveElement)) return; if (disclosure && _LZ6L3ECGcjs.contains.call(void 0, disclosure, nextActiveElement)) return; if (_LZ6L3ECGcjs.isElement.call(void 0, nextActiveElement) && nextActiveElement.hasAttribute("data-focus-trap")) return; } setVisible(false); }; return _LZ6L3ECGcjs.addGlobalEventListener.call(void 0, "focusout", onBlur, true); }, [visible, store]); _react.useEffect.call(void 0, () => { return _5FQZLBJ7cjs.sync.call(void 0, store, ["anchorElement"], (state) => { const anchor = state.anchorElement; if (!anchor) return; const observer = new MutationObserver(() => { if (!anchor.hasAttribute("data-focus-visible")) return; setVisible(true); }); observer.observe(anchor, { attributeFilter: ["data-focus-visible"] }); return () => observer.disconnect(); }); }, [store]); const onClickProp = props.onClick; const onClick = _LZ6L3ECGcjs.useEvent.call(void 0, (event) => { onClickProp == null ? void 0 : onClickProp(event); if (event.defaultPrevented) return; store == null ? void 0 : store.setAutoFocusOnShow(true); }); const onFocusProp = props.onFocus; const onFocus = _LZ6L3ECGcjs.useEvent.call(void 0, (event) => { onFocusProp == null ? void 0 : onFocusProp(event); if (event.defaultPrevented) return; setVisible(true); }); const { style } = _S64IPIO4cjs.useVisuallyHidden.call(void 0, ); if (!visible) props = { ...props, style: { ...style, ...props.style } }; props = { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { display: "block", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, viewBox: "0 0 16 16", height: "1em", width: "1em", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "polyline", { points: "4,6 8,10 12,6" }) }), ...props, ref: _LZ6L3ECGcjs.useMergeRefs.call(void 0, store.setDisclosureElement, props.ref), onClick, onFocus }; props = _YAZY4X3Pcjs.useDialogDisclosure.call(void 0, { store, ...props }); return props; }); var HovercardDisclosure = _LZ6L3ECGcjs.forwardRef.call(void 0, function HovercardDisclosure2(props) { return _LZ6L3ECGcjs.createElement.call(void 0, TagName2, useHovercardDisclosure(props)); }); // ../ariakit-react-components/dist/hovercard/hovercard-provider.js function HovercardProvider(props = {}) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _JGG73QWScjs.HovercardContextProvider, { value: _JGG73QWScjs.useHovercardStore.call(void 0, props), children: props.children }); } exports.HovercardArrow = HovercardArrow; exports.HovercardDisclosure = HovercardDisclosure; exports.HovercardProvider = HovercardProvider;