@rescui/dropdown 0.13.2 → 0.13.3-floating-ui-migration-19bb1e9d6.6.sha-19bb1e9d6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `autoUpdate()` that applies a new trigger width in the next animation frame.
3
+ * The new width resizes the dropdown content, which `useScrollableContainer` observes.
4
+ * If it happens in the same ResizeObserver loop as the trigger resize, the browser can't
5
+ * deliver that notification and reports "ResizeObserver loop completed with undelivered notifications".
6
+ */
7
+ export declare function autoUpdateDropdown(reference: Element, floating: HTMLElement, update: () => void): () => void;
@@ -0,0 +1,50 @@
1
+ import { autoUpdate } from '@floating-ui/react-dom';
2
+
3
+ /**
4
+ * `autoUpdate()` that applies a new trigger width in the next animation frame.
5
+ * The new width resizes the dropdown content, which `useScrollableContainer` observes.
6
+ * If it happens in the same ResizeObserver loop as the trigger resize, the browser can't
7
+ * deliver that notification and reports "ResizeObserver loop completed with undelivered notifications".
8
+ */
9
+ function autoUpdateDropdown(reference, floating, update) {
10
+ const cleanupAutoUpdate = autoUpdate(reference, floating, update, {
11
+ elementResize: false
12
+ });
13
+ let referenceWidth = reference.getBoundingClientRect().width;
14
+ let updateFrame = -1;
15
+ let reobserveFrame = -1;
16
+ const resizeObserver = new ResizeObserver(entries => {
17
+ if (entries.some(_ref => {
18
+ let {
19
+ target
20
+ } = _ref;
21
+ return target === reference;
22
+ })) {
23
+ // Like `autoUpdate()`, stop observing the dropdown until the next frame:
24
+ // the new position can change its size within the same loop
25
+ resizeObserver.unobserve(floating);
26
+ cancelAnimationFrame(reobserveFrame);
27
+ reobserveFrame = requestAnimationFrame(() => {
28
+ resizeObserver.observe(floating);
29
+ });
30
+ }
31
+ const previousWidth = referenceWidth;
32
+ referenceWidth = reference.getBoundingClientRect().width;
33
+ if (referenceWidth !== previousWidth) {
34
+ cancelAnimationFrame(updateFrame);
35
+ updateFrame = requestAnimationFrame(update);
36
+ } else {
37
+ update();
38
+ }
39
+ });
40
+ resizeObserver.observe(reference);
41
+ resizeObserver.observe(floating);
42
+ return () => {
43
+ cleanupAutoUpdate();
44
+ resizeObserver.disconnect();
45
+ cancelAnimationFrame(updateFrame);
46
+ cancelAnimationFrame(reobserveFrame);
47
+ };
48
+ }
49
+
50
+ export { autoUpdateDropdown };
@@ -0,0 +1,23 @@
1
+ import type { Middleware, Placement } from '@floating-ui/react-dom';
2
+ import { Property } from 'csstype';
3
+ export type DropdownMaxWidth = 'trigger' | Property.MaxWidth;
4
+ export type DropdownMinWidth = 'trigger' | Property.MinWidth;
5
+ type AutoPlacement = 'auto' | 'auto-start' | 'auto-end';
6
+ export type DropdownPlacement = Placement | AutoPlacement;
7
+ export declare const isAutoPlacement: (placement: DropdownPlacement) => placement is AutoPlacement;
8
+ /**
9
+ * Candidates for `autoPlacement()`, in the order Popper.js used to try them when
10
+ * several placements have the same space: `auto-start` and `auto-end` both try
11
+ * all aligned placements, `-start` first.
12
+ */
13
+ export declare const AUTO_PLACEMENTS: Record<AutoPlacement, Placement[]>;
14
+ export declare const sameWidth: ({ maxWidth, minWidth }: {
15
+ maxWidth?: DropdownMaxWidth;
16
+ minWidth?: DropdownMinWidth;
17
+ }) => Middleware;
18
+ export declare const applyMaxSize: ({ leastMaxHeight, maxHeight, flip }: {
19
+ leastMaxHeight?: number;
20
+ maxHeight?: number;
21
+ flip: boolean;
22
+ }) => Middleware;
23
+ export {};
@@ -0,0 +1,151 @@
1
+ import { detectOverflow } from '@floating-ui/react-dom';
2
+
3
+ const isAutoPlacement = placement => placement.startsWith('auto');
4
+ const ALIGNED_PLACEMENTS = ['top-start', 'top-end', 'bottom-start', 'bottom-end', 'right-start', 'right-end', 'left-start', 'left-end'];
5
+ /**
6
+ * Candidates for `autoPlacement()`, in the order Popper.js used to try them when
7
+ * several placements have the same space: `auto-start` and `auto-end` both try
8
+ * all aligned placements, `-start` first.
9
+ */
10
+ const AUTO_PLACEMENTS = {
11
+ auto: ['top', 'bottom', 'right', 'left'],
12
+ 'auto-start': ALIGNED_PLACEMENTS,
13
+ 'auto-end': ALIGNED_PLACEMENTS
14
+ };
15
+ const OPPOSITE_SIDES = {
16
+ top: 'bottom',
17
+ bottom: 'top'
18
+ };
19
+ function getMaxWidth(dropdownMaxWidth, referenceWidth) {
20
+ if (dropdownMaxWidth === 'trigger') {
21
+ return `${referenceWidth}px`;
22
+ } else if (typeof dropdownMaxWidth === 'number') {
23
+ return `${dropdownMaxWidth}px`;
24
+ } else if (dropdownMaxWidth) {
25
+ return dropdownMaxWidth;
26
+ }
27
+ return ''; //rely on CSS by default
28
+ }
29
+ function getMinWidth(dropdownMinWidth, referenceWidth) {
30
+ if (dropdownMinWidth === 'trigger') {
31
+ return `${referenceWidth}px`;
32
+ }
33
+ if (typeof dropdownMinWidth === 'number') {
34
+ return `${dropdownMinWidth}px`;
35
+ } else if (dropdownMinWidth) {
36
+ return dropdownMinWidth;
37
+ }
38
+ return ''; //rely on CSS by default
39
+ }
40
+ const sameWidth = _ref => {
41
+ let {
42
+ maxWidth,
43
+ minWidth
44
+ } = _ref;
45
+ return {
46
+ name: 'sameWidth',
47
+ options: {
48
+ maxWidth,
49
+ minWidth
50
+ },
51
+ async fn(_ref2) {
52
+ let {
53
+ elements,
54
+ platform,
55
+ rects
56
+ } = _ref2;
57
+ // Apply the widths right away, so the next middleware get the final size of the dropdown
58
+ elements.floating.style.minWidth = getMinWidth(minWidth, rects.reference.width);
59
+ elements.floating.style.maxWidth = getMaxWidth(maxWidth, rects.reference.width);
60
+ const {
61
+ width
62
+ } = await platform.getDimensions(elements.floating);
63
+ return width === rects.floating.width ? {} : {
64
+ reset: {
65
+ rects: true
66
+ }
67
+ };
68
+ }
69
+ };
70
+ };
71
+ const applyMaxSize = _ref3 => {
72
+ let {
73
+ leastMaxHeight = 0,
74
+ maxHeight = Infinity,
75
+ flip
76
+ } = _ref3;
77
+ return {
78
+ name: 'applyMaxSize',
79
+ options: {
80
+ leastMaxHeight,
81
+ maxHeight,
82
+ flip
83
+ },
84
+ async fn(state) {
85
+ const {
86
+ placement,
87
+ initialPlacement,
88
+ rects,
89
+ middlewareData,
90
+ elements,
91
+ platform
92
+ } = state;
93
+ const data = middlewareData.applyMaxSize ?? {};
94
+ const measuredHeight = data.measuredHeight ?? rects.floating.height;
95
+ const [side, alignment] = placement.split('-');
96
+ const overflow = await detectOverflow(state);
97
+ const heightLeft = rects.floating.height - overflow[side === 'top' ? 'top' : 'bottom'];
98
+ if (flip && !data.flipped && placement === initialPlacement && OPPOSITE_SIDES[side] && heightLeft < leastMaxHeight && measuredHeight >= leastMaxHeight) {
99
+ // Even `leastMaxHeight` doesn't fit: check if it fits on the opposite side
100
+ return {
101
+ data: {
102
+ measuredHeight,
103
+ flipped: true
104
+ },
105
+ reset: {
106
+ placement: [OPPOSITE_SIDES[side], alignment].filter(Boolean).join('-'),
107
+ rects: {
108
+ ...rects,
109
+ floating: {
110
+ ...rects.floating,
111
+ height: leastMaxHeight
112
+ }
113
+ }
114
+ }
115
+ };
116
+ }
117
+ let resultMaxHeight;
118
+ if (maxHeight > heightLeft && heightLeft > leastMaxHeight) {
119
+ resultMaxHeight = heightLeft;
120
+ } else if (heightLeft < leastMaxHeight) {
121
+ resultMaxHeight = leastMaxHeight;
122
+ } else {
123
+ resultMaxHeight = maxHeight;
124
+ }
125
+ const resultData = {
126
+ measuredHeight,
127
+ maxHeight: resultMaxHeight === Infinity ? undefined : resultMaxHeight
128
+ };
129
+ // Apply the limit right away and position the dropdown by its final size, it matters for the top placements.
130
+ // Borders, paddings and min-height make the dropdown taller than its max-height.
131
+ elements.floating.style.maxHeight = typeof resultData.maxHeight === 'number' ? `${resultData.maxHeight}px` : resultData.maxHeight ?? '';
132
+ const {
133
+ width,
134
+ height
135
+ } = await platform.getDimensions(elements.floating);
136
+ if (width !== rects.floating.width || height !== rects.floating.height) {
137
+ return {
138
+ data: resultData,
139
+ reset: {
140
+ rects: true
141
+ }
142
+ };
143
+ }
144
+ return {
145
+ data: resultData
146
+ };
147
+ }
148
+ };
149
+ };
150
+
151
+ export { AUTO_PLACEMENTS, applyMaxSize, isAutoPlacement, sameWidth };
package/lib/dropdown.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { ReactNode, JSX } from 'react';
3
- import type { ReferenceChildrenProps } from 'react-popper';
4
3
  import { Theme } from '@rescui/ui-contexts';
