@yamada-ui/popover 1.3.3-dev-20240926165323 → 1.3.3-dev-20240926171200

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/dist/{chunk-JDFT5ECK.mjs → chunk-2EUPTTRC.mjs} +4 -2
  2. package/dist/{chunk-JDFT5ECK.mjs.map → chunk-2EUPTTRC.mjs.map} +1 -1
  3. package/dist/{chunk-ZUN4C7RP.mjs → chunk-4XXWFN6L.mjs} +4 -2
  4. package/dist/chunk-4XXWFN6L.mjs.map +1 -0
  5. package/dist/{chunk-L5V3DH65.mjs → chunk-6THCC2BT.mjs} +3 -1
  6. package/dist/{chunk-L5V3DH65.mjs.map → chunk-6THCC2BT.mjs.map} +1 -1
  7. package/dist/{chunk-ZTNVKVLS.mjs → chunk-FAPYWOWO.mjs} +5 -3
  8. package/dist/{chunk-ZTNVKVLS.mjs.map → chunk-FAPYWOWO.mjs.map} +1 -1
  9. package/dist/{chunk-MLEEMVQI.mjs → chunk-FIADAGVP.mjs} +4 -2
  10. package/dist/chunk-FIADAGVP.mjs.map +1 -0
  11. package/dist/{chunk-KDUZQWBX.mjs → chunk-GXJI2MI3.mjs} +4 -2
  12. package/dist/{chunk-KDUZQWBX.mjs.map → chunk-GXJI2MI3.mjs.map} +1 -1
  13. package/dist/{chunk-MWWNZ7OL.mjs → chunk-ITQ2KUJZ.mjs} +4 -2
  14. package/dist/{chunk-MWWNZ7OL.mjs.map → chunk-ITQ2KUJZ.mjs.map} +1 -1
  15. package/dist/{chunk-NO5ZQLT6.mjs → chunk-P4MJ5IU7.mjs} +4 -2
  16. package/dist/{chunk-NO5ZQLT6.mjs.map → chunk-P4MJ5IU7.mjs.map} +1 -1
  17. package/dist/index.js +16 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +8 -8
  20. package/dist/popover-anchor.d.mts +2 -1
  21. package/dist/popover-anchor.d.ts +2 -1
  22. package/dist/popover-anchor.js +220 -0
  23. package/dist/popover-anchor.js.map +1 -1
  24. package/dist/popover-anchor.mjs +2 -2
  25. package/dist/popover-body.js +220 -0
  26. package/dist/popover-body.js.map +1 -1
  27. package/dist/popover-body.mjs +2 -2
  28. package/dist/popover-close-button.js +220 -0
  29. package/dist/popover-close-button.js.map +1 -1
  30. package/dist/popover-close-button.mjs +2 -2
  31. package/dist/popover-content.js +222 -0
  32. package/dist/popover-content.js.map +1 -1
  33. package/dist/popover-content.mjs +3 -3
  34. package/dist/popover-footer.js +220 -0
  35. package/dist/popover-footer.js.map +1 -1
  36. package/dist/popover-footer.mjs +2 -2
  37. package/dist/popover-header.js +220 -0
  38. package/dist/popover-header.js.map +1 -1
  39. package/dist/popover-header.mjs +2 -2
  40. package/dist/popover-trigger.d.mts +2 -1
  41. package/dist/popover-trigger.d.ts +2 -1
  42. package/dist/popover-trigger.js +220 -0
  43. package/dist/popover-trigger.js.map +1 -1
  44. package/dist/popover-trigger.mjs +2 -2
  45. package/dist/popover.d.mts +2 -2
  46. package/dist/popover.d.ts +2 -2
  47. package/dist/popover.js +2 -0
  48. package/dist/popover.js.map +1 -1
  49. package/dist/popover.mjs +1 -1
  50. package/package.json +10 -10
  51. package/dist/chunk-MLEEMVQI.mjs.map +0 -1
  52. package/dist/chunk-ZUN4C7RP.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,29 +1,29 @@
1
1
  "use client"
