@yamada-ui/popover 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/popover.tsx
21
+ var popover_exports = {};
22
+ __export(popover_exports, {
23
+ Popover: () => Popover,
24
+ usePopover: () => usePopover
25
+ });
26
+ module.exports = __toCommonJS(popover_exports);
27
+ var import_core = require("@yamada-ui/core");
28
+ var import_use_animation = require("@yamada-ui/use-animation");
29
+ var import_use_disclosure = require("@yamada-ui/use-disclosure");
30
+ var import_use_focus = require("@yamada-ui/use-focus");
31
+ var import_use_popper = require("@yamada-ui/use-popper");
32
+ var import_utils = require("@yamada-ui/utils");
33
+ var import_react = require("react");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var [PopoverProvider, usePopover] = (0, import_utils.createContext)({
36
+ strict: false,
37
+ name: "PopoverContext"
38
+ });
39
+ var Popover = (props) => {
40
+ const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Popover", props);
41
+ const {
42
+ children,
43
+ initialFocusRef,
44
+ restoreFocus = true,
45
+ autoFocus = true,
46
+ closeOnBlur = true,
47
+ closeOnEsc = true,
48
+ closeOnButton = true,
49
+ trigger = "click",
50
+ openDelay = 200,
51
+ closeDelay = 200,
52
+ isLazy,
53
+ lazyBehavior = "unmount",
54
+ animation = "scale",
55
+ duration,
56
+ ...rest
57
+ } = (0, import_core.omitThemeProps)(mergedProps);
58
+ const [isOpen, onOpen, onClose, onToggle] = (0, import_use_disclosure.useDisclosure)(mergedProps);
59
+ const anchorRef = (0, import_react.useRef)(null);
60
+ const triggerRef = (0, import_react.useRef)(null);
61
+ const popoverRef = (0, import_react.useRef)(null);
62
+ const { present, onAnimationComplete } = (0, import_use_animation.useAnimationObserver)({ isOpen, ref: popoverRef });
63
+ const openTimeout = (0, import_react.useRef)(void 0);
64
+ const closeTimeout = (0, import_react.useRef)(void 0);
65
+ const isHoveringRef = (0, import_react.useRef)(false);
66
+ const hasBeenOpened = (0, import_react.useRef)(false);
67
+ if (isOpen)
68
+ hasBeenOpened.current = true;
69
+ const { referenceRef, getPopperProps, forceUpdate, transformOrigin } = (0, import_use_popper.usePopper)({
70
+ ...rest,
71
+ enabled: isOpen
72
+ });
73
+ (0, import_react.useEffect)(() => {
74
+ return () => {
75
+ if (openTimeout.current)
76
+ clearTimeout(openTimeout.current);
77
+ if (closeTimeout.current)
78
+ clearTimeout(closeTimeout.current);
79
+ };
80
+ }, []);
81
+ (0, import_use_focus.useFocusOnPointerDown)({
82
+ enabled: isOpen,
83
+ ref: triggerRef
84
+ });
85
+ (0, import_use_focus.useFocusOnHide)(popoverRef, {
86
+ focusRef: triggerRef,
87
+ visible: isOpen,
88
+ shouldFocus: restoreFocus && trigger === "click"
89
+ });
90
+ (0, import_use_focus.useFocusOnShow)(popoverRef, {
91
+ focusRef: initialFocusRef,
92
+ visible: isOpen,
93
+ shouldFocus: autoFocus && trigger === "click"
94
+ });
95
+ const shouldRenderChildren = (0, import_use_disclosure.useLazyDisclosure)({
96
+ wasSelected: hasBeenOpened.current,
97
+ enabled: isLazy,
98
+ mode: lazyBehavior,
99
+ isSelected: present
100
+ });
101
+ const getPopoverProps = (0, import_react.useCallback)(
102
+ (props2 = {}, ref = null) => {
103
+ const popoverProps = {
104
+ ...props2,
105
+ style: {
106
+ ...props2.style,
107
+ transformOrigin
108
+ },
109
+ ref: (0, import_utils.mergeRefs)(popoverRef, ref),
110
+ children: shouldRenderChildren ? props2.children : null,
111
+ tabIndex: -1,
112
+ onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, (event) => {
113
+ if (closeOnEsc && event.key === "Escape")
114
+ onClose();
115
+ }),
116
+ onBlur: (0, import_utils.handlerAll)(props2.onBlur, (event) => {
117
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(event);
118
+ const targetIsPopover = (0, import_utils.isContains)(popoverRef.current, relatedTarget);
119
+ const targetIsTrigger = (0, import_utils.isContains)(triggerRef.current, relatedTarget);
120
+ const isValidBlur = !targetIsPopover && !targetIsTrigger;
121
+ if (isOpen && closeOnBlur && isValidBlur)
122
+ onClose();
123
+ })
124
+ };
125
+ if (trigger === "hover") {
126
+ popoverProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
127
+ isHoveringRef.current = true;
128
+ });
129
+ popoverProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, (event) => {
130
+ if (event.nativeEvent.relatedTarget === null)
131
+ return;
132
+ isHoveringRef.current = false;
133
+ setTimeout(onClose, closeDelay);
134
+ });
135
+ }
136
+ return popoverProps;
137
+ },
138
+ [
139
+ closeDelay,
140
+ closeOnBlur,
141
+ closeOnEsc,
142
+ isOpen,
143
+ onClose,
144
+ shouldRenderChildren,
145
+ transformOrigin,
146
+ trigger
147
+ ]
148
+ );
149
+ const maybeReferenceRef = (0, import_react.useCallback)(
150
+ (node) => {
151
+ if (anchorRef.current == null)
152
+ referenceRef(node);
153
+ },
154
+ [referenceRef]
155
+ );
156
+ const getTriggerProps = (0, import_react.useCallback)(
157
+ (props2 = {}, ref = null) => {
158
+ const triggerProps = {
159
+ ...props2,
160
+ ref: (0, import_utils.mergeRefs)(triggerRef, ref, maybeReferenceRef)
161
+ };
162
+ if (trigger === "click")
163
+ triggerProps.onClick = (0, import_utils.handlerAll)(props2.onClick, onToggle);
164
+ if (trigger === "hover") {
165
+ triggerProps.onFocus = (0, import_utils.handlerAll)(props2.onFocus, () => {
166
+ if (openTimeout.current === void 0)
167
+ onOpen();
168
+ });
169
+ triggerProps.onBlur = (0, import_utils.handlerAll)(props2.onBlur, (event) => {
170
+ const relatedTarget = (0, import_utils.getEventRelatedTarget)(event);
171
+ const isValidBlur = !(0, import_utils.isContains)(popoverRef.current, relatedTarget);
172
+ if (isOpen && closeOnBlur && isValidBlur)
173
+ onClose();
174
+ });
175
+ triggerProps.onKeyDown = (0, import_utils.handlerAll)(props2.onKeyDown, (event) => {
176
+ if (event.key === "Escape")
177
+ onClose();
178
+ });
179
+ triggerProps.onMouseEnter = (0, import_utils.handlerAll)(props2.onMouseEnter, () => {
180
+ isHoveringRef.current = true;
181
+ openTimeout.current = window.setTimeout(onOpen, openDelay);
182
+ });
183
+ triggerProps.onMouseLeave = (0, import_utils.handlerAll)(props2.onMouseLeave, () => {
184
+ isHoveringRef.current = false;
185
+ if (openTimeout.current) {
186
+ clearTimeout(openTimeout.current);
187
+ openTimeout.current = void 0;
188
+ }
189
+ closeTimeout.current = window.setTimeout(() => {
190
+ if (isHoveringRef.current === false)
191
+ onClose();
192
+ }, closeDelay);
193
+ });
194
+ }
195
+ return triggerProps;
196
+ },
197
+ [
198
+ closeDelay,
199
+ closeOnBlur,
200
+ isOpen,
201
+ maybeReferenceRef,
202
+ onClose,
203
+ onOpen,
204
+ onToggle,
205
+ openDelay,
206
+ trigger
207
+ ]
208
+ );
209
+ const getAnchorProps = (0, import_react.useCallback)(
210
+ (props2 = {}, ref = null) => {
211
+ return {
212
+ ...props2,
213
+ ref: (0, import_utils.mergeRefs)(ref, anchorRef, referenceRef)
214
+ };
215
+ },
216
+ [anchorRef, referenceRef]
217
+ );
218
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
219
+ PopoverProvider,
220
+ {
221
+ value: {
222
+ isOpen,
223
+ onClose,
224
+ closeOnButton,
225
+ onAnimationComplete,
226
+ forceUpdate,
227
+ getTriggerProps,
228
+ getAnchorProps,
229
+ getPopperProps,
230
+ getPopoverProps,
231
+ animation,
232
+ duration,
233
+ styles
234
+ },
235
+ children: (0, import_utils.runIfFunc)(children, {
236
+ isOpen,
237
+ onClose,
238
+ forceUpdate
239
+ })
240
+ }
241
+ );
242
+ };
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ Popover,
246
+ usePopover
247
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ Popover,
3
+ usePopover
4
+ } from "./chunk-DQEXAU5O.mjs";
5
+ export {
6
+ Popover,
7
+ usePopover
8
+ };
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@yamada-ui/popover",
3
+ "version": "0.1.0",
4
+ "description": "Yamada UI popover component",
5
+ "keywords": [
6
+ "yamada",
7
+ "yamada ui",
8
+ "react",
9
+ "emotion",
10
+ "component",
11
+ "popover",
12
+ "ui",
13
+ "uikit",
14
+ "styled",
15
+ "style-props",
16
+ "styled-component",
17
+ "css-in-js"
18
+ ],
19
+ "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
20
+ "license": "MIT",
21
+ "main": "dist/index.js",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/hirotomoyamada/yamada-ui",
32
+ "directory": "packages/components/popover"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
36
+ },
37
+ "dependencies": {
38
+ "@yamada-ui/core": "0.1.0",
39
+ "@yamada-ui/utils": "0.1.0",
40
+ "@yamada-ui/transitions": "0.1.0",
41
+ "@yamada-ui/close-button": "0.1.0",
42
+ "@yamada-ui/motion": "0.1.0",
43
+ "@yamada-ui/use-animation": "0.1.0",
44
+ "@yamada-ui/use-disclosure": "0.1.0",
45
+ "@yamada-ui/use-popper": "0.1.0",
46
+ "@yamada-ui/use-focus": "0.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "react": "^18.0.0",
50
+ "clean-package": "2.2.0"
51
+ },
52
+ "peerDependencies": {
53
+ "react": ">=18"
54
+ },
55
+ "clean-package": "../../../clean-package.config.json",
56
+ "tsup": {
57
+ "clean": true,
58
+ "target": "es2019",
59
+ "format": [
60
+ "cjs",
61
+ "esm"
62
+ ]
63
+ },
64
+ "module": "dist/index.mjs",
65
+ "types": "dist/index.d.ts",
66
+ "exports": {
67
+ ".": {
68
+ "types": "./dist/index.d.ts",
69
+ "import": "./dist/index.mjs",
70
+ "require": "./dist/index.js"
71
+ },
72
+ "./package.json": "./package.json"
73
+ },
74
+ "scripts": {
75
+ "dev": "pnpm build:fast -- --watch",
76
+ "build": "tsup src --dts",
77
+ "build:fast": "tsup src",
78
+ "clean": "rimraf dist .turbo",
79
+ "typecheck": "tsc --noEmit",
80
+ "gen:docs": "tsx ../../../scripts/generate-docs"
81
+ }
82
+ }