idea-react 3.0.0-alpha.1 → 3.0.0-beta.1
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/AGENTS.md +11 -2
- package/ReadMe.md +86 -46
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1069 -245
- package/dist/index.d.ts +1069 -245
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +69 -66
- package/package.json +4 -2
- package/source/Accordion.tsx +137 -0
- package/source/Alert.tsx +138 -0
- package/source/Avatar.tsx +7 -1
- package/source/Badge.tsx +2 -0
- package/source/Breadcrumb.tsx +36 -0
- package/source/Button.tsx +40 -5
- package/source/ButtonGroup.tsx +10 -1
- package/source/Card.tsx +73 -4
- package/source/Carousel/index.tsx +391 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/Collapse.tsx +178 -0
- package/source/Drawer.tsx +127 -30
- package/source/{CodeBlock.tsx → Extension/CodeBlock/index.tsx} +23 -5
- package/source/Extension/CodeBlock/style.module.css +3 -0
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/{EditorHTML.tsx → Extension/EditorHTML.tsx} +1 -1
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/{Icon.tsx → Extension/Icon.tsx} +1 -7
- package/source/{Loading.tsx → Extension/Loading.tsx} +8 -3
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +3 -3
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +280 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +27 -9
- package/source/{ScrollNav → Extension/ScrollNav}/index.tsx +1 -1
- package/source/Extension/Select.tsx +127 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/{SpinnerButton.tsx → Extension/SpinnerButton.tsx} +2 -2
- package/source/{TableSpinner.tsx → Extension/TableSpinner.tsx} +1 -1
- package/source/{Timeline → Extension/Timeline}/index.tsx +1 -1
- package/source/{UserRank → Extension/UserRank}/index.tsx +4 -4
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +59 -0
- package/source/Form/Checkbox.tsx +78 -0
- package/source/Form/ChipInput.tsx +125 -0
- package/source/Form/Chips.tsx +69 -0
- package/source/Form/Combobox.tsx +374 -0
- package/source/Form/Control.tsx +94 -0
- package/source/Form/DatePicker.tsx +280 -0
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +35 -0
- package/source/Form/FloatingLabel.tsx +32 -0
- package/source/Form/InputGroup.tsx +173 -0
- package/source/Form/OTP.tsx +141 -0
- package/source/Form/PasswordStrength.tsx +183 -0
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +88 -0
- package/source/Form/Radio.tsx +43 -0
- package/source/Form/Range.tsx +116 -0
- package/source/Form/Switch.tsx +58 -0
- package/source/Form/index.ts +16 -0
- package/source/Grid.tsx +4 -0
- package/source/ListGroup.tsx +28 -15
- package/source/Menu.tsx +226 -17
- package/source/NativeDialog/index.tsx +109 -5
- package/source/Nav.tsx +18 -2
- package/source/NavOverflow/index.tsx +307 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +31 -6
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +92 -0
- package/source/Placeholder.tsx +66 -0
- package/source/Popover.tsx +7 -2
- package/source/Progress/index.tsx +76 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +365 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +10 -0
- package/source/Stepper.tsx +85 -0
- package/source/Tab.tsx +248 -0
- package/source/Toast.tsx +65 -27
- package/source/ToggleButton.tsx +21 -7
- package/source/Toggler.tsx +108 -0
- package/source/Tooltip.tsx +6 -1
- package/source/index.ts +16 -27
- package/source/OverlayBox.tsx +0 -208
- package/source/Select.tsx +0 -95
- /package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +0 -0
- /package/source/{Countdown.tsx → Extension/Countdown.tsx} +0 -0
- /package/source/{Editor.tsx → Extension/Editor.tsx} +0 -0
- /package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.tsx +0 -0
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/index.tsx +0 -0
- /package/source/{Time.tsx → Extension/Time.tsx} +0 -0
- /package/source/{TimeDistance.tsx → Extension/TimeDistance.tsx} +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/Content.tsx +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/index.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/Address.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.tsx +0 -0
- /package/source/{ZodiacBar.tsx → Extension/ZodiacBar.tsx} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './Adorn';
|
|
2
|
+
export * from './Checkbox';
|
|
3
|
+
export * from './ChipInput';
|
|
4
|
+
export * from './Chips';
|
|
5
|
+
export * from './Combobox';
|
|
6
|
+
export * from './Control';
|
|
7
|
+
export * from './DatePicker';
|
|
8
|
+
export * from './Feedback';
|
|
9
|
+
export * from './FloatingLabel';
|
|
10
|
+
export * from './InputGroup';
|
|
11
|
+
export * from './OTP';
|
|
12
|
+
export * from './PasswordStrength';
|
|
13
|
+
export * from './Primitives';
|
|
14
|
+
export * from './Radio';
|
|
15
|
+
export * from './Range';
|
|
16
|
+
export * from './Switch';
|
package/source/Grid.tsx
CHANGED
package/source/ListGroup.tsx
CHANGED
|
@@ -6,32 +6,45 @@ import type { Breakpoint } from './Grid';
|
|
|
6
6
|
|
|
7
7
|
export type ListGroupHorizontal = boolean | Breakpoint;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface ListGroupStyleProps {
|
|
10
10
|
flush?: boolean;
|
|
11
11
|
numbered?: boolean;
|
|
12
12
|
horizontal?: ListGroupHorizontal;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export type ListGroupProps = ListGroupStyleProps &
|
|
16
|
+
(
|
|
17
|
+
| (ComponentPropsWithRef<'ul'> & { as?: 'ul' })
|
|
18
|
+
| (ComponentPropsWithRef<'ol'> & { as: 'ol' })
|
|
19
|
+
| (ComponentPropsWithRef<'div'> & { as: 'div' })
|
|
20
|
+
);
|
|
21
|
+
|
|
15
22
|
export const ListGroup: FC<ListGroupProps> = ({
|
|
16
23
|
flush,
|
|
17
24
|
numbered,
|
|
18
25
|
horizontal,
|
|
19
26
|
className,
|
|
20
27
|
...props
|
|
21
|
-
}) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
28
|
+
}) => {
|
|
29
|
+
const classes = classNames(
|
|
30
|
+
'list-group',
|
|
31
|
+
{ 'list-group-flush': flush, 'list-group-numbered': numbered },
|
|
32
|
+
horizontal &&
|
|
33
|
+
(horizontal === true ? 'list-group-horizontal' : `${horizontal}:list-group-horizontal`),
|
|
34
|
+
className
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (props.as === 'ol') {
|
|
38
|
+
const { as: _as, ...attributes } = props;
|
|
39
|
+
return <ol {...attributes} className={classes} />;
|
|
40
|
+
}
|
|
41
|
+
if (props.as === 'div') {
|
|
42
|
+
const { as: _as, ...attributes } = props;
|
|
43
|
+
return <div {...attributes} className={classes} />;
|
|
44
|
+
}
|
|
45
|
+
const { as: _as, ...attributes } = props;
|
|
46
|
+
return <ul {...attributes} className={classes} />;
|
|
47
|
+
};
|
|
35
48
|
|
|
36
49
|
interface ListGroupItemStyleProps {
|
|
37
50
|
theme?: ComponentTheme;
|
package/source/Menu.tsx
CHANGED
|
@@ -16,13 +16,60 @@ import {
|
|
|
16
16
|
} from 'react';
|
|
17
17
|
|
|
18
18
|
import { Button, ButtonProps } from './Button';
|
|
19
|
+
import { Icon, IconProps } from './Extension/Icon';
|
|
20
|
+
import { Breakpoint } from './Grid';
|
|
21
|
+
import { FloatingOptions, FloatingPosition } from './Overlay';
|
|
22
|
+
|
|
23
|
+
export type MenuItemProps = ButtonProps & { active?: boolean; selected?: boolean };
|
|
24
|
+
|
|
25
|
+
export const MenuItem: FC<MenuItemProps> = ({ active, selected, className, ...props }) => (
|
|
26
|
+
<Button
|
|
27
|
+
{...props}
|
|
28
|
+
aria-current={active || (selected && props.href) ? 'true' : props['aria-current']}
|
|
29
|
+
aria-pressed={props.href ? props['aria-pressed'] : (selected ?? props['aria-pressed'])}
|
|
30
|
+
className={classNames('menu-item', { active, selected }, className)}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export interface MenuPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
35
|
+
theme?: 'light' | 'dark';
|
|
36
|
+
translucent?: boolean;
|
|
37
|
+
scrollable?: boolean;
|
|
38
|
+
show?: boolean;
|
|
39
|
+
}
|
|
19
40
|
|
|
20
|
-
export const
|
|
21
|
-
|
|
41
|
+
export const MenuPanel: FC<MenuPanelProps> = ({
|
|
42
|
+
theme,
|
|
43
|
+
translucent,
|
|
44
|
+
scrollable,
|
|
45
|
+
show,
|
|
46
|
+
className,
|
|
47
|
+
...props
|
|
48
|
+
}) => (
|
|
49
|
+
<div
|
|
50
|
+
{...props}
|
|
51
|
+
data-bs-theme={theme}
|
|
52
|
+
className={classNames(
|
|
53
|
+
'menu',
|
|
54
|
+
{ show },
|
|
55
|
+
translucent && 'menu-translucent',
|
|
56
|
+
scrollable && 'menu-scrollable',
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
/>
|
|
22
60
|
);
|
|
23
61
|
|
|
24
|
-
export const
|
|
25
|
-
<
|
|
62
|
+
export const MenuItemIcon: FC<IconProps> = ({ className, ...props }) => (
|
|
63
|
+
<Icon aria-hidden="true" {...props} className={classNames('menu-item-icon', className)} />
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export const MenuItemCheck: FC<Omit<IconProps, 'name'>> = ({ className, ...props }) => (
|
|
67
|
+
<Icon
|
|
68
|
+
aria-hidden="true"
|
|
69
|
+
{...props}
|
|
70
|
+
name="check"
|
|
71
|
+
className={classNames('menu-item-check', className)}
|
|
72
|
+
/>
|
|
26
73
|
);
|
|
27
74
|
|
|
28
75
|
export const MenuText: FC<HTMLAttributes<HTMLSpanElement>> = ({ className, ...props }) => (
|
|
@@ -55,11 +102,29 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
55
102
|
@observable accessor open = false;
|
|
56
103
|
|
|
57
104
|
panel = createRef<HTMLDivElement>();
|
|
105
|
+
trigger = createRef<HTMLButtonElement>();
|
|
106
|
+
position = new FloatingPosition();
|
|
107
|
+
|
|
108
|
+
componentDidUpdate() {
|
|
109
|
+
const { position, panel, trigger } = this;
|
|
110
|
+
|
|
111
|
+
if (!this.open) return position.dispose();
|
|
112
|
+
if (!panel.current || !trigger.current) return;
|
|
113
|
+
|
|
114
|
+
if (position.element !== panel.current)
|
|
115
|
+
position.attach(trigger.current, panel.current, {
|
|
116
|
+
placement: 'right-start',
|
|
117
|
+
offset: 2
|
|
118
|
+
});
|
|
119
|
+
else position.update();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
componentWillUnmount() {
|
|
123
|
+
this.position.dispose();
|
|
124
|
+
}
|
|
58
125
|
|
|
59
126
|
@action
|
|
60
|
-
setOpen = (open: boolean) =>
|
|
61
|
-
this.open = open;
|
|
62
|
-
};
|
|
127
|
+
setOpen = (open: boolean) => (this.open = open);
|
|
63
128
|
|
|
64
129
|
handleClick = () => this.setOpen(!this.open);
|
|
65
130
|
|
|
@@ -72,6 +137,7 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
72
137
|
|
|
73
138
|
if (key === 'ArrowRight') {
|
|
74
139
|
event.preventDefault();
|
|
140
|
+
event.stopPropagation();
|
|
75
141
|
this.setOpen(true);
|
|
76
142
|
|
|
77
143
|
queueMicrotask(() =>
|
|
@@ -80,9 +146,12 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
80
146
|
?.focus()
|
|
81
147
|
);
|
|
82
148
|
}
|
|
83
|
-
if (key === 'ArrowLeft' && this.open) {
|
|
149
|
+
if ((key === 'ArrowLeft' || key === 'Escape') && this.open) {
|
|
84
150
|
event.preventDefault();
|
|
151
|
+
event.stopPropagation();
|
|
152
|
+
|
|
85
153
|
this.setOpen(false);
|
|
154
|
+
this.trigger.current?.focus();
|
|
86
155
|
}
|
|
87
156
|
};
|
|
88
157
|
|
|
@@ -98,6 +167,7 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
98
167
|
onKeyDown={this.handleKeyDown}
|
|
99
168
|
>
|
|
100
169
|
<Button
|
|
170
|
+
ref={this.trigger}
|
|
101
171
|
className="menu-item"
|
|
102
172
|
aria-haspopup="true"
|
|
103
173
|
aria-expanded={open}
|
|
@@ -107,6 +177,8 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
107
177
|
</Button>
|
|
108
178
|
<div
|
|
109
179
|
ref={this.panel}
|
|
180
|
+
style={{ ...this.position.style }}
|
|
181
|
+
data-bs-placement={this.position.placement}
|
|
110
182
|
className={classNames('menu start-100 top-0', { show: open })}
|
|
111
183
|
hidden={!open}
|
|
112
184
|
>
|
|
@@ -122,28 +194,121 @@ export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChang
|
|
|
122
194
|
autoClose?: boolean | 'inside' | 'outside';
|
|
123
195
|
align?: 'start' | 'end';
|
|
124
196
|
menuClassName?: string;
|
|
197
|
+
placement?: MenuPlacement;
|
|
198
|
+
responsivePlacement?: Partial<Record<Breakpoint, MenuPlacement>>;
|
|
199
|
+
theme?: 'light' | 'dark';
|
|
200
|
+
translucent?: boolean;
|
|
201
|
+
scrollable?: boolean;
|
|
202
|
+
split?: boolean;
|
|
203
|
+
nav?: boolean;
|
|
204
|
+
offset?: FloatingOptions['offset'];
|
|
205
|
+
padding?: number;
|
|
206
|
+
flip?: boolean;
|
|
125
207
|
toggleProps?: Omit<
|
|
126
208
|
Extract<ButtonProps, { href?: never }>,
|
|
127
209
|
'children' | 'onClick' | 'onKeyDown'
|
|
128
210
|
>;
|
|
129
|
-
onOpenChange?: (open: boolean) =>
|
|
211
|
+
onOpenChange?: (open: boolean) => unknown;
|
|
130
212
|
}
|
|
131
213
|
|
|
214
|
+
export type MenuPlacement =
|
|
215
|
+
| 'top-start'
|
|
216
|
+
| 'top-end'
|
|
217
|
+
| 'bottom-start'
|
|
218
|
+
| 'bottom-end'
|
|
219
|
+
| 'left-start'
|
|
220
|
+
| 'left-end'
|
|
221
|
+
| 'right-start'
|
|
222
|
+
| 'right-end';
|
|
223
|
+
|
|
224
|
+
const MENU_PLACEMENT_CLASSES: Record<MenuPlacement, string[]> = {
|
|
225
|
+
'top-start': ['bottom-100', 'start-0'],
|
|
226
|
+
'top-end': ['bottom-100', 'end-0'],
|
|
227
|
+
'bottom-start': ['top-100', 'start-0'],
|
|
228
|
+
'bottom-end': ['top-100', 'end-0'],
|
|
229
|
+
'left-start': ['end-100', 'top-0'],
|
|
230
|
+
'left-end': ['end-100', 'bottom-0'],
|
|
231
|
+
'right-start': ['start-100', 'top-0'],
|
|
232
|
+
'right-end': ['start-100', 'bottom-0']
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const MENU_BREAKPOINT_WIDTHS: Record<Breakpoint, number> = {
|
|
236
|
+
sm: 576,
|
|
237
|
+
md: 768,
|
|
238
|
+
lg: 1024,
|
|
239
|
+
xl: 1280,
|
|
240
|
+
'2xl': 1536
|
|
241
|
+
};
|
|
242
|
+
|
|
132
243
|
@observer
|
|
133
244
|
export class Menu extends Component<MenuProps> {
|
|
134
245
|
@observable accessor open = false;
|
|
246
|
+
@observable accessor responsiveDirection: MenuPlacement | undefined;
|
|
247
|
+
|
|
135
248
|
root = createRef<HTMLDivElement>();
|
|
136
249
|
trigger = createRef<HTMLButtonElement>();
|
|
137
250
|
panel = createRef<HTMLDivElement>();
|
|
251
|
+
media: { query: MediaQueryList; placement: MenuPlacement }[] = [];
|
|
252
|
+
position = new FloatingPosition();
|
|
138
253
|
|
|
139
254
|
componentDidMount() {
|
|
140
255
|
document.addEventListener('pointerdown', this.handleOutside);
|
|
256
|
+
this.observePlacement();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
componentDidUpdate({ responsivePlacement }: MenuProps) {
|
|
260
|
+
const { trigger, panel, position, props } = this;
|
|
261
|
+
|
|
262
|
+
if (responsivePlacement !== props.responsivePlacement) this.observePlacement();
|
|
263
|
+
|
|
264
|
+
if (!this.open) return position.dispose();
|
|
265
|
+
if (!trigger.current || !panel.current) return;
|
|
266
|
+
|
|
267
|
+
const { placement, align, offset, padding, flip } = props;
|
|
268
|
+
|
|
269
|
+
const options: FloatingOptions = {
|
|
270
|
+
placement: this.responsiveDirection ?? placement ?? `bottom-${align ?? 'end'}`,
|
|
271
|
+
offset,
|
|
272
|
+
padding,
|
|
273
|
+
flip
|
|
274
|
+
};
|
|
275
|
+
if (position.element !== panel.current)
|
|
276
|
+
position.attach(trigger.current, panel.current, options);
|
|
277
|
+
else {
|
|
278
|
+
position.options = options;
|
|
279
|
+
position.update();
|
|
280
|
+
}
|
|
141
281
|
}
|
|
142
282
|
|
|
143
283
|
componentWillUnmount() {
|
|
144
284
|
document.removeEventListener('pointerdown', this.handleOutside);
|
|
285
|
+
this.position.dispose();
|
|
286
|
+
|
|
287
|
+
for (const { query } of this.media)
|
|
288
|
+
query.removeEventListener('change', this.handlePlacement);
|
|
145
289
|
}
|
|
146
290
|
|
|
291
|
+
observePlacement = () => {
|
|
292
|
+
for (const { query } of this.media)
|
|
293
|
+
query.removeEventListener('change', this.handlePlacement);
|
|
294
|
+
|
|
295
|
+
this.media = (Object.keys(MENU_BREAKPOINT_WIDTHS) as Breakpoint[]).flatMap(breakpoint => {
|
|
296
|
+
const placement = this.props.responsivePlacement?.[breakpoint];
|
|
297
|
+
if (!placement) return [];
|
|
298
|
+
|
|
299
|
+
const query = window.matchMedia(`(min-width: ${MENU_BREAKPOINT_WIDTHS[breakpoint]}px)`);
|
|
300
|
+
query.addEventListener('change', this.handlePlacement);
|
|
301
|
+
return [{ query, placement }];
|
|
302
|
+
});
|
|
303
|
+
this.handlePlacement();
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
@action
|
|
307
|
+
handlePlacement = () =>
|
|
308
|
+
(this.responsiveDirection = [...this.media]
|
|
309
|
+
.reverse()
|
|
310
|
+
.find(({ query }) => query.matches)?.placement);
|
|
311
|
+
|
|
147
312
|
@action
|
|
148
313
|
setOpen = (open: boolean) => {
|
|
149
314
|
if (this.open === open) return;
|
|
@@ -162,12 +327,12 @@ export class Menu extends Component<MenuProps> {
|
|
|
162
327
|
this.setOpen(false);
|
|
163
328
|
};
|
|
164
329
|
|
|
165
|
-
items() {
|
|
330
|
+
items(panel: HTMLElement | null = this.panel.current) {
|
|
166
331
|
return [
|
|
167
|
-
...(
|
|
332
|
+
...(panel?.querySelectorAll<HTMLElement>(
|
|
168
333
|
'a[href]:not([aria-disabled="true"]), button:not(:disabled):not([aria-disabled="true"])'
|
|
169
334
|
) ?? [])
|
|
170
|
-
].filter(item => !item.closest('[hidden]'));
|
|
335
|
+
].filter(item => !item.closest('[hidden]') && item.closest('.menu') === panel);
|
|
171
336
|
}
|
|
172
337
|
|
|
173
338
|
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -182,13 +347,23 @@ export class Menu extends Component<MenuProps> {
|
|
|
182
347
|
return this.trigger.current?.focus();
|
|
183
348
|
}
|
|
184
349
|
if (key === 'Tab') return this.setOpen(false);
|
|
350
|
+
if (
|
|
351
|
+
event.target instanceof Element &&
|
|
352
|
+
event.target.matches('input, textarea, select, [contenteditable="true"]')
|
|
353
|
+
)
|
|
354
|
+
return;
|
|
355
|
+
|
|
185
356
|
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(key)) return;
|
|
186
357
|
|
|
187
358
|
event.preventDefault();
|
|
188
359
|
this.setOpen(true);
|
|
189
360
|
|
|
190
361
|
queueMicrotask(() => {
|
|
191
|
-
const
|
|
362
|
+
const panel =
|
|
363
|
+
event.target instanceof Element
|
|
364
|
+
? event.target.closest<HTMLElement>('.menu')
|
|
365
|
+
: undefined;
|
|
366
|
+
const items = this.items(panel ?? this.panel.current);
|
|
192
367
|
const index = items.findIndex(item => item === document.activeElement);
|
|
193
368
|
|
|
194
369
|
let next = key === 'Home' ? 0 : items.length - 1;
|
|
@@ -215,10 +390,11 @@ export class Menu extends Component<MenuProps> {
|
|
|
215
390
|
|
|
216
391
|
handleToggle = () => this.setOpen(!this.open);
|
|
217
392
|
|
|
218
|
-
handleSelect = ({ target }: MouseEvent<HTMLDivElement>) => {
|
|
393
|
+
handleSelect = ({ target, defaultPrevented }: MouseEvent<HTMLDivElement>) => {
|
|
219
394
|
const { autoClose = true } = this.props;
|
|
220
395
|
if (
|
|
221
396
|
autoClose &&
|
|
397
|
+
!defaultPrevented &&
|
|
222
398
|
autoClose !== 'outside' &&
|
|
223
399
|
target instanceof Element &&
|
|
224
400
|
!target.closest('.submenu > .menu-item') &&
|
|
@@ -232,6 +408,16 @@ export class Menu extends Component<MenuProps> {
|
|
|
232
408
|
label,
|
|
233
409
|
autoClose: _autoClose,
|
|
234
410
|
align = 'end',
|
|
411
|
+
placement,
|
|
412
|
+
responsivePlacement: _responsivePlacement,
|
|
413
|
+
theme,
|
|
414
|
+
translucent,
|
|
415
|
+
scrollable,
|
|
416
|
+
split,
|
|
417
|
+
nav,
|
|
418
|
+
offset: _offset,
|
|
419
|
+
padding: _padding,
|
|
420
|
+
flip: _flip,
|
|
235
421
|
menuClassName,
|
|
236
422
|
toggleProps,
|
|
237
423
|
onOpenChange: _onOpenChange,
|
|
@@ -243,20 +429,39 @@ export class Menu extends Component<MenuProps> {
|
|
|
243
429
|
...props
|
|
244
430
|
} = this.props;
|
|
245
431
|
const { open } = this;
|
|
432
|
+
const preferred = this.responsiveDirection ?? placement;
|
|
433
|
+
const direction = this.position.element
|
|
434
|
+
? (this.position.placement as MenuPlacement)
|
|
435
|
+
: preferred;
|
|
436
|
+
const placementClasses = direction
|
|
437
|
+
? MENU_PLACEMENT_CLASSES[direction]
|
|
438
|
+
: ['top-100', align === 'end' ? 'end-0' : 'start-0'];
|
|
246
439
|
|
|
247
440
|
return (
|
|
248
441
|
<div
|
|
249
442
|
{...props}
|
|
250
443
|
ref={this.root}
|
|
251
444
|
id={id}
|
|
252
|
-
|
|
445
|
+
data-bs-theme={theme}
|
|
446
|
+
className={classNames(
|
|
447
|
+
split ? 'btn-group' : 'd-inline-block',
|
|
448
|
+
'position-relative',
|
|
449
|
+
className
|
|
450
|
+
)}
|
|
253
451
|
onKeyDown={this.handleKeyDown}
|
|
254
452
|
onBlur={this.handleBlur}
|
|
255
453
|
>
|
|
256
454
|
<Button
|
|
455
|
+
variant={nav ? false : undefined}
|
|
257
456
|
{...toggleProps}
|
|
258
457
|
ref={this.trigger}
|
|
259
458
|
aria-expanded={open}
|
|
459
|
+
aria-haspopup="true"
|
|
460
|
+
className={classNames(
|
|
461
|
+
toggleProps?.className,
|
|
462
|
+
split && 'menu-toggle-split',
|
|
463
|
+
nav && 'nav-link'
|
|
464
|
+
)}
|
|
260
465
|
aria-controls={id ? `${id}-menu` : undefined}
|
|
261
466
|
onClick={this.handleToggle}
|
|
262
467
|
>
|
|
@@ -265,9 +470,13 @@ export class Menu extends Component<MenuProps> {
|
|
|
265
470
|
<div
|
|
266
471
|
ref={this.panel}
|
|
267
472
|
id={id ? `${id}-menu` : undefined}
|
|
473
|
+
data-bs-placement={direction ?? `bottom-${align}`}
|
|
474
|
+
style={{ ...this.position.style }}
|
|
268
475
|
className={classNames(
|
|
269
|
-
'menu
|
|
270
|
-
|
|
476
|
+
'menu',
|
|
477
|
+
placementClasses,
|
|
478
|
+
translucent && 'menu-translucent',
|
|
479
|
+
scrollable && 'menu-scrollable',
|
|
271
480
|
{ show: open },
|
|
272
481
|
menuClassName
|
|
273
482
|
)}
|
|
@@ -12,8 +12,12 @@ import {
|
|
|
12
12
|
SyntheticEvent
|
|
13
13
|
} from 'react';
|
|
14
14
|
|
|
15
|
+
import { Breakpoint } from '../Grid';
|
|
15
16
|
import styles from './style.module.css';
|
|
16
17
|
|
|
18
|
+
const transitionMilliseconds = (value: string) =>
|
|
19
|
+
(parseFloat(value) || 0) * (value.trim().endsWith('ms') ? 1 : 1000);
|
|
20
|
+
|
|
17
21
|
export interface NativeDialogProps extends Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open'> {
|
|
18
22
|
modal?: boolean;
|
|
19
23
|
dialog?: boolean;
|
|
@@ -21,6 +25,11 @@ export interface NativeDialogProps extends Omit<DialogHTMLAttributes<HTMLDialogE
|
|
|
21
25
|
keyboard?: boolean;
|
|
22
26
|
backdrop?: boolean | 'static';
|
|
23
27
|
open?: boolean;
|
|
28
|
+
size?: 'sm' | 'lg' | 'xl';
|
|
29
|
+
fullscreen?: boolean | Breakpoint;
|
|
30
|
+
scrollable?: boolean;
|
|
31
|
+
animation?: 'fade' | 'instant' | 'slide-down' | 'slide-up';
|
|
32
|
+
scroll?: boolean;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
export const DialogHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
@@ -40,8 +49,13 @@ export const DialogFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...p
|
|
|
40
49
|
);
|
|
41
50
|
|
|
42
51
|
export class NativeDialog extends Component<NativeDialogProps> {
|
|
52
|
+
static scrollLocks = new Set<NativeDialog>();
|
|
53
|
+
static bodyOverflow = '';
|
|
54
|
+
|
|
43
55
|
element = createRef<HTMLDialogElement>();
|
|
44
56
|
returnFocus?: HTMLElement;
|
|
57
|
+
switchingMode = false;
|
|
58
|
+
closeTimer?: ReturnType<typeof setTimeout>;
|
|
45
59
|
|
|
46
60
|
get open() {
|
|
47
61
|
return this.element.current?.open ?? false;
|
|
@@ -51,46 +65,119 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
51
65
|
if (this.props.open) this.show();
|
|
52
66
|
}
|
|
53
67
|
|
|
54
|
-
componentDidUpdate({ open }: NativeDialogProps) {
|
|
55
|
-
|
|
68
|
+
componentDidUpdate({ open, modal, scroll }: NativeDialogProps) {
|
|
69
|
+
const modeChanged = this.props.modal !== modal;
|
|
70
|
+
const openChanged = this.props.open !== open;
|
|
71
|
+
const wasOpen = this.open;
|
|
72
|
+
if (!openChanged && !modeChanged && this.props.scroll === scroll) return;
|
|
56
73
|
|
|
57
|
-
if (this.
|
|
74
|
+
if (this.open && this.props.modal !== modal) {
|
|
75
|
+
this.switchingMode = true;
|
|
76
|
+
this.close();
|
|
77
|
+
}
|
|
78
|
+
if (this.props.scroll) this.unlockScroll();
|
|
79
|
+
else if (this.open && this.props.modal !== false) this.lockScroll();
|
|
80
|
+
|
|
81
|
+
if (!openChanged && !modeChanged) return;
|
|
82
|
+
|
|
83
|
+
if (this.props.open || (!openChanged && modeChanged && wasOpen)) this.show();
|
|
58
84
|
else this.close();
|
|
59
85
|
}
|
|
60
86
|
|
|
61
87
|
show = () => {
|
|
88
|
+
clearTimeout(this.closeTimer);
|
|
89
|
+
this.element.current?.classList.remove('hiding');
|
|
62
90
|
if (this.open) return;
|
|
91
|
+
|
|
63
92
|
const element = this.element.current;
|
|
64
93
|
if (!element) return;
|
|
65
|
-
|
|
94
|
+
|
|
95
|
+
if (!this.switchingMode && document.activeElement instanceof HTMLElement)
|
|
66
96
|
this.returnFocus = document.activeElement;
|
|
97
|
+
|
|
67
98
|
if (this.props.modal === false) element.show();
|
|
68
99
|
else element.showModal();
|
|
100
|
+
|
|
101
|
+
if (this.props.modal !== false && !this.props.scroll) this.lockScroll();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
lockScroll = () => {
|
|
105
|
+
const { scrollLocks } = NativeDialog;
|
|
106
|
+
|
|
107
|
+
if (!scrollLocks.size) {
|
|
108
|
+
NativeDialog.bodyOverflow = document.body.style.overflow;
|
|
109
|
+
document.body.style.overflow = 'hidden';
|
|
110
|
+
}
|
|
111
|
+
scrollLocks.add(this);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
unlockScroll = () => {
|
|
115
|
+
const { scrollLocks } = NativeDialog;
|
|
116
|
+
|
|
117
|
+
if (!scrollLocks.delete(this)) return;
|
|
118
|
+
if (!scrollLocks.size) document.body.style.overflow = NativeDialog.bodyOverflow;
|
|
69
119
|
};
|
|
70
120
|
|
|
71
121
|
close = () => {
|
|
122
|
+
const element = this.element.current;
|
|
123
|
+
if (!this.open || !element || this.switchingMode) return this.finishClose();
|
|
124
|
+
|
|
125
|
+
const { transitionDuration, transitionDelay } = getComputedStyle(element);
|
|
126
|
+
const durations = transitionDuration.split(',').map(transitionMilliseconds);
|
|
127
|
+
const delays = transitionDelay.split(',').map(transitionMilliseconds);
|
|
128
|
+
const duration = Math.max(
|
|
129
|
+
0,
|
|
130
|
+
...durations.map((value, index) => value + delays[index % delays.length])
|
|
131
|
+
);
|
|
132
|
+
if (!duration) return this.finishClose();
|
|
133
|
+
if (element.classList.contains('hiding')) return;
|
|
134
|
+
|
|
135
|
+
element.classList.add('hiding');
|
|
136
|
+
this.closeTimer = setTimeout(this.finishClose, duration);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
finishClose = () => {
|
|
140
|
+
clearTimeout(this.closeTimer);
|
|
141
|
+
this.element.current?.classList.remove('hiding');
|
|
142
|
+
this.unlockScroll();
|
|
143
|
+
|
|
72
144
|
if (!this.open) return;
|
|
145
|
+
|
|
73
146
|
this.element.current?.close();
|
|
74
147
|
this.returnFocus?.focus();
|
|
75
148
|
};
|
|
76
149
|
|
|
150
|
+
handleClose = (event: SyntheticEvent<HTMLDialogElement>) => {
|
|
151
|
+
if (!this.switchingMode) this.props.onClose?.(event);
|
|
152
|
+
|
|
153
|
+
if (!this.open) {
|
|
154
|
+
this.unlockScroll();
|
|
155
|
+
this.returnFocus?.focus();
|
|
156
|
+
}
|
|
157
|
+
this.switchingMode = false;
|
|
158
|
+
};
|
|
159
|
+
|
|
77
160
|
componentWillUnmount() {
|
|
78
|
-
this.
|
|
161
|
+
this.finishClose();
|
|
79
162
|
}
|
|
80
163
|
|
|
81
164
|
handleCancel = (event: SyntheticEvent<HTMLDialogElement>) => {
|
|
82
165
|
const { onCancel, keyboard = true } = this.props;
|
|
83
166
|
onCancel?.(event);
|
|
167
|
+
|
|
84
168
|
const { defaultPrevented } = event;
|
|
85
169
|
event.preventDefault();
|
|
170
|
+
|
|
86
171
|
if (keyboard && !defaultPrevented) this.close();
|
|
87
172
|
};
|
|
88
173
|
|
|
89
174
|
handleKeyDown = (event: KeyboardEvent<HTMLDialogElement>) => {
|
|
90
175
|
const { onKeyDown, keyboard = true } = this.props;
|
|
91
176
|
onKeyDown?.(event);
|
|
177
|
+
|
|
92
178
|
const { key, defaultPrevented } = event;
|
|
93
179
|
if (key !== 'Escape' || !keyboard || defaultPrevented) return;
|
|
180
|
+
|
|
94
181
|
event.preventDefault();
|
|
95
182
|
this.close();
|
|
96
183
|
};
|
|
@@ -98,8 +185,10 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
98
185
|
handleClick = (event: MouseEvent<HTMLDialogElement>) => {
|
|
99
186
|
const { onClick, backdrop = true } = this.props;
|
|
100
187
|
onClick?.(event);
|
|
188
|
+
|
|
101
189
|
const { defaultPrevented, target, currentTarget, clientX, clientY } = event;
|
|
102
190
|
if (backdrop !== true || defaultPrevented || target !== currentTarget) return;
|
|
191
|
+
|
|
103
192
|
const { left, right, top, bottom } = currentTarget.getBoundingClientRect();
|
|
104
193
|
if (clientX < left || clientX > right || clientY < top || clientY > bottom) this.close();
|
|
105
194
|
};
|
|
@@ -112,10 +201,16 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
112
201
|
backdrop = true,
|
|
113
202
|
theme,
|
|
114
203
|
dialog = true,
|
|
204
|
+
size,
|
|
205
|
+
fullscreen,
|
|
206
|
+
scrollable,
|
|
207
|
+
animation = 'fade',
|
|
208
|
+
scroll: _scroll,
|
|
115
209
|
className,
|
|
116
210
|
onCancel: _onCancel,
|
|
117
211
|
onClick: _onClick,
|
|
118
212
|
onKeyDown: _onKeyDown,
|
|
213
|
+
onClose: _onClose,
|
|
119
214
|
...props
|
|
120
215
|
} = this.props;
|
|
121
216
|
|
|
@@ -125,6 +220,14 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
125
220
|
ref={this.element}
|
|
126
221
|
className={classNames(
|
|
127
222
|
dialog && 'dialog',
|
|
223
|
+
dialog && size && `dialog-${size}`,
|
|
224
|
+
dialog &&
|
|
225
|
+
fullscreen &&
|
|
226
|
+
(fullscreen === true
|
|
227
|
+
? 'dialog-fullscreen'
|
|
228
|
+
: `${fullscreen}-down:dialog-fullscreen`),
|
|
229
|
+
dialog && scrollable && 'dialog-scrollable',
|
|
230
|
+
dialog && animation !== 'fade' && `dialog-${animation}`,
|
|
128
231
|
backdrop === false && styles.hiddenBackdrop,
|
|
129
232
|
className
|
|
130
233
|
)}
|
|
@@ -133,6 +236,7 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
133
236
|
onCancel={this.handleCancel}
|
|
134
237
|
onKeyDown={this.handleKeyDown}
|
|
135
238
|
onClick={this.handleClick}
|
|
239
|
+
onClose={this.handleClose}
|
|
136
240
|
/>
|
|
137
241
|
);
|
|
138
242
|
}
|