idea-react 3.0.0-beta.1 → 3.0.0-beta.3
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 +12 -3
- package/ReadMe.md +34 -6
- package/dist/index.d.mts +313 -230
- package/dist/index.d.ts +313 -230
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/style.css +0 -3
- package/package.json +13 -13
- package/source/Accordion.tsx +61 -37
- package/source/Alert.tsx +30 -15
- package/source/Avatar.tsx +55 -50
- package/source/Badge.tsx +16 -16
- package/source/Breadcrumb.tsx +36 -22
- package/source/Button.tsx +63 -69
- package/source/ButtonGroup.tsx +21 -25
- package/source/Card.tsx +67 -59
- package/source/Carousel/index.tsx +22 -21
- package/source/CloseButton.tsx +20 -15
- package/source/Collapse.tsx +74 -19
- package/source/Drawer.tsx +40 -17
- package/source/Extension/ClickBoundary.tsx +24 -5
- package/source/Extension/CodeBlock.tsx +64 -0
- package/source/Extension/Countdown.tsx +21 -9
- package/source/Extension/Editor.tsx +53 -18
- package/source/Extension/EditorHTML.tsx +7 -3
- package/source/Extension/HorizontalMarquee/index.tsx +69 -45
- package/source/Extension/Icon.tsx +15 -14
- package/source/Extension/Loading.tsx +20 -17
- package/source/Extension/MonthCalendar.tsx +26 -10
- package/source/Extension/OverlayBox.tsx +28 -15
- package/source/Extension/PageNav.tsx +16 -7
- package/source/Extension/ScrollNav/Scroller.tsx +21 -5
- package/source/Extension/ScrollNav/index.tsx +32 -7
- package/source/Extension/Select.tsx +12 -11
- package/source/Extension/SpinnerButton.tsx +19 -24
- package/source/Extension/TableSpinner.tsx +10 -14
- package/source/Extension/TextTruncate/index.tsx +17 -13
- package/source/Extension/Time.tsx +7 -5
- package/source/Extension/TimeDistance.tsx +22 -18
- package/source/Extension/Timeline/index.tsx +37 -34
- package/source/Extension/TypeEcho/Content.tsx +79 -14
- package/source/Extension/TypeEcho/index.tsx +13 -5
- package/source/Extension/UserRank/Address.tsx +17 -15
- package/source/Extension/UserRank/index.tsx +79 -84
- package/source/Extension/VerticalMarquee/index.tsx +14 -16
- package/source/Extension/ZodiacBar.tsx +40 -32
- package/source/Form/Adorn.tsx +30 -32
- package/source/Form/Checkbox.tsx +9 -5
- package/source/Form/ChipInput.tsx +9 -5
- package/source/Form/Chips.tsx +41 -39
- package/source/Form/Combobox.tsx +80 -61
- package/source/Form/Control.tsx +53 -58
- package/source/Form/DatePicker.tsx +74 -65
- package/source/Form/Feedback.tsx +18 -19
- package/source/Form/FloatingLabel.tsx +16 -19
- package/source/Form/InputGroup.tsx +27 -26
- package/source/Form/OTP.tsx +30 -12
- package/source/Form/Primitives.tsx +47 -39
- package/source/Form/Radio.tsx +25 -22
- package/source/Form/Range.tsx +30 -12
- package/source/Form/Switch.tsx +73 -48
- package/source/Form/inputProps.ts +184 -0
- package/source/Grid.tsx +67 -59
- package/source/Image.tsx +10 -6
- package/source/ListGroup.tsx +57 -69
- package/source/Menu.tsx +128 -66
- package/source/NativeDialog/index.tsx +51 -29
- package/source/Nav.tsx +46 -46
- package/source/NavOverflow/index.tsx +26 -10
- package/source/Navbar.tsx +60 -55
- package/source/Pagination.tsx +63 -69
- package/source/Placeholder.tsx +47 -43
- package/source/Polymorphic.ts +57 -0
- package/source/Popover.tsx +34 -31
- package/source/Progress/index.tsx +59 -54
- package/source/ScrollSpy/index.tsx +48 -33
- package/source/Spinner.tsx +27 -23
- package/source/Stack.tsx +25 -0
- package/source/Stepper.tsx +46 -40
- package/source/Tab.tsx +40 -27
- package/source/Table.tsx +53 -42
- package/source/Toast.tsx +62 -47
- package/source/ToggleButton.tsx +65 -54
- package/source/Toggler.tsx +17 -8
- package/source/Tooltip.tsx +31 -29
- package/source/index.ts +2 -0
- package/tsconfig.json +2 -2
- package/source/Extension/CodeBlock/index.tsx +0 -58
- package/source/Extension/CodeBlock/style.module.css +0 -3
package/source/Menu.tsx
CHANGED
|
@@ -6,12 +6,11 @@ import { observer } from 'mobx-react';
|
|
|
6
6
|
import {
|
|
7
7
|
Component,
|
|
8
8
|
createRef,
|
|
9
|
-
|
|
9
|
+
ElementType,
|
|
10
10
|
FocusEvent,
|
|
11
11
|
HTMLAttributes,
|
|
12
12
|
KeyboardEvent,
|
|
13
13
|
MouseEvent,
|
|
14
|
-
PropsWithChildren,
|
|
15
14
|
ReactNode
|
|
16
15
|
} from 'react';
|
|
17
16
|
|
|
@@ -19,17 +18,22 @@ import { Button, ButtonProps } from './Button';
|
|
|
19
18
|
import { Icon, IconProps } from './Extension/Icon';
|
|
20
19
|
import { Breakpoint } from './Grid';
|
|
21
20
|
import { FloatingOptions, FloatingPosition } from './Overlay';
|
|
21
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
|
|
22
22
|
|
|
23
23
|
export type MenuItemProps = ButtonProps & { active?: boolean; selected?: boolean };
|
|
24
24
|
|
|
25
|
-
export const MenuItem
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
export const MenuItem = polymorphic<MenuItemProps>(
|
|
26
|
+
({ as: RootAs, active, selected, className, ...props }) => (
|
|
27
|
+
<Button
|
|
28
|
+
as={RootAs}
|
|
29
|
+
{...props}
|
|
30
|
+
className={classNames('menu-item', { active, selected }, className)}
|
|
31
|
+
aria-current={active || (selected && props.href) ? 'true' : props['aria-current']}
|
|
32
|
+
aria-pressed={props.href ? props['aria-pressed'] : (selected ?? props['aria-pressed'])}
|
|
33
|
+
/>
|
|
34
|
+
)
|
|
32
35
|
);
|
|
36
|
+
MenuItem.displayName = 'MenuItem';
|
|
33
37
|
|
|
34
38
|
export interface MenuPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
35
39
|
theme?: 'light' | 'dark';
|
|
@@ -38,67 +42,98 @@ export interface MenuPanelProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
38
42
|
show?: boolean;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
export const MenuPanel
|
|
42
|
-
theme,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
translucent && 'menu-translucent',
|
|
56
|
-
scrollable && 'menu-scrollable',
|
|
57
|
-
className
|
|
58
|
-
)}
|
|
59
|
-
/>
|
|
45
|
+
export const MenuPanel = polymorphic<MenuPanelProps>(
|
|
46
|
+
({ as: Root = 'div', theme, translucent, scrollable, show, className, ...props }) => (
|
|
47
|
+
<Root
|
|
48
|
+
{...props}
|
|
49
|
+
data-bs-theme={theme}
|
|
50
|
+
className={classNames(
|
|
51
|
+
'menu',
|
|
52
|
+
{ show },
|
|
53
|
+
translucent && 'menu-translucent',
|
|
54
|
+
scrollable && 'menu-scrollable',
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
60
59
|
);
|
|
60
|
+
MenuPanel.displayName = 'MenuPanel';
|
|
61
61
|
|
|
62
|
-
export const MenuItemIcon
|
|
63
|
-
<Icon aria-hidden="true" {...props} className={classNames('menu-item-icon', className)} />
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
export const MenuItemCheck: FC<Omit<IconProps, 'name'>> = ({ className, ...props }) => (
|
|
62
|
+
export const MenuItemIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
|
|
67
63
|
<Icon
|
|
64
|
+
as={RootAs}
|
|
68
65
|
aria-hidden="true"
|
|
69
66
|
{...props}
|
|
70
|
-
|
|
71
|
-
className={classNames('menu-item-check', className)}
|
|
67
|
+
className={classNames('menu-item-icon', className)}
|
|
72
68
|
/>
|
|
69
|
+
));
|
|
70
|
+
MenuItemIcon.displayName = 'MenuItemIcon';
|
|
71
|
+
|
|
72
|
+
export const MenuItemCheck = polymorphic<Omit<IconProps, 'name'>>(
|
|
73
|
+
({ as: RootAs, className, ...props }) => (
|
|
74
|
+
<Icon
|
|
75
|
+
as={RootAs}
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
{...props}
|
|
78
|
+
name="check"
|
|
79
|
+
className={classNames('menu-item-check', className)}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
73
82
|
);
|
|
83
|
+
MenuItemCheck.displayName = 'MenuItemCheck';
|
|
74
84
|
|
|
75
|
-
export const MenuText
|
|
76
|
-
|
|
85
|
+
export const MenuText = polymorphic<HTMLAttributes<HTMLSpanElement>>(
|
|
86
|
+
({ as: Root = 'span', className, ...props }) => (
|
|
87
|
+
<Root {...props} className={classNames('menu-text', className)} />
|
|
88
|
+
)
|
|
77
89
|
);
|
|
90
|
+
MenuText.displayName = 'MenuText';
|
|
78
91
|
|
|
79
|
-
export const MenuHeader
|
|
80
|
-
|
|
92
|
+
export const MenuHeader = polymorphic<HTMLAttributes<HTMLHeadingElement>>(
|
|
93
|
+
({ as: Root = 'h6', className, ...props }) => (
|
|
94
|
+
<Root {...props} className={classNames('menu-header', className)} />
|
|
95
|
+
)
|
|
81
96
|
);
|
|
97
|
+
MenuHeader.displayName = 'MenuHeader';
|
|
82
98
|
|
|
83
|
-
export const MenuDivider
|
|
84
|
-
|
|
99
|
+
export const MenuDivider = polymorphic<HTMLAttributes<HTMLHRElement>>(
|
|
100
|
+
({ as: Root = 'hr', className, ...props }) => (
|
|
101
|
+
<Root {...props} className={classNames('menu-divider', className)} />
|
|
102
|
+
)
|
|
85
103
|
);
|
|
104
|
+
MenuDivider.displayName = 'MenuDivider';
|
|
86
105
|
|
|
87
|
-
export const MenuItemContent
|
|
88
|
-
|
|
106
|
+
export const MenuItemContent = polymorphic<HTMLAttributes<HTMLSpanElement>>(
|
|
107
|
+
({ as: Root = 'span', className, ...props }) => (
|
|
108
|
+
<Root {...props} className={classNames('menu-item-content', className)} />
|
|
109
|
+
)
|
|
89
110
|
);
|
|
111
|
+
MenuItemContent.displayName = 'MenuItemContent';
|
|
90
112
|
|
|
91
|
-
export const MenuItemDescription
|
|
92
|
-
|
|
113
|
+
export const MenuItemDescription = polymorphic<HTMLAttributes<HTMLElement>>(
|
|
114
|
+
({ as: Root = 'small', className, ...props }) => (
|
|
115
|
+
<Root {...props} className={classNames('menu-item-description', className)} />
|
|
116
|
+
)
|
|
93
117
|
);
|
|
118
|
+
MenuItemDescription.displayName = 'MenuItemDescription';
|
|
94
119
|
|
|
95
|
-
export interface MenuSubmenuProps extends
|
|
120
|
+
export interface MenuSubmenuProps extends HTMLAttributes<HTMLDivElement> {
|
|
96
121
|
label: ReactNode;
|
|
97
122
|
className?: string;
|
|
98
123
|
}
|
|
99
124
|
|
|
100
125
|
@observer
|
|
101
|
-
export class MenuSubmenu extends Component<
|
|
126
|
+
export class MenuSubmenu<T extends ElementType | undefined = 'div'> extends Component<
|
|
127
|
+
PolymorphicClassProps<T, MenuSubmenuProps>
|
|
128
|
+
> {
|
|
129
|
+
static displayName = 'MenuSubmenu';
|
|
130
|
+
|
|
131
|
+
declare readonly props: PolymorphicClassProps<T, MenuSubmenuProps>;
|
|
132
|
+
|
|
133
|
+
protected get componentProps(): Readonly<MenuSubmenuProps & AsProps> {
|
|
134
|
+
return this.props;
|
|
135
|
+
}
|
|
136
|
+
|
|
102
137
|
@observable accessor open = false;
|
|
103
138
|
|
|
104
139
|
panel = createRef<HTMLDivElement>();
|
|
@@ -128,11 +163,23 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
128
163
|
|
|
129
164
|
handleClick = () => this.setOpen(!this.open);
|
|
130
165
|
|
|
131
|
-
handleMouseEnter = () =>
|
|
166
|
+
handleMouseEnter = (event: MouseEvent<HTMLDivElement>) => {
|
|
167
|
+
this.componentProps.onMouseEnter?.(event);
|
|
132
168
|
|
|
133
|
-
|
|
169
|
+
if (!event.defaultPrevented) this.setOpen(true);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
handleMouseLeave = (event: MouseEvent<HTMLDivElement>) => {
|
|
173
|
+
this.componentProps.onMouseLeave?.(event);
|
|
174
|
+
|
|
175
|
+
if (!event.defaultPrevented) this.setOpen(false);
|
|
176
|
+
};
|
|
134
177
|
|
|
135
178
|
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
179
|
+
this.componentProps.onKeyDown?.(event);
|
|
180
|
+
|
|
181
|
+
if (event.defaultPrevented) return;
|
|
182
|
+
|
|
136
183
|
const { key } = event;
|
|
137
184
|
|
|
138
185
|
if (key === 'ArrowRight') {
|
|
@@ -156,11 +203,14 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
156
203
|
};
|
|
157
204
|
|
|
158
205
|
render() {
|
|
159
|
-
const
|
|
206
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
207
|
+
|
|
208
|
+
const { as: _as, label, className, children, ...props } = this.componentProps;
|
|
160
209
|
const { open } = this;
|
|
161
210
|
|
|
162
211
|
return (
|
|
163
|
-
<
|
|
212
|
+
<Root
|
|
213
|
+
{...props}
|
|
164
214
|
className={classNames('submenu', { show: open }, className)}
|
|
165
215
|
onMouseEnter={this.handleMouseEnter}
|
|
166
216
|
onMouseLeave={this.handleMouseLeave}
|
|
@@ -184,7 +234,7 @@ export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
|
184
234
|
>
|
|
185
235
|
{children}
|
|
186
236
|
</div>
|
|
187
|
-
</
|
|
237
|
+
</Root>
|
|
188
238
|
);
|
|
189
239
|
}
|
|
190
240
|
}
|
|
@@ -241,7 +291,17 @@ const MENU_BREAKPOINT_WIDTHS: Record<Breakpoint, number> = {
|
|
|
241
291
|
};
|
|
242
292
|
|
|
243
293
|
@observer
|
|
244
|
-
export class Menu extends Component<
|
|
294
|
+
export class Menu<T extends ElementType | undefined = 'div'> extends Component<
|
|
295
|
+
PolymorphicClassProps<T, MenuProps>
|
|
296
|
+
> {
|
|
297
|
+
static displayName = 'Menu';
|
|
298
|
+
|
|
299
|
+
declare readonly props: PolymorphicClassProps<T, MenuProps>;
|
|
300
|
+
|
|
301
|
+
protected get componentProps(): Readonly<MenuProps & AsProps> {
|
|
302
|
+
return this.props;
|
|
303
|
+
}
|
|
304
|
+
|
|
245
305
|
@observable accessor open = false;
|
|
246
306
|
@observable accessor responsiveDirection: MenuPlacement | undefined;
|
|
247
307
|
|
|
@@ -257,10 +317,9 @@ export class Menu extends Component<MenuProps> {
|
|
|
257
317
|
}
|
|
258
318
|
|
|
259
319
|
componentDidUpdate({ responsivePlacement }: MenuProps) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
320
|
+
if (responsivePlacement !== this.componentProps.responsivePlacement)
|
|
321
|
+
this.observePlacement();
|
|
322
|
+
const { trigger, panel, position, componentProps: props } = this;
|
|
264
323
|
if (!this.open) return position.dispose();
|
|
265
324
|
if (!trigger.current || !panel.current) return;
|
|
266
325
|
|
|
@@ -293,7 +352,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
293
352
|
query.removeEventListener('change', this.handlePlacement);
|
|
294
353
|
|
|
295
354
|
this.media = (Object.keys(MENU_BREAKPOINT_WIDTHS) as Breakpoint[]).flatMap(breakpoint => {
|
|
296
|
-
const placement = this.
|
|
355
|
+
const placement = this.componentProps.responsivePlacement?.[breakpoint];
|
|
297
356
|
if (!placement) return [];
|
|
298
357
|
|
|
299
358
|
const query = window.matchMedia(`(min-width: ${MENU_BREAKPOINT_WIDTHS[breakpoint]}px)`);
|
|
@@ -313,11 +372,11 @@ export class Menu extends Component<MenuProps> {
|
|
|
313
372
|
setOpen = (open: boolean) => {
|
|
314
373
|
if (this.open === open) return;
|
|
315
374
|
this.open = open;
|
|
316
|
-
this.
|
|
375
|
+
this.componentProps.onOpenChange?.(open);
|
|
317
376
|
};
|
|
318
377
|
|
|
319
378
|
handleOutside = ({ target }: PointerEvent) => {
|
|
320
|
-
const { autoClose = true } = this.
|
|
379
|
+
const { autoClose = true } = this.componentProps;
|
|
321
380
|
if (
|
|
322
381
|
autoClose !== false &&
|
|
323
382
|
autoClose !== 'inside' &&
|
|
@@ -336,7 +395,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
336
395
|
}
|
|
337
396
|
|
|
338
397
|
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
339
|
-
this.
|
|
398
|
+
this.componentProps.onKeyDown?.(event);
|
|
340
399
|
|
|
341
400
|
const { key, defaultPrevented } = event;
|
|
342
401
|
if (defaultPrevented) return;
|
|
@@ -375,7 +434,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
375
434
|
};
|
|
376
435
|
|
|
377
436
|
handleBlur = (event: FocusEvent<HTMLDivElement>) => {
|
|
378
|
-
const { onBlur, autoClose = true } = this.
|
|
437
|
+
const { onBlur, autoClose = true } = this.componentProps;
|
|
379
438
|
onBlur?.(event);
|
|
380
439
|
|
|
381
440
|
const { defaultPrevented, currentTarget, relatedTarget } = event;
|
|
@@ -391,7 +450,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
391
450
|
handleToggle = () => this.setOpen(!this.open);
|
|
392
451
|
|
|
393
452
|
handleSelect = ({ target, defaultPrevented }: MouseEvent<HTMLDivElement>) => {
|
|
394
|
-
const { autoClose = true } = this.
|
|
453
|
+
const { autoClose = true } = this.componentProps;
|
|
395
454
|
if (
|
|
396
455
|
autoClose &&
|
|
397
456
|
!defaultPrevented &&
|
|
@@ -404,7 +463,10 @@ export class Menu extends Component<MenuProps> {
|
|
|
404
463
|
};
|
|
405
464
|
|
|
406
465
|
render() {
|
|
466
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
467
|
+
|
|
407
468
|
const {
|
|
469
|
+
as: _as,
|
|
408
470
|
label,
|
|
409
471
|
autoClose: _autoClose,
|
|
410
472
|
align = 'end',
|
|
@@ -427,7 +489,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
427
489
|
className,
|
|
428
490
|
id,
|
|
429
491
|
...props
|
|
430
|
-
} = this.
|
|
492
|
+
} = this.componentProps;
|
|
431
493
|
const { open } = this;
|
|
432
494
|
const preferred = this.responsiveDirection ?? placement;
|
|
433
495
|
const direction = this.position.element
|
|
@@ -438,7 +500,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
438
500
|
: ['top-100', align === 'end' ? 'end-0' : 'start-0'];
|
|
439
501
|
|
|
440
502
|
return (
|
|
441
|
-
<
|
|
503
|
+
<Root
|
|
442
504
|
{...props}
|
|
443
505
|
ref={this.root}
|
|
444
506
|
id={id}
|
|
@@ -485,7 +547,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
485
547
|
>
|
|
486
548
|
{children}
|
|
487
549
|
</div>
|
|
488
|
-
</
|
|
550
|
+
</Root>
|
|
489
551
|
);
|
|
490
552
|
}
|
|
491
553
|
}
|
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
ComponentPropsWithRef,
|
|
7
7
|
createRef,
|
|
8
8
|
DialogHTMLAttributes,
|
|
9
|
-
|
|
9
|
+
ElementType,
|
|
10
10
|
KeyboardEvent,
|
|
11
11
|
MouseEvent,
|
|
12
12
|
SyntheticEvent
|
|
13
13
|
} from 'react';
|
|
14
14
|
|
|
15
15
|
import { Breakpoint } from '../Grid';
|
|
16
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from '../Polymorphic';
|
|
16
17
|
import styles from './style.module.css';
|
|
17
18
|
|
|
18
19
|
const transitionMilliseconds = (value: string) =>
|
|
@@ -32,24 +33,44 @@ export interface NativeDialogProps extends Omit<DialogHTMLAttributes<HTMLDialogE
|
|
|
32
33
|
scroll?: boolean;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export const DialogHeader
|
|
36
|
-
|
|
36
|
+
export const DialogHeader = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
37
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
38
|
+
<Root {...props} className={classNames('dialog-header', className)} />
|
|
39
|
+
)
|
|
37
40
|
);
|
|
41
|
+
DialogHeader.displayName = 'DialogHeader';
|
|
38
42
|
|
|
39
|
-
export const DialogTitle
|
|
40
|
-
|
|
43
|
+
export const DialogTitle = polymorphic<ComponentPropsWithRef<'h1'>>(
|
|
44
|
+
({ as: Root = 'h1', className, ...props }) => (
|
|
45
|
+
<Root {...props} className={classNames('dialog-title', className)} />
|
|
46
|
+
)
|
|
41
47
|
);
|
|
48
|
+
DialogTitle.displayName = 'DialogTitle';
|
|
42
49
|
|
|
43
|
-
export const DialogBody
|
|
44
|
-
|
|
50
|
+
export const DialogBody = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
51
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
52
|
+
<Root {...props} className={classNames('dialog-body', className)} />
|
|
53
|
+
)
|
|
45
54
|
);
|
|
55
|
+
DialogBody.displayName = 'DialogBody';
|
|
46
56
|
|
|
47
|
-
export const DialogFooter
|
|
48
|
-
|
|
57
|
+
export const DialogFooter = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
58
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
59
|
+
<Root {...props} className={classNames('dialog-footer', className)} />
|
|
60
|
+
)
|
|
49
61
|
);
|
|
62
|
+
DialogFooter.displayName = 'DialogFooter';
|
|
50
63
|
|
|
51
|
-
export class NativeDialog extends Component<
|
|
52
|
-
|
|
64
|
+
export class NativeDialog<T extends ElementType | undefined = 'dialog'> extends Component<
|
|
65
|
+
PolymorphicClassProps<T, NativeDialogProps>
|
|
66
|
+
> {
|
|
67
|
+
declare readonly props: PolymorphicClassProps<T, NativeDialogProps>;
|
|
68
|
+
|
|
69
|
+
protected get componentProps(): Readonly<NativeDialogProps & AsProps> {
|
|
70
|
+
return this.props;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static scrollLocks = new Set<NativeDialog<ElementType>>();
|
|
53
74
|
static bodyOverflow = '';
|
|
54
75
|
|
|
55
76
|
element = createRef<HTMLDialogElement>();
|
|
@@ -62,25 +83,25 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
componentDidMount() {
|
|
65
|
-
if (this.
|
|
86
|
+
if (this.componentProps.open) this.show();
|
|
66
87
|
}
|
|
67
88
|
|
|
68
89
|
componentDidUpdate({ open, modal, scroll }: NativeDialogProps) {
|
|
69
|
-
const modeChanged = this.
|
|
70
|
-
const openChanged = this.
|
|
90
|
+
const modeChanged = this.componentProps.modal !== modal;
|
|
91
|
+
const openChanged = this.componentProps.open !== open;
|
|
71
92
|
const wasOpen = this.open;
|
|
72
|
-
if (!openChanged && !modeChanged && this.
|
|
93
|
+
if (!openChanged && !modeChanged && this.componentProps.scroll === scroll) return;
|
|
73
94
|
|
|
74
|
-
if (this.open && this.
|
|
95
|
+
if (this.open && this.componentProps.modal !== modal) {
|
|
75
96
|
this.switchingMode = true;
|
|
76
97
|
this.close();
|
|
77
98
|
}
|
|
78
|
-
if (this.
|
|
79
|
-
else if (this.open && this.
|
|
99
|
+
if (this.componentProps.scroll) this.unlockScroll();
|
|
100
|
+
else if (this.open && this.componentProps.modal !== false) this.lockScroll();
|
|
80
101
|
|
|
81
102
|
if (!openChanged && !modeChanged) return;
|
|
82
103
|
|
|
83
|
-
if (this.
|
|
104
|
+
if (this.componentProps.open || (!openChanged && modeChanged && wasOpen)) this.show();
|
|
84
105
|
else this.close();
|
|
85
106
|
}
|
|
86
107
|
|
|
@@ -94,11 +115,9 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
94
115
|
|
|
95
116
|
if (!this.switchingMode && document.activeElement instanceof HTMLElement)
|
|
96
117
|
this.returnFocus = document.activeElement;
|
|
97
|
-
|
|
98
|
-
if (this.props.modal === false) element.show();
|
|
118
|
+
if (this.componentProps.modal === false) element.show();
|
|
99
119
|
else element.showModal();
|
|
100
|
-
|
|
101
|
-
if (this.props.modal !== false && !this.props.scroll) this.lockScroll();
|
|
120
|
+
if (this.componentProps.modal !== false && !this.componentProps.scroll) this.lockScroll();
|
|
102
121
|
};
|
|
103
122
|
|
|
104
123
|
lockScroll = () => {
|
|
@@ -148,7 +167,7 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
148
167
|
};
|
|
149
168
|
|
|
150
169
|
handleClose = (event: SyntheticEvent<HTMLDialogElement>) => {
|
|
151
|
-
if (!this.switchingMode) this.
|
|
170
|
+
if (!this.switchingMode) this.componentProps.onClose?.(event);
|
|
152
171
|
|
|
153
172
|
if (!this.open) {
|
|
154
173
|
this.unlockScroll();
|
|
@@ -162,7 +181,7 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
162
181
|
}
|
|
163
182
|
|
|
164
183
|
handleCancel = (event: SyntheticEvent<HTMLDialogElement>) => {
|
|
165
|
-
const { onCancel, keyboard = true } = this.
|
|
184
|
+
const { onCancel, keyboard = true } = this.componentProps;
|
|
166
185
|
onCancel?.(event);
|
|
167
186
|
|
|
168
187
|
const { defaultPrevented } = event;
|
|
@@ -172,7 +191,7 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
172
191
|
};
|
|
173
192
|
|
|
174
193
|
handleKeyDown = (event: KeyboardEvent<HTMLDialogElement>) => {
|
|
175
|
-
const { onKeyDown, keyboard = true } = this.
|
|
194
|
+
const { onKeyDown, keyboard = true } = this.componentProps;
|
|
176
195
|
onKeyDown?.(event);
|
|
177
196
|
|
|
178
197
|
const { key, defaultPrevented } = event;
|
|
@@ -183,7 +202,7 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
183
202
|
};
|
|
184
203
|
|
|
185
204
|
handleClick = (event: MouseEvent<HTMLDialogElement>) => {
|
|
186
|
-
const { onClick, backdrop = true } = this.
|
|
205
|
+
const { onClick, backdrop = true } = this.componentProps;
|
|
187
206
|
onClick?.(event);
|
|
188
207
|
|
|
189
208
|
const { defaultPrevented, target, currentTarget, clientX, clientY } = event;
|
|
@@ -194,7 +213,10 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
194
213
|
};
|
|
195
214
|
|
|
196
215
|
render() {
|
|
216
|
+
const Root: ElementType = this.componentProps.as ?? 'dialog';
|
|
217
|
+
|
|
197
218
|
const {
|
|
219
|
+
as: _as,
|
|
198
220
|
open: _open,
|
|
199
221
|
modal: _modal,
|
|
200
222
|
keyboard: _keyboard,
|
|
@@ -212,10 +234,10 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
212
234
|
onKeyDown: _onKeyDown,
|
|
213
235
|
onClose: _onClose,
|
|
214
236
|
...props
|
|
215
|
-
} = this.
|
|
237
|
+
} = this.componentProps;
|
|
216
238
|
|
|
217
239
|
return (
|
|
218
|
-
<
|
|
240
|
+
<Root
|
|
219
241
|
{...props}
|
|
220
242
|
ref={this.element}
|
|
221
243
|
className={classNames(
|
package/source/Nav.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from './Polymorphic';
|
|
3
5
|
|
|
4
6
|
export interface NavProps extends ComponentPropsWithRef<'nav'> {
|
|
5
7
|
variant?: 'tabs' | 'pills' | 'underline';
|
|
@@ -10,59 +12,57 @@ export interface NavProps extends ComponentPropsWithRef<'nav'> {
|
|
|
10
12
|
navbar?: boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export const Nav
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
export const Nav = polymorphic<NavProps>(
|
|
16
|
+
({
|
|
17
|
+
as: Root = 'nav',
|
|
18
|
+
variant,
|
|
19
|
+
vertical,
|
|
20
|
+
fill,
|
|
21
|
+
justified,
|
|
22
|
+
cardHeader,
|
|
23
|
+
navbar,
|
|
24
|
+
className,
|
|
25
|
+
...props
|
|
26
|
+
}) => (
|
|
27
|
+
<Root
|
|
28
|
+
{...props}
|
|
29
|
+
className={classNames(
|
|
30
|
+
'nav',
|
|
31
|
+
navbar && 'navbar-nav',
|
|
32
|
+
variant && `nav-${variant}`,
|
|
33
|
+
cardHeader && variant === 'tabs' && 'card-header-tabs',
|
|
34
|
+
vertical && (variant === 'pills' ? 'nav-pills-vertical' : 'flex-column'),
|
|
35
|
+
{ 'nav-fill': fill, 'nav-justified': justified },
|
|
36
|
+
className
|
|
37
|
+
)}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
35
40
|
);
|
|
41
|
+
Nav.displayName = 'Nav';
|
|
36
42
|
|
|
37
|
-
export const NavItem
|
|
38
|
-
|
|
43
|
+
export const NavItem = polymorphic<ComponentPropsWithRef<'li'>>(
|
|
44
|
+
({ as: Root = 'li', className, ...props }) => (
|
|
45
|
+
<Root {...props} className={classNames('nav-item', className)} />
|
|
46
|
+
)
|
|
39
47
|
);
|
|
48
|
+
NavItem.displayName = 'NavItem';
|
|
40
49
|
|
|
41
50
|
export interface NavLinkProps extends ComponentPropsWithRef<'a'> {
|
|
42
51
|
disabled?: boolean;
|
|
43
52
|
active?: boolean;
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
export const NavLink
|
|
47
|
-
disabled,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tabIndex={disabled ? -1 : tabIndex}
|
|
59
|
-
aria-disabled={disabled || undefined}
|
|
60
|
-
aria-current={active ? 'page' : props['aria-current']}
|
|
61
|
-
className={classNames('nav-link', { active, disabled, 'pe-none': disabled }, className)}
|
|
62
|
-
onClick={disabled ? undefined : onClick}
|
|
63
|
-
/>
|
|
55
|
+
export const NavLink = polymorphic<NavLinkProps>(
|
|
56
|
+
({ as: Root = 'a', disabled, active, className, href, onClick, tabIndex, ...props }) => (
|
|
57
|
+
<Root
|
|
58
|
+
{...props}
|
|
59
|
+
href={disabled ? undefined : href}
|
|
60
|
+
tabIndex={disabled ? -1 : tabIndex}
|
|
61
|
+
aria-disabled={disabled || undefined}
|
|
62
|
+
aria-current={active ? 'page' : props['aria-current']}
|
|
63
|
+
className={classNames('nav-link', { active, disabled, 'pe-none': disabled }, className)}
|
|
64
|
+
onClick={disabled ? undefined : onClick}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
64
67
|
);
|
|
65
|
-
|
|
66
|
-
Nav.displayName = 'Nav';
|
|
67
|
-
NavItem.displayName = 'NavItem';
|
|
68
68
|
NavLink.displayName = 'NavLink';
|