@rescui/dropdown 0.13.4 → 0.15.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/auto-update.d.ts +7 -0
- package/lib/auto-update.js +54 -0
- package/lib/custom-middleware.d.ts +23 -0
- package/lib/custom-middleware.js +151 -0
- package/lib/dropdown.d.ts +51 -7
- package/lib/dropdown.js +299 -187
- package/lib/dropdown.p.module.css.js +1 -1
- package/lib/focus-utils.d.ts +9 -0
- package/lib/focus-utils.js +30 -0
- package/lib/index.css +35 -19
- package/lib/index.d.ts +1 -1
- package/lib/types.d.ts +9 -0
- package/lib/use-dropdown-aria.d.ts +19 -0
- package/lib/use-dropdown-aria.js +121 -0
- package/lib/use-hide-others.d.ts +6 -0
- package/lib/use-hide-others.js +36 -0
- package/llm/components/dropdown.md +59 -0
- package/package.json +5 -6
- package/lib/custom-modifiers.d.ts +0 -12
- package/lib/custom-modifiers.js +0 -91
package/lib/index.css
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
initial-value:0;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
.
|
|
7
|
+
._themeLight_17wpuuu_7{
|
|
8
8
|
--rs-theme-dark:0;
|
|
9
9
|
}
|
|
10
|
-
.
|
|
10
|
+
._themeDark_17wpuuu_10{
|
|
11
11
|
--rs-theme-dark:1;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
.
|
|
14
|
+
._dropdown_17wpuuu_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
|
-
.
|
|
26
|
+
._dropdown_17wpuuu_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
|
-
.
|
|
37
|
+
._dropdown_17wpuuu_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,32 @@
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
.
|
|
46
|
+
._dropdown_17wpuuu_14 {
|
|
47
47
|
display:flex;
|
|
48
48
|
flex-direction:column;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
.
|
|
51
|
+
._triggerWrapper_17wpuuu_21{
|
|
52
52
|
display:inline-block;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
.
|
|
55
|
+
._visuallyHidden_17wpuuu_25{
|
|
56
|
+
position:absolute;
|
|
57
|
+
|
|
58
|
+
overflow:hidden;
|
|
59
|
+
|
|
60
|
+
width:1px;
|
|
61
|
+
height:1px;
|
|
62
|
+
margin:-1px;
|
|
63
|
+
padding:0;
|
|
64
|
+
border:0;
|
|
65
|
+
|
|
66
|
+
white-space:nowrap;
|
|
67
|
+
|
|
68
|
+
clip-path:inset(50%);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
._contentWrapper_17wpuuu_41{
|
|
56
72
|
position:relative;
|
|
57
73
|
|
|
58
74
|
display:block;
|
|
@@ -67,42 +83,42 @@
|
|
|
67
83
|
transition:opacity var(--rs-transition-function, ease) 200ms, transform var(--rs-transition-function, ease) 200ms;
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
.
|
|
86
|
+
._wrapperInitial_17wpuuu_57{
|
|
71
87
|
transition:none;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
.
|
|
90
|
+
._wrapperHidden_17wpuuu_61{
|
|
75
91
|
opacity:0;
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
[data-popper-placement^='top'] .
|
|
94
|
+
[data-popper-placement^='top'] ._wrapperHidden_17wpuuu_61{
|
|
79
95
|
transform:translateY(10px);
|
|
80
96
|
}
|
|
81
97
|
|
|
82
|
-
[data-popper-placement^='bottom'] .
|
|
98
|
+
[data-popper-placement^='bottom'] ._wrapperHidden_17wpuuu_61{
|
|
83
99
|
transform:translateY(-10px);
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
[data-popper-placement^='right'] .
|
|
102
|
+
[data-popper-placement^='right'] ._wrapperHidden_17wpuuu_61{
|
|
87
103
|
transform:translateX(-10px);
|
|
88
104
|
}
|
|
89
105
|
|
|
90
|
-
[data-popper-placement^='left'] .
|
|
106
|
+
[data-popper-placement^='left'] ._wrapperHidden_17wpuuu_61{
|
|
91
107
|
transform:translateX(10px);
|
|
92
108
|
}
|
|
93
109
|
|
|
94
|
-
.
|
|
110
|
+
._modeClassic_17wpuuu_81 ._contentWrapper_17wpuuu_41{
|
|
95
111
|
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
112
|
}
|
|
97
113
|
|
|
98
|
-
.
|
|
114
|
+
._modeRock_17wpuuu_85 ._contentWrapper_17wpuuu_41{
|
|
99
115
|
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
116
|
}
|
|
101
117
|
|
|
102
|
-
.
|
|
118
|
+
._modeClassic_17wpuuu_81._themeDark_17wpuuu_10 ._contentWrapper_17wpuuu_41, ._modeRock_17wpuuu_85._themeLight_17wpuuu_7 ._contentWrapper_17wpuuu_41{
|
|
103
119
|
color-scheme:dark;
|
|
104
120
|
}
|
|
105
|
-
.
|
|
121
|
+
._modeRock_17wpuuu_85{
|
|
106
122
|
--rs-parent-color-primary-light-theme:var(--rs-color-primary-light-theme);
|
|
107
123
|
--rs-parent-color-primary-dim-light-theme:var(
|
|
108
124
|
--rs-color-primary-dim-light-theme
|
|
@@ -132,7 +148,7 @@
|
|
|
132
148
|
);
|
|
133
149
|
}
|
|
134
150
|
|
|
135
|
-
.
|
|
151
|
+
._modeRock_17wpuuu_85 > *{
|
|
136
152
|
--rs-color-primary-dark-theme:var(--rs-parent-color-primary-light-theme);
|
|
137
153
|
--rs-color-primary-dim-dark-theme:var(
|
|
138
154
|
--rs-parent-color-primary-dim-light-theme
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
declare const DefaultDropdown: import("react").ForwardRefExoticComponent<import("./dropdown").DropdownProps & import("react").RefAttributes<import("./dropdown").DropdownImperativeHandle>>;
|
|
5
5
|
export default DefaultDropdown;
|
|
6
6
|
export { Dropdown } from './dropdown';
|
|
7
|
-
export type { DropdownProps, DropdownImperativeHandle } from './dropdown';
|
|
7
|
+
export type { DropdownProps, DropdownImperativeHandle, DropdownTrigger, DropdownTriggerProps, DropdownRole, DropdownInitialFocus } from './dropdown';
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { JSX, RefObject } from 'react';
|
|
3
|
+
export type DropdownRole = 'dialog' | 'alertdialog' | 'menu' | 'listbox' | 'grid' | 'tree';
|
|
4
|
+
export type DropdownInitialFocus = number | RefObject<HTMLElement | null> | 'container';
|
|
5
|
+
export type DropdownTriggerAriaProps = Pick<React.HTMLAttributes<HTMLElement>, 'id' | 'role' | 'aria-haspopup' | 'aria-expanded' | 'aria-controls'>;
|
|
6
|
+
export interface DropdownTriggerProps extends DropdownTriggerAriaProps {
|
|
7
|
+
ref: React.Ref<any>;
|
|
8
|
+
}
|
|
9
|
+
export type DropdownTrigger = ((props: DropdownTriggerProps) => JSX.Element) | JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DropdownRole, DropdownTrigger, DropdownTriggerAriaProps } from './types';
|
|
3
|
+
interface UseDropdownAriaOptions {
|
|
4
|
+
role?: DropdownRole;
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
isModal: boolean;
|
|
7
|
+
trigger: DropdownTrigger;
|
|
8
|
+
/** `id` passed to Dropdown, it's used instead of a generated one */
|
|
9
|
+
id?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* ARIA attributes of the trigger and the popup element for `role`.
|
|
13
|
+
* Without `role`, the trigger gets no attributes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDropdownAria({ role, isOpen, isModal, trigger, id }: UseDropdownAriaOptions): {
|
|
16
|
+
triggerProps: DropdownTriggerAriaProps;
|
|
17
|
+
getPopupProps: (userProps: React.HTMLAttributes<HTMLDivElement>) => React.HTMLAttributes<HTMLDivElement>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
3
|
+
import React, { isValidElement, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
// React 17 has no `useId`. The generated ids are rendered only while the dropdown is open,
|
|
6
|
+
// and it opens only on the client, so a counter doesn't break hydration.
|
|
7
|
+
const useReactId = React.useId ?? (() => undefined);
|
|
8
|
+
let idCounter = 0;
|
|
9
|
+
function useGeneratedId(prefix) {
|
|
10
|
+
const $ = c(6);
|
|
11
|
+
const reactId = useReactId();
|
|
12
|
+
let t0;
|
|
13
|
+
if ($[0] !== prefix) {
|
|
14
|
+
t0 = () => {
|
|
15
|
+
idCounter = idCounter + 1;
|
|
16
|
+
return `${prefix}-${idCounter}`;
|
|
17
|
+
};
|
|
18
|
+
$[0] = prefix;
|
|
19
|
+
$[1] = t0;
|
|
20
|
+
} else {
|
|
21
|
+
t0 = $[1];
|
|
22
|
+
}
|
|
23
|
+
const [fallbackId] = useState(t0);
|
|
24
|
+
let t1;
|
|
25
|
+
if ($[2] !== fallbackId || $[3] !== prefix || $[4] !== reactId) {
|
|
26
|
+
t1 = reactId ? `${prefix}-${reactId.replace(/:/g, "")}` : fallbackId;
|
|
27
|
+
$[2] = fallbackId;
|
|
28
|
+
$[3] = prefix;
|
|
29
|
+
$[4] = reactId;
|
|
30
|
+
$[5] = t1;
|
|
31
|
+
} else {
|
|
32
|
+
t1 = $[5];
|
|
33
|
+
}
|
|
34
|
+
return t1;
|
|
35
|
+
}
|
|
36
|
+
const ARIA_HASPOPUP = {
|
|
37
|
+
dialog: 'dialog',
|
|
38
|
+
alertdialog: 'dialog',
|
|
39
|
+
menu: 'menu',
|
|
40
|
+
listbox: 'listbox',
|
|
41
|
+
grid: 'grid',
|
|
42
|
+
tree: 'tree'
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* ARIA attributes of the trigger and the popup element for `role`.
|
|
46
|
+
* Without `role`, the trigger gets no attributes.
|
|
47
|
+
*/
|
|
48
|
+
function useDropdownAria(t0) {
|
|
49
|
+
const $ = c(14);
|
|
50
|
+
const {
|
|
51
|
+
role,
|
|
52
|
+
isOpen,
|
|
53
|
+
isModal,
|
|
54
|
+
trigger,
|
|
55
|
+
id
|
|
56
|
+
} = t0;
|
|
57
|
+
const generatedPopupId = useGeneratedId("rs-dropdown");
|
|
58
|
+
const generatedTriggerId = useGeneratedId("rs-dropdown-trigger");
|
|
59
|
+
const popupId = id ?? generatedPopupId;
|
|
60
|
+
const elementTriggerId = /*#__PURE__*/isValidElement(trigger) ? trigger.props.id : undefined;
|
|
61
|
+
const menuTriggerId = elementTriggerId ?? generatedTriggerId;
|
|
62
|
+
let t1;
|
|
63
|
+
if ($[0] !== isOpen || $[1] !== menuTriggerId || $[2] !== popupId || $[3] !== role) {
|
|
64
|
+
t1 = role === undefined ? {} : {
|
|
65
|
+
"aria-haspopup": ARIA_HASPOPUP[role],
|
|
66
|
+
"aria-expanded": isOpen,
|
|
67
|
+
"aria-controls": isOpen ? popupId : undefined,
|
|
68
|
+
...(role === "listbox" && {
|
|
69
|
+
role: "combobox"
|
|
70
|
+
}),
|
|
71
|
+
...(role === "menu" && isOpen && {
|
|
72
|
+
id: menuTriggerId
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
$[0] = isOpen;
|
|
76
|
+
$[1] = menuTriggerId;
|
|
77
|
+
$[2] = popupId;
|
|
78
|
+
$[3] = role;
|
|
79
|
+
$[4] = t1;
|
|
80
|
+
} else {
|
|
81
|
+
t1 = $[4];
|
|
82
|
+
}
|
|
83
|
+
const triggerProps = t1;
|
|
84
|
+
const isDialog = role === "dialog" || role === "alertdialog";
|
|
85
|
+
let t2;
|
|
86
|
+
if ($[5] !== isDialog || $[6] !== isModal || $[7] !== menuTriggerId || $[8] !== popupId || $[9] !== role) {
|
|
87
|
+
t2 = userProps => ({
|
|
88
|
+
...(role === "menu" && !userProps["aria-label"] && {
|
|
89
|
+
"aria-labelledby": menuTriggerId
|
|
90
|
+
}),
|
|
91
|
+
...userProps,
|
|
92
|
+
id: role === undefined ? userProps.id : popupId,
|
|
93
|
+
role,
|
|
94
|
+
"aria-modal": isDialog && isModal ? "true" : undefined
|
|
95
|
+
});
|
|
96
|
+
$[5] = isDialog;
|
|
97
|
+
$[6] = isModal;
|
|
98
|
+
$[7] = menuTriggerId;
|
|
99
|
+
$[8] = popupId;
|
|
100
|
+
$[9] = role;
|
|
101
|
+
$[10] = t2;
|
|
102
|
+
} else {
|
|
103
|
+
t2 = $[10];
|
|
104
|
+
}
|
|
105
|
+
const getPopupProps = t2;
|
|
106
|
+
let t3;
|
|
107
|
+
if ($[11] !== getPopupProps || $[12] !== triggerProps) {
|
|
108
|
+
t3 = {
|
|
109
|
+
triggerProps,
|
|
110
|
+
getPopupProps
|
|
111
|
+
};
|
|
112
|
+
$[11] = getPopupProps;
|
|
113
|
+
$[12] = triggerProps;
|
|
114
|
+
$[13] = t3;
|
|
115
|
+
} else {
|
|
116
|
+
t3 = $[13];
|
|
117
|
+
}
|
|
118
|
+
return t3;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { useDropdownAria };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hides everything except the element from screen readers with `aria-hidden`, like a modal dialog does.
|
|
3
|
+
* Live regions stay visible, so their announcements are still heard.
|
|
4
|
+
* Elements that already have `aria-hidden` keep it after the dropdown closes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useHideOthers(isEnabled: boolean, element: HTMLElement | null): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { hideOthers } from 'aria-hidden';
|
|
5
|
+
|
|
6
|
+
const LIVE_REGIONS_SELECTOR = '[aria-live], [role="status"], [role="alert"], output';
|
|
7
|
+
/**
|
|
8
|
+
* Hides everything except the element from screen readers with `aria-hidden`, like a modal dialog does.
|
|
9
|
+
* Live regions stay visible, so their announcements are still heard.
|
|
10
|
+
* Elements that already have `aria-hidden` keep it after the dropdown closes.
|
|
11
|
+
*/
|
|
12
|
+
function useHideOthers(isEnabled, element) {
|
|
13
|
+
const $ = c(4);
|
|
14
|
+
let t0;
|
|
15
|
+
let t1;
|
|
16
|
+
if ($[0] !== element || $[1] !== isEnabled) {
|
|
17
|
+
t0 = () => {
|
|
18
|
+
if (!isEnabled || !element) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const liveRegions = Array.from(element.ownerDocument.querySelectorAll(LIVE_REGIONS_SELECTOR));
|
|
22
|
+
return hideOthers([element, ...liveRegions]);
|
|
23
|
+
};
|
|
24
|
+
t1 = [element, isEnabled];
|
|
25
|
+
$[0] = element;
|
|
26
|
+
$[1] = isEnabled;
|
|
27
|
+
$[2] = t0;
|
|
28
|
+
$[3] = t1;
|
|
29
|
+
} else {
|
|
30
|
+
t0 = $[2];
|
|
31
|
+
t1 = $[3];
|
|
32
|
+
}
|
|
33
|
+
useEffect(t0, t1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { useHideOthers };
|
|
@@ -70,3 +70,62 @@ const Demo = () => {
|
|
|
70
70
|
|
|
71
71
|
render(<Demo />);
|
|
72
72
|
```
|
|
73
|
+
|
|
74
|
+
### Focus management
|
|
75
|
+
|
|
76
|
+
When the dropdown opens, it moves the focus to the first tabbable element inside, or to the element with the `data-autofocus` attribute. If there is nothing to focus, the focus stays where it was. While the dropdown is open, Tab and Shift+Tab move the focus only between its elements. When it closes, on `Esc`, on a click outside or, with `closeOnTab`, on Tab, the focus returns to the element that had it before the dropdown opened, usually the trigger. If nothing had the focus, for example, because Safari doesn't focus a button on click, the focus returns to the trigger.
|
|
77
|
+
|
|
78
|
+
To change this behavior:
|
|
79
|
+
|
|
80
|
+
- `initialFocus` picks the element that gets the focus on open: an index of a tabbable element, a ref to an element inside the dropdown, or `'container'` for the dropdown itself. `'container'` helps when the first tabbable element reacts to the focus, like a native select on iOS, which opens its picker;
|
|
81
|
+
- `returnFocus={false}` leaves the focus where it is on close;
|
|
82
|
+
- `disableFocusLock` turns the focus management off, for example, when the focus has to stay in the trigger, like in a combobox.
|
|
83
|
+
|
|
84
|
+
### Accessibility
|
|
85
|
+
|
|
86
|
+
Without `role`, the dropdown doesn't set ARIA attributes, so the trigger and the content have to describe themselves. With `role`, the dropdown sets `role` and `id` on the element that wraps its children and `aria-haspopup`, `aria-expanded` and `aria-controls` on the trigger. A function trigger gets these attributes in its props, spread them onto the element. An element trigger gets them through `cloneElement`, so its component has to pass them to the DOM element; RescUI components do. `DropdownMenu` and `Select` set the roles of their lists themselves.
|
|
87
|
+
|
|
88
|
+
- `role="dialog"` or `role="alertdialog"` is for a popup with any content. Name it with `aria-label` or `aria-labelledby`, and describe it with `aria-describedby` if needed: these and other unknown props go to the element with the role. `className` and `style` go to the outer element that positions the dropdown.
|
|
89
|
+
- `modal` hides the rest of the page from screen readers with `aria-hidden` while the dropdown is open, and a dialog gets `aria-modal="true"`. Use it when the dropdown behaves like a modal dialog. `role="alertdialog"` is always modal.
|
|
90
|
+
- `visuallyHiddenDismiss` adds visually hidden buttons that close a modal dropdown. Touch screen readers have no `Esc` key, so use it when the dropdown has no visible close button.
|
|
91
|
+
|
|
92
|
+
```jsx
|
|
93
|
+
import { useId, useState } from 'react';
|
|
94
|
+
import { Dropdown } from '@rescui/dropdown';
|
|
95
|
+
import { Button } from '@rescui/button';
|
|
96
|
+
import { Input } from '@rescui/input';
|
|
97
|
+
import { textCn } from '@rescui/typography';
|
|
98
|
+
|
|
99
|
+
const Demo = () => {
|
|
100
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
101
|
+
const titleId = useId();
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Dropdown
|
|
105
|
+
isOpen={isOpen}
|
|
106
|
+
onRequestClose={() => setIsOpen(false)}
|
|
107
|
+
role="dialog"
|
|
108
|
+
modal
|
|
109
|
+
aria-labelledby={titleId}
|
|
110
|
+
trigger={
|
|
111
|
+
<Button onClick={() => setIsOpen(open => !open)}>Subscribe</Button>
|
|
112
|
+
}
|
|
113
|
+
>
|
|
114
|
+
<div style={{ padding: 16 }}>
|
|
115
|
+
<h3 id={titleId} className={textCn('rs-h4')}>
|
|
116
|
+
Subscribe to the newsletter
|
|
117
|
+
</h3>
|
|
118
|
+
<Input className="rs-docs-offset-top-12" label="Email" type="email" />
|
|
119
|
+
<Button
|
|
120
|
+
className="rs-docs-offset-top-12"
|
|
121
|
+
onClick={() => setIsOpen(false)}
|
|
122
|
+
>
|
|
123
|
+
Subscribe
|
|
124
|
+
</Button>
|
|
125
|
+
</div>
|
|
126
|
+
</Dropdown>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
render(<Demo />);
|
|
131
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
19
|
+
"@floating-ui/react-dom": "^2.1.9",
|
|
20
20
|
"@rescui/use-resize-observer": "^0.5.0",
|
|
21
|
+
"aria-hidden": "^1.2.6",
|
|
21
22
|
"classnames": "^2.2.6",
|
|
22
|
-
"popper-max-size-modifier": "^0.2.0",
|
|
23
23
|
"react-compiler-runtime": "^1.0.0",
|
|
24
|
-
"react-focus-lock": "^2.8.1"
|
|
25
|
-
"react-popper": "^2.2.5"
|
|
24
|
+
"react-focus-lock": "^2.8.1"
|
|
26
25
|
},
|
|
27
26
|
"peerDependencies": {
|
|
28
27
|
"@rescui/ui-contexts": "^0.7.0 || ^0.8.0",
|
|
@@ -41,5 +40,5 @@
|
|
|
41
40
|
"build": "rescui-scripts build"
|
|
42
41
|
},
|
|
43
42
|
"nx": {},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "0f91a16281acdb65e534dddc25951e5f0658c955"
|
|
45
44
|
}
|
|
@@ -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
|
-
}>;
|
package/lib/custom-modifiers.js
DELETED
|
@@ -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 };
|