2
2
  import {
3
3
  PopoverAnchor
4
- } from "./chunk-MLEEMVQI.mjs";
4
+ } from "./chunk-FIADAGVP.mjs";
5
5
  import {
6
6
  PopoverBody
7
- } from "./chunk-MWWNZ7OL.mjs";
7
+ } from "./chunk-ITQ2KUJZ.mjs";
8
8
  import {
9
9
  PopoverContent
10
- } from "./chunk-ZTNVKVLS.mjs";
10
+ } from "./chunk-FAPYWOWO.mjs";
11
11
  import {
12
12
  PopoverCloseButton
13
- } from "./chunk-NO5ZQLT6.mjs";
13
+ } from "./chunk-P4MJ5IU7.mjs";
14
14
  import {
15
15
  PopoverFooter
16
- } from "./chunk-KDUZQWBX.mjs";
16
+ } from "./chunk-GXJI2MI3.mjs";
17
17
  import {
18
18
  PopoverHeader
19
- } from "./chunk-JDFT5ECK.mjs";
19
+ } from "./chunk-2EUPTTRC.mjs";
20
20
  import {
21
21
  PopoverTrigger
22
- } from "./chunk-ZUN4C7RP.mjs";
22
+ } from "./chunk-4XXWFN6L.mjs";
23
23
  import {
24
24
  Popover,
25
25
  popoverProperties
26
- } from "./chunk-L5V3DH65.mjs";
26
+ } from "./chunk-6THCC2BT.mjs";
27
27
  export {
28
28
  Popover,
29
29
  PopoverAnchor,
@@ -1,4 +1,5 @@
1
- import { FC, PropsWithChildren } from 'react';
1
+ import { FC } from '@yamada-ui/core';
2
+ import { PropsWithChildren } from 'react';
2
3
 
3
4
  declare const PopoverAnchor: FC<PropsWithChildren<{}>>;
4
5
 
@@ -1,4 +1,5 @@
1
- import { FC, PropsWithChildren } from 'react';
1
+ import { FC } from '@yamada-ui/core';
2
+ import { PropsWithChildren } from 'react';
2
3
 
3
4
  declare const PopoverAnchor: FC<PropsWithChildren<{}>>;
4
5
 
@@ -59,6 +59,224 @@ var [PopoverProvider, usePopover] = (0, import_utils.createContext)({
59
59
  strict: false,
60
60
  name: "PopoverContext"
61
61
  });
62
+ var Popover = (props) => {
63
+ const [styles, mergedProps] = (0, import_core.useComponentMultiStyle)("Popover", props);
64
+ const {
65
+ children,
66
+ initialFocusRef,
67
+ restoreFocus = true,
68
+ autoFocus = true,
69
+ closeOnBlur = true,
70
+ closeOnEsc = true,
71
+ closeOnButton = true,
72
+ trigger = "click",
73
+ openDelay = 200,
74
+ closeDelay = 200,
75
+ isLazy,
76
+ lazyBehavior = "unmount",
77
+ animation = "scale",
78
+ duration,
79
+ relatedRef,
80
+ ...rest
81
+ } = (0, import_core.omitThemeProps)(mergedProps);
82
+ const { isOpen, onOpen, onClose, onToggle } = (0, import_use_disclosure.useDisclosure)(mergedProps);
83
+ const anchorRef = (0, import_react.useRef)(null);
84
+ const triggerRef = (0, import_react.useRef)(null);
85
+ const popoverRef = (0, import_react.useRef)(null);
86
+ const { present, onAnimationComplete } = (0, import_use_animation.useAnimationObserver)({
87
+ isOpen,
88
+ ref: popoverRef
89
+ });
90
+ const openTimeout = (0, import_react.useRef)(void 0);
91
+ const closeTimeout = (0, import_react.useRef)(void 0);
92
+ const isHoveringRef = (0, import_react.useRef)(false);
93
+ const hasBeenOpened = (0, import_react.useRef)(false);
94
+ if (isOpen) hasBeenOpened.current = true;
95
+ const { referenceRef, getPopperProps, forceUpdate, transformOrigin } = (0, import_use_popper.usePopper)({
96
+ ...rest,
97
+ enabled: isOpen
98
+ });
99
+ (0, import_react.useEffect)(() => {
100
+ return () => {
101
+ if (openTimeout.current) clearTimeout(openTimeout.current);
102
+ if (closeTimeout.current) clearTimeout(closeTimeout.current);
103
+ };
104
+ }, []);
105
+ (0, import_use_focus.useFocusOnPointerDown)({
106
+ enabled: isOpen,
107
+ ref: triggerRef
108
+ });
109
+ (0, import_use_focus.useFocusOnHide)(popoverRef, {
110
+ focusRef: triggerRef,
111
+ visible: isOpen,
112
+ shouldFocus: restoreFocus && (trigger === "click" || trigger === "contextmenu")
113
+ });
114
+ (0, import_use_focus.useFocusOnShow)(popoverRef, {
115
+ focusRef: initialFocusRef,
116
+ visible: isOpen,
117
+ shouldFocus: autoFocus && (trigger === "click" || trigger === "contextmenu")
118
+ });
119
+ const shouldRenderChildren = (0, import_use_disclosure.useLazyDisclosure)({
120
+ wasSelected: hasBeenOpened.current,
121
+ enabled: isLazy,
122
+ mode: lazyBehavior,
123
+ isSelected: present
124
+ });
125
+ const getPopoverProps = (0, import_react.useCallback)(
126
+ (props2 = {}, ref = null) => {
127
+ const popoverProps = {
128
+ ...props2,
129
+ style: {
130
+ ...props2.style,
131
+ transformOrigin
132
+ },
133
+ ref: (0, import_utils.mergeRefs)(popoverRef, ref),
134
+ children: shouldRenderChildren ? props2.children : null,
135
+ tabIndex: -1,
136
+ onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, (ev) => {
137
+ if (closeOnEsc && ev.key === "Escape") onClose();
138
+ }),
139
+ onBlur: (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
140
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
141
+ const targetIsPopover = (0, import_utils.isContains)(popoverRef.current, relatedTarget);
142
+ const targetIsTrigger = (0, import_utils.isContains)(triggerRef.current, relatedTarget);
143
+ const targetIsRelated = (relatedRef == null ? void 0 : relatedRef.current) ? (0, import_utils.isContains)(relatedRef.current, relatedTarget) : false;
144
+ const isValidBlur = !targetIsPopover && !targetIsTrigger && !targetIsRelated;
145
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
146
+ })
147
+ };
148
+ if (trigger === "hover") {
149
+ popoverProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
150
+ isHoveringRef.current = true;
151
+ });
152
+ popoverProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, (ev) => {
153
+ if (ev.nativeEvent.relatedTarget === null) return;
154
+ isHoveringRef.current = false;
155
+ if (closeOnBlur) setTimeout(onClose, closeDelay);
156
+ });
157
+ }
158
+ return popoverProps;
159
+ },
160
+ [
161
+ closeDelay,
162
+ closeOnBlur,
163
+ closeOnEsc,
164
+ isOpen,
165
+ onClose,
166
+ shouldRenderChildren,
167
+ transformOrigin,
168
+ trigger,
169
+ relatedRef
170
+ ]
171
+ );
172
+ const maybeReferenceRef = (0, import_react.useCallback)(
173
+ (node) => {
174
+ if (anchorRef.current == null) referenceRef(node);
175
+ },
176
+ [referenceRef]
177
+ );
178
+ const getTriggerProps = (0, import_react.useCallback)(
179
+ (props2 = {}, ref = null) => {
180
+ const triggerProps = {
181
+ ...props2,
182
+ ref: (0, import_utils.mergeRefs)(triggerRef, ref, maybeReferenceRef)
183
+ };
184
+ if (trigger === "click") {
185
+ triggerProps.onClick = (0, import_utils.handlerAll)(props2.onClick, onToggle);
186
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
187
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
188
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
189
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
190
+ });
191
+ }
192
+ if (trigger === "contextmenu") {
193
+ triggerProps.onContextMenu = (0, import_utils.handlerAll)(props2.onContextMenu, (ev) => {
194
+ ev.preventDefault();
195
+ onOpen();
196
+ });
197
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
198
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
199
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
200
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
201
+ });
202
+ }
203
+ if (trigger === "hover") {
204
+ triggerProps.onFocus = (0, import_utils.handlerAll)(props2.onFocus, () => {
205
+ if (openTimeout.current === void 0) onOpen();
206
+ });
207
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
208
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
209
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
210
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
211
+ });
212
+ triggerProps.onKeyDown = (0, import_utils.handlerAll)(props2.onKeyDown, (ev) => {
213
+ if (ev.key === "Escape") onClose();
214
+ });
215
+ triggerProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
216
+ isHoveringRef.current = true;
217
+ openTimeout.current = window.setTimeout(onOpen, openDelay);
218
+ });
219
+ triggerProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, () => {
220
+ isHoveringRef.current = false;
221
+ if (openTimeout.current) {
222
+ clearTimeout(openTimeout.current);
223
+ openTimeout.current = void 0;
224
+ }
225
+ closeTimeout.current = window.setTimeout(() => {
226
+ if (!isHoveringRef.current) onClose();
227
+ }, closeDelay);
228
+ });
229
+ }
230
+ return triggerProps;
231
+ },
232
+ [
233
+ closeDelay,
234
+ closeOnBlur,
235
+ isOpen,
236
+ maybeReferenceRef,
237
+ onClose,
238
+ onOpen,
239
+ onToggle,
240
+ openDelay,
241
+ trigger
242
+ ]
243
+ );
244
+ const getAnchorProps = (0, import_react.useCallback)(
245
+ (props2 = {}, ref = null) => {
246
+ return {
247
+ ...props2,
248
+ ref: (0, import_utils.mergeRefs)(ref, anchorRef, referenceRef)
249
+ };
250
+ },
251
+ [anchorRef, referenceRef]
252
+ );
253
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
254
+ PopoverProvider,
255
+ {
256
+ value: {
257
+ isOpen,
258
+ onClose,
259
+ closeOnButton,
260
+ onAnimationComplete,
261
+ forceUpdate,
262
+ getTriggerProps,
263
+ getAnchorProps,
264
+ getPopperProps,
265
+ getPopoverProps,
266
+ animation,
267
+ duration,
268
+ styles
269
+ },
270
+ children: (0, import_utils.runIfFunc)(children, {
271
+ isOpen,
272
+ onClose,
273
+ forceUpdate
274
+ })
275
+ }
276
+ );
277
+ };
278
+ Popover.displayName = "Popover";
279
+ Popover.__ui__ = "Popover";
62
280
 