5
- import type { Placement } from '@popperjs/core';
6
- import { DropdownMaxWidth, DropdownMinWidth } from './custom-modifiers';
7
- export type DropdownTrigger = ((props: ReferenceChildrenProps) => JSX.Element) | JSX.Element;
4
+ import { DropdownMaxWidth, DropdownMinWidth, DropdownPlacement } from './custom-middleware';
5
+ interface DropdownTriggerProps {
6
+ ref: React.Ref<any>;
7
+ }
8
+ export type DropdownTrigger = ((props: DropdownTriggerProps) => JSX.Element) | JSX.Element;
8
9
  export interface DropdownProps {
9
10
  trigger: DropdownTrigger;
10
11
  isOpen: boolean;
@@ -27,7 +28,7 @@ export interface DropdownProps {
27
28
  maxWidth?: DropdownMaxWidth;
28
29
  className?: string;
29
30
  mode?: 'classic' | 'rock';
30
- placement?: Placement;
31
+ placement?: DropdownPlacement;
31
32
  /** @ignore */
32
33
  cancelCloseAnimation?: boolean;
33
34
  children?: ReactNode;
package/lib/dropdown.js CHANGED
@@ -3,18 +3,18 @@ import { c } from 'react-compiler-runtime';
3
3
  import React, { useState, useRef, useImperativeHandle, useContext, useEffect } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import cn from 'classnames';
6
- import { usePopper } from 'react-popper';
7
- import maxSizeModifier from 'popper-max-size-modifier';
6
+ import { useFloating, offset, autoPlacement, flip, shift, limitShift } from '@floating-ui/react-dom';
8
7
  import { useLayeringContext, ThemeContext, getInverseTheme, LayeringProvider, ThemeProvider } from '@rescui/ui-contexts';
9
8
  import FocusLock from 'react-focus-lock';
10
9
  import ReactDOM from 'react-dom';
10
+ import { autoUpdateDropdown } from './auto-update.js';
11
11
  import { useDropdownState, DROPDOWN_STATES } from './use-dropdown-state.js';
12
12
  import { useScrollableContainer } from './use-scrollable-container.js';
13
13
  import styles from './dropdown.p.module.css.js';
14
- import { applyMaxSize, sameWidthModifier } from './custom-modifiers.js';
14
+ import { isAutoPlacement, sameWidth, AUTO_PLACEMENTS, applyMaxSize } from './custom-middleware.js';
15
15
  import { useExtractCssValues } from './use-extract-css-values.js';
16
16
 
17
- function getPopperOptions(_ref) {
17
+ function getMiddleware(_ref) {
18
18
  let {
19
19
  placement,
20
20
  maxHeight,
@@ -23,34 +23,21 @@ function getPopperOptions(_ref) {
23
23
  minWidth,
24
24
  disableFlip = false
25
25
  } = _ref;
26
- return {
27
- placement,
28
- modifiers: [{
29
- name: 'hide',
30
- enabled: false
31
- }, {
32
- name: 'flip',
33
- enabled: !disableFlip
34
- }, {
35
- name: 'offset',
36
- enabled: true,
37
- options: {
38
- offset: [0, 8]
39
- }
40
- }, maxSizeModifier, {
41
- ...applyMaxSize,
42
- options: {
43
- maxHeight,
44
- leastMaxHeight
45
- }
46
- }, {
47
- ...sameWidthModifier,
48
- options: {
49
- maxWidth,
50
- minWidth
51
- }
52
- }]
53
- };
26
+ const isAuto = isAutoPlacement(placement);
27
+ return [sameWidth({
28
+ maxWidth,
29
+ minWidth
30
+ }), offset(8), isAuto ? autoPlacement({
31
+ allowedPlacements: AUTO_PLACEMENTS[placement]
32
+ }) : !disableFlip && flip({
33
+ fallbackStrategy: 'initialPlacement'
34
+ }), shift({
35
+ limiter: limitShift()
36
+ }), applyMaxSize({
37
+ maxHeight,
38
+ leastMaxHeight,
39
+ flip: !isAuto && !disableFlip
40
+ })];
54
41
  }
55
42
  const Portal = _ref2 => {
56
43
  let {
@@ -172,7 +159,7 @@ const MODE_STYLES = {
172
159
  rock: styles.modeRock
173
160
  };
174
161
  const DropdownRender = (t0, externalRef) => {
175
- const $ = c(60);
162
+ const $ = c(70);
176
163
  const {
177
164
  children,
178
165
  trigger,
@@ -274,8 +261,21 @@ const DropdownRender = (t0, externalRef) => {
274
261
  }
275
262
  useKeyPress(t16);
276
263
  let t17;
277
- if ($[16] !== disableFlip || $[17] !== leastMaxHeight || $[18] !== maxHeight || $[19] !== maxWidth || $[20] !== minWidth || $[21] !== placement) {
278
- t17 = getPopperOptions({
264
+ if ($[16] !== popperRef || $[17] !== triggerRef) {
265
+ t17 = {
266
+ reference: triggerRef,
267
+ floating: popperRef
268
+ };
269
+ $[16] = popperRef;
270
+ $[17] = triggerRef;
271
+ $[18] = t17;
272
+ } else {
273
+ t17 = $[18];
274
+ }
275
+ const t18 = isAutoPlacement(placement) ? undefined : placement;
276
+ let t19;
277
+ if ($[19] !== disableFlip || $[20] !== leastMaxHeight || $[21] !== maxHeight || $[22] !== maxWidth || $[23] !== minWidth || $[24] !== placement) {
278
+ t19 = getMiddleware({
279
279
  placement,
280
280
  maxHeight,
281
281
  leastMaxHeight,
@@ -283,71 +283,94 @@ const DropdownRender = (t0, externalRef) => {
283
283
  maxWidth,
284
284
  disableFlip
285
285
  });
286
- $[16] = disableFlip;
287
- $[17] = leastMaxHeight;
288
- $[18] = maxHeight;
289
- $[19] = maxWidth;
290
- $[20] = minWidth;
291
- $[21] = placement;
292
- $[22] = t17;
286
+ $[19] = disableFlip;
287
+ $[20] = leastMaxHeight;
288
+ $[21] = maxHeight;
289
+ $[22] = maxWidth;
290
+ $[23] = minWidth;
291
+ $[24] = placement;
292
+ $[25] = t19;
293
293
  } else {
294
- t17 = $[22];
294
+ t19 = $[25];
295
+ }
296
+ const t20 = popperRef !== null;
297
+ let t21;
298
+ if ($[26] !== t17 || $[27] !== t18 || $[28] !== t19 || $[29] !== t20) {
299
+ t21 = {
300
+ elements: t17,
301
+ placement: t18,
302
+ middleware: t19,
303
+ whileElementsMounted: autoUpdateDropdown,
304
+ open: t20
305
+ };
306
+ $[26] = t17;
307
+ $[27] = t18;
308
+ $[28] = t19;
309
+ $[29] = t20;
310
+ $[30] = t21;
311
+ } else {
312
+ t21 = $[30];
295
313
  }
296
314
  const {
297
- styles: popperStyles,
298
- attributes,
315
+ floatingStyles,
316
+ middlewareData,
317
+ placement: floatingPlacement,
318
+ isPositioned,
299
319
  update
300
- } = usePopper(triggerRef ?? null, popperRef, t17);
301
- const resolvedPlacement = attributes.popper?.["data-popper-placement"] ?? null;
302
- let t18;
303
- if ($[23] !== cancelCloseAnimation || $[24] !== isOpen || $[25] !== popperRef || $[26] !== resolvedPlacement) {
304
- t18 = {
320
+ } = useFloating(t21);
321
+ const resolvedPlacement = isPositioned ? floatingPlacement : null;
322
+ let t22;
323
+ if ($[31] !== cancelCloseAnimation || $[32] !== isOpen || $[33] !== popperRef || $[34] !== resolvedPlacement) {
324
+ t22 = {
305
325
  isOpen,
306
326
  cancelCloseAnimation,
307
327
  contentRef: scrollableRef,
308
328
  popperElement: popperRef,
309
329
  resolvedPlacement
310
330
  };
311
- $[23] = cancelCloseAnimation;
312
- $[24] = isOpen;
313
- $[25] = popperRef;
314
- $[26] = resolvedPlacement;
315
- $[27] = t18;
331
+ $[31] = cancelCloseAnimation;
332
+ $[32] = isOpen;
333
+ $[33] = popperRef;
334
+ $[34] = resolvedPlacement;
335
+ $[35] = t22;
316
336
  } else {
317
- t18 = $[27];
337
+ t22 = $[35];
318
338
  }
319
- const dropdownState = useDropdownState(t18);
320
- let t19;
321
- if ($[28] !== update) {
322
- t19 = () => ({
339
+ const dropdownState = useDropdownState(t22);
340
+ let t23;
341
+ if ($[36] !== popperRef || $[37] !== update) {
342
+ t23 = () => ({
323
343
  scheduleUpdate: () => {
324
- update?.();
344
+ if (popperRef) {
345
+ update();
346
+ }
325
347
  }
326
348
  });
327
- $[28] = update;
328
- $[29] = t19;
349
+ $[36] = popperRef;
350
+ $[37] = update;
351
+ $[38] = t23;
329
352
  } else {
330
- t19 = $[29];
353
+ t23 = $[38];
331
354
  }
332
- useImperativeHandle(externalRef, t19);
355
+ useImperativeHandle(externalRef, t23);
333
356
  const {
334
357
  dropdownZIndex
335
358
  } = useLayeringContext();
336
- let t20;
337
- if ($[30] !== trigger) {
338
- t20 = typeof trigger === "function" ? trigger({
359
+ let t24;
360
+ if ($[39] !== trigger) {
361
+ t24 = typeof trigger === "function" ? trigger({
339
362
  ref: setTriggerRef
340
363
  }) : /*#__PURE__*/React.createElement("span", {
341
364
  "data-test": "dropdown-trigger",
342
365
  className: styles.triggerWrapper,
343
366
  ref: setTriggerRef
344
367
  }, trigger);
345
- $[30] = trigger;
346
- $[31] = t20;
368
+ $[39] = trigger;
369
+ $[40] = t24;
347
370
  } else {
348
- t20 = $[31];
371
+ t24 = $[40];
349
372
  }
350
- const triggerRenderer = t20;
373
+ const triggerRenderer = t24;
351
374
  const dropdownShouldBeRendered = dropdownState !== DROPDOWN_STATES.CLOSE;
352
375
  const wrapperIsInitial = dropdownState === DROPDOWN_STATES.OPENING_PREPARE;
353
376
  const wrapperShouldBeHidden = wrapperIsInitial || dropdownState === DROPDOWN_STATES.CLOSING;
@@ -360,31 +383,32 @@ const DropdownRender = (t0, externalRef) => {
360
383
  noProvider
361
384
  } = useContext(ThemeContext);
362
385
  const theme = themeFromProps || (noProvider ? themeFromCss : themeFromContext);
363
- let t21;
364
- if ($[32] !== mode || $[33] !== theme) {
365
- t21 = mode === "rock" ? getInverseTheme(theme) : theme;
366
- $[32] = mode;
367
- $[33] = theme;
368
- $[34] = t21;
386
+ let t25;
387
+ if ($[41] !== mode || $[42] !== theme) {
388
+ t25 = mode === "rock" ? getInverseTheme(theme) : theme;
389
+ $[41] = mode;
390
+ $[42] = theme;
391
+ $[43] = t25;
369
392
  } else {
370
- t21 = $[34];
393
+ t25 = $[43];
371
394
  }
372
- const childrenTheme = t21;
373
- let t22;
374
- 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) {
375
- t22 = dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
395
+ const childrenTheme = t25;
396
+ let t26;
397
+ if ($[44] !== children || $[45] !== childrenTheme || $[46] !== className || $[47] !== disableFocusLock || $[48] !== dropdownShouldBeRendered || $[49] !== dropdownState || $[50] !== dropdownZIndex || $[51] !== floatingStyles || $[52] !== maxHeight || $[53] !== middlewareData || $[54] !== mode || $[55] !== noProvider || $[56] !== ownerDocument?.body || $[57] !== primaryColors || $[58] !== renderInTrigger || $[59] !== resolvedPlacement || $[60] !== scrollableStyles || $[61] !== setContentEl || $[62] !== theme || $[63] !== triggerRef || $[64] !== wrapperIsInitial || $[65] !== wrapperShouldBeHidden) {
398
+ t26 = dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
376
399
  target: renderInTrigger ? triggerRef : ownerDocument?.body
377
- }, /*#__PURE__*/React.createElement("div", Object.assign({
400
+ }, /*#__PURE__*/React.createElement("div", {
378
401
  ref: setPopperRef,
379
402
  style: {
380
- maxHeight,
381
- ...popperStyles.popper,
403
+ maxHeight: middlewareData.applyMaxSize?.maxHeight ?? maxHeight,
404
+ ...floatingStyles,
382
405
  zIndex: dropdownZIndex,
383
406
  ...primaryColors
384
407
  },
385
408
  className: cn(styles.dropdown, className, MODE_STYLES[mode], THEME_STYLES[theme]),
386
- "data-test": "dropdown"
387
- }, attributes.popper), /*#__PURE__*/React.createElement(LayeringProvider, {
409
+ "data-test": "dropdown",
410
+ "data-popper-placement": resolvedPlacement ?? undefined
411
+ }, /*#__PURE__*/React.createElement(LayeringProvider, {
388
412
  baseLayer: "dropdown"
389
413
  }, /*#__PURE__*/React.createElement("div", {
390
414
  ref: scrollableRef,
@@ -405,41 +429,42 @@ const DropdownRender = (t0, externalRef) => {
405
429
  preventScroll: true
406
430
  }
407
431
  }, children))))));
408
- $[35] = attributes.popper;
409
- $[36] = children;
410
- $[37] = childrenTheme;
411
- $[38] = className;
412
- $[39] = disableFocusLock;
413
- $[40] = dropdownShouldBeRendered;
414
- $[41] = dropdownState;
415
- $[42] = dropdownZIndex;
416
- $[43] = maxHeight;
417
- $[44] = mode;
418
- $[45] = noProvider;
419
- $[46] = ownerDocument?.body;
420
- $[47] = popperStyles;
421
- $[48] = primaryColors;
422
- $[49] = renderInTrigger;
423
- $[50] = scrollableStyles;
424
- $[51] = setContentEl;
425
- $[52] = theme;
426
- $[53] = triggerRef;
427
- $[54] = wrapperIsInitial;
428
- $[55] = wrapperShouldBeHidden;
429
- $[56] = t22;
432
+ $[44] = children;
433
+ $[45] = childrenTheme;
434
+ $[46] = className;
435
+ $[47] = disableFocusLock;
436
+ $[48] = dropdownShouldBeRendered;
437
+ $[49] = dropdownState;
438
+ $[50] = dropdownZIndex;
439
+ $[51] = floatingStyles;
440
+ $[52] = maxHeight;
441
+ $[53] = middlewareData;
442
+ $[54] = mode;
443
+ $[55] = noProvider;
444
+ $[56] = ownerDocument?.body;
445
+ $[57] = primaryColors;
446
+ $[58] = renderInTrigger;
447
+ $[59] = resolvedPlacement;
448
+ $[60] = scrollableStyles;
449
+ $[61] = setContentEl;
450
+ $[62] = theme;
451
+ $[63] = triggerRef;
452
+ $[64] = wrapperIsInitial;
453
+ $[65] = wrapperShouldBeHidden;
454
+ $[66] = t26;
430
455
  } else {
431
- t22 = $[56];
456
+ t26 = $[66];
432
457
  }
433
- let t23;
434
- if ($[57] !== t22 || $[58] !== triggerRenderer) {
435
- t23 = /*#__PURE__*/React.createElement(React.Fragment, null, triggerRenderer, t22);
436
- $[57] = t22;
437
- $[58] = triggerRenderer;
438
- $[59] = t23;
458
+ let t27;
459
+ if ($[67] !== t26 || $[68] !== triggerRenderer) {
460
+ t27 = /*#__PURE__*/React.createElement(React.Fragment, null, triggerRenderer, t26);
461
+ $[67] = t26;
462
+ $[68] = triggerRenderer;
463
+ $[69] = t27;
439
464
  } else {
440
- t23 = $[59];
465
+ t27 = $[69];
441
466
  }
442
- return t23;
467
+ return t27;
443
468
  };
444
469
  /* eslint-enable react/prop-types */
445
470
  const Dropdown = /*#__PURE__*/React.forwardRef(DropdownRender);
@@ -1,3 +1,3 @@
1
- var styles = {"themeLight":"_themeLight_1hz0kyq_7","themeDark":"_themeDark_1hz0kyq_10","dropdown":"_dropdown_1hz0kyq_14","triggerWrapper":"_triggerWrapper_1hz0kyq_21","contentWrapper":"_contentWrapper_1hz0kyq_25","wrapperInitial":"_wrapperInitial_1hz0kyq_41","wrapperHidden":"_wrapperHidden_1hz0kyq_45","modeClassic":"_modeClassic_1hz0kyq_65","modeRock":"_modeRock_1hz0kyq_69"};
1
+ var styles = {"themeLight":"_themeLight_1tv08om_7","themeDark":"_themeDark_1tv08om_10","dropdown":"_dropdown_1tv08om_14","triggerWrapper":"_triggerWrapper_1tv08om_21","contentWrapper":"_contentWrapper_1tv08om_25","wrapperInitial":"_wrapperInitial_1tv08om_41","wrapperHidden":"_wrapperHidden_1tv08om_45","modeClassic":"_modeClassic_1tv08om_65","modeRock":"_modeRock_1tv08om_69"};
2
2
 
3
3
  export { styles as default };
package/lib/index.css CHANGED
@@ -4,14 +4,14 @@
4
4
  initial-value:0;
5
5
  }
6
6
 
7
- ._themeLight_1hz0kyq_7{
7
+ ._themeLight_1tv08om_7{
8
8
  --rs-theme-dark:0;
9
9
  }
10
- ._themeDark_1hz0kyq_10{
10
+ ._themeDark_1tv08om_10{
11
11
  --rs-theme-dark:1;
12
12
  }
13
13
 
14
- ._dropdown_1hz0kyq_14{
14
+ ._dropdown_1tv08om_14{
15
15
  --_rs-theme-dark:var(
16
16
  --_rs-internal-force-theme-dark-consult-rescui-before-using,
17
17
  var(--rs-theme-dark, 0)
@@ -23,7 +23,7 @@
23
23
 
24
24
  @supports (color: color-mix(in srgb, #fff 50%, #000 50%)){
25
25
 
26
- ._dropdown_1hz0kyq_14{
26
+ ._dropdown_1tv08om_14{
27
27
  --_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)));
28
28
  --_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)));
29
29
  --_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)));
@@ -34,7 +34,7 @@
34
34
 
35
35
  @supports not (color: color-mix(in srgb, #fff 50%, #000 50%)){
36
36
 
37
- ._dropdown_1hz0kyq_14{
37
+ ._dropdown_1tv08om_14{
38
38
  --_rs-color-primary:rgb(calc(107 * var(--_rs-theme-light-coefficient, 1) + 132 * var(--_rs-theme-dark-coefficient, 0)), calc(87 * var(--_rs-theme-light-coefficient, 1) + 115 * var(--_rs-theme-dark-coefficient, 0)), 255);
39
39
  --_rs-color-primary-dim:rgb(calc(137 * var(--_rs-theme-light-coefficient, 1) + 111 * var(--_rs-theme-dark-coefficient, 0)), calc(121 * var(--_rs-theme-light-coefficient, 1) + 97 * var(--_rs-theme-dark-coefficient, 0)), calc(255 * var(--_rs-theme-light-coefficient, 1) + 210 * var(--_rs-theme-dark-coefficient, 0)));
40
40
  --_rs-color-primary-fog:rgb(calc(225 * var(--_rs-theme-light-coefficient, 1) + 46 * var(--_rs-theme-dark-coefficient, 0)), calc(221 * var(--_rs-theme-light-coefficient, 1) + 43 * var(--_rs-theme-dark-coefficient, 0)), calc(255 * var(--_rs-theme-light-coefficient, 1) + 73 * var(--_rs-theme-dark-coefficient, 0)));
@@ -43,16 +43,16 @@
43
43
  }
44
44
  }
45
45
 
46
- ._dropdown_1hz0kyq_14 {
46
+ ._dropdown_1tv08om_14 {
47
47
  display:flex;
48
48
  flex-direction:column;
49
49
  }
50
50
 
51
- ._triggerWrapper_1hz0kyq_21{
51
+ ._triggerWrapper_1tv08om_21{
52
52
  display:inline-block;
53
53
  }
54
54
 
55
- ._contentWrapper_1hz0kyq_25{
55
+ ._contentWrapper_1tv08om_25{
56
56
  position:relative;
57
57
 
58
58
  display:block;
@@ -67,42 +67,42 @@
67
67
  transition:opacity var(--rs-transition-function, ease) 200ms, transform var(--rs-transition-function, ease) 200ms;
68
68
  }
69
69
 
70
- ._wrapperInitial_1hz0kyq_41{
70
+ ._wrapperInitial_1tv08om_41{
71
71
  transition:none;
72
72
  }
73
73
 
74
- ._wrapperHidden_1hz0kyq_45{
74
+ ._wrapperHidden_1tv08om_45{
75
75
  opacity:0;
76
76
  }
77
77
 
78
- [data-popper-placement^='top'] ._wrapperHidden_1hz0kyq_45{
78
+ [data-popper-placement^='top'] ._wrapperHidden_1tv08om_45{
79
79
  transform:translateY(10px);
80
80
  }
81
81
 
82
- [data-popper-placement^='bottom'] ._wrapperHidden_1hz0kyq_45{
82
+ [data-popper-placement^='bottom'] ._wrapperHidden_1tv08om_45{
83
83
  transform:translateY(-10px);
84
84
  }
85
85
 
86
- [data-popper-placement^='right'] ._wrapperHidden_1hz0kyq_45{
86
+ [data-popper-placement^='right'] ._wrapperHidden_1tv08om_45{
87
87
  transform:translateX(-10px);
88
88
  }
89
89
 
90
- [data-popper-placement^='left'] ._wrapperHidden_1hz0kyq_45{
90
+ [data-popper-placement^='left'] ._wrapperHidden_1tv08om_45{
91
91
  transform:translateX(10px);
92
92
  }
93
93
 
94
- ._modeClassic_1hz0kyq_65 ._contentWrapper_1hz0kyq_25{
94
+ ._modeClassic_1tv08om_65 ._contentWrapper_1tv08om_25{
95
95
  background-color:rgb(calc(255 - 230 * var(--_rs-theme-dark-coefficient, 0)), calc(255 - 230 * var(--_rs-theme-dark-coefficient, 0)), calc(255 - 227 * var(--_rs-theme-dark-coefficient, 0)));
96
96
  }
97
97
 
98
- ._modeRock_1hz0kyq_69 ._contentWrapper_1hz0kyq_25{
98
+ ._modeRock_1tv08om_69 ._contentWrapper_1tv08om_25{
99
99
  background-color:rgb(calc(25 + 230 * var(--_rs-theme-dark-coefficient, 0)), calc(25 + 230 * var(--_rs-theme-dark-coefficient, 0)), calc(28 + 227 * var(--_rs-theme-dark-coefficient, 0)));
100
100
  }
101
101
 
102
- ._modeClassic_1hz0kyq_65._themeDark_1hz0kyq_10 ._contentWrapper_1hz0kyq_25, ._modeRock_1hz0kyq_69._themeLight_1hz0kyq_7 ._contentWrapper_1hz0kyq_25{
102
+ ._modeClassic_1tv08om_65._themeDark_1tv08om_10 ._contentWrapper_1tv08om_25, ._modeRock_1tv08om_69._themeLight_1tv08om_7 ._contentWrapper_1tv08om_25{
103
103
  color-scheme:dark;
104
104
  }
105
- ._modeRock_1hz0kyq_69{
105
+ ._modeRock_1tv08om_69{
106
106
  --rs-parent-color-primary-light-theme:var(--rs-color-primary-light-theme);
107
107
  --rs-parent-color-primary-dim-light-theme:var(
108
108
  --rs-color-primary-dim-light-theme
@@ -132,7 +132,7 @@
132
132
  );
133
133
  }
134
134
 
135
- ._modeRock_1hz0kyq_69 > *{
135
+ ._modeRock_1tv08om_69 > *{
136
136
  --rs-color-primary-dark-theme:var(--rs-parent-color-primary-light-theme);
137
137
  --rs-color-primary-dim-dark-theme:var(
138
138
  --rs-parent-color-primary-dim-light-theme
@@ -8,7 +8,7 @@ Dropdown components allow you to display content in an overlay beneath a trigger
8
8
 
9
9
  #### Fixed width example
10
10
 
11
- ```tsx
11
+ ```jsx
12
12
  import { useState } from 'react';
13
13
  import { Dropdown } from '@rescui/dropdown';
14
14
  import { Button } from '@rescui/button';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/dropdown",
3
- "version": "0.13.2",
3
+ "version": "0.13.3-floating-ui-migration-19bb1e9d6.6.sha-19bb1e9d6",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -16,30 +16,28 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@popperjs/core": "^2.11.8",
20
- "@rescui/use-resize-observer": "^0.5.0",
19
+ "@floating-ui/react-dom": "^2.1.9",
20
+ "@rescui/use-resize-observer": "0.5.1-floating-ui-migration-19bb1e9d6.19.sha-19bb1e9d6",
21
21
  "classnames": "^2.2.6",
22
- "popper-max-size-modifier": "^0.2.0",
23
22
  "react-compiler-runtime": "^1.0.0",
24
- "react-focus-lock": "^2.8.1",
25
- "react-popper": "^2.2.5"
23
+ "react-focus-lock": "^2.8.1"
26
24
  },
27
25
  "peerDependencies": {
28
- "@rescui/ui-contexts": "^0.7.0",
26
+ "@rescui/ui-contexts": "^0.7.0 || ^0.8.0",
29
27
  "prop-types": "^15",
30
28
  "react": ">=17.0.0 <20",
31
29
  "react-dom": ">=17.0.0 <20"
32
30
  },
33
31
  "devDependencies": {
34
- "@rescui/colors": "^0.3.6",
35
- "@rescui/icons": "^1.11.2",
36
- "@rescui/scripts": "^0.6.0",
37
- "@rescui/typography": "^0.30.1",
38
- "@rescui/visual-regression": "^0.1.5"
32
+ "@rescui/colors": "0.3.7-floating-ui-migration-19bb1e9d6.6.sha-19bb1e9d6",
33
+ "@rescui/icons": "1.11.3-floating-ui-migration-19bb1e9d6.6.sha-19bb1e9d6",
34
+ "@rescui/scripts": "0.6.0",
35
+ "@rescui/typography": "0.30.2-floating-ui-migration-19bb1e9d6.6.sha-19bb1e9d6",
36
+ "@rescui/visual-regression": "0.1.5"
39
37
  },
40
38
  "scripts": {
41
39
  "build": "rescui-scripts build"
42
40
  },
43
41
  "nx": {},
44
- "gitHead": "428fe8428862945a1199cf875bbe180ccbb71df3"
42
+ "gitHead": "19bb1e9d6209ed46222713346d964bc6af332c37"
45
43
  }
@@ -1,12 +0,0 @@
1
- import type { Modifier } from 'react-popper';
2
- import { Property } from 'csstype';
3
- export type DropdownMaxWidth = 'trigger' | Property.MaxWidth;
4
- export type DropdownMinWidth = 'trigger' | Property.MinWidth;
5
- export declare const sameWidthModifier: Modifier<'sameWidth', {
6
- maxWidth: DropdownMaxWidth;
7
- minWidth: DropdownMinWidth;
8
- }>;
9
- export declare const applyMaxSize: Modifier<'applyMaxSize', {
10
- leastMaxHeight: number;
11
- maxHeight: number;
12
- }>;
@@ -1,91 +0,0 @@
1
- function getMaxWidth(dropdownMaxWidth, referenceWidth) {
2
- if (dropdownMaxWidth === 'trigger') {
3
- return `${referenceWidth}px`;
4
- } else if (typeof dropdownMaxWidth === 'number') {
5
- return `${dropdownMaxWidth}px`;
6
- } else if (dropdownMaxWidth) {
7
- return dropdownMaxWidth;
8
- }
9
- return undefined; //rely on CSS by default
10
- }
11
- function getMinWidth(dropdownMinWidth, referenceWidth) {
12
- if (dropdownMinWidth === 'trigger') {
13
- return `${referenceWidth}px`;
14
- }
15
- if (typeof dropdownMinWidth === 'number') {
16
- return `${dropdownMinWidth}px`;
17
- } else if (dropdownMinWidth) {
18
- return dropdownMinWidth;
19
- }
20
- return undefined; //rely on CSS by default
21
- }
22
- const sameWidthModifier = {
23
- name: 'sameWidth',
24
- enabled: true,
25
- phase: 'beforeWrite',
26
- requires: ['computeStyles'],
27
- fn: _ref => {
28
- let {
29
- state,
30
- options: {
31
- maxWidth,
32
- minWidth
33
- } = {}
34
- } = _ref;
35
- state.styles.popper.minWidth = getMinWidth(minWidth, state.rects.reference.width);
36
- state.styles.popper.maxWidth = getMaxWidth(maxWidth, state.rects.reference.width);
37
- },
38
- effect: _ref2 => {
39
- let {
40
- state,
41
- options: {
42
- maxWidth,
43
- minWidth
44
- } = {}
45
- } = _ref2;
46
- state.elements.popper.style.minWidth = getMinWidth(minWidth, state.elements.reference.offsetWidth);
47
- state.elements.popper.style.maxWidth = getMaxWidth(maxWidth, state.elements.reference.offsetWidth);
48
- return undefined;
49
- }
50
- };
51
- const applyMaxSize = {
52
- name: 'applyMaxSize',
53
- enabled: true,
54
- phase: 'beforeWrite',
55
- requires: ['maxSize'],
56
- // eslint-disable-next-line complexity
57
- fn(_ref3) {
58
- let {
59
- state,
60
- options: {
61
- leastMaxHeight = 0,
62
- maxHeight = Infinity
63
- }
64
- } = _ref3;
65
- const {
66
- height
67
- } = state.modifiersData.maxSize;
68
- const heightLeft = height;
69
- let resultHeightString;
70
- if (maxHeight > heightLeft && heightLeft > leastMaxHeight) {
71
- resultHeightString = `${heightLeft}px`;
72
- if (state.styles.popper.maxHeight !== resultHeightString && state.rects.popper.height >= heightLeft) {
73
- // change popper height for detectOverflow util to force flip modifier to find better placement
74
- state.rects.popper.height = heightLeft;
75
- state.reset = true;
76
- }
77
- } else if (heightLeft < leastMaxHeight) {
78
- resultHeightString = `${leastMaxHeight}px`;
79
- if (state.styles.popper.maxHeight !== resultHeightString && state.rects.popper.height >= leastMaxHeight) {
80
- // change popper height for detectOverflow util to force flip modifier to find better placement
81
- state.rects.popper.height = leastMaxHeight;
82
- state.reset = true;
83
- }
84
- } else {
85
- resultHeightString = `${maxHeight}px`;
86
- }
87
- state.styles.popper.maxHeight = resultHeightString;
88
- }
89
- };
90
-
91
- export { applyMaxSize, sameWidthModifier };