@rescui/dropdown 0.11.2 → 0.12.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.
- package/lib/dropdown.js +373 -153
- package/lib/dropdown.p.module.css.js +9 -9
- package/lib/index.css +19 -19
- package/lib/use-dropdown-state.js +140 -77
- package/lib/use-extract-css-values.d.ts +5 -0
- package/lib/use-extract-css-values.js +78 -0
- package/lib/use-scrollable-container.js +37 -14
- package/package.json +10 -9
- package/lib/css-vars-utils.d.ts +0 -3
- package/lib/css-vars-utils.js +0 -20
package/lib/dropdown.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
|
|
3
|
+
import { c } from 'react-compiler-runtime';
|
|
4
|
+
import React, { useState, useRef, useImperativeHandle, useContext, useEffect } from 'react';
|
|
3
5
|
import PropTypes from 'prop-types';
|
|
4
6
|
import cn from 'classnames';
|
|
5
7
|
import { usePopper } from 'react-popper';
|
|
@@ -11,7 +13,7 @@ import { useDropdownState, DROPDOWN_STATES } from './use-dropdown-state.js';
|
|
|
11
13
|
import { useScrollableContainer } from './use-scrollable-container.js';
|
|
12
14
|
import styles from './dropdown.p.module.css.js';
|
|
13
15
|
import { applyMaxSize, sameWidthModifier } from './custom-modifiers.js';
|
|
14
|
-
import {
|
|
16
|
+
import { useExtractCssValues } from './use-extract-css-values.js';
|
|
15
17
|
|
|
16
18
|
function getPopperOptions(_ref) {
|
|
17
19
|
let {
|
|
@@ -58,57 +60,126 @@ const Portal = _ref2 => {
|
|
|
58
60
|
return target ? /*#__PURE__*/ReactDOM.createPortal(children, target) : null;
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
function useOnOutsideClick(
|
|
62
|
-
|
|
63
|
+
function useOnOutsideClick(t0) {
|
|
64
|
+
const $ = c(13);
|
|
65
|
+
const {
|
|
63
66
|
onOutsideClick,
|
|
64
67
|
isEnabled,
|
|
65
|
-
ignoreElements
|
|
68
|
+
ignoreElements: t1,
|
|
66
69
|
ownerDocument
|
|
67
|
-
} =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
} = t0;
|
|
71
|
+
let t2;
|
|
72
|
+
|
|
73
|
+
if ($[0] !== t1) {
|
|
74
|
+
t2 = t1 === undefined ? [] : t1;
|
|
75
|
+
$[0] = t1;
|
|
76
|
+
$[1] = t2;
|
|
77
|
+
} else {
|
|
78
|
+
t2 = $[1];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const ignoreElements = t2;
|
|
82
|
+
let t3;
|
|
83
|
+
|
|
84
|
+
if ($[2] !== ignoreElements) {
|
|
85
|
+
t3 = ignoreElements.length > 0 && ignoreElements.every(Boolean);
|
|
86
|
+
$[2] = ignoreElements;
|
|
87
|
+
$[3] = t3;
|
|
88
|
+
} else {
|
|
89
|
+
t3 = $[3];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ignoreElementRefsExists = t3;
|
|
93
|
+
let t4;
|
|
94
|
+
|
|
95
|
+
if ($[4] !== ignoreElements || $[5] !== onOutsideClick) {
|
|
96
|
+
t4 = e => {
|
|
97
|
+
for (const element of ignoreElements) {
|
|
98
|
+
if (!element || e.target === element || element.contains(e.target)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
onOutsideClick();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
$[4] = ignoreElements;
|
|
107
|
+
$[5] = onOutsideClick;
|
|
108
|
+
$[6] = t4;
|
|
109
|
+
} else {
|
|
110
|
+
t4 = $[6];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const handleDocumentClick = t4;
|
|
114
|
+
let t5;
|
|
115
|
+
let t6;
|
|
116
|
+
|
|
117
|
+
if ($[7] !== handleDocumentClick || $[8] !== ignoreElementRefsExists || $[9] !== isEnabled || $[10] !== ownerDocument) {
|
|
118
|
+
t5 = () => {
|
|
119
|
+
if (isEnabled && ignoreElementRefsExists && ownerDocument) {
|
|
120
|
+
ownerDocument.addEventListener("click", handleDocumentClick, true);
|
|
121
|
+
return () => ownerDocument.removeEventListener("click", handleDocumentClick, true);
|
|
73
122
|
}
|
|
74
|
-
}
|
|
123
|
+
};
|
|
75
124
|
|
|
76
|
-
|
|
77
|
-
|
|
125
|
+
t6 = [handleDocumentClick, ignoreElementRefsExists, isEnabled, ownerDocument];
|
|
126
|
+
$[7] = handleDocumentClick;
|
|
127
|
+
$[8] = ignoreElementRefsExists;
|
|
128
|
+
$[9] = isEnabled;
|
|
129
|
+
$[10] = ownerDocument;
|
|
130
|
+
$[11] = t5;
|
|
131
|
+
$[12] = t6;
|
|
132
|
+
} else {
|
|
133
|
+
t5 = $[11];
|
|
134
|
+
t6 = $[12];
|
|
135
|
+
}
|
|
78
136
|
|
|
79
|
-
useEffect(
|
|
80
|
-
if (isEnabled && ignoreElementRefsExists && ownerDocument) {
|
|
81
|
-
ownerDocument.addEventListener('click', handleDocumentClick, true);
|
|
82
|
-
return () => ownerDocument.removeEventListener('click', handleDocumentClick, true);
|
|
83
|
-
}
|
|
84
|
-
}, [handleDocumentClick, ignoreElementRefsExists, isEnabled, ownerDocument]);
|
|
137
|
+
useEffect(t5, t6);
|
|
85
138
|
}
|
|
86
139
|
|
|
87
|
-
function useKeyPress(
|
|
88
|
-
|
|
140
|
+
function useKeyPress(t0) {
|
|
141
|
+
const $ = c(6);
|
|
142
|
+
const {
|
|
89
143
|
key,
|
|
90
144
|
onKeyPress,
|
|
91
145
|
isEnabled,
|
|
92
146
|
ownerDocument
|
|
93
|
-
} =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
e.preventDefault();
|
|
102
|
-
onKeyPress();
|
|
147
|
+
} = t0;
|
|
148
|
+
let t1;
|
|
149
|
+
let t2;
|
|
150
|
+
|
|
151
|
+
if ($[0] !== isEnabled || $[1] !== key || $[2] !== onKeyPress || $[3] !== ownerDocument) {
|
|
152
|
+
t1 = () => {
|
|
153
|
+
if (!isEnabled || !ownerDocument) {
|
|
154
|
+
return;
|
|
103
155
|
}
|
|
104
|
-
};
|
|
105
156
|
|
|
106
|
-
|
|
157
|
+
const keyDownHandler = e => {
|
|
158
|
+
if (e.key === key) {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
onKeyPress();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
107
163
|
|
|
108
|
-
|
|
109
|
-
|
|
164
|
+
ownerDocument.addEventListener("keydown", keyDownHandler, true);
|
|
165
|
+
return () => {
|
|
166
|
+
ownerDocument.removeEventListener("keydown", keyDownHandler, true);
|
|
167
|
+
};
|
|
110
168
|
};
|
|
111
|
-
|
|
169
|
+
|
|
170
|
+
t2 = [isEnabled, key, onKeyPress, ownerDocument];
|
|
171
|
+
$[0] = isEnabled;
|
|
172
|
+
$[1] = key;
|
|
173
|
+
$[2] = onKeyPress;
|
|
174
|
+
$[3] = ownerDocument;
|
|
175
|
+
$[4] = t1;
|
|
176
|
+
$[5] = t2;
|
|
177
|
+
} else {
|
|
178
|
+
t1 = $[4];
|
|
179
|
+
t2 = $[5];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
useEffect(t1, t2);
|
|
112
183
|
}
|
|
113
184
|
|
|
114
185
|
const THEME_STYLES = {
|
|
@@ -120,152 +191,298 @@ const MODE_STYLES = {
|
|
|
120
191
|
rock: styles.modeRock
|
|
121
192
|
};
|
|
122
193
|
|
|
123
|
-
const DropdownRender = (
|
|
124
|
-
|
|
194
|
+
const DropdownRender = (t0, externalRef) => {
|
|
195
|
+
const $ = c(60);
|
|
196
|
+
const {
|
|
125
197
|
children,
|
|
126
198
|
trigger,
|
|
127
199
|
theme: themeFromProps,
|
|
128
|
-
isOpen:
|
|
129
|
-
placement
|
|
130
|
-
mode
|
|
131
|
-
|
|
132
|
-
onRequestClose = () => {},
|
|
200
|
+
isOpen: t1,
|
|
201
|
+
placement: t2,
|
|
202
|
+
mode: t3,
|
|
203
|
+
onRequestClose: t4,
|
|
133
204
|
minWidth,
|
|
134
205
|
maxWidth,
|
|
135
206
|
maxHeight,
|
|
136
207
|
leastMaxHeight,
|
|
137
|
-
cancelCloseAnimation
|
|
208
|
+
cancelCloseAnimation: t5,
|
|
138
209
|
className,
|
|
139
|
-
closeOnEsc
|
|
140
|
-
closeOnTab
|
|
141
|
-
disableFocusLock
|
|
142
|
-
renderInTrigger
|
|
143
|
-
disableFlip
|
|
144
|
-
} =
|
|
210
|
+
closeOnEsc: t6,
|
|
211
|
+
closeOnTab: t7,
|
|
212
|
+
disableFocusLock: t8,
|
|
213
|
+
renderInTrigger: t9,
|
|
214
|
+
disableFlip: t10
|
|
215
|
+
} = t0;
|
|
216
|
+
const isOpenFromProps = t1 === undefined ? false : t1;
|
|
217
|
+
const placement = t2 === undefined ? "bottom-start" : t2;
|
|
218
|
+
const mode = t3 === undefined ? "classic" : t3;
|
|
219
|
+
const onRequestClose = t4 === undefined ? _temp : t4;
|
|
220
|
+
const cancelCloseAnimation = t5 === undefined ? false : t5;
|
|
221
|
+
const closeOnEsc = t6 === undefined ? true : t6;
|
|
222
|
+
const closeOnTab = t7 === undefined ? false : t7;
|
|
223
|
+
const disableFocusLock = t8 === undefined ? false : t8;
|
|
224
|
+
const renderInTrigger = t9 === undefined ? false : t9;
|
|
225
|
+
const disableFlip = t10 === undefined ? false : t10;
|
|
145
226
|
const [popperRef, setPopperRef] = useState(null);
|
|
146
227
|
const [triggerRef, setTriggerRef] = useState(undefined);
|
|
147
228
|
const {
|
|
148
229
|
setContentEl,
|
|
149
230
|
scrollableStyles
|
|
150
231
|
} = useScrollableContainer();
|
|
151
|
-
const scrollableRef = useRef(null);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const isOpen = typeof triggerRef !== 'undefined' || renderInTrigger ? isOpenFromProps : false;
|
|
232
|
+
const scrollableRef = useRef(null);
|
|
233
|
+
const isOpen = typeof triggerRef !== "undefined" || renderInTrigger ? isOpenFromProps : false;
|
|
155
234
|
const ownerDocument = triggerRef?.ownerDocument;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
235
|
+
let t11;
|
|
236
|
+
|
|
237
|
+
if ($[0] !== popperRef || $[1] !== triggerRef) {
|
|
238
|
+
t11 = [popperRef, triggerRef];
|
|
239
|
+
$[0] = popperRef;
|
|
240
|
+
$[1] = triggerRef;
|
|
241
|
+
$[2] = t11;
|
|
242
|
+
} else {
|
|
243
|
+
t11 = $[2];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const outsideClickIgnoreElements = t11;
|
|
247
|
+
let t12;
|
|
248
|
+
|
|
249
|
+
if ($[3] !== isOpen || $[4] !== onRequestClose || $[5] !== outsideClickIgnoreElements || $[6] !== ownerDocument) {
|
|
250
|
+
t12 = {
|
|
251
|
+
isEnabled: isOpen,
|
|
252
|
+
onOutsideClick: onRequestClose,
|
|
253
|
+
ignoreElements: outsideClickIgnoreElements,
|
|
254
|
+
ownerDocument
|
|
255
|
+
};
|
|
256
|
+
$[3] = isOpen;
|
|
257
|
+
$[4] = onRequestClose;
|
|
258
|
+
$[5] = outsideClickIgnoreElements;
|
|
259
|
+
$[6] = ownerDocument;
|
|
260
|
+
$[7] = t12;
|
|
261
|
+
} else {
|
|
262
|
+
t12 = $[7];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
useOnOutsideClick(t12);
|
|
266
|
+
const t13 = isOpen && closeOnEsc;
|
|
267
|
+
let t14;
|
|
268
|
+
|
|
269
|
+
if ($[8] !== onRequestClose || $[9] !== ownerDocument || $[10] !== t13) {
|
|
270
|
+
t14 = {
|
|
271
|
+
key: "Escape",
|
|
272
|
+
isEnabled: t13,
|
|
273
|
+
onKeyPress: onRequestClose,
|
|
274
|
+
ownerDocument
|
|
275
|
+
};
|
|
276
|
+
$[8] = onRequestClose;
|
|
277
|
+
$[9] = ownerDocument;
|
|
278
|
+
$[10] = t13;
|
|
279
|
+
$[11] = t14;
|
|
280
|
+
} else {
|
|
281
|
+
t14 = $[11];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
useKeyPress(t14);
|
|
285
|
+
const t15 = isOpen && closeOnTab;
|
|
286
|
+
let t16;
|
|
287
|
+
|
|
288
|
+
if ($[12] !== onRequestClose || $[13] !== ownerDocument || $[14] !== t15) {
|
|
289
|
+
t16 = {
|
|
290
|
+
key: "Tab",
|
|
291
|
+
isEnabled: t15,
|
|
292
|
+
onKeyPress: onRequestClose,
|
|
293
|
+
ownerDocument
|
|
294
|
+
};
|
|
295
|
+
$[12] = onRequestClose;
|
|
296
|
+
$[13] = ownerDocument;
|
|
297
|
+
$[14] = t15;
|
|
298
|
+
$[15] = t16;
|
|
299
|
+
} else {
|
|
300
|
+
t16 = $[15];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
useKeyPress(t16);
|
|
304
|
+
let t17;
|
|
305
|
+
|
|
306
|
+
if ($[16] !== disableFlip || $[17] !== leastMaxHeight || $[18] !== maxHeight || $[19] !== maxWidth || $[20] !== minWidth || $[21] !== placement) {
|
|
307
|
+
t17 = getPopperOptions({
|
|
308
|
+
placement,
|
|
309
|
+
maxHeight,
|
|
310
|
+
leastMaxHeight,
|
|
311
|
+
minWidth,
|
|
312
|
+
maxWidth,
|
|
313
|
+
disableFlip
|
|
314
|
+
});
|
|
315
|
+
$[16] = disableFlip;
|
|
316
|
+
$[17] = leastMaxHeight;
|
|
317
|
+
$[18] = maxHeight;
|
|
318
|
+
$[19] = maxWidth;
|
|
319
|
+
$[20] = minWidth;
|
|
320
|
+
$[21] = placement;
|
|
321
|
+
$[22] = t17;
|
|
322
|
+
} else {
|
|
323
|
+
t17 = $[22];
|
|
324
|
+
}
|
|
325
|
+
|
|
175
326
|
const {
|
|
176
327
|
styles: popperStyles,
|
|
177
328
|
attributes,
|
|
178
329
|
update
|
|
179
|
-
} = usePopper(triggerRef ?? null, popperRef,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
330
|
+
} = usePopper(triggerRef ?? null, popperRef, t17);
|
|
331
|
+
const resolvedPlacement = attributes.popper?.["data-popper-placement"] ?? null;
|
|
332
|
+
let t18;
|
|
333
|
+
|
|
334
|
+
if ($[23] !== cancelCloseAnimation || $[24] !== isOpen || $[25] !== popperRef || $[26] !== resolvedPlacement) {
|
|
335
|
+
t18 = {
|
|
336
|
+
isOpen,
|
|
337
|
+
cancelCloseAnimation,
|
|
338
|
+
contentRef: scrollableRef,
|
|
339
|
+
popperElement: popperRef,
|
|
340
|
+
resolvedPlacement
|
|
341
|
+
};
|
|
342
|
+
$[23] = cancelCloseAnimation;
|
|
343
|
+
$[24] = isOpen;
|
|
344
|
+
$[25] = popperRef;
|
|
345
|
+
$[26] = resolvedPlacement;
|
|
346
|
+
$[27] = t18;
|
|
347
|
+
} else {
|
|
348
|
+
t18 = $[27];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const dropdownState = useDropdownState(t18);
|
|
352
|
+
let t19;
|
|
353
|
+
|
|
354
|
+
if ($[28] !== update) {
|
|
355
|
+
t19 = () => ({
|
|
356
|
+
scheduleUpdate: () => {
|
|
357
|
+
update?.();
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
$[28] = update;
|
|
362
|
+
$[29] = t19;
|
|
363
|
+
} else {
|
|
364
|
+
t19 = $[29];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
useImperativeHandle(externalRef, t19);
|
|
200
368
|
const {
|
|
201
369
|
dropdownZIndex
|
|
202
370
|
} = useLayeringContext();
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
371
|
+
let t20;
|
|
372
|
+
|
|
373
|
+
if ($[30] !== trigger) {
|
|
374
|
+
t20 = typeof trigger === "function" ? trigger({
|
|
375
|
+
ref: setTriggerRef
|
|
376
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
377
|
+
"data-test": "dropdown-trigger",
|
|
378
|
+
className: styles.triggerWrapper,
|
|
379
|
+
ref: setTriggerRef
|
|
380
|
+
}, trigger);
|
|
381
|
+
$[30] = trigger;
|
|
382
|
+
$[31] = t20;
|
|
383
|
+
} else {
|
|
384
|
+
t20 = $[31];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const triggerRenderer = t20;
|
|
210
388
|
const dropdownShouldBeRendered = dropdownState !== DROPDOWN_STATES.CLOSE;
|
|
211
389
|
const wrapperIsInitial = dropdownState === DROPDOWN_STATES.OPENING_PREPARE;
|
|
212
390
|
const wrapperShouldBeHidden = wrapperIsInitial || dropdownState === DROPDOWN_STATES.CLOSING;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// In theory this part of the code might cause issues with SSR.
|
|
218
|
-
// But in this specific context, because of the nature of the state-ref "triggerRef",
|
|
219
|
-
// we are sure that the dropdown wouldn't be rendered on the first client render.
|
|
220
|
-
// Therefore, the first render on the client will be the same as on the server.
|
|
221
|
-
const triggerStyles = ownerDocument?.defaultView?.getComputedStyle(triggerRef);
|
|
222
|
-
|
|
223
|
-
if (triggerStyles) {
|
|
224
|
-
themeFromCss = extractThemeFromCss(triggerStyles);
|
|
225
|
-
primaryColors = extractPrimaryColors(triggerStyles);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
391
|
+
const {
|
|
392
|
+
primaryColors,
|
|
393
|
+
themeFromCss
|
|
394
|
+
} = useExtractCssValues(triggerRef, dropdownShouldBeRendered, ownerDocument?.defaultView);
|
|
229
395
|
const {
|
|
230
396
|
theme: themeFromContext,
|
|
231
397
|
noProvider
|
|
232
398
|
} = useContext(ThemeContext);
|
|
233
399
|
const theme = themeFromProps || (noProvider ? themeFromCss : themeFromContext);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
400
|
+
let t21;
|
|
401
|
+
|
|
402
|
+
if ($[32] !== mode || $[33] !== theme) {
|
|
403
|
+
t21 = mode === "rock" ? getInverseTheme(theme) : theme;
|
|
404
|
+
$[32] = mode;
|
|
405
|
+
$[33] = theme;
|
|
406
|
+
$[34] = t21;
|
|
407
|
+
} else {
|
|
408
|
+
t21 = $[34];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const childrenTheme = t21;
|
|
412
|
+
let t22;
|
|
413
|
+
|
|
414
|
+
if ($[35] !== attributes.popper || $[36] !== children || $[37] !== childrenTheme || $[38] !== className || $[39] !== disableFocusLock || $[40] !== dropdownShouldBeRendered || $[41] !== dropdownState || $[42] !== dropdownZIndex || $[43] !== maxHeight || $[44] !== mode || $[45] !== noProvider || $[46] !== ownerDocument?.body || $[47] !== popperStyles || $[48] !== primaryColors || $[49] !== renderInTrigger || $[50] !== scrollableStyles || $[51] !== setContentEl || $[52] !== theme || $[53] !== triggerRef || $[54] !== wrapperIsInitial || $[55] !== wrapperShouldBeHidden) {
|
|
415
|
+
t22 = dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
|
|
416
|
+
target: renderInTrigger ? triggerRef : ownerDocument?.body
|
|
417
|
+
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
418
|
+
ref: setPopperRef,
|
|
419
|
+
style: {
|
|
420
|
+
maxHeight,
|
|
421
|
+
...popperStyles.popper,
|
|
422
|
+
zIndex: dropdownZIndex,
|
|
423
|
+
...primaryColors
|
|
424
|
+
},
|
|
425
|
+
className: cn(styles.dropdown, className, MODE_STYLES[mode], THEME_STYLES[theme]),
|
|
426
|
+
"data-test": "dropdown"
|
|
427
|
+
}, attributes.popper), /*#__PURE__*/React.createElement(LayeringProvider, {
|
|
428
|
+
baseLayer: "dropdown"
|
|
429
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
430
|
+
ref: scrollableRef,
|
|
431
|
+
style: scrollableStyles,
|
|
432
|
+
className: cn(styles.contentWrapper, wrapperIsInitial && styles.wrapperInitial, wrapperShouldBeHidden && styles.wrapperHidden),
|
|
433
|
+
"data-test": "dropdown-content"
|
|
434
|
+
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
435
|
+
ignoreThemeValueForCSSApi: noProvider,
|
|
436
|
+
theme: childrenTheme
|
|
437
|
+
}, /*#__PURE__*/React.createElement(FocusLock, {
|
|
438
|
+
className: THEME_STYLES[childrenTheme],
|
|
439
|
+
ref: setContentEl,
|
|
440
|
+
disabled: dropdownState === DROPDOWN_STATES.CLOSING || disableFocusLock,
|
|
441
|
+
returnFocus: {
|
|
442
|
+
preventScroll: true
|
|
443
|
+
},
|
|
444
|
+
focusOptions: {
|
|
445
|
+
preventScroll: true
|
|
446
|
+
}
|
|
447
|
+
}, children))))));
|
|
448
|
+
$[35] = attributes.popper;
|
|
449
|
+
$[36] = children;
|
|
450
|
+
$[37] = childrenTheme;
|
|
451
|
+
$[38] = className;
|
|
452
|
+
$[39] = disableFocusLock;
|
|
453
|
+
$[40] = dropdownShouldBeRendered;
|
|
454
|
+
$[41] = dropdownState;
|
|
455
|
+
$[42] = dropdownZIndex;
|
|
456
|
+
$[43] = maxHeight;
|
|
457
|
+
$[44] = mode;
|
|
458
|
+
$[45] = noProvider;
|
|
459
|
+
$[46] = ownerDocument?.body;
|
|
460
|
+
$[47] = popperStyles;
|
|
461
|
+
$[48] = primaryColors;
|
|
462
|
+
$[49] = renderInTrigger;
|
|
463
|
+
$[50] = scrollableStyles;
|
|
464
|
+
$[51] = setContentEl;
|
|
465
|
+
$[52] = theme;
|
|
466
|
+
$[53] = triggerRef;
|
|
467
|
+
$[54] = wrapperIsInitial;
|
|
468
|
+
$[55] = wrapperShouldBeHidden;
|
|
469
|
+
$[56] = t22;
|
|
470
|
+
} else {
|
|
471
|
+
t22 = $[56];
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
let t23;
|
|
475
|
+
|
|
476
|
+
if ($[57] !== t22 || $[58] !== triggerRenderer) {
|
|
477
|
+
t23 = /*#__PURE__*/React.createElement(React.Fragment, null, triggerRenderer, t22);
|
|
478
|
+
$[57] = t22;
|
|
479
|
+
$[58] = triggerRenderer;
|
|
480
|
+
$[59] = t23;
|
|
481
|
+
} else {
|
|
482
|
+
t23 = $[59];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return t23;
|
|
269
486
|
};
|
|
270
487
|
/* eslint-enable react/prop-types */
|
|
271
488
|
|
|
@@ -285,4 +502,7 @@ Dropdown.propTypes = {
|
|
|
285
502
|
renderInTrigger: PropTypes.bool,
|
|
286
503
|
disableFlip: PropTypes.bool
|
|
287
504
|
};
|
|
505
|
+
|
|
506
|
+
function _temp() {}
|
|
507
|
+
|
|
288
508
|
export { Dropdown, Dropdown as default };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"themeLight": "
|
|
3
|
-
"themeDark": "
|
|
4
|
-
"dropdown": "
|
|
5
|
-
"triggerWrapper": "
|
|
6
|
-
"contentWrapper": "
|
|
7
|
-
"wrapperInitial": "
|
|
8
|
-
"wrapperHidden": "
|
|
9
|
-
"modeClassic": "
|
|
10
|
-
"modeRock": "
|
|
2
|
+
"themeLight": "_themeLight_4nj7mk_7",
|
|
3
|
+
"themeDark": "_themeDark_4nj7mk_10",
|
|
4
|
+
"dropdown": "_dropdown_4nj7mk_14",
|
|
5
|
+
"triggerWrapper": "_triggerWrapper_4nj7mk_21",
|
|
6
|
+
"contentWrapper": "_contentWrapper_4nj7mk_25",
|
|
7
|
+
"wrapperInitial": "_wrapperInitial_4nj7mk_41",
|
|
8
|
+
"wrapperHidden": "_wrapperHidden_4nj7mk_45",
|
|
9
|
+
"modeClassic": "_modeClassic_4nj7mk_65",
|
|
10
|
+
"modeRock": "_modeRock_4nj7mk_69"
|
|
11
11
|
};
|
|
12
12
|
export { styles as default };
|
package/lib/index.css
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
inherits:true;
|
|
4
4
|
initial-value:0;
|
|
5
5
|
}
|
|
6
|
-
.
|
|
6
|
+
._themeLight_4nj7mk_7{
|
|
7
7
|
--rs-theme-dark:0;
|
|
8
8
|
}
|
|
9
|
-
.
|
|
9
|
+
._themeDark_4nj7mk_10{
|
|
10
10
|
--rs-theme-dark:1;
|
|
11
11
|
}
|
|
12
|
-
.
|
|
12
|
+
._dropdown_4nj7mk_14{
|
|
13
13
|
--_rs-theme-dark:var(
|
|
14
14
|
--_rs-internal-force-theme-dark-consult-rescui-before-using,
|
|
15
15
|
var(--rs-theme-dark, 0)
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
--_rs-theme-light-coefficient:calc(1 - var(--_rs-theme-dark-coefficient));
|
|
20
20
|
}
|
|
21
21
|
@supports (color: color-mix(in srgb, #fff 50%, #000 50%)){
|
|
22
|
-
.
|
|
22
|
+
._dropdown_4nj7mk_14{
|
|
23
23
|
--_rs-color-primary:color-mix(in srgb, var(--rs-color-primary-light-theme, #6B57FF) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-dark-theme, #8473FF) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
24
24
|
--_rs-color-primary-dim:color-mix(in srgb, var(--rs-color-primary-dim-light-theme, #8979ff) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-dim-dark-theme, #6f61d2) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
25
25
|
--_rs-color-primary-fog:color-mix(in srgb, var(--rs-color-primary-fog-light-theme, #e1ddff) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-fog-dark-theme, #2e2b49) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
@supports not (color: color-mix(in srgb, #fff 50%, #000 50%)){
|
|
31
|
-
.
|
|
31
|
+
._dropdown_4nj7mk_14{
|
|
32
32
|
--_rs-color-primary:rgb(calc(var(--_rs-theme-light-coefficient, 1)*107 + var(--_rs-theme-dark-coefficient, 0)*132), calc(var(--_rs-theme-light-coefficient, 1)*87 + var(--_rs-theme-dark-coefficient, 0)*115), 255);
|
|
33
33
|
--_rs-color-primary-dim:rgb(calc(var(--_rs-theme-light-coefficient, 1)*137 + var(--_rs-theme-dark-coefficient, 0)*111), calc(var(--_rs-theme-light-coefficient, 1)*121 + var(--_rs-theme-dark-coefficient, 0)*97), calc(var(--_rs-theme-light-coefficient, 1)*255 + var(--_rs-theme-dark-coefficient, 0)*210));
|
|
34
34
|
--_rs-color-primary-fog:rgb(calc(var(--_rs-theme-light-coefficient, 1)*225 + var(--_rs-theme-dark-coefficient, 0)*46), calc(var(--_rs-theme-light-coefficient, 1)*221 + var(--_rs-theme-dark-coefficient, 0)*43), calc(var(--_rs-theme-light-coefficient, 1)*255 + var(--_rs-theme-dark-coefficient, 0)*73));
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
--_rs-color-primary-t-fog:rgba(calc(var(--_rs-theme-light-coefficient, 1)*107 + var(--_rs-theme-dark-coefficient, 0)*132), calc(var(--_rs-theme-light-coefficient, 1)*87 + var(--_rs-theme-dark-coefficient, 0)*115), 255, calc(var(--_rs-theme-light-coefficient, 1)*0.2 + var(--_rs-theme-dark-coefficient, 0)*0.3));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
.
|
|
39
|
+
._dropdown_4nj7mk_14 {
|
|
40
40
|
display:flex;
|
|
41
41
|
flex-direction:column;
|
|
42
42
|
}
|
|
43
|
-
.
|
|
43
|
+
._triggerWrapper_4nj7mk_21{
|
|
44
44
|
display:inline-block;
|
|
45
45
|
}
|
|
46
|
-
.
|
|
46
|
+
._contentWrapper_4nj7mk_25{
|
|
47
47
|
position:relative;
|
|
48
48
|
|
|
49
49
|
display:block;
|
|
@@ -57,34 +57,34 @@
|
|
|
57
57
|
|
|
58
58
|
transition:opacity var(--rs-transition-function, ease) 200ms, transform var(--rs-transition-function, ease) 200ms;
|
|
59
59
|
}
|
|
60
|
-
.
|
|
60
|
+
._wrapperInitial_4nj7mk_41{
|
|
61
61
|
transition:none;
|
|
62
62
|
}
|
|
63
|
-
.
|
|
63
|
+
._wrapperHidden_4nj7mk_45{
|
|
64
64
|
opacity:0;
|
|
65
65
|
}
|
|
66
|
-
[data-popper-placement^='top'] .
|
|
66
|
+
[data-popper-placement^='top'] ._wrapperHidden_4nj7mk_45{
|
|
67
67
|
transform:translateY(10px);
|
|
68
68
|
}
|
|
69
|
-
[data-popper-placement^='bottom'] .
|
|
69
|
+
[data-popper-placement^='bottom'] ._wrapperHidden_4nj7mk_45{
|
|
70
70
|
transform:translateY(-10px);
|
|
71
71
|
}
|
|
72
|
-
[data-popper-placement^='right'] .
|
|
72
|
+
[data-popper-placement^='right'] ._wrapperHidden_4nj7mk_45{
|
|
73
73
|
transform:translateX(-10px);
|
|
74
74
|
}
|
|
75
|
-
[data-popper-placement^='left'] .
|
|
75
|
+
[data-popper-placement^='left'] ._wrapperHidden_4nj7mk_45{
|
|
76
76
|
transform:translateX(10px);
|
|
77
77
|
}
|
|
78
|
-
.
|
|
78
|
+
._modeClassic_4nj7mk_65 ._contentWrapper_4nj7mk_25{
|
|
79
79
|
background-color:rgb(calc(255 - var(--_rs-theme-dark-coefficient, 0)*230), calc(255 - var(--_rs-theme-dark-coefficient, 0)*230), calc(255 - var(--_rs-theme-dark-coefficient, 0)*227));
|
|
80
80
|
}
|
|
81
|
-
.
|
|
81
|
+
._modeRock_4nj7mk_69 ._contentWrapper_4nj7mk_25{
|
|
82
82
|
background-color:rgb(calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(28 + var(--_rs-theme-dark-coefficient, 0)*227));
|
|
83
83
|
}
|
|
84
|
-
.
|
|
84
|
+
._modeClassic_4nj7mk_65._themeDark_4nj7mk_10 ._contentWrapper_4nj7mk_25, ._modeRock_4nj7mk_69._themeLight_4nj7mk_7 ._contentWrapper_4nj7mk_25{
|
|
85
85
|
color-scheme:dark;
|
|
86
86
|
}
|
|
87
|
-
.
|
|
87
|
+
._modeRock_4nj7mk_69{
|
|
88
88
|
--rs-parent-color-primary-light-theme:var(--rs-color-primary-light-theme);
|
|
89
89
|
--rs-parent-color-primary-dim-light-theme:var(
|
|
90
90
|
--rs-color-primary-dim-light-theme
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
--rs-color-primary-t-fog-dark-theme
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
|
-
.
|
|
116
|
+
._modeRock_4nj7mk_69 > *{
|
|
117
117
|
--rs-color-primary-dark-theme:var(--rs-parent-color-primary-light-theme);
|
|
118
118
|
--rs-color-primary-dim-dark-theme:var(
|
|
119
119
|
--rs-parent-color-primary-dim-light-theme
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
3
|
+
import { useState, useEffect, useLayoutEffect } from 'react';
|
|
3
4
|
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
4
5
|
const DROPDOWN_TRANSITION_PROPERTIES = ['opacity', 'transform'];
|
|
5
6
|
|
|
@@ -15,119 +16,181 @@ var DROPDOWN_STATES;
|
|
|
15
16
|
DROPDOWN_STATES["CLOSE"] = "CLOSE";
|
|
16
17
|
})(DROPDOWN_STATES || (DROPDOWN_STATES = {}));
|
|
17
18
|
|
|
18
|
-
function useDropdownState(
|
|
19
|
-
|
|
19
|
+
function useDropdownState(t0) {
|
|
20
|
+
const $ = c(16);
|
|
21
|
+
const {
|
|
20
22
|
isOpen,
|
|
21
23
|
cancelCloseAnimation,
|
|
22
24
|
contentRef,
|
|
23
25
|
popperElement,
|
|
24
26
|
resolvedPlacement
|
|
25
|
-
} =
|
|
27
|
+
} = t0;
|
|
26
28
|
const [dropdownState, setDropdownState] = useState(isOpen ? DROPDOWN_STATES.OPENING_PREPARE : DROPDOWN_STATES.CLOSE);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
let t1;
|
|
30
|
+
|
|
31
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
32
|
+
t1 = expectedState => {
|
|
33
|
+
setDropdownState(state => {
|
|
34
|
+
if (state !== expectedState) {
|
|
35
|
+
return state;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (expectedState === DROPDOWN_STATES.CLOSING) {
|
|
39
|
+
return DROPDOWN_STATES.CLOSE;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (expectedState === DROPDOWN_STATES.OPENING) {
|
|
43
|
+
return DROPDOWN_STATES.OPEN;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
return state;
|
|
31
|
-
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
$[0] = t1;
|
|
51
|
+
} else {
|
|
52
|
+
t1 = $[0];
|
|
53
|
+
}
|
|
36
54
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
55
|
+
const completeTransition = t1;
|
|
56
|
+
let t2;
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setDropdownState(state => state === DROPDOWN_STATES.OPENING_PREPARE ? DROPDOWN_STATES.OPENING : state);
|
|
46
|
-
}, []);
|
|
47
|
-
useIsomorphicLayoutEffect(() => {
|
|
48
|
-
const contentElement = contentRef.current;
|
|
49
|
-
|
|
50
|
-
if (dropdownState !== DROPDOWN_STATES.OPENING_PREPARE || !popperElement || !contentElement || !resolvedPlacement) {
|
|
51
|
-
return;
|
|
52
|
-
} // Register the initial opacity/transform with the resolved placement before
|
|
53
|
-
// removing the initial class and starting the opening transition.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
contentElement.getBoundingClientRect();
|
|
57
|
-
completeOpeningPreparation();
|
|
58
|
-
}, [completeOpeningPreparation, contentRef, dropdownState, popperElement, resolvedPlacement]); // Track the transitions that currently belong to the OPENING/CLOSING phase:
|
|
59
|
-
// - normally, wait for both opacity and transform before completing the phase;
|
|
60
|
-
// - a style/placement change can cancel or replace a transition without
|
|
61
|
-
// changing the phase; follow the latest one, including a replacement that
|
|
62
|
-
// appears just after the previous transition finishes;
|
|
63
|
-
// - if OPENING changes to CLOSING (or vice versa), cleanup invalidates these
|
|
64
|
-
// waiters and the next phase installs its own, so a stale transition cannot
|
|
65
|
-
// complete it;
|
|
66
|
-
// - if no transitions are created (for example, their duration is 0s),
|
|
67
|
-
// complete the phase immediately.
|
|
68
|
-
|
|
69
|
-
useIsomorphicLayoutEffect(() => {
|
|
70
|
-
if (dropdownState !== DROPDOWN_STATES.OPENING && dropdownState !== DROPDOWN_STATES.CLOSING) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
58
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
59
|
+
t2 = () => {
|
|
60
|
+
setDropdownState(_temp);
|
|
61
|
+
};
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
$[1] = t2;
|
|
64
|
+
} else {
|
|
65
|
+
t2 = $[1];
|
|
66
|
+
}
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
const completeOpeningPreparation = t2;
|
|
69
|
+
let t3;
|
|
70
|
+
let t4;
|
|
79
71
|
|
|
80
|
-
|
|
72
|
+
if ($[2] !== contentRef || $[3] !== dropdownState || $[4] !== popperElement || $[5] !== resolvedPlacement) {
|
|
73
|
+
t3 = () => {
|
|
74
|
+
const contentElement = contentRef.current;
|
|
81
75
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
completeTransition(dropdownState);
|
|
76
|
+
if (dropdownState !== DROPDOWN_STATES.OPENING_PREPARE || !popperElement || !contentElement || !resolvedPlacement) {
|
|
77
|
+
return;
|
|
85
78
|
}
|
|
79
|
+
|
|
80
|
+
contentElement.getBoundingClientRect();
|
|
81
|
+
completeOpeningPreparation();
|
|
86
82
|
};
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
t4 = [completeOpeningPreparation, contentRef, dropdownState, popperElement, resolvedPlacement];
|
|
85
|
+
$[2] = contentRef;
|
|
86
|
+
$[3] = dropdownState;
|
|
87
|
+
$[4] = popperElement;
|
|
88
|
+
$[5] = resolvedPlacement;
|
|
89
|
+
$[6] = t3;
|
|
90
|
+
$[7] = t4;
|
|
91
|
+
} else {
|
|
92
|
+
t3 = $[6];
|
|
93
|
+
t4 = $[7];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
useIsomorphicLayoutEffect(t3, t4);
|
|
97
|
+
let t5;
|
|
98
|
+
|
|
99
|
+
if ($[8] !== contentRef || $[9] !== dropdownState) {
|
|
100
|
+
t5 = () => {
|
|
101
|
+
if (dropdownState !== DROPDOWN_STATES.OPENING && dropdownState !== DROPDOWN_STATES.CLOSING) {
|
|
102
|
+
return;
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
const
|
|
105
|
+
const contentElement_0 = contentRef.current;
|
|
94
106
|
|
|
95
|
-
if (!
|
|
96
|
-
return
|
|
107
|
+
if (!contentElement_0) {
|
|
108
|
+
return;
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
let isCurrentPhase = true;
|
|
112
|
+
|
|
113
|
+
const completeCurrentPhase = () => {
|
|
114
|
+
if (isCurrentPhase) {
|
|
115
|
+
completeTransition(dropdownState);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const waitForCurrentTransition = (property, previousTransition) => {
|
|
100
120
|
if (!isCurrentPhase) {
|
|
101
121
|
return Promise.resolve();
|
|
102
122
|
}
|
|
103
123
|
|
|
104
|
-
const
|
|
124
|
+
const transition = getDropdownTransition(contentElement_0, property);
|
|
105
125
|
|
|
106
|
-
if (
|
|
107
|
-
return
|
|
126
|
+
if (!transition || transition === previousTransition) {
|
|
127
|
+
return Promise.resolve();
|
|
108
128
|
}
|
|
109
129
|
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
130
|
+
return transition.finished.then(() => {
|
|
131
|
+
if (!isCurrentPhase) {
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
}
|
|
113
134
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
const replacementTransition = getDropdownTransition(contentElement_0, property);
|
|
136
|
+
|
|
137
|
+
if (replacementTransition && replacementTransition !== transition) {
|
|
138
|
+
return waitForCurrentTransition(property, transition);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return Promise.resolve();
|
|
142
|
+
}, () => waitForCurrentTransition(property, transition));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
Promise.all(DROPDOWN_TRANSITION_PROPERTIES.map(property_0 => waitForCurrentTransition(property_0))).then(completeCurrentPhase);
|
|
146
|
+
return () => {
|
|
147
|
+
isCurrentPhase = false;
|
|
148
|
+
};
|
|
117
149
|
};
|
|
118
|
-
|
|
150
|
+
|
|
151
|
+
$[8] = contentRef;
|
|
152
|
+
$[9] = dropdownState;
|
|
153
|
+
$[10] = t5;
|
|
154
|
+
} else {
|
|
155
|
+
t5 = $[10];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let t6;
|
|
159
|
+
|
|
160
|
+
if ($[11] !== contentRef || $[12] !== dropdownState || $[13] !== popperElement || $[14] !== resolvedPlacement) {
|
|
161
|
+
t6 = [completeTransition, contentRef, dropdownState, popperElement, resolvedPlacement];
|
|
162
|
+
$[11] = contentRef;
|
|
163
|
+
$[12] = dropdownState;
|
|
164
|
+
$[13] = popperElement;
|
|
165
|
+
$[14] = resolvedPlacement;
|
|
166
|
+
$[15] = t6;
|
|
167
|
+
} else {
|
|
168
|
+
t6 = $[15];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
useIsomorphicLayoutEffect(t5, t6);
|
|
119
172
|
|
|
120
173
|
if (isOpen && dropdownState === DROPDOWN_STATES.CLOSE) {
|
|
121
174
|
setDropdownState(DROPDOWN_STATES.OPENING_PREPARE);
|
|
122
|
-
} else
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
175
|
+
} else {
|
|
176
|
+
if (isOpen && dropdownState === DROPDOWN_STATES.CLOSING) {
|
|
177
|
+
setDropdownState(DROPDOWN_STATES.OPENING);
|
|
178
|
+
} else {
|
|
179
|
+
if (!isOpen && dropdownState === DROPDOWN_STATES.OPENING_PREPARE) {
|
|
180
|
+
setDropdownState(DROPDOWN_STATES.CLOSE);
|
|
181
|
+
} else {
|
|
182
|
+
if (!isOpen && (dropdownState === DROPDOWN_STATES.OPEN || dropdownState === DROPDOWN_STATES.OPENING)) {
|
|
183
|
+
setDropdownState(cancelCloseAnimation ? DROPDOWN_STATES.CLOSE : DROPDOWN_STATES.CLOSING);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
128
187
|
}
|
|
129
188
|
|
|
130
189
|
return dropdownState;
|
|
131
190
|
}
|
|
132
191
|
|
|
192
|
+
function _temp(state_0) {
|
|
193
|
+
return state_0 === DROPDOWN_STATES.OPENING_PREPARE ? DROPDOWN_STATES.OPENING : state_0;
|
|
194
|
+
}
|
|
195
|
+
|
|
133
196
|
export { DROPDOWN_STATES, useDropdownState };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
2
|
+
import { useState, useEffect, useLayoutEffect } from 'react';
|
|
3
|
+
const PRIMARY_COLORS = ['--rs-color-primary-light-theme', '--rs-color-primary-dim-light-theme', '--rs-color-primary-fog-light-theme', '--rs-color-primary-t-dim-light-theme', '--rs-color-primary-t-fog-light-theme', '--rs-color-primary-dark-theme', '--rs-color-primary-dim-dark-theme', '--rs-color-primary-fog-dark-theme', '--rs-color-primary-t-dim-dark-theme', '--rs-color-primary-t-fog-dark-theme'];
|
|
4
|
+
|
|
5
|
+
const extractPrimaryColors = styles => {
|
|
6
|
+
const colors = {};
|
|
7
|
+
PRIMARY_COLORS.forEach(varName => {
|
|
8
|
+
colors[varName] = styles.getPropertyValue(varName) || 'initial';
|
|
9
|
+
});
|
|
10
|
+
return colors;
|
|
11
|
+
};
|
|
12
|
+
/** Check out `@rescui/colors/src/public-api.p.css` file */
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const extractThemeFromCss = styles => {
|
|
16
|
+
const themeDark = parseInt(styles.getPropertyValue('--rs-theme-dark'), 10) || 0;
|
|
17
|
+
const themeFlip = parseInt(styles.getPropertyValue('--rs-theme-flip'), 10) || 0;
|
|
18
|
+
const themeDarkCoefficient = themeDark * (1 - themeFlip) + themeFlip * (1 - themeDark);
|
|
19
|
+
return themeDarkCoefficient === 1 ? 'dark' : 'light';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
23
|
+
|
|
24
|
+
const useExtractCssValues = (triggerRef, shouldBeRendered, defaultView) => {
|
|
25
|
+
const $ = c(6);
|
|
26
|
+
let t0;
|
|
27
|
+
|
|
28
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
29
|
+
t0 = {
|
|
30
|
+
primaryColors: {},
|
|
31
|
+
themeFromCss: "light"
|
|
32
|
+
};
|
|
33
|
+
$[0] = t0;
|
|
34
|
+
} else {
|
|
35
|
+
t0 = $[0];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const [cssValues, setCssValues] = useState(t0);
|
|
39
|
+
let t1;
|
|
40
|
+
let t2;
|
|
41
|
+
|
|
42
|
+
if ($[1] !== defaultView || $[2] !== shouldBeRendered || $[3] !== triggerRef) {
|
|
43
|
+
t1 = () => {
|
|
44
|
+
if (triggerRef && shouldBeRendered) {
|
|
45
|
+
const triggerStyles = defaultView?.getComputedStyle(triggerRef);
|
|
46
|
+
|
|
47
|
+
if (triggerStyles) {
|
|
48
|
+
const newCssValues = {
|
|
49
|
+
primaryColors: extractPrimaryColors(triggerStyles),
|
|
50
|
+
themeFromCss: extractThemeFromCss(triggerStyles)
|
|
51
|
+
};
|
|
52
|
+
setCssValues(oldValues => {
|
|
53
|
+
if (JSON.stringify(oldValues) !== JSON.stringify(newCssValues)) {
|
|
54
|
+
return newCssValues;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return oldValues;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
t2 = [triggerRef, shouldBeRendered, defaultView];
|
|
64
|
+
$[1] = defaultView;
|
|
65
|
+
$[2] = shouldBeRendered;
|
|
66
|
+
$[3] = triggerRef;
|
|
67
|
+
$[4] = t1;
|
|
68
|
+
$[5] = t2;
|
|
69
|
+
} else {
|
|
70
|
+
t1 = $[4];
|
|
71
|
+
t2 = $[5];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
useIsomorphicLayoutEffect(t1, t2);
|
|
75
|
+
return cssValues;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { useExtractCssValues };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
2
3
|
import { useState } from 'react';
|
|
3
4
|
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
4
5
|
|
|
@@ -14,22 +15,44 @@ function isOverflown(element) {
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
const useScrollableContainer = () => {
|
|
18
|
+
const $ = c(3);
|
|
17
19
|
const [contentEl, setContentEl] = useState(null);
|
|
18
20
|
const [isScrollable, setIsScrollable] = useState(false);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
let t0;
|
|
22
|
+
|
|
23
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
24
|
+
t0 = entry => {
|
|
25
|
+
const containerEl = entry.target.parentElement;
|
|
26
|
+
|
|
27
|
+
if (containerEl) {
|
|
28
|
+
setIsScrollable(isOverflown(containerEl));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
$[0] = t0;
|
|
33
|
+
} else {
|
|
34
|
+
t0 = $[0];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
useResizeObserver(contentEl, t0);
|
|
38
|
+
const t1 = isScrollable ? "scroll" : "auto";
|
|
39
|
+
let t2;
|
|
40
|
+
|
|
41
|
+
if ($[1] !== t1) {
|
|
42
|
+
const scrollableStyles = {
|
|
43
|
+
overflowY: t1
|
|
44
|
+
};
|
|
45
|
+
t2 = {
|
|
46
|
+
setContentEl,
|
|
47
|
+
scrollableStyles
|
|
48
|
+
};
|
|
49
|
+
$[1] = t1;
|
|
50
|
+
$[2] = t2;
|
|
51
|
+
} else {
|
|
52
|
+
t2 = $[2];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return t2;
|
|
33
56
|
};
|
|
34
57
|
|
|
35
58
|
export { useScrollableContainer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -18,28 +18,29 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
20
20
|
"@popperjs/core": "^2.11.8",
|
|
21
|
-
"@rescui/use-resize-observer": "^0.
|
|
21
|
+
"@rescui/use-resize-observer": "^0.4.0",
|
|
22
22
|
"classnames": "^2.2.6",
|
|
23
23
|
"popper-max-size-modifier": "^0.2.0",
|
|
24
|
+
"react-compiler-runtime": "^1.0.0",
|
|
24
25
|
"react-focus-lock": "^2.8.1",
|
|
25
26
|
"react-popper": "^2.2.5"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"@rescui/ui-contexts": "^0.6.0",
|
|
29
30
|
"prop-types": "^15",
|
|
30
|
-
"react": ">=
|
|
31
|
-
"react-dom": ">=
|
|
31
|
+
"react": ">=17.0.0 <20",
|
|
32
|
+
"react-dom": ">=17.0.0 <20"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@rescui/colors": "^0.3.
|
|
35
|
-
"@rescui/icons": "^1.
|
|
36
|
-
"@rescui/scripts": "^0.5.
|
|
37
|
-
"@rescui/typography": "^0.
|
|
35
|
+
"@rescui/colors": "^0.3.4",
|
|
36
|
+
"@rescui/icons": "^1.9.0",
|
|
37
|
+
"@rescui/scripts": "^0.5.3",
|
|
38
|
+
"@rescui/typography": "^0.28.0",
|
|
38
39
|
"@rescui/visual-regression": "^0.1.4"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "rescui-scripts build"
|
|
42
43
|
},
|
|
43
44
|
"nx": {},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8ffbbe20b8bcbb9ea15204113ab603675d4c03cd"
|
|
45
46
|
}
|
package/lib/css-vars-utils.d.ts
DELETED
package/lib/css-vars-utils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const PRIMARY_COLORS = ['--rs-color-primary-light-theme', '--rs-color-primary-dim-light-theme', '--rs-color-primary-fog-light-theme', '--rs-color-primary-t-dim-light-theme', '--rs-color-primary-t-fog-light-theme', '--rs-color-primary-dark-theme', '--rs-color-primary-dim-dark-theme', '--rs-color-primary-fog-dark-theme', '--rs-color-primary-t-dim-dark-theme', '--rs-color-primary-t-fog-dark-theme'];
|
|
2
|
-
|
|
3
|
-
const extractPrimaryColors = styles => {
|
|
4
|
-
const colors = {};
|
|
5
|
-
PRIMARY_COLORS.forEach(varName => {
|
|
6
|
-
colors[varName] = styles.getPropertyValue(varName) || 'initial';
|
|
7
|
-
});
|
|
8
|
-
return colors;
|
|
9
|
-
};
|
|
10
|
-
/** Check out `@rescui/colors/src/public-api.p.css` file */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const extractThemeFromCss = styles => {
|
|
14
|
-
const themeDark = parseInt(styles.getPropertyValue('--rs-theme-dark'), 10) || 0;
|
|
15
|
-
const themeFlip = parseInt(styles.getPropertyValue('--rs-theme-flip'), 10) || 0;
|
|
16
|
-
const themeDarkCoefficient = themeDark * (1 - themeFlip) + themeFlip * (1 - themeDark);
|
|
17
|
-
return themeDarkCoefficient === 1 ? 'dark' : 'light';
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { extractPrimaryColors, extractThemeFromCss };
|