63
281
  // src/popover-anchor.tsx
64
282
  var PopoverAnchor = ({ children }) => {
@@ -66,6 +284,8 @@ var PopoverAnchor = ({ children }) => {
66
284
  const { getAnchorProps } = usePopover();
67
285
  return (0, import_react2.cloneElement)(child, getAnchorProps(child.props, child.ref));
68
286
  };
287
+ PopoverAnchor.displayName = "PopoverAnchor";
288
+ PopoverAnchor.__ui__ = "PopoverAnchor";
69
289
  // Annotate the CommonJS export names for ESM import in node:
70
290
  0 && (module.exports = {
71
291
  PopoverAnchor
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/popover-anchor.tsx","../src/popover.tsx"],"sourcesContent":["import type { FC, PropsWithChildren, ReactElement, RefObject } from \"react\"\nimport { Children, cloneElement } from \"react\"\nimport { usePopover } from \"./popover\"\n\nexport const PopoverAnchor: FC<PropsWithChildren<{}>> = ({ children }) => {\n const child = Children.only(children) as ReactElement & {\n ref: RefObject<any>\n }\n const { getAnchorProps } = usePopover()\n\n return cloneElement(child, getAnchorProps(child.props, child.ref))\n}\n","import type {\n CSSUIObject,\n HTMLUIPropsWithRef,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport { useComponentMultiStyle, omitThemeProps } from \"@yamada-ui/core\"\nimport type { MotionProps, MotionTransitionProps } from \"@yamada-ui/motion\"\nimport { useAnimationObserver } from \"@yamada-ui/use-animation\"\nimport type { LazyMode } from \"@yamada-ui/use-disclosure\"\nimport { useDisclosure, useLazyDisclosure } from \"@yamada-ui/use-disclosure\"\nimport {\n useFocusOnHide,\n useFocusOnShow,\n useFocusOnPointerDown,\n} from \"@yamada-ui/use-focus\"\nimport type { UsePopperProps } from \"@yamada-ui/use-popper\"\nimport { usePopper, popperProperties } from \"@yamada-ui/use-popper\"\nimport {\n createContext,\n getEventRelatedTarget,\n handlerAll,\n isContains,\n mergeRefs,\n runIfFunc,\n} from \"@yamada-ui/utils\"\nimport type {\n ComponentProps,\n FC,\n PropsWithChildren,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport { useCallback, useEffect, useRef } from \"react\"\n\nexport type PopoverProperty = (typeof popoverProperties)[number]\n\nexport const popoverProperties = [\n ...popperProperties,\n \"isOpen\",\n \"defaultIsOpen\",\n \"onOpen\",\n \"onClose\",\n \"initialFocusRef\",\n \"restoreFocus\",\n \"autoFocus\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnButton\",\n \"trigger\",\n \"openDelay\",\n \"closeDelay\",\n \"isLazy\",\n \"lazyBehavior\",\n \"animation\",\n \"duration\",\n] as const\n\nexport interface ComboBoxProps\n extends Omit<\n PopoverOptions,\n | \"initialFocusRef\"\n | \"relatedRef\"\n | \"autoFocus\"\n | \"restoreFocus\"\n | \"closeOnButton\"\n | \"trigger\"\n >,\n Omit<UsePopperProps, \"enabled\"> {}\n\ninterface PopoverOptions {\n /**\n * If `true`, the popover will be opened.\n */\n isOpen?: boolean\n /**\n * If `true`, the popover will be initially opened.\n */\n defaultIsOpen?: boolean\n /**\n * Callback fired when the popover opens.\n */\n onOpen?: () => void\n /**\n * Callback fired when the popover closes.\n */\n onClose?: () => void\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<{ focus(): void }>\n /**\n * The `ref` of the element related to the popover.\n * This is used during the `onBlur` event.\n */\n relatedRef?: RefObject<HTMLElement>\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, focus will be returned to the element that triggers the popover when it closes.\n *\n * @default true\n */\n restoreFocus?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will close when you hit the `Esc` key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, display the popover close button.\n *\n * @default true\n */\n closeOnButton?: boolean\n /**\n * The interaction that triggers the popover.\n *\n * - `hover`: means the popover will open when you hover with mouse or focus with keyboard on the popover trigger.\n * - `click`: means the popover will open on click or press `Enter` to `Space` on keyboard.\n *\n * @default 'click'\n */\n trigger?: \"click\" | \"hover\" | \"never\" | \"contextmenu\"\n /**\n * The number of delay time to open.\n *\n * @default 200\n */\n openDelay?: number\n /**\n * The number of delay time to close.\n *\n * @default 200\n */\n closeDelay?: number\n /**\n * If `true`, the PopoverContent rendering will be deferred until the popover is open.\n *\n * @default false\n */\n isLazy?: boolean\n /**\n * The lazy behavior of popover's content when not visible. Only works when `isLazy={true}`\n *\n * - `unmount`: The popover's content is always unmounted when not open.\n * - `keepMounted`: The popover's content initially unmounted, but stays mounted when popover is open.\n *\n * @default 'unmount'\n */\n lazyBehavior?: LazyMode\n /**\n * The animation of the popover.\n *\n * @default 'scale'\n */\n animation?: \"scale\" | \"top\" | \"right\" | \"left\" | \"bottom\" | \"none\"\n /**\n * The animation duration.\n */\n duration?: MotionTransitionProps[\"duration\"]\n}\n\nexport interface PopoverProps\n extends ThemeProps<\"Popover\">,\n Omit<UsePopperProps, \"enabled\">,\n PropsWithChildren<PopoverOptions> {}\n\ninterface PopoverContext\n extends Pick<\n PopoverOptions,\n \"isOpen\" | \"onClose\" | \"closeOnButton\" | \"animation\" | \"duration\"\n > {\n onAnimationComplete: () => void\n forceUpdate: () => void | undefined\n getTriggerProps: PropGetter\n getAnchorProps: PropGetter\n getPopperProps: PropGetter<ComponentProps<\"div\">>\n getPopoverProps: PropGetter<MotionProps<\"section\">, MotionProps<\"section\">>\n styles: { [key: string]: CSSUIObject }\n}\n\nconst [PopoverProvider, usePopover] = createContext<PopoverContext>({\n strict: false,\n name: \"PopoverContext\",\n})\n\nexport { usePopover }\n\n/**\n * `Popover` is a component that floats around an element to display information.\n *\n * @see Docs https://yamada-ui.com/components/overlay/popover\n */\nexport const Popover: FC<PopoverProps> = (props) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Popover\", props)\n const {\n children,\n initialFocusRef,\n restoreFocus = true,\n autoFocus = true,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnButton = true,\n trigger = \"click\",\n openDelay = 200,\n closeDelay = 200,\n isLazy,\n lazyBehavior = \"unmount\",\n animation = \"scale\",\n duration,\n relatedRef,\n ...rest\n } = omitThemeProps(mergedProps)\n\n const { isOpen, onOpen, onClose, onToggle } = useDisclosure(mergedProps)\n\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLElement>(null)\n const popoverRef = useRef<HTMLElement>(null)\n\n const { present, onAnimationComplete } = useAnimationObserver({\n isOpen,\n ref: popoverRef,\n })\n\n const openTimeout = useRef<number | undefined>(undefined)\n const closeTimeout = useRef<number | undefined>(undefined)\n\n const isHoveringRef = useRef(false)\n\n const hasBeenOpened = useRef(false)\n\n if (isOpen) hasBeenOpened.current = true\n\n const { referenceRef, getPopperProps, forceUpdate, transformOrigin } =\n usePopper({\n ...rest,\n enabled: isOpen,\n })\n\n useEffect(() => {\n return () => {\n if (openTimeout.current) clearTimeout(openTimeout.current)\n\n if (closeTimeout.current) clearTimeout(closeTimeout.current)\n }\n }, [])\n\n useFocusOnPointerDown({\n enabled: isOpen,\n ref: triggerRef,\n })\n\n useFocusOnHide(popoverRef, {\n focusRef: triggerRef,\n visible: isOpen,\n shouldFocus:\n restoreFocus && (trigger === \"click\" || trigger === \"contextmenu\"),\n })\n\n useFocusOnShow(popoverRef, {\n focusRef: initialFocusRef,\n visible: isOpen,\n shouldFocus:\n autoFocus && (trigger === \"click\" || trigger === \"contextmenu\"),\n })\n\n const shouldRenderChildren = useLazyDisclosure({\n wasSelected: hasBeenOpened.current,\n enabled: isLazy,\n mode: lazyBehavior,\n isSelected: present,\n })\n\n const getPopoverProps: PropGetter<\n MotionProps<\"section\">,\n MotionProps<\"section\">\n > = useCallback(\n (props = {}, ref = null) => {\n const popoverProps: MotionProps & RefAttributes<any> = {\n ...props,\n style: {\n ...props.style,\n transformOrigin,\n },\n ref: mergeRefs(popoverRef, ref),\n children: shouldRenderChildren ? props.children : null,\n tabIndex: -1,\n onKeyDown: handlerAll(props.onKeyDown, (ev) => {\n if (closeOnEsc && ev.key === \"Escape\") onClose()\n }),\n onBlur: handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const targetIsPopover = isContains(popoverRef.current, relatedTarget)\n const targetIsTrigger = isContains(triggerRef.current, relatedTarget)\n const targetIsRelated = relatedRef?.current\n ? isContains(relatedRef.current, relatedTarget)\n : false\n\n const isValidBlur =\n !targetIsPopover && !targetIsTrigger && !targetIsRelated\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n }),\n }\n\n if (trigger === \"hover\") {\n popoverProps.onMouseEnter = handlerAll(props.onMouseEnter, () => {\n isHoveringRef.current = true\n })\n\n popoverProps.onMouseLeave = handlerAll(props.onMouseLeave, (ev) => {\n if (ev.nativeEvent.relatedTarget === null) return\n\n isHoveringRef.current = false\n\n if (closeOnBlur) setTimeout(onClose, closeDelay)\n })\n }\n\n return popoverProps\n },\n [\n closeDelay,\n closeOnBlur,\n closeOnEsc,\n isOpen,\n onClose,\n shouldRenderChildren,\n transformOrigin,\n trigger,\n relatedRef,\n ],\n )\n\n const maybeReferenceRef = useCallback(\n (node: Element) => {\n if (anchorRef.current == null) referenceRef(node)\n },\n [referenceRef],\n )\n\n const getTriggerProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const triggerProps: HTMLUIPropsWithRef = {\n ...props,\n ref: mergeRefs(triggerRef, ref, maybeReferenceRef),\n }\n\n if (trigger === \"click\") {\n triggerProps.onClick = handlerAll(props.onClick, onToggle)\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n }\n\n if (trigger === \"contextmenu\") {\n triggerProps.onContextMenu = handlerAll(props.onContextMenu, (ev) => {\n ev.preventDefault()\n onOpen()\n })\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n }\n\n if (trigger === \"hover\") {\n triggerProps.onFocus = handlerAll(props.onFocus, () => {\n if (openTimeout.current === undefined) onOpen()\n })\n\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n\n triggerProps.onKeyDown = handlerAll(props.onKeyDown, (ev) => {\n if (ev.key === \"Escape\") onClose()\n })\n\n triggerProps.onMouseEnter = handlerAll(props.onMouseEnter, () => {\n isHoveringRef.current = true\n openTimeout.current = window.setTimeout(onOpen, openDelay)\n })\n\n triggerProps.onMouseLeave = handlerAll(props.onMouseLeave, () => {\n isHoveringRef.current = false\n\n if (openTimeout.current) {\n clearTimeout(openTimeout.current)\n openTimeout.current = undefined\n }\n\n closeTimeout.current = window.setTimeout(() => {\n if (!isHoveringRef.current) onClose()\n }, closeDelay)\n })\n }\n\n return triggerProps\n },\n [\n closeDelay,\n closeOnBlur,\n isOpen,\n maybeReferenceRef,\n onClose,\n onOpen,\n onToggle,\n openDelay,\n trigger,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n return {\n ...props,\n ref: mergeRefs(ref, anchorRef, referenceRef),\n }\n },\n [anchorRef, referenceRef],\n )\n\n return (\n <PopoverProvider\n value={{\n isOpen,\n onClose,\n closeOnButton,\n onAnimationComplete,\n forceUpdate,\n getTriggerProps,\n getAnchorProps,\n getPopperProps,\n getPopoverProps,\n animation,\n duration,\n styles,\n }}\n >\n {runIfFunc(children, {\n isOpen,\n onClose,\n forceUpdate,\n })}\n </PopoverProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gBAAuC;;;ACKvC,kBAAuD;AAEvD,2BAAqC;AAErC,4BAAiD;AACjD,uBAIO;AAEP,wBAA4C;AAC5C,mBAOO;AAQP,mBAA+C;AA4Z3C;AAxZG,IAAM,oBAAoB;AAAA,EAC/B,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAyIA,IAAM,CAAC,iBAAiB,UAAU,QAAI,4BAA8B;AAAA,EAClE,QAAQ;AAAA,EACR,MAAM;AACR,CAAC;;;ADhMM,IAAM,gBAA2C,CAAC,EAAE,SAAS,MAAM;AACxE,QAAM,QAAQ,uBAAS,KAAK,QAAQ;AAGpC,QAAM,EAAE,eAAe,IAAI,WAAW;AAEtC,aAAO,4BAAa,OAAO,eAAe,MAAM,OAAO,MAAM,GAAG,CAAC;AACnE;","names":["import_react"]}
1
+ {"version":3,"sources":["../src/popover-anchor.tsx","../src/popover.tsx"],"sourcesContent":["import type { FC } from \"@yamada-ui/core\"\nimport type { PropsWithChildren, ReactElement, RefObject } from \"react\"\nimport { Children, cloneElement } from \"react\"\nimport { usePopover } from \"./popover\"\n\nexport const PopoverAnchor: FC<PropsWithChildren<{}>> = ({ children }) => {\n const child = Children.only(children) as ReactElement & {\n ref: RefObject<any>\n }\n const { getAnchorProps } = usePopover()\n\n return cloneElement(child, getAnchorProps(child.props, child.ref))\n}\n\nPopoverAnchor.displayName = \"PopoverAnchor\"\nPopoverAnchor.__ui__ = \"PopoverAnchor\"\n","import type {\n CSSUIObject,\n FC,\n HTMLUIPropsWithRef,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport { useComponentMultiStyle, omitThemeProps } from \"@yamada-ui/core\"\nimport type { MotionProps, MotionTransitionProps } from \"@yamada-ui/motion\"\nimport { useAnimationObserver } from \"@yamada-ui/use-animation\"\nimport type { LazyMode } from \"@yamada-ui/use-disclosure\"\nimport { useDisclosure, useLazyDisclosure } from \"@yamada-ui/use-disclosure\"\nimport {\n useFocusOnHide,\n useFocusOnShow,\n useFocusOnPointerDown,\n} from \"@yamada-ui/use-focus\"\nimport type { UsePopperProps } from \"@yamada-ui/use-popper\"\nimport { usePopper, popperProperties } from \"@yamada-ui/use-popper\"\nimport {\n createContext,\n getEventRelatedTarget,\n handlerAll,\n isContains,\n mergeRefs,\n runIfFunc,\n} from \"@yamada-ui/utils\"\nimport type {\n ComponentProps,\n PropsWithChildren,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport { useCallback, useEffect, useRef } from \"react\"\n\nexport type PopoverProperty = (typeof popoverProperties)[number]\n\nexport const popoverProperties = [\n ...popperProperties,\n \"isOpen\",\n \"defaultIsOpen\",\n \"onOpen\",\n \"onClose\",\n \"initialFocusRef\",\n \"restoreFocus\",\n \"autoFocus\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnButton\",\n \"trigger\",\n \"openDelay\",\n \"closeDelay\",\n \"isLazy\",\n \"lazyBehavior\",\n \"animation\",\n \"duration\",\n] as const\n\nexport interface ComboBoxProps\n extends Omit<\n PopoverOptions,\n | \"initialFocusRef\"\n | \"relatedRef\"\n | \"autoFocus\"\n | \"restoreFocus\"\n | \"closeOnButton\"\n | \"trigger\"\n >,\n Omit<UsePopperProps, \"enabled\"> {}\n\ninterface PopoverOptions {\n /**\n * If `true`, the popover will be opened.\n */\n isOpen?: boolean\n /**\n * If `true`, the popover will be initially opened.\n */\n defaultIsOpen?: boolean\n /**\n * Callback fired when the popover opens.\n */\n onOpen?: () => void\n /**\n * Callback fired when the popover closes.\n */\n onClose?: () => void\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<{ focus(): void }>\n /**\n * The `ref` of the element related to the popover.\n * This is used during the `onBlur` event.\n */\n relatedRef?: RefObject<HTMLElement>\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, focus will be returned to the element that triggers the popover when it closes.\n *\n * @default true\n */\n restoreFocus?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will close when you hit the `Esc` key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, display the popover close button.\n *\n * @default true\n */\n closeOnButton?: boolean\n /**\n * The interaction that triggers the popover.\n *\n * - `hover`: means the popover will open when you hover with mouse or focus with keyboard on the popover trigger.\n * - `click`: means the popover will open on click or press `Enter` to `Space` on keyboard.\n *\n * @default 'click'\n */\n trigger?: \"click\" | \"hover\" | \"never\" | \"contextmenu\"\n /**\n * The number of delay time to open.\n *\n * @default 200\n */\n openDelay?: number\n /**\n * The number of delay time to close.\n *\n * @default 200\n */\n closeDelay?: number\n /**\n * If `true`, the PopoverContent rendering will be deferred until the popover is open.\n *\n * @default false\n */\n isLazy?: boolean\n /**\n * The lazy behavior of popover's content when not visible. Only works when `isLazy={true}`\n *\n * - `unmount`: The popover's content is always unmounted when not open.\n * - `keepMounted`: The popover's content initially unmounted, but stays mounted when popover is open.\n *\n * @default 'unmount'\n */\n lazyBehavior?: LazyMode\n /**\n * The animation of the popover.\n *\n * @default 'scale'\n */\n animation?: \"scale\" | \"top\" | \"right\" | \"left\" | \"bottom\" | \"none\"\n /**\n * The animation duration.\n */\n duration?: MotionTransitionProps[\"duration\"]\n}\n\nexport interface PopoverProps\n extends ThemeProps<\"Popover\">,\n Omit<UsePopperProps, \"enabled\">,\n PropsWithChildren<PopoverOptions> {}\n\ninterface PopoverContext\n extends Pick<\n PopoverOptions,\n \"isOpen\" | \"onClose\" | \"closeOnButton\" | \"animation\" | \"duration\"\n > {\n onAnimationComplete: () => void\n forceUpdate: () => void | undefined\n getTriggerProps: PropGetter\n getAnchorProps: PropGetter\n getPopperProps: PropGetter<ComponentProps<\"div\">>\n getPopoverProps: PropGetter<MotionProps<\"section\">, MotionProps<\"section\">>\n styles: { [key: string]: CSSUIObject }\n}\n\nconst [PopoverProvider, usePopover] = createContext<PopoverContext>({\n strict: false,\n name: \"PopoverContext\",\n})\n\nexport { usePopover }\n\n/**\n * `Popover` is a component that floats around an element to display information.\n *\n * @see Docs https://yamada-ui.com/components/overlay/popover\n */\nexport const Popover: FC<PopoverProps> = (props) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Popover\", props)\n const {\n children,\n initialFocusRef,\n restoreFocus = true,\n autoFocus = true,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnButton = true,\n trigger = \"click\",\n openDelay = 200,\n closeDelay = 200,\n isLazy,\n lazyBehavior = \"unmount\",\n animation = \"scale\",\n duration,\n relatedRef,\n ...rest\n } = omitThemeProps(mergedProps)\n\n const { isOpen, onOpen, onClose, onToggle } = useDisclosure(mergedProps)\n\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLElement>(null)\n const popoverRef = useRef<HTMLElement>(null)\n\n const { present, onAnimationComplete } = useAnimationObserver({\n isOpen,\n ref: popoverRef,\n })\n\n const openTimeout = useRef<number | undefined>(undefined)\n const closeTimeout = useRef<number | undefined>(undefined)\n\n const isHoveringRef = useRef(false)\n\n const hasBeenOpened = useRef(false)\n\n if (isOpen) hasBeenOpened.current = true\n\n const { referenceRef, getPopperProps, forceUpdate, transformOrigin } =\n usePopper({\n ...rest,\n enabled: isOpen,\n })\n\n useEffect(() => {\n return () => {\n if (openTimeout.current) clearTimeout(openTimeout.current)\n\n if (closeTimeout.current) clearTimeout(closeTimeout.current)\n }\n }, [])\n\n useFocusOnPointerDown({\n enabled: isOpen,\n ref: triggerRef,\n })\n\n useFocusOnHide(popoverRef, {\n focusRef: triggerRef,\n visible: isOpen,\n shouldFocus:\n restoreFocus && (trigger === \"click\" || trigger === \"contextmenu\"),\n })\n\n useFocusOnShow(popoverRef, {\n focusRef: initialFocusRef,\n visible: isOpen,\n shouldFocus:\n autoFocus && (trigger === \"click\" || trigger === \"contextmenu\"),\n })\n\n const shouldRenderChildren = useLazyDisclosure({\n wasSelected: hasBeenOpened.current,\n enabled: isLazy,\n mode: lazyBehavior,\n isSelected: present,\n })\n\n const getPopoverProps: PropGetter<\n MotionProps<\"section\">,\n MotionProps<\"section\">\n > = useCallback(\n (props = {}, ref = null) => {\n const popoverProps: MotionProps & RefAttributes<any> = {\n ...props,\n style: {\n ...props.style,\n transformOrigin,\n },\n ref: mergeRefs(popoverRef, ref),\n children: shouldRenderChildren ? props.children : null,\n tabIndex: -1,\n onKeyDown: handlerAll(props.onKeyDown, (ev) => {\n if (closeOnEsc && ev.key === \"Escape\") onClose()\n }),\n onBlur: handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const targetIsPopover = isContains(popoverRef.current, relatedTarget)\n const targetIsTrigger = isContains(triggerRef.current, relatedTarget)\n const targetIsRelated = relatedRef?.current\n ? isContains(relatedRef.current, relatedTarget)\n : false\n\n const isValidBlur =\n !targetIsPopover && !targetIsTrigger && !targetIsRelated\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n }),\n }\n\n if (trigger === \"hover\") {\n popoverProps.onMouseEnter = handlerAll(props.onMouseEnter, () => {\n isHoveringRef.current = true\n })\n\n popoverProps.onMouseLeave = handlerAll(props.onMouseLeave, (ev) => {\n if (ev.nativeEvent.relatedTarget === null) return\n\n isHoveringRef.current = false\n\n if (closeOnBlur) setTimeout(onClose, closeDelay)\n })\n }\n\n return popoverProps\n },\n [\n closeDelay,\n closeOnBlur,\n closeOnEsc,\n isOpen,\n onClose,\n shouldRenderChildren,\n transformOrigin,\n trigger,\n relatedRef,\n ],\n )\n\n const maybeReferenceRef = useCallback(\n (node: Element) => {\n if (anchorRef.current == null) referenceRef(node)\n },\n [referenceRef],\n )\n\n const getTriggerProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const triggerProps: HTMLUIPropsWithRef = {\n ...props,\n ref: mergeRefs(triggerRef, ref, maybeReferenceRef),\n }\n\n if (trigger === \"click\") {\n triggerProps.onClick = handlerAll(props.onClick, onToggle)\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n }\n\n if (trigger === \"contextmenu\") {\n triggerProps.onContextMenu = handlerAll(props.onContextMenu, (ev) => {\n ev.preventDefault()\n onOpen()\n })\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n }\n\n if (trigger === \"hover\") {\n triggerProps.onFocus = handlerAll(props.onFocus, () => {\n if (openTimeout.current === undefined) onOpen()\n })\n\n triggerProps.onBlur = handlerAll(props.onBlur, (ev) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const isValidBlur = !isContains(popoverRef.current, relatedTarget)\n\n if (isOpen && closeOnBlur && isValidBlur) onClose()\n })\n\n triggerProps.onKeyDown = handlerAll(props.onKeyDown, (ev) => {\n if (ev.key === \"Escape\") onClose()\n })\n\n triggerProps.onMouseEnter = handlerAll(props.onMouseEnter, () => {\n isHoveringRef.current = true\n openTimeout.current = window.setTimeout(onOpen, openDelay)\n })\n\n triggerProps.onMouseLeave = handlerAll(props.onMouseLeave, () => {\n isHoveringRef.current = false\n\n if (openTimeout.current) {\n clearTimeout(openTimeout.current)\n openTimeout.current = undefined\n }\n\n closeTimeout.current = window.setTimeout(() => {\n if (!isHoveringRef.current) onClose()\n }, closeDelay)\n })\n }\n\n return triggerProps\n },\n [\n closeDelay,\n closeOnBlur,\n isOpen,\n maybeReferenceRef,\n onClose,\n onOpen,\n onToggle,\n openDelay,\n trigger,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n return {\n ...props,\n ref: mergeRefs(ref, anchorRef, referenceRef),\n }\n },\n [anchorRef, referenceRef],\n )\n\n return (\n <PopoverProvider\n value={{\n isOpen,\n onClose,\n closeOnButton,\n onAnimationComplete,\n forceUpdate,\n getTriggerProps,\n getAnchorProps,\n getPopperProps,\n getPopoverProps,\n animation,\n duration,\n styles,\n }}\n >\n {runIfFunc(children, {\n isOpen,\n onClose,\n forceUpdate,\n })}\n </PopoverProvider>\n )\n}\n\nPopover.displayName = \"Popover\"\nPopover.__ui__ = \"Popover\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAuC;;;ACKvC,kBAAuD;AAEvD,2BAAqC;AAErC,4BAAiD;AACjD,uBAIO;AAEP,wBAA4C;AAC5C,mBAOO;AAOP,mBAA+C;AA4Z3C;AAxZG,IAAM,oBAAoB;AAAA,EAC/B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GAAG,MAAM,SAAS;AAC1B,aAAO;AAAA,QACL,GAAGA;AAAA,QACH,SAAK,wBAAU,KAAK,WAAW,YAAY;AAAA,MAC7C;AAAA,IACF;AAAA,IACA,CAAC,WAAW,YAAY;AAAA,EAC1B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MAEC,sCAAU,UAAU;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA;AAAA,EACH;AAEJ;AAEA,QAAQ,cAAc;AACtB,QAAQ,SAAS;;;ADldV,IAAM,gBAA2C,CAAC,EAAE,SAAS,MAAM;AACxE,QAAM,QAAQ,uBAAS,KAAK,QAAQ;AAGpC,QAAM,EAAE,eAAe,IAAI,WAAW;AAEtC,aAAO,4BAAa,OAAO,eAAe,MAAM,OAAO,MAAM,GAAG,CAAC;AACnE;AAEA,cAAc,cAAc;AAC5B,cAAc,SAAS;","names":["import_react","props"]}
@@ -1,8 +1,8 @@
1
1
  "use client"
2
2
  import {
3
3
  PopoverAnchor
4
- } from "./chunk-MLEEMVQI.mjs";
5
- import "./chunk-L5V3DH65.mjs";
4
+ } from "./chunk-FIADAGVP.mjs";
5
+ import "./chunk-6THCC2BT.mjs";
6
6
  export {
7
7
  PopoverAnchor
8
8
  };
@@ -60,6 +60,224 @@ var [PopoverProvider, usePopover] = (0, import_utils.createContext)({
60
60
  strict: false,
61
61
  name: "PopoverContext"
62
62
  });
63
+ var Popover = (props) => {
64
+ const [styles, mergedProps] = (0, import_core.useComponentMultiStyle)("Popover", props);
65
+ const {
66
+ children,
67
+ initialFocusRef,
68
+ restoreFocus = true,
69
+ autoFocus = true,
70
+ closeOnBlur = true,
71
+ closeOnEsc = true,
72
+ closeOnButton = true,
73
+ trigger = "click",
74
+ openDelay = 200,
75
+ closeDelay = 200,
76
+ isLazy,
77
+ lazyBehavior = "unmount",
78
+ animation = "scale",
79
+ duration,
80
+ relatedRef,
81
+ ...rest
82
+ } = (0, import_core.omitThemeProps)(mergedProps);
83
+ const { isOpen, onOpen, onClose, onToggle } = (0, import_use_disclosure.useDisclosure)(mergedProps);
84
+ const anchorRef = (0, import_react.useRef)(null);
85
+ const triggerRef = (0, import_react.useRef)(null);
86
+ const popoverRef = (0, import_react.useRef)(null);
87
+ const { present, onAnimationComplete } = (0, import_use_animation.useAnimationObserver)({
88
+ isOpen,
89
+ ref: popoverRef
90
+ });
91
+ const openTimeout = (0, import_react.useRef)(void 0);
92
+ const closeTimeout = (0, import_react.useRef)(void 0);
93
+ const isHoveringRef = (0, import_react.useRef)(false);
94
+ const hasBeenOpened = (0, import_react.useRef)(false);
95
+ if (isOpen) hasBeenOpened.current = true;
96
+ const { referenceRef, getPopperProps, forceUpdate, transformOrigin } = (0, import_use_popper.usePopper)({
97
+ ...rest,
98
+ enabled: isOpen
99
+ });
100
+ (0, import_react.useEffect)(() => {
101
+ return () => {
102
+ if (openTimeout.current) clearTimeout(openTimeout.current);
103
+ if (closeTimeout.current) clearTimeout(closeTimeout.current);
104
+ };
105
+ }, []);
106
+ (0, import_use_focus.useFocusOnPointerDown)({
107
+ enabled: isOpen,
108
+ ref: triggerRef
109
+ });
110
+ (0, import_use_focus.useFocusOnHide)(popoverRef, {
111
+ focusRef: triggerRef,
112
+ visible: isOpen,
113
+ shouldFocus: restoreFocus && (trigger === "click" || trigger === "contextmenu")
114
+ });
115
+ (0, import_use_focus.useFocusOnShow)(popoverRef, {
116
+ focusRef: initialFocusRef,
117
+ visible: isOpen,
118
+ shouldFocus: autoFocus && (trigger === "click" || trigger === "contextmenu")
119
+ });
120
+ const shouldRenderChildren = (0, import_use_disclosure.useLazyDisclosure)({
121
+ wasSelected: hasBeenOpened.current,
122
+ enabled: isLazy,
123
+ mode: lazyBehavior,
124
+ isSelected: present
125
+ });
126
+ const getPopoverProps = (0, import_react.useCallback)(
127
+ (props2 = {}, ref = null) => {
128
+ const popoverProps = {
129
+ ...props2,
130
+ style: {
131
+ ...props2.style,
132
+ transformOrigin
133
+ },
134
+ ref: (0, import_utils.mergeRefs)(popoverRef, ref),
135
+ children: shouldRenderChildren ? props2.children : null,
136
+ tabIndex: -1,
137
+ onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, (ev) => {
138
+ if (closeOnEsc && ev.key === "Escape") onClose();
139
+ }),
140
+ onBlur: (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
141
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
142
+ const targetIsPopover = (0, import_utils.isContains)(popoverRef.current, relatedTarget);
143
+ const targetIsTrigger = (0, import_utils.isContains)(triggerRef.current, relatedTarget);
144
+ const targetIsRelated = (relatedRef == null ? void 0 : relatedRef.current) ? (0, import_utils.isContains)(relatedRef.current, relatedTarget) : false;
145
+ const isValidBlur = !targetIsPopover && !targetIsTrigger && !targetIsRelated;
146
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
147
+ })
148
+ };
149
+ if (trigger === "hover") {
150
+ popoverProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
151
+ isHoveringRef.current = true;
152
+ });
153
+ popoverProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, (ev) => {
154
+ if (ev.nativeEvent.relatedTarget === null) return;
155
+ isHoveringRef.current = false;
156
+ if (closeOnBlur) setTimeout(onClose, closeDelay);
157
+ });
158
+ }
159
+ return popoverProps;
160
+ },
161
+ [
162
+ closeDelay,
163
+ closeOnBlur,
164
+ closeOnEsc,
165
+ isOpen,
166
+ onClose,
167
+ shouldRenderChildren,
168
+ transformOrigin,
169
+ trigger,
170
+ relatedRef
171
+ ]
172
+ );
173
+ const maybeReferenceRef = (0, import_react.useCallback)(
174
+ (node) => {
175
+ if (anchorRef.current == null) referenceRef(node);
176
+ },
177
+ [referenceRef]
178
+ );
179
+ const getTriggerProps = (0, import_react.useCallback)(
180
+ (props2 = {}, ref = null) => {
181
+ const triggerProps = {
182
+ ...props2,
183
+ ref: (0, import_utils.mergeRefs)(triggerRef, ref, maybeReferenceRef)
184
+ };
185
+ if (trigger === "click") {
186
+ triggerProps.onClick = (0, import_utils.handlerAll)(props2.onClick, onToggle);
187
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
188
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
189
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
190
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
191
+ });
192
+ }
193
+ if (trigger === "contextmenu") {
194
+ triggerProps.onContextMenu = (0, import_utils.handlerAll)(props2.onContextMenu, (ev) => {
195
+ ev.preventDefault();
196
+ onOpen();
197
+ });
198
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
199
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
200
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
201
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
202
+ });
203
+ }
204
+ if (trigger === "hover") {
205
+ triggerProps.onFocus = (0, import_utils.handlerAll)(props2.onFocus, () => {
206
+ if (openTimeout.current === void 0) onOpen();
207
+ });
208
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (ev) => {
209
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
210
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
211
+ if (isOpen && closeOnBlur && isValidBlur) onClose();
212
+ });
213
+ triggerProps.onKeyDown = (0, import_utils.handlerAll)(props2.onKeyDown, (ev) => {
214
+ if (ev.key === "Escape") onClose();
215
+ });
216
+ triggerProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
217
+ isHoveringRef.current = true;
218
+ openTimeout.current = window.setTimeout(onOpen, openDelay);
219
+ });
220
+ triggerProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, () => {
221
+ isHoveringRef.current = false;
222
+ if (openTimeout.current) {
223
+ clearTimeout(openTimeout.current);
224
+ openTimeout.current = void 0;
225
+ }
226
+ closeTimeout.current = window.setTimeout(() => {
227
+ if (!isHoveringRef.current) onClose();
228
+ }, closeDelay);
229
+ });
230
+ }
231
+ return triggerProps;
232
+ },
233
+ [
234
+ closeDelay,
235
+ closeOnBlur,
236
+ isOpen,
237
+ maybeReferenceRef,
238
+ onClose,
239
+ onOpen,
240
+ onToggle,
241
+ openDelay,
242
+ trigger
243
+ ]
244
+ );
245
+ const getAnchorProps = (0, import_react.useCallback)(
246
+ (props2 = {}, ref = null) => {
247
+ return {
248
+ ...props2,
249
+ ref: (0, import_utils.mergeRefs)(ref, anchorRef, referenceRef)
250
+ };
251
+ },
252
+ [anchorRef, referenceRef]
253
+ );
254
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
255
+ PopoverProvider,
256
+ {
257
+ value: {
258
+ isOpen,
259
+ onClose,
260
+ closeOnButton,
261
+ onAnimationComplete,
262
+ forceUpdate,
263
+ getTriggerProps,
264
+ getAnchorProps,
265
+ getPopperProps,
266
+ getPopoverProps,
267
+ animation,
268
+ duration,
269
+ styles
270
+ },
271
+ children: (0, import_utils.runIfFunc)(children, {
272
+ isOpen,
273
+ onClose,
274
+ forceUpdate
275
+ })
276
+ }
277
+ );
278
+ };
279
+ Popover.displayName = "Popover";
280
+ Popover.__ui__ = "Popover";
63
281
 
64
282
  // src/popover-body.tsx
65
283
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -83,6 +301,8 @@ var PopoverBody = (0, import_core2.forwardRef)(
83
301
  );
84
302
  }
85
303
  );
304
+ PopoverBody.displayName = "PopoverBody";
305
+ PopoverBody.__ui__ = "PopoverBody";
86
306
  // Annotate the CommonJS export names for ESM import in node:
87
307
  0 && (module.exports = {
88
308
  PopoverBody