@x-plat/design-system 0.14.12 → 0.14.13
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.
- package/dist/components/Dropdown/index.cjs +17 -8
- package/dist/components/Dropdown/index.js +17 -8
- package/dist/components/PopOver/index.cjs +16 -8
- package/dist/components/PopOver/index.js +16 -8
- package/dist/components/Select/index.cjs +17 -8
- package/dist/components/Select/index.js +17 -8
- package/dist/components/TimePicker/index.cjs +15 -6
- package/dist/components/TimePicker/index.js +15 -6
- package/dist/components/index.cjs +20 -12
- package/dist/components/index.js +20 -12
- package/dist/index.cjs +20 -12
- package/dist/index.js +20 -12
- package/package.json +1 -1
|
@@ -98,15 +98,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
101
|
-
const [direction, setDirection] = import_react.default.useState("bottom");
|
|
102
101
|
const directionRef = import_react.default.useRef("bottom");
|
|
103
102
|
const sizeRef = import_react.default.useRef(null);
|
|
104
103
|
const scrollParentRef = import_react.default.useRef(null);
|
|
104
|
+
const placedRef = import_react.default.useRef(false);
|
|
105
105
|
const calculatePosition = import_react.default.useCallback((remeasure = false) => {
|
|
106
106
|
const pop = popRef.current;
|
|
107
107
|
if (!triggerRef.current || !pop) return;
|
|
108
108
|
if (remeasure || !sizeRef.current) {
|
|
109
|
-
sizeRef.current = {
|
|
109
|
+
sizeRef.current = {
|
|
110
|
+
w: pop.offsetWidth,
|
|
111
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
112
|
+
};
|
|
110
113
|
}
|
|
111
114
|
const { w: popW, h: popH } = sizeRef.current;
|
|
112
115
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -121,6 +124,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
121
124
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
122
125
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
123
126
|
};
|
|
127
|
+
const first = !placedRef.current;
|
|
128
|
+
if (first) pop.style.transition = "none";
|
|
124
129
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
125
130
|
triggerRect,
|
|
126
131
|
popW,
|
|
@@ -131,15 +136,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
131
136
|
pop.style.left = `${left + window.scrollX}px`;
|
|
132
137
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
133
138
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
directionRef.current = next;
|
|
140
|
+
pop.classList.toggle("top", next === "top");
|
|
141
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
142
|
+
if (first) {
|
|
143
|
+
void pop.offsetHeight;
|
|
144
|
+
pop.style.transition = "";
|
|
145
|
+
placedRef.current = true;
|
|
137
146
|
}
|
|
138
147
|
}, [triggerRef, popRef]);
|
|
139
148
|
import_react.default.useLayoutEffect(() => {
|
|
140
149
|
if (!enabled) {
|
|
141
150
|
sizeRef.current = null;
|
|
142
151
|
scrollParentRef.current = null;
|
|
152
|
+
placedRef.current = false;
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
155
|
if (triggerRef.current) {
|
|
@@ -168,7 +178,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
168
178
|
window.removeEventListener("scroll", onScroll, true);
|
|
169
179
|
};
|
|
170
180
|
}, [calculatePosition, enabled]);
|
|
171
|
-
return { direction };
|
|
172
181
|
};
|
|
173
182
|
var useAutoPosition_default = useAutoPosition;
|
|
174
183
|
|
|
@@ -263,7 +272,7 @@ var Dropdown = (props) => {
|
|
|
263
272
|
const [visible, setVisible] = import_react4.default.useState(false);
|
|
264
273
|
const triggerRef = import_react4.default.useRef(null);
|
|
265
274
|
const menuRef = import_react4.default.useRef(null);
|
|
266
|
-
|
|
275
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
267
276
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
268
277
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
269
278
|
useEscapeKey(isOpen, () => {
|
|
@@ -299,7 +308,7 @@ var Dropdown = (props) => {
|
|
|
299
308
|
"div",
|
|
300
309
|
{
|
|
301
310
|
ref: menuRef,
|
|
302
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
311
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
303
312
|
role: "menu",
|
|
304
313
|
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
305
314
|
"button",
|
|
@@ -62,15 +62,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
65
|
-
const [direction, setDirection] = React.useState("bottom");
|
|
66
65
|
const directionRef = React.useRef("bottom");
|
|
67
66
|
const sizeRef = React.useRef(null);
|
|
68
67
|
const scrollParentRef = React.useRef(null);
|
|
68
|
+
const placedRef = React.useRef(false);
|
|
69
69
|
const calculatePosition = React.useCallback((remeasure = false) => {
|
|
70
70
|
const pop = popRef.current;
|
|
71
71
|
if (!triggerRef.current || !pop) return;
|
|
72
72
|
if (remeasure || !sizeRef.current) {
|
|
73
|
-
sizeRef.current = {
|
|
73
|
+
sizeRef.current = {
|
|
74
|
+
w: pop.offsetWidth,
|
|
75
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
const { w: popW, h: popH } = sizeRef.current;
|
|
76
79
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -85,6 +88,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
85
88
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
86
89
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
87
90
|
};
|
|
91
|
+
const first = !placedRef.current;
|
|
92
|
+
if (first) pop.style.transition = "none";
|
|
88
93
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
89
94
|
triggerRect,
|
|
90
95
|
popW,
|
|
@@ -95,15 +100,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
95
100
|
pop.style.left = `${left + window.scrollX}px`;
|
|
96
101
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
97
102
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
directionRef.current = next;
|
|
104
|
+
pop.classList.toggle("top", next === "top");
|
|
105
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
106
|
+
if (first) {
|
|
107
|
+
void pop.offsetHeight;
|
|
108
|
+
pop.style.transition = "";
|
|
109
|
+
placedRef.current = true;
|
|
101
110
|
}
|
|
102
111
|
}, [triggerRef, popRef]);
|
|
103
112
|
React.useLayoutEffect(() => {
|
|
104
113
|
if (!enabled) {
|
|
105
114
|
sizeRef.current = null;
|
|
106
115
|
scrollParentRef.current = null;
|
|
116
|
+
placedRef.current = false;
|
|
107
117
|
return;
|
|
108
118
|
}
|
|
109
119
|
if (triggerRef.current) {
|
|
@@ -132,7 +142,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
132
142
|
window.removeEventListener("scroll", onScroll, true);
|
|
133
143
|
};
|
|
134
144
|
}, [calculatePosition, enabled]);
|
|
135
|
-
return { direction };
|
|
136
145
|
};
|
|
137
146
|
var useAutoPosition_default = useAutoPosition;
|
|
138
147
|
|
|
@@ -227,7 +236,7 @@ var Dropdown = (props) => {
|
|
|
227
236
|
const [visible, setVisible] = React4.useState(false);
|
|
228
237
|
const triggerRef = React4.useRef(null);
|
|
229
238
|
const menuRef = React4.useRef(null);
|
|
230
|
-
|
|
239
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
231
240
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
232
241
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
233
242
|
useEscapeKey(isOpen, () => {
|
|
@@ -263,7 +272,7 @@ var Dropdown = (props) => {
|
|
|
263
272
|
"div",
|
|
264
273
|
{
|
|
265
274
|
ref: menuRef,
|
|
266
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
275
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
267
276
|
role: "menu",
|
|
268
277
|
children: items.map((item) => /* @__PURE__ */ jsx(
|
|
269
278
|
"button",
|
|
@@ -98,15 +98,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
101
|
-
const [direction, setDirection] = import_react.default.useState("bottom");
|
|
102
101
|
const directionRef = import_react.default.useRef("bottom");
|
|
103
102
|
const sizeRef = import_react.default.useRef(null);
|
|
104
103
|
const scrollParentRef = import_react.default.useRef(null);
|
|
104
|
+
const placedRef = import_react.default.useRef(false);
|
|
105
105
|
const calculatePosition = import_react.default.useCallback((remeasure = false) => {
|
|
106
106
|
const pop = popRef.current;
|
|
107
107
|
if (!triggerRef.current || !pop) return;
|
|
108
108
|
if (remeasure || !sizeRef.current) {
|
|
109
|
-
sizeRef.current = {
|
|
109
|
+
sizeRef.current = {
|
|
110
|
+
w: pop.offsetWidth,
|
|
111
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
112
|
+
};
|
|
110
113
|
}
|
|
111
114
|
const { w: popW, h: popH } = sizeRef.current;
|
|
112
115
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -121,6 +124,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
121
124
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
122
125
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
123
126
|
};
|
|
127
|
+
const first = !placedRef.current;
|
|
128
|
+
if (first) pop.style.transition = "none";
|
|
124
129
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
125
130
|
triggerRect,
|
|
126
131
|
popW,
|
|
@@ -131,15 +136,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
131
136
|
pop.style.left = `${left + window.scrollX}px`;
|
|
132
137
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
133
138
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
directionRef.current = next;
|
|
140
|
+
pop.classList.toggle("top", next === "top");
|
|
141
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
142
|
+
if (first) {
|
|
143
|
+
void pop.offsetHeight;
|
|
144
|
+
pop.style.transition = "";
|
|
145
|
+
placedRef.current = true;
|
|
137
146
|
}
|
|
138
147
|
}, [triggerRef, popRef]);
|
|
139
148
|
import_react.default.useLayoutEffect(() => {
|
|
140
149
|
if (!enabled) {
|
|
141
150
|
sizeRef.current = null;
|
|
142
151
|
scrollParentRef.current = null;
|
|
152
|
+
placedRef.current = false;
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
155
|
if (triggerRef.current) {
|
|
@@ -168,7 +178,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
168
178
|
window.removeEventListener("scroll", onScroll, true);
|
|
169
179
|
};
|
|
170
180
|
}, [calculatePosition, enabled]);
|
|
171
|
-
return { direction };
|
|
172
181
|
};
|
|
173
182
|
var useAutoPosition_default = useAutoPosition;
|
|
174
183
|
|
|
@@ -268,7 +277,7 @@ var PopOver = (props) => {
|
|
|
268
277
|
onClose();
|
|
269
278
|
triggerRef.current?.focus({ preventScroll: true });
|
|
270
279
|
});
|
|
271
|
-
|
|
280
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
272
281
|
import_react4.default.useEffect(() => {
|
|
273
282
|
if (isOpen) {
|
|
274
283
|
setLocalOpen(isOpen);
|
|
@@ -297,7 +306,6 @@ var PopOver = (props) => {
|
|
|
297
306
|
{
|
|
298
307
|
className: clsx_default(
|
|
299
308
|
"lib-xplat-pop-over-content",
|
|
300
|
-
position.direction,
|
|
301
309
|
eventTrigger && "visible"
|
|
302
310
|
),
|
|
303
311
|
ref: popRef,
|
|
@@ -62,15 +62,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
65
|
-
const [direction, setDirection] = React.useState("bottom");
|
|
66
65
|
const directionRef = React.useRef("bottom");
|
|
67
66
|
const sizeRef = React.useRef(null);
|
|
68
67
|
const scrollParentRef = React.useRef(null);
|
|
68
|
+
const placedRef = React.useRef(false);
|
|
69
69
|
const calculatePosition = React.useCallback((remeasure = false) => {
|
|
70
70
|
const pop = popRef.current;
|
|
71
71
|
if (!triggerRef.current || !pop) return;
|
|
72
72
|
if (remeasure || !sizeRef.current) {
|
|
73
|
-
sizeRef.current = {
|
|
73
|
+
sizeRef.current = {
|
|
74
|
+
w: pop.offsetWidth,
|
|
75
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
const { w: popW, h: popH } = sizeRef.current;
|
|
76
79
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -85,6 +88,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
85
88
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
86
89
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
87
90
|
};
|
|
91
|
+
const first = !placedRef.current;
|
|
92
|
+
if (first) pop.style.transition = "none";
|
|
88
93
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
89
94
|
triggerRect,
|
|
90
95
|
popW,
|
|
@@ -95,15 +100,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
95
100
|
pop.style.left = `${left + window.scrollX}px`;
|
|
96
101
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
97
102
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
directionRef.current = next;
|
|
104
|
+
pop.classList.toggle("top", next === "top");
|
|
105
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
106
|
+
if (first) {
|
|
107
|
+
void pop.offsetHeight;
|
|
108
|
+
pop.style.transition = "";
|
|
109
|
+
placedRef.current = true;
|
|
101
110
|
}
|
|
102
111
|
}, [triggerRef, popRef]);
|
|
103
112
|
React.useLayoutEffect(() => {
|
|
104
113
|
if (!enabled) {
|
|
105
114
|
sizeRef.current = null;
|
|
106
115
|
scrollParentRef.current = null;
|
|
116
|
+
placedRef.current = false;
|
|
107
117
|
return;
|
|
108
118
|
}
|
|
109
119
|
if (triggerRef.current) {
|
|
@@ -132,7 +142,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
132
142
|
window.removeEventListener("scroll", onScroll, true);
|
|
133
143
|
};
|
|
134
144
|
}, [calculatePosition, enabled]);
|
|
135
|
-
return { direction };
|
|
136
145
|
};
|
|
137
146
|
var useAutoPosition_default = useAutoPosition;
|
|
138
147
|
|
|
@@ -232,7 +241,7 @@ var PopOver = (props) => {
|
|
|
232
241
|
onClose();
|
|
233
242
|
triggerRef.current?.focus({ preventScroll: true });
|
|
234
243
|
});
|
|
235
|
-
|
|
244
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
236
245
|
React4.useEffect(() => {
|
|
237
246
|
if (isOpen) {
|
|
238
247
|
setLocalOpen(isOpen);
|
|
@@ -261,7 +270,6 @@ var PopOver = (props) => {
|
|
|
261
270
|
{
|
|
262
271
|
className: clsx_default(
|
|
263
272
|
"lib-xplat-pop-over-content",
|
|
264
|
-
position.direction,
|
|
265
273
|
eventTrigger && "visible"
|
|
266
274
|
),
|
|
267
275
|
ref: popRef,
|
|
@@ -99,15 +99,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
101
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
102
|
-
const [direction, setDirection] = import_react.default.useState("bottom");
|
|
103
102
|
const directionRef = import_react.default.useRef("bottom");
|
|
104
103
|
const sizeRef = import_react.default.useRef(null);
|
|
105
104
|
const scrollParentRef = import_react.default.useRef(null);
|
|
105
|
+
const placedRef = import_react.default.useRef(false);
|
|
106
106
|
const calculatePosition = import_react.default.useCallback((remeasure = false) => {
|
|
107
107
|
const pop = popRef.current;
|
|
108
108
|
if (!triggerRef.current || !pop) return;
|
|
109
109
|
if (remeasure || !sizeRef.current) {
|
|
110
|
-
sizeRef.current = {
|
|
110
|
+
sizeRef.current = {
|
|
111
|
+
w: pop.offsetWidth,
|
|
112
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
113
|
+
};
|
|
111
114
|
}
|
|
112
115
|
const { w: popW, h: popH } = sizeRef.current;
|
|
113
116
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -122,6 +125,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
122
125
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
123
126
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
124
127
|
};
|
|
128
|
+
const first = !placedRef.current;
|
|
129
|
+
if (first) pop.style.transition = "none";
|
|
125
130
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
126
131
|
triggerRect,
|
|
127
132
|
popW,
|
|
@@ -132,15 +137,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
132
137
|
pop.style.left = `${left + window.scrollX}px`;
|
|
133
138
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
134
139
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
directionRef.current = next;
|
|
141
|
+
pop.classList.toggle("top", next === "top");
|
|
142
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
143
|
+
if (first) {
|
|
144
|
+
void pop.offsetHeight;
|
|
145
|
+
pop.style.transition = "";
|
|
146
|
+
placedRef.current = true;
|
|
138
147
|
}
|
|
139
148
|
}, [triggerRef, popRef]);
|
|
140
149
|
import_react.default.useLayoutEffect(() => {
|
|
141
150
|
if (!enabled) {
|
|
142
151
|
sizeRef.current = null;
|
|
143
152
|
scrollParentRef.current = null;
|
|
153
|
+
placedRef.current = false;
|
|
144
154
|
return;
|
|
145
155
|
}
|
|
146
156
|
if (triggerRef.current) {
|
|
@@ -169,7 +179,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
169
179
|
window.removeEventListener("scroll", onScroll, true);
|
|
170
180
|
};
|
|
171
181
|
}, [calculatePosition, enabled]);
|
|
172
|
-
return { direction };
|
|
173
182
|
};
|
|
174
183
|
var useAutoPosition_default = useAutoPosition;
|
|
175
184
|
|
|
@@ -1399,7 +1408,7 @@ var SelectRoot = (props) => {
|
|
|
1399
1408
|
close();
|
|
1400
1409
|
triggerRef.current?.focus({ preventScroll: true });
|
|
1401
1410
|
});
|
|
1402
|
-
|
|
1411
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
1403
1412
|
const setSelected = import_react6.default.useCallback(
|
|
1404
1413
|
(label2, itemValue) => {
|
|
1405
1414
|
if (!isControlled) {
|
|
@@ -1492,7 +1501,7 @@ var SelectRoot = (props) => {
|
|
|
1492
1501
|
mounted && /* @__PURE__ */ (0, import_jsx_runtime297.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime297.jsxs)(
|
|
1493
1502
|
"div",
|
|
1494
1503
|
{
|
|
1495
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
1504
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
1496
1505
|
ref: contentRef,
|
|
1497
1506
|
style: { width: triggerRef.current?.offsetWidth },
|
|
1498
1507
|
role: "listbox",
|
|
@@ -62,15 +62,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
65
|
-
const [direction, setDirection] = React.useState("bottom");
|
|
66
65
|
const directionRef = React.useRef("bottom");
|
|
67
66
|
const sizeRef = React.useRef(null);
|
|
68
67
|
const scrollParentRef = React.useRef(null);
|
|
68
|
+
const placedRef = React.useRef(false);
|
|
69
69
|
const calculatePosition = React.useCallback((remeasure = false) => {
|
|
70
70
|
const pop = popRef.current;
|
|
71
71
|
if (!triggerRef.current || !pop) return;
|
|
72
72
|
if (remeasure || !sizeRef.current) {
|
|
73
|
-
sizeRef.current = {
|
|
73
|
+
sizeRef.current = {
|
|
74
|
+
w: pop.offsetWidth,
|
|
75
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
const { w: popW, h: popH } = sizeRef.current;
|
|
76
79
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -85,6 +88,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
85
88
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
86
89
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
87
90
|
};
|
|
91
|
+
const first = !placedRef.current;
|
|
92
|
+
if (first) pop.style.transition = "none";
|
|
88
93
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
89
94
|
triggerRect,
|
|
90
95
|
popW,
|
|
@@ -95,15 +100,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
95
100
|
pop.style.left = `${left + window.scrollX}px`;
|
|
96
101
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
97
102
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
directionRef.current = next;
|
|
104
|
+
pop.classList.toggle("top", next === "top");
|
|
105
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
106
|
+
if (first) {
|
|
107
|
+
void pop.offsetHeight;
|
|
108
|
+
pop.style.transition = "";
|
|
109
|
+
placedRef.current = true;
|
|
101
110
|
}
|
|
102
111
|
}, [triggerRef, popRef]);
|
|
103
112
|
React.useLayoutEffect(() => {
|
|
104
113
|
if (!enabled) {
|
|
105
114
|
sizeRef.current = null;
|
|
106
115
|
scrollParentRef.current = null;
|
|
116
|
+
placedRef.current = false;
|
|
107
117
|
return;
|
|
108
118
|
}
|
|
109
119
|
if (triggerRef.current) {
|
|
@@ -132,7 +142,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
132
142
|
window.removeEventListener("scroll", onScroll, true);
|
|
133
143
|
};
|
|
134
144
|
}, [calculatePosition, enabled]);
|
|
135
|
-
return { direction };
|
|
136
145
|
};
|
|
137
146
|
var useAutoPosition_default = useAutoPosition;
|
|
138
147
|
|
|
@@ -1362,7 +1371,7 @@ var SelectRoot = (props) => {
|
|
|
1362
1371
|
close();
|
|
1363
1372
|
triggerRef.current?.focus({ preventScroll: true });
|
|
1364
1373
|
});
|
|
1365
|
-
|
|
1374
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
1366
1375
|
const setSelected = React6.useCallback(
|
|
1367
1376
|
(label2, itemValue) => {
|
|
1368
1377
|
if (!isControlled) {
|
|
@@ -1455,7 +1464,7 @@ var SelectRoot = (props) => {
|
|
|
1455
1464
|
mounted && /* @__PURE__ */ jsx297(Portal_default, { children: /* @__PURE__ */ jsxs190(
|
|
1456
1465
|
"div",
|
|
1457
1466
|
{
|
|
1458
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
1467
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
1459
1468
|
ref: contentRef,
|
|
1460
1469
|
style: { width: triggerRef.current?.offsetWidth },
|
|
1461
1470
|
role: "listbox",
|
|
@@ -98,15 +98,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
101
|
-
const [direction, setDirection] = import_react.default.useState("bottom");
|
|
102
101
|
const directionRef = import_react.default.useRef("bottom");
|
|
103
102
|
const sizeRef = import_react.default.useRef(null);
|
|
104
103
|
const scrollParentRef = import_react.default.useRef(null);
|
|
104
|
+
const placedRef = import_react.default.useRef(false);
|
|
105
105
|
const calculatePosition = import_react.default.useCallback((remeasure = false) => {
|
|
106
106
|
const pop = popRef.current;
|
|
107
107
|
if (!triggerRef.current || !pop) return;
|
|
108
108
|
if (remeasure || !sizeRef.current) {
|
|
109
|
-
sizeRef.current = {
|
|
109
|
+
sizeRef.current = {
|
|
110
|
+
w: pop.offsetWidth,
|
|
111
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
112
|
+
};
|
|
110
113
|
}
|
|
111
114
|
const { w: popW, h: popH } = sizeRef.current;
|
|
112
115
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -121,6 +124,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
121
124
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
122
125
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
123
126
|
};
|
|
127
|
+
const first = !placedRef.current;
|
|
128
|
+
if (first) pop.style.transition = "none";
|
|
124
129
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
125
130
|
triggerRect,
|
|
126
131
|
popW,
|
|
@@ -131,15 +136,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
131
136
|
pop.style.left = `${left + window.scrollX}px`;
|
|
132
137
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
133
138
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
directionRef.current = next;
|
|
140
|
+
pop.classList.toggle("top", next === "top");
|
|
141
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
142
|
+
if (first) {
|
|
143
|
+
void pop.offsetHeight;
|
|
144
|
+
pop.style.transition = "";
|
|
145
|
+
placedRef.current = true;
|
|
137
146
|
}
|
|
138
147
|
}, [triggerRef, popRef]);
|
|
139
148
|
import_react.default.useLayoutEffect(() => {
|
|
140
149
|
if (!enabled) {
|
|
141
150
|
sizeRef.current = null;
|
|
142
151
|
scrollParentRef.current = null;
|
|
152
|
+
placedRef.current = false;
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
155
|
if (triggerRef.current) {
|
|
@@ -168,7 +178,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
168
178
|
window.removeEventListener("scroll", onScroll, true);
|
|
169
179
|
};
|
|
170
180
|
}, [calculatePosition, enabled]);
|
|
171
|
-
return { direction };
|
|
172
181
|
};
|
|
173
182
|
var useAutoPosition_default = useAutoPosition;
|
|
174
183
|
|
|
@@ -62,15 +62,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
65
|
-
const [direction, setDirection] = React.useState("bottom");
|
|
66
65
|
const directionRef = React.useRef("bottom");
|
|
67
66
|
const sizeRef = React.useRef(null);
|
|
68
67
|
const scrollParentRef = React.useRef(null);
|
|
68
|
+
const placedRef = React.useRef(false);
|
|
69
69
|
const calculatePosition = React.useCallback((remeasure = false) => {
|
|
70
70
|
const pop = popRef.current;
|
|
71
71
|
if (!triggerRef.current || !pop) return;
|
|
72
72
|
if (remeasure || !sizeRef.current) {
|
|
73
|
-
sizeRef.current = {
|
|
73
|
+
sizeRef.current = {
|
|
74
|
+
w: pop.offsetWidth,
|
|
75
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
const { w: popW, h: popH } = sizeRef.current;
|
|
76
79
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -85,6 +88,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
85
88
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
86
89
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
87
90
|
};
|
|
91
|
+
const first = !placedRef.current;
|
|
92
|
+
if (first) pop.style.transition = "none";
|
|
88
93
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
89
94
|
triggerRect,
|
|
90
95
|
popW,
|
|
@@ -95,15 +100,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
95
100
|
pop.style.left = `${left + window.scrollX}px`;
|
|
96
101
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
97
102
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
directionRef.current = next;
|
|
104
|
+
pop.classList.toggle("top", next === "top");
|
|
105
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
106
|
+
if (first) {
|
|
107
|
+
void pop.offsetHeight;
|
|
108
|
+
pop.style.transition = "";
|
|
109
|
+
placedRef.current = true;
|
|
101
110
|
}
|
|
102
111
|
}, [triggerRef, popRef]);
|
|
103
112
|
React.useLayoutEffect(() => {
|
|
104
113
|
if (!enabled) {
|
|
105
114
|
sizeRef.current = null;
|
|
106
115
|
scrollParentRef.current = null;
|
|
116
|
+
placedRef.current = false;
|
|
107
117
|
return;
|
|
108
118
|
}
|
|
109
119
|
if (triggerRef.current) {
|
|
@@ -132,7 +142,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
132
142
|
window.removeEventListener("scroll", onScroll, true);
|
|
133
143
|
};
|
|
134
144
|
}, [calculatePosition, enabled]);
|
|
135
|
-
return { direction };
|
|
136
145
|
};
|
|
137
146
|
var useAutoPosition_default = useAutoPosition;
|
|
138
147
|
|
|
@@ -4042,15 +4042,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
4042
4042
|
};
|
|
4043
4043
|
};
|
|
4044
4044
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
4045
|
-
const [direction, setDirection] = import_react19.default.useState("bottom");
|
|
4046
4045
|
const directionRef = import_react19.default.useRef("bottom");
|
|
4047
4046
|
const sizeRef = import_react19.default.useRef(null);
|
|
4048
4047
|
const scrollParentRef = import_react19.default.useRef(null);
|
|
4048
|
+
const placedRef = import_react19.default.useRef(false);
|
|
4049
4049
|
const calculatePosition = import_react19.default.useCallback((remeasure = false) => {
|
|
4050
4050
|
const pop = popRef.current;
|
|
4051
4051
|
if (!triggerRef.current || !pop) return;
|
|
4052
4052
|
if (remeasure || !sizeRef.current) {
|
|
4053
|
-
sizeRef.current = {
|
|
4053
|
+
sizeRef.current = {
|
|
4054
|
+
w: pop.offsetWidth,
|
|
4055
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
4056
|
+
};
|
|
4054
4057
|
}
|
|
4055
4058
|
const { w: popW, h: popH } = sizeRef.current;
|
|
4056
4059
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -4065,6 +4068,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
4065
4068
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
4066
4069
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
4067
4070
|
};
|
|
4071
|
+
const first = !placedRef.current;
|
|
4072
|
+
if (first) pop.style.transition = "none";
|
|
4068
4073
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
4069
4074
|
triggerRect,
|
|
4070
4075
|
popW,
|
|
@@ -4075,15 +4080,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
4075
4080
|
pop.style.left = `${left + window.scrollX}px`;
|
|
4076
4081
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
4077
4082
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4083
|
+
directionRef.current = next;
|
|
4084
|
+
pop.classList.toggle("top", next === "top");
|
|
4085
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
4086
|
+
if (first) {
|
|
4087
|
+
void pop.offsetHeight;
|
|
4088
|
+
pop.style.transition = "";
|
|
4089
|
+
placedRef.current = true;
|
|
4081
4090
|
}
|
|
4082
4091
|
}, [triggerRef, popRef]);
|
|
4083
4092
|
import_react19.default.useLayoutEffect(() => {
|
|
4084
4093
|
if (!enabled) {
|
|
4085
4094
|
sizeRef.current = null;
|
|
4086
4095
|
scrollParentRef.current = null;
|
|
4096
|
+
placedRef.current = false;
|
|
4087
4097
|
return;
|
|
4088
4098
|
}
|
|
4089
4099
|
if (triggerRef.current) {
|
|
@@ -4112,7 +4122,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
4112
4122
|
window.removeEventListener("scroll", onScroll, true);
|
|
4113
4123
|
};
|
|
4114
4124
|
}, [calculatePosition, enabled]);
|
|
4115
|
-
return { direction };
|
|
4116
4125
|
};
|
|
4117
4126
|
var useAutoPosition_default = useAutoPosition;
|
|
4118
4127
|
|
|
@@ -4150,7 +4159,7 @@ var Dropdown = (props) => {
|
|
|
4150
4159
|
const [visible, setVisible] = import_react21.default.useState(false);
|
|
4151
4160
|
const triggerRef = import_react21.default.useRef(null);
|
|
4152
4161
|
const menuRef = import_react21.default.useRef(null);
|
|
4153
|
-
|
|
4162
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
4154
4163
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
4155
4164
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
4156
4165
|
useEscapeKey(isOpen, () => {
|
|
@@ -4186,7 +4195,7 @@ var Dropdown = (props) => {
|
|
|
4186
4195
|
"div",
|
|
4187
4196
|
{
|
|
4188
4197
|
ref: menuRef,
|
|
4189
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
4198
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
4190
4199
|
role: "menu",
|
|
4191
4200
|
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime322.jsx)(
|
|
4192
4201
|
"button",
|
|
@@ -6088,7 +6097,7 @@ var PopOver = (props) => {
|
|
|
6088
6097
|
onClose();
|
|
6089
6098
|
triggerRef.current?.focus({ preventScroll: true });
|
|
6090
6099
|
});
|
|
6091
|
-
|
|
6100
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
6092
6101
|
import_react27.default.useEffect(() => {
|
|
6093
6102
|
if (isOpen) {
|
|
6094
6103
|
setLocalOpen(isOpen);
|
|
@@ -6117,7 +6126,6 @@ var PopOver = (props) => {
|
|
|
6117
6126
|
{
|
|
6118
6127
|
className: clsx_default(
|
|
6119
6128
|
"lib-xplat-pop-over-content",
|
|
6120
|
-
position.direction,
|
|
6121
6129
|
eventTrigger && "visible"
|
|
6122
6130
|
),
|
|
6123
6131
|
ref: popRef,
|
|
@@ -6369,7 +6377,7 @@ var SelectRoot = (props) => {
|
|
|
6369
6377
|
close();
|
|
6370
6378
|
triggerRef.current?.focus({ preventScroll: true });
|
|
6371
6379
|
});
|
|
6372
|
-
|
|
6380
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
6373
6381
|
const setSelected = import_react31.default.useCallback(
|
|
6374
6382
|
(label2, itemValue) => {
|
|
6375
6383
|
if (!isControlled) {
|
|
@@ -6462,7 +6470,7 @@ var SelectRoot = (props) => {
|
|
|
6462
6470
|
mounted && /* @__PURE__ */ (0, import_jsx_runtime337.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime337.jsxs)(
|
|
6463
6471
|
"div",
|
|
6464
6472
|
{
|
|
6465
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
6473
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
6466
6474
|
ref: contentRef,
|
|
6467
6475
|
style: { width: triggerRef.current?.offsetWidth },
|
|
6468
6476
|
role: "listbox",
|
package/dist/components/index.js
CHANGED
|
@@ -3940,15 +3940,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
3940
3940
|
};
|
|
3941
3941
|
};
|
|
3942
3942
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
3943
|
-
const [direction, setDirection] = React19.useState("bottom");
|
|
3944
3943
|
const directionRef = React19.useRef("bottom");
|
|
3945
3944
|
const sizeRef = React19.useRef(null);
|
|
3946
3945
|
const scrollParentRef = React19.useRef(null);
|
|
3946
|
+
const placedRef = React19.useRef(false);
|
|
3947
3947
|
const calculatePosition = React19.useCallback((remeasure = false) => {
|
|
3948
3948
|
const pop = popRef.current;
|
|
3949
3949
|
if (!triggerRef.current || !pop) return;
|
|
3950
3950
|
if (remeasure || !sizeRef.current) {
|
|
3951
|
-
sizeRef.current = {
|
|
3951
|
+
sizeRef.current = {
|
|
3952
|
+
w: pop.offsetWidth,
|
|
3953
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
3954
|
+
};
|
|
3952
3955
|
}
|
|
3953
3956
|
const { w: popW, h: popH } = sizeRef.current;
|
|
3954
3957
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -3963,6 +3966,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
3963
3966
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
3964
3967
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
3965
3968
|
};
|
|
3969
|
+
const first = !placedRef.current;
|
|
3970
|
+
if (first) pop.style.transition = "none";
|
|
3966
3971
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
3967
3972
|
triggerRect,
|
|
3968
3973
|
popW,
|
|
@@ -3973,15 +3978,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
3973
3978
|
pop.style.left = `${left + window.scrollX}px`;
|
|
3974
3979
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
3975
3980
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3981
|
+
directionRef.current = next;
|
|
3982
|
+
pop.classList.toggle("top", next === "top");
|
|
3983
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
3984
|
+
if (first) {
|
|
3985
|
+
void pop.offsetHeight;
|
|
3986
|
+
pop.style.transition = "";
|
|
3987
|
+
placedRef.current = true;
|
|
3979
3988
|
}
|
|
3980
3989
|
}, [triggerRef, popRef]);
|
|
3981
3990
|
React19.useLayoutEffect(() => {
|
|
3982
3991
|
if (!enabled) {
|
|
3983
3992
|
sizeRef.current = null;
|
|
3984
3993
|
scrollParentRef.current = null;
|
|
3994
|
+
placedRef.current = false;
|
|
3985
3995
|
return;
|
|
3986
3996
|
}
|
|
3987
3997
|
if (triggerRef.current) {
|
|
@@ -4010,7 +4020,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
4010
4020
|
window.removeEventListener("scroll", onScroll, true);
|
|
4011
4021
|
};
|
|
4012
4022
|
}, [calculatePosition, enabled]);
|
|
4013
|
-
return { direction };
|
|
4014
4023
|
};
|
|
4015
4024
|
var useAutoPosition_default = useAutoPosition;
|
|
4016
4025
|
|
|
@@ -4048,7 +4057,7 @@ var Dropdown = (props) => {
|
|
|
4048
4057
|
const [visible, setVisible] = React21.useState(false);
|
|
4049
4058
|
const triggerRef = React21.useRef(null);
|
|
4050
4059
|
const menuRef = React21.useRef(null);
|
|
4051
|
-
|
|
4060
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
4052
4061
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
4053
4062
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
4054
4063
|
useEscapeKey(isOpen, () => {
|
|
@@ -4084,7 +4093,7 @@ var Dropdown = (props) => {
|
|
|
4084
4093
|
"div",
|
|
4085
4094
|
{
|
|
4086
4095
|
ref: menuRef,
|
|
4087
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
4096
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
4088
4097
|
role: "menu",
|
|
4089
4098
|
children: items.map((item) => /* @__PURE__ */ jsx322(
|
|
4090
4099
|
"button",
|
|
@@ -5986,7 +5995,7 @@ var PopOver = (props) => {
|
|
|
5986
5995
|
onClose();
|
|
5987
5996
|
triggerRef.current?.focus({ preventScroll: true });
|
|
5988
5997
|
});
|
|
5989
|
-
|
|
5998
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
5990
5999
|
React27.useEffect(() => {
|
|
5991
6000
|
if (isOpen) {
|
|
5992
6001
|
setLocalOpen(isOpen);
|
|
@@ -6015,7 +6024,6 @@ var PopOver = (props) => {
|
|
|
6015
6024
|
{
|
|
6016
6025
|
className: clsx_default(
|
|
6017
6026
|
"lib-xplat-pop-over-content",
|
|
6018
|
-
position.direction,
|
|
6019
6027
|
eventTrigger && "visible"
|
|
6020
6028
|
),
|
|
6021
6029
|
ref: popRef,
|
|
@@ -6267,7 +6275,7 @@ var SelectRoot = (props) => {
|
|
|
6267
6275
|
close();
|
|
6268
6276
|
triggerRef.current?.focus({ preventScroll: true });
|
|
6269
6277
|
});
|
|
6270
|
-
|
|
6278
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
6271
6279
|
const setSelected = React31.useCallback(
|
|
6272
6280
|
(label2, itemValue) => {
|
|
6273
6281
|
if (!isControlled) {
|
|
@@ -6360,7 +6368,7 @@ var SelectRoot = (props) => {
|
|
|
6360
6368
|
mounted && /* @__PURE__ */ jsx337(Portal_default, { children: /* @__PURE__ */ jsxs216(
|
|
6361
6369
|
"div",
|
|
6362
6370
|
{
|
|
6363
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
6371
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
6364
6372
|
ref: contentRef,
|
|
6365
6373
|
style: { width: triggerRef.current?.offsetWidth },
|
|
6366
6374
|
role: "listbox",
|
package/dist/index.cjs
CHANGED
|
@@ -8454,15 +8454,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
8454
8454
|
};
|
|
8455
8455
|
};
|
|
8456
8456
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
8457
|
-
const [direction, setDirection] = import_react19.default.useState("bottom");
|
|
8458
8457
|
const directionRef = import_react19.default.useRef("bottom");
|
|
8459
8458
|
const sizeRef = import_react19.default.useRef(null);
|
|
8460
8459
|
const scrollParentRef = import_react19.default.useRef(null);
|
|
8460
|
+
const placedRef = import_react19.default.useRef(false);
|
|
8461
8461
|
const calculatePosition = import_react19.default.useCallback((remeasure = false) => {
|
|
8462
8462
|
const pop = popRef.current;
|
|
8463
8463
|
if (!triggerRef.current || !pop) return;
|
|
8464
8464
|
if (remeasure || !sizeRef.current) {
|
|
8465
|
-
sizeRef.current = {
|
|
8465
|
+
sizeRef.current = {
|
|
8466
|
+
w: pop.offsetWidth,
|
|
8467
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
8468
|
+
};
|
|
8466
8469
|
}
|
|
8467
8470
|
const { w: popW, h: popH } = sizeRef.current;
|
|
8468
8471
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -8477,6 +8480,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8477
8480
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
8478
8481
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
8479
8482
|
};
|
|
8483
|
+
const first = !placedRef.current;
|
|
8484
|
+
if (first) pop.style.transition = "none";
|
|
8480
8485
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
8481
8486
|
triggerRect,
|
|
8482
8487
|
popW,
|
|
@@ -8487,15 +8492,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8487
8492
|
pop.style.left = `${left + window.scrollX}px`;
|
|
8488
8493
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
8489
8494
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8495
|
+
directionRef.current = next;
|
|
8496
|
+
pop.classList.toggle("top", next === "top");
|
|
8497
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
8498
|
+
if (first) {
|
|
8499
|
+
void pop.offsetHeight;
|
|
8500
|
+
pop.style.transition = "";
|
|
8501
|
+
placedRef.current = true;
|
|
8493
8502
|
}
|
|
8494
8503
|
}, [triggerRef, popRef]);
|
|
8495
8504
|
import_react19.default.useLayoutEffect(() => {
|
|
8496
8505
|
if (!enabled) {
|
|
8497
8506
|
sizeRef.current = null;
|
|
8498
8507
|
scrollParentRef.current = null;
|
|
8508
|
+
placedRef.current = false;
|
|
8499
8509
|
return;
|
|
8500
8510
|
}
|
|
8501
8511
|
if (triggerRef.current) {
|
|
@@ -8524,7 +8534,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8524
8534
|
window.removeEventListener("scroll", onScroll, true);
|
|
8525
8535
|
};
|
|
8526
8536
|
}, [calculatePosition, enabled]);
|
|
8527
|
-
return { direction };
|
|
8528
8537
|
};
|
|
8529
8538
|
var useAutoPosition_default = useAutoPosition;
|
|
8530
8539
|
|
|
@@ -8562,7 +8571,7 @@ var Dropdown = (props) => {
|
|
|
8562
8571
|
const [visible, setVisible] = import_react21.default.useState(false);
|
|
8563
8572
|
const triggerRef = import_react21.default.useRef(null);
|
|
8564
8573
|
const menuRef = import_react21.default.useRef(null);
|
|
8565
|
-
|
|
8574
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
8566
8575
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
8567
8576
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
8568
8577
|
useEscapeKey(isOpen, () => {
|
|
@@ -8598,7 +8607,7 @@ var Dropdown = (props) => {
|
|
|
8598
8607
|
"div",
|
|
8599
8608
|
{
|
|
8600
8609
|
ref: menuRef,
|
|
8601
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
8610
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
8602
8611
|
role: "menu",
|
|
8603
8612
|
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime322.jsx)(
|
|
8604
8613
|
"button",
|
|
@@ -10500,7 +10509,7 @@ var PopOver = (props) => {
|
|
|
10500
10509
|
onClose();
|
|
10501
10510
|
triggerRef.current?.focus({ preventScroll: true });
|
|
10502
10511
|
});
|
|
10503
|
-
|
|
10512
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
10504
10513
|
import_react27.default.useEffect(() => {
|
|
10505
10514
|
if (isOpen) {
|
|
10506
10515
|
setLocalOpen(isOpen);
|
|
@@ -10529,7 +10538,6 @@ var PopOver = (props) => {
|
|
|
10529
10538
|
{
|
|
10530
10539
|
className: clsx_default(
|
|
10531
10540
|
"lib-xplat-pop-over-content",
|
|
10532
|
-
position.direction,
|
|
10533
10541
|
eventTrigger && "visible"
|
|
10534
10542
|
),
|
|
10535
10543
|
ref: popRef,
|
|
@@ -10781,7 +10789,7 @@ var SelectRoot = (props) => {
|
|
|
10781
10789
|
close();
|
|
10782
10790
|
triggerRef.current?.focus({ preventScroll: true });
|
|
10783
10791
|
});
|
|
10784
|
-
|
|
10792
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
10785
10793
|
const setSelected = import_react31.default.useCallback(
|
|
10786
10794
|
(label2, itemValue) => {
|
|
10787
10795
|
if (!isControlled) {
|
|
@@ -10874,7 +10882,7 @@ var SelectRoot = (props) => {
|
|
|
10874
10882
|
mounted && /* @__PURE__ */ (0, import_jsx_runtime337.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime337.jsxs)(
|
|
10875
10883
|
"div",
|
|
10876
10884
|
{
|
|
10877
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
10885
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
10878
10886
|
ref: contentRef,
|
|
10879
10887
|
style: { width: triggerRef.current?.offsetWidth },
|
|
10880
10888
|
role: "listbox",
|
package/dist/index.js
CHANGED
|
@@ -8043,15 +8043,18 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
|
|
|
8043
8043
|
};
|
|
8044
8044
|
};
|
|
8045
8045
|
var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
8046
|
-
const [direction, setDirection] = React19.useState("bottom");
|
|
8047
8046
|
const directionRef = React19.useRef("bottom");
|
|
8048
8047
|
const sizeRef = React19.useRef(null);
|
|
8049
8048
|
const scrollParentRef = React19.useRef(null);
|
|
8049
|
+
const placedRef = React19.useRef(false);
|
|
8050
8050
|
const calculatePosition = React19.useCallback((remeasure = false) => {
|
|
8051
8051
|
const pop = popRef.current;
|
|
8052
8052
|
if (!triggerRef.current || !pop) return;
|
|
8053
8053
|
if (remeasure || !sizeRef.current) {
|
|
8054
|
-
sizeRef.current = {
|
|
8054
|
+
sizeRef.current = {
|
|
8055
|
+
w: pop.offsetWidth,
|
|
8056
|
+
h: Math.max(pop.offsetHeight, pop.scrollHeight)
|
|
8057
|
+
};
|
|
8055
8058
|
}
|
|
8056
8059
|
const { w: popW, h: popH } = sizeRef.current;
|
|
8057
8060
|
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
@@ -8066,6 +8069,8 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8066
8069
|
left: Math.max(parentRect?.left ?? 0, 0),
|
|
8067
8070
|
right: Math.min(parentRect?.right ?? window.innerWidth, window.innerWidth)
|
|
8068
8071
|
};
|
|
8072
|
+
const first = !placedRef.current;
|
|
8073
|
+
if (first) pop.style.transition = "none";
|
|
8069
8074
|
const { direction: next, top, left, over, maxHeight } = computePlacement(
|
|
8070
8075
|
triggerRect,
|
|
8071
8076
|
popW,
|
|
@@ -8076,15 +8081,20 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8076
8081
|
pop.style.left = `${left + window.scrollX}px`;
|
|
8077
8082
|
pop.style.maxHeight = maxHeight === null ? "" : `${maxHeight}px`;
|
|
8078
8083
|
pop.style.clipPath = over.top || over.right || over.bottom || over.left ? `inset(${over.top}px ${over.right}px ${over.bottom}px ${over.left}px)` : "none";
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8084
|
+
directionRef.current = next;
|
|
8085
|
+
pop.classList.toggle("top", next === "top");
|
|
8086
|
+
pop.classList.toggle("bottom", next === "bottom");
|
|
8087
|
+
if (first) {
|
|
8088
|
+
void pop.offsetHeight;
|
|
8089
|
+
pop.style.transition = "";
|
|
8090
|
+
placedRef.current = true;
|
|
8082
8091
|
}
|
|
8083
8092
|
}, [triggerRef, popRef]);
|
|
8084
8093
|
React19.useLayoutEffect(() => {
|
|
8085
8094
|
if (!enabled) {
|
|
8086
8095
|
sizeRef.current = null;
|
|
8087
8096
|
scrollParentRef.current = null;
|
|
8097
|
+
placedRef.current = false;
|
|
8088
8098
|
return;
|
|
8089
8099
|
}
|
|
8090
8100
|
if (triggerRef.current) {
|
|
@@ -8113,7 +8123,6 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
|
|
|
8113
8123
|
window.removeEventListener("scroll", onScroll, true);
|
|
8114
8124
|
};
|
|
8115
8125
|
}, [calculatePosition, enabled]);
|
|
8116
|
-
return { direction };
|
|
8117
8126
|
};
|
|
8118
8127
|
var useAutoPosition_default = useAutoPosition;
|
|
8119
8128
|
|
|
@@ -8151,7 +8160,7 @@ var Dropdown = (props) => {
|
|
|
8151
8160
|
const [visible, setVisible] = React21.useState(false);
|
|
8152
8161
|
const triggerRef = React21.useRef(null);
|
|
8153
8162
|
const menuRef = React21.useRef(null);
|
|
8154
|
-
|
|
8163
|
+
useAutoPosition_default(triggerRef, menuRef, mounted);
|
|
8155
8164
|
useClickOutside_default([triggerRef, menuRef], () => setIsOpen(false), isOpen);
|
|
8156
8165
|
useCloseOnContainerScroll(isOpen, menuRef, () => setIsOpen(false));
|
|
8157
8166
|
useEscapeKey(isOpen, () => {
|
|
@@ -8187,7 +8196,7 @@ var Dropdown = (props) => {
|
|
|
8187
8196
|
"div",
|
|
8188
8197
|
{
|
|
8189
8198
|
ref: menuRef,
|
|
8190
|
-
className: clsx_default("lib-xplat-dropdown-menu",
|
|
8199
|
+
className: clsx_default("lib-xplat-dropdown-menu", { visible }),
|
|
8191
8200
|
role: "menu",
|
|
8192
8201
|
children: items.map((item) => /* @__PURE__ */ jsx322(
|
|
8193
8202
|
"button",
|
|
@@ -10089,7 +10098,7 @@ var PopOver = (props) => {
|
|
|
10089
10098
|
onClose();
|
|
10090
10099
|
triggerRef.current?.focus({ preventScroll: true });
|
|
10091
10100
|
});
|
|
10092
|
-
|
|
10101
|
+
useAutoPosition_default(triggerRef, popRef, localOpen);
|
|
10093
10102
|
React27.useEffect(() => {
|
|
10094
10103
|
if (isOpen) {
|
|
10095
10104
|
setLocalOpen(isOpen);
|
|
@@ -10118,7 +10127,6 @@ var PopOver = (props) => {
|
|
|
10118
10127
|
{
|
|
10119
10128
|
className: clsx_default(
|
|
10120
10129
|
"lib-xplat-pop-over-content",
|
|
10121
|
-
position.direction,
|
|
10122
10130
|
eventTrigger && "visible"
|
|
10123
10131
|
),
|
|
10124
10132
|
ref: popRef,
|
|
@@ -10370,7 +10378,7 @@ var SelectRoot = (props) => {
|
|
|
10370
10378
|
close();
|
|
10371
10379
|
triggerRef.current?.focus({ preventScroll: true });
|
|
10372
10380
|
});
|
|
10373
|
-
|
|
10381
|
+
useAutoPosition_default(triggerRef, contentRef, mounted);
|
|
10374
10382
|
const setSelected = React31.useCallback(
|
|
10375
10383
|
(label2, itemValue) => {
|
|
10376
10384
|
if (!isControlled) {
|
|
@@ -10463,7 +10471,7 @@ var SelectRoot = (props) => {
|
|
|
10463
10471
|
mounted && /* @__PURE__ */ jsx337(Portal_default, { children: /* @__PURE__ */ jsxs216(
|
|
10464
10472
|
"div",
|
|
10465
10473
|
{
|
|
10466
|
-
className: clsx_default("lib-xplat-select-content", size,
|
|
10474
|
+
className: clsx_default("lib-xplat-select-content", size, stateClass),
|
|
10467
10475
|
ref: contentRef,
|
|
10468
10476
|
style: { width: triggerRef.current?.offsetWidth },
|
|
10469
10477
|
role: "listbox",
|