idea-react 3.0.0-beta.0 → 3.0.0-beta.2
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 +19 -2
- package/ReadMe.md +95 -54
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1232 -474
- package/dist/index.d.ts +1232 -474
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +66 -66
- package/package.json +1 -1
- package/source/Accordion.tsx +161 -0
- package/source/Alert.tsx +153 -0
- package/source/Avatar.tsx +57 -46
- package/source/Badge.tsx +17 -15
- package/source/Breadcrumb.tsx +50 -0
- package/source/Button.tsx +69 -40
- package/source/ButtonGroup.tsx +23 -18
- package/source/Card.tsx +86 -17
- package/source/Carousel/index.tsx +392 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/CloseButton.tsx +20 -15
- package/source/Collapse.tsx +233 -0
- package/source/Drawer.tsx +158 -38
- package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +24 -5
- package/source/Extension/CodeBlock.tsx +64 -0
- package/source/{Countdown.tsx → Extension/Countdown.tsx} +21 -9
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/Extension/Editor.tsx +78 -0
- package/source/Extension/EditorHTML.tsx +20 -0
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/Extension/HorizontalMarquee/index.tsx +85 -0
- package/source/Extension/Icon.tsx +19 -0
- package/source/Extension/Loading.tsx +30 -0
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +29 -13
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +293 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +43 -16
- package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +21 -5
- package/source/Extension/ScrollNav/index.tsx +47 -0
- package/source/Extension/Select.tsx +128 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/Extension/SpinnerButton.tsx +30 -0
- package/source/Extension/TableSpinner.tsx +22 -0
- package/source/Extension/TextTruncate/index.tsx +29 -0
- package/source/Extension/Time.tsx +17 -0
- package/source/Extension/TimeDistance.tsx +45 -0
- package/source/Extension/Timeline/index.tsx +63 -0
- package/source/Extension/TypeEcho/Content.tsx +123 -0
- package/source/Extension/TypeEcho/index.tsx +22 -0
- package/source/Extension/UserRank/Address.tsx +22 -0
- package/source/Extension/UserRank/index.tsx +106 -0
- package/source/Extension/VerticalMarquee/index.tsx +23 -0
- package/source/Extension/ZodiacBar.tsx +59 -0
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +45 -26
- package/source/Form/Checkbox.tsx +20 -11
- package/source/Form/ChipInput.tsx +129 -0
- package/source/Form/Chips.tsx +57 -37
- package/source/Form/Combobox.tsx +362 -78
- package/source/Form/Control.tsx +72 -42
- package/source/Form/DatePicker.tsx +245 -45
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +21 -16
- package/source/Form/FloatingLabel.tsx +21 -7
- package/source/Form/InputGroup.tsx +162 -11
- package/source/Form/OTP.tsx +156 -45
- package/source/Form/PasswordStrength.tsx +43 -17
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +70 -20
- package/source/Form/Radio.tsx +35 -40
- package/source/Form/Range.tsx +125 -56
- package/source/Form/Switch.tsx +53 -27
- package/source/Form/index.ts +1 -0
- package/source/Grid.tsx +68 -56
- package/source/Image.tsx +10 -6
- package/source/ListGroup.tsx +59 -58
- package/source/Menu.tsx +317 -46
- package/source/NativeDialog/index.tsx +148 -22
- package/source/Nav.tsx +49 -33
- package/source/NavOverflow/index.tsx +323 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +65 -45
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +86 -0
- package/source/Placeholder.tsx +70 -0
- package/source/Polymorphic.ts +57 -0
- package/source/Popover.tsx +34 -26
- package/source/Progress/index.tsx +81 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +380 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +31 -17
- package/source/Stack.tsx +25 -0
- package/source/Stepper.tsx +91 -0
- package/source/Tab.tsx +261 -0
- package/source/Table.tsx +53 -42
- package/source/Toast.tsx +93 -46
- package/source/ToggleButton.tsx +47 -30
- package/source/Toggler.tsx +117 -0
- package/source/Tooltip.tsx +31 -24
- package/source/index.ts +17 -27
- package/source/CodeBlock.tsx +0 -40
- package/source/Editor.tsx +0 -43
- package/source/EditorHTML.tsx +0 -16
- package/source/HorizontalMarquee/index.tsx +0 -61
- package/source/Icon.tsx +0 -24
- package/source/Loading.tsx +0 -22
- package/source/OverlayBox.tsx +0 -208
- package/source/ScrollNav/index.tsx +0 -22
- package/source/Select.tsx +0 -95
- package/source/SpinnerButton.tsx +0 -35
- package/source/TableSpinner.tsx +0 -26
- package/source/TextTruncate/index.tsx +0 -25
- package/source/Time.tsx +0 -15
- package/source/TimeDistance.tsx +0 -41
- package/source/Timeline/index.tsx +0 -60
- package/source/TypeEcho/Content.tsx +0 -58
- package/source/TypeEcho/index.tsx +0 -14
- package/source/UserRank/Address.tsx +0 -20
- package/source/UserRank/index.tsx +0 -111
- package/source/VerticalMarquee/index.tsx +0 -25
- package/source/ZodiacBar.tsx +0 -51
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
package/source/Alert.tsx
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import {
|
|
7
|
+
Component,
|
|
8
|
+
ComponentPropsWithoutRef,
|
|
9
|
+
ComponentPropsWithRef,
|
|
10
|
+
createRef,
|
|
11
|
+
ElementType,
|
|
12
|
+
MouseEvent,
|
|
13
|
+
TransitionEvent
|
|
14
|
+
} from 'react';
|
|
15
|
+
|
|
16
|
+
import { ComponentTheme } from './Button';
|
|
17
|
+
import { CloseButton } from './CloseButton';
|
|
18
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
|
|
19
|
+
|
|
20
|
+
export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
|
|
21
|
+
theme?: ComponentTheme;
|
|
22
|
+
dismissible?: boolean;
|
|
23
|
+
instant?: boolean;
|
|
24
|
+
closeLabel?: string;
|
|
25
|
+
onClose?: () => unknown;
|
|
26
|
+
onClosed?: () => unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@observer
|
|
30
|
+
export class Alert<T extends ElementType | undefined = 'div'> extends Component<
|
|
31
|
+
PolymorphicClassProps<T, AlertProps>
|
|
32
|
+
> {
|
|
33
|
+
declare readonly props: PolymorphicClassProps<T, AlertProps>;
|
|
34
|
+
|
|
35
|
+
protected get componentProps(): Readonly<AlertProps & AsProps> {
|
|
36
|
+
return this.props;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static displayName = 'Alert';
|
|
40
|
+
|
|
41
|
+
@observable accessor hiding = false;
|
|
42
|
+
@observable accessor closed = false;
|
|
43
|
+
|
|
44
|
+
root = createRef<HTMLDivElement>();
|
|
45
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
46
|
+
notified = false;
|
|
47
|
+
|
|
48
|
+
componentDidUpdate() {
|
|
49
|
+
if (this.closed && !this.notified) {
|
|
50
|
+
this.notified = true;
|
|
51
|
+
this.componentProps.onClosed?.();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
componentWillUnmount() {
|
|
56
|
+
clearTimeout(this.timer);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
finishClose = action(() => {
|
|
60
|
+
if (this.closed) return;
|
|
61
|
+
|
|
62
|
+
clearTimeout(this.timer);
|
|
63
|
+
this.closed = true;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
close = action(() => {
|
|
67
|
+
if (this.hiding || this.closed) return;
|
|
68
|
+
|
|
69
|
+
this.componentProps.onClose?.();
|
|
70
|
+
|
|
71
|
+
if (this.componentProps.instant) return this.finishClose();
|
|
72
|
+
|
|
73
|
+
this.hiding = true;
|
|
74
|
+
|
|
75
|
+
const style = getComputedStyle(this.root.current!);
|
|
76
|
+
const durations = style.transitionDuration.split(',').map(Alert.milliseconds);
|
|
77
|
+
const delays = style.transitionDelay.split(',').map(Alert.milliseconds);
|
|
78
|
+
const timeout = Math.max(
|
|
79
|
+
0,
|
|
80
|
+
...durations.map((duration, index) => duration + (delays[index % delays.length] || 0))
|
|
81
|
+
);
|
|
82
|
+
this.timer = setTimeout(this.finishClose, timeout);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
static milliseconds = (value: string) =>
|
|
86
|
+
(parseFloat(value) || 0) * (value.trim().endsWith('ms') ? 1 : 1000);
|
|
87
|
+
|
|
88
|
+
handleClose = (event: MouseEvent<HTMLButtonElement>) => {
|
|
89
|
+
if (!event.defaultPrevented) this.close();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
handleTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {
|
|
93
|
+
this.componentProps.onTransitionEnd?.(event);
|
|
94
|
+
|
|
95
|
+
if (event.target === event.currentTarget && this.hiding) this.finishClose();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
render() {
|
|
99
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
as: _as,
|
|
103
|
+
theme,
|
|
104
|
+
dismissible,
|
|
105
|
+
instant,
|
|
106
|
+
closeLabel = 'Close',
|
|
107
|
+
onClose: _onClose,
|
|
108
|
+
onClosed: _onClosed,
|
|
109
|
+
className,
|
|
110
|
+
children,
|
|
111
|
+
...props
|
|
112
|
+
} = this.componentProps;
|
|
113
|
+
|
|
114
|
+
return this.closed ? null : (
|
|
115
|
+
<Root
|
|
116
|
+
{...props}
|
|
117
|
+
ref={this.root}
|
|
118
|
+
role={props.role ?? 'alert'}
|
|
119
|
+
className={classNames(
|
|
120
|
+
'alert',
|
|
121
|
+
theme && `theme-${theme}`,
|
|
122
|
+
{ 'alert-instant': instant, hiding: this.hiding },
|
|
123
|
+
className
|
|
124
|
+
)}
|
|
125
|
+
onTransitionEnd={this.handleTransitionEnd}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
|
|
129
|
+
{dismissible && (
|
|
130
|
+
<CloseButton
|
|
131
|
+
className="ms-auto"
|
|
132
|
+
aria-label={closeLabel}
|
|
133
|
+
onClick={this.handleClose}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
</Root>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const AlertLink = polymorphic<ComponentPropsWithRef<'a'>>(
|
|
142
|
+
({ as: Root = 'a', className, ...props }) => (
|
|
143
|
+
<Root {...props} className={classNames('alert-link', className)} />
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
AlertLink.displayName = 'AlertLink';
|
|
147
|
+
|
|
148
|
+
export const AlertHeading = polymorphic<ComponentPropsWithRef<'h4'>>(
|
|
149
|
+
({ as: Root = 'h4', className, ...props }) => (
|
|
150
|
+
<Root {...props} className={classNames('alert-heading', className)} />
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
AlertHeading.displayName = 'AlertHeading';
|
package/source/Avatar.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentPropsWithRef, CSSProperties, HTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from './Button';
|
|
5
|
+
import { polymorphic } from './Polymorphic';
|
|
5
6
|
|
|
6
7
|
export type AvatarSize = 'xs' | 'sm' | 'lg' | 'xl';
|
|
7
8
|
export type AvatarStatus = 'online' | 'offline' | 'busy' | 'away';
|
|
@@ -20,59 +21,69 @@ export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
|
20
21
|
statusLabel?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export const Avatar
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
export const Avatar = polymorphic<AvatarProps>(
|
|
25
|
+
({
|
|
26
|
+
as: Root = 'span',
|
|
27
|
+
className,
|
|
28
|
+
style,
|
|
29
|
+
size,
|
|
30
|
+
theme,
|
|
31
|
+
subtle,
|
|
32
|
+
src,
|
|
33
|
+
alt,
|
|
34
|
+
status,
|
|
35
|
+
statusLabel = status,
|
|
36
|
+
children,
|
|
37
|
+
...props
|
|
38
|
+
}) => (
|
|
39
|
+
<Root
|
|
40
|
+
className={classNames(
|
|
41
|
+
'avatar',
|
|
42
|
+
typeof size === 'string' && `avatar-${size}`,
|
|
43
|
+
theme && `theme-${theme}`,
|
|
44
|
+
subtle && 'avatar-subtle',
|
|
45
|
+
className
|
|
46
|
+
)}
|
|
47
|
+
style={
|
|
48
|
+
typeof size === 'number'
|
|
49
|
+
? ({ '--bs-avatar-size': `${size}rem`, ...style } as CSSProperties)
|
|
50
|
+
: style
|
|
51
|
+
}
|
|
52
|
+
{...props}
|
|
53
|
+
>
|
|
54
|
+
{src ? <img className="avatar-img" src={src} alt={alt} /> : children}
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
{status && (
|
|
57
|
+
<span
|
|
58
|
+
className={`avatar-status status-${status}`}
|
|
59
|
+
role="img"
|
|
60
|
+
aria-label={statusLabel}
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
</Root>
|
|
64
|
+
)
|
|
61
65
|
);
|
|
62
|
-
|
|
63
66
|
Avatar.displayName = 'Avatar';
|
|
64
67
|
|
|
65
68
|
export interface AvatarStackProps extends HTMLAttributes<HTMLDivElement> {
|
|
66
69
|
size?: AvatarSize;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
export const
|
|
70
|
-
|
|
71
|
-
className={classNames('avatar-
|
|
72
|
-
|
|
73
|
-
>
|
|
74
|
-
{children}
|
|
75
|
-
</div>
|
|
72
|
+
export const AvatarImage = polymorphic<ComponentPropsWithRef<'img'>>(
|
|
73
|
+
({ as: Root = 'img', className, ...props }) => (
|
|
74
|
+
<Root {...props} className={classNames('avatar-img', className)} />
|
|
75
|
+
)
|
|
76
76
|
);
|
|
77
|
+
AvatarImage.displayName = 'AvatarImage';
|
|
77
78
|
|
|
79
|
+
export const AvatarStack = polymorphic<AvatarStackProps>(
|
|
80
|
+
({ as: Root = 'div', className, size, children, ...props }) => (
|
|
81
|
+
<Root
|
|
82
|
+
className={classNames('avatar-stack', size && `avatar-stack-${size}`, className)}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</Root>
|
|
87
|
+
)
|
|
88
|
+
);
|
|
78
89
|
AvatarStack.displayName = 'AvatarStack';
|
package/source/Badge.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from './Button';
|
|
5
|
+
import { polymorphic } from './Polymorphic';
|
|
5
6
|
|
|
6
7
|
interface BadgeStyleProps {
|
|
7
8
|
variant?: 'solid' | 'subtle' | 'outline';
|
|
@@ -12,23 +13,24 @@ interface BadgeStyleProps {
|
|
|
12
13
|
type BadgeLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
|
|
13
14
|
type BadgeElementAttributes =
|
|
14
15
|
(ComponentPropsWithRef<'span'> & { href?: never }) | BadgeLinkAttributes;
|
|
16
|
+
|
|
15
17
|
export type BadgeProps = BadgeStyleProps & BadgeElementAttributes;
|
|
16
18
|
|
|
17
19
|
const isBadgeLink = (props: BadgeElementAttributes): props is BadgeLinkAttributes =>
|
|
18
20
|
typeof props.href === 'string';
|
|
19
21
|
|
|
20
|
-
export const Badge
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
export const Badge = polymorphic<BadgeProps>(
|
|
23
|
+
({ as: RootAs, variant = 'solid', theme, pill, className, ...props }) => {
|
|
24
|
+
const Root = RootAs ?? (isBadgeLink(props) ? 'a' : 'span');
|
|
25
|
+
const classes = classNames(
|
|
26
|
+
'badge',
|
|
27
|
+
variant !== 'solid' && `badge-${variant}`,
|
|
28
|
+
theme && `theme-${theme}`,
|
|
29
|
+
{ 'rounded-pill': pill },
|
|
30
|
+
className
|
|
31
|
+
);
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
};
|
|
33
|
+
return <Root {...props} className={classes} />;
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
Badge.displayName = 'Badge';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from './Polymorphic';
|
|
5
|
+
|
|
6
|
+
export const Breadcrumb = polymorphic<ComponentPropsWithRef<'ol'>>(
|
|
7
|
+
({ as: Root = 'ol', className, ...props }) => (
|
|
8
|
+
<Root {...props} className={classNames('breadcrumb', className)} />
|
|
9
|
+
)
|
|
10
|
+
);
|
|
11
|
+
Breadcrumb.displayName = 'Breadcrumb';
|
|
12
|
+
|
|
13
|
+
export const BreadcrumbItem = polymorphic<ComponentPropsWithRef<'li'>>(
|
|
14
|
+
({ as: Root = 'li', ...props }) => (
|
|
15
|
+
<Root {...props} className={classNames('breadcrumb-item', props.className)} />
|
|
16
|
+
)
|
|
17
|
+
);
|
|
18
|
+
BreadcrumbItem.displayName = 'BreadcrumbItem';
|
|
19
|
+
|
|
20
|
+
export interface BreadcrumbLinkProps extends ComponentPropsWithRef<'a'> {
|
|
21
|
+
active?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const BreadcrumbLink = polymorphic<BreadcrumbLinkProps>(
|
|
25
|
+
({
|
|
26
|
+
as: Root = 'a',
|
|
27
|
+
active,
|
|
28
|
+
className,
|
|
29
|
+
'aria-current': current = active ? 'page' : undefined,
|
|
30
|
+
...props
|
|
31
|
+
}) => (
|
|
32
|
+
<Root
|
|
33
|
+
{...props}
|
|
34
|
+
className={classNames('breadcrumb-link', { active }, className)}
|
|
35
|
+
aria-current={current}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
BreadcrumbLink.displayName = 'BreadcrumbLink';
|
|
40
|
+
|
|
41
|
+
export const BreadcrumbDivider = polymorphic<ComponentPropsWithRef<'li'>>(
|
|
42
|
+
({ as: Root = 'li', className, ...props }) => (
|
|
43
|
+
<Root
|
|
44
|
+
{...props}
|
|
45
|
+
className={classNames('breadcrumb-divider', className)}
|
|
46
|
+
aria-hidden="true"
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
BreadcrumbDivider.displayName = 'BreadcrumbDivider';
|
package/source/Button.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
1
|
import classNames from 'classnames';
|
|
4
|
-
import { ComponentPropsWithRef,
|
|
2
|
+
import { ComponentPropsWithRef, MouseEvent } from 'react';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from './Polymorphic';
|
|
5
5
|
|
|
6
6
|
export type ComponentTheme =
|
|
7
7
|
| 'primary'
|
|
@@ -16,58 +16,87 @@ export type ComponentTheme =
|
|
|
16
16
|
| 'inverse';
|
|
17
17
|
|
|
18
18
|
interface ButtonStyleProps {
|
|
19
|
-
variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link';
|
|
19
|
+
variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link' | false;
|
|
20
20
|
theme?: ComponentTheme;
|
|
21
21
|
size?: 'xs' | 'sm' | 'lg';
|
|
22
22
|
icon?: boolean;
|
|
23
23
|
styled?: boolean;
|
|
24
24
|
disabled?: boolean;
|
|
25
|
+
active?: boolean;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type ButtonLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
|
|
28
29
|
type ButtonAttributes = ComponentPropsWithRef<'button'> & { href?: never };
|
|
29
30
|
type ButtonElementAttributes = ButtonAttributes | ButtonLinkAttributes;
|
|
31
|
+
|
|
30
32
|
export type ButtonProps = ButtonStyleProps & ButtonElementAttributes;
|
|
31
33
|
|
|
32
34
|
const isButtonLink = (props: ButtonElementAttributes): props is ButtonLinkAttributes =>
|
|
33
35
|
typeof props.href === 'string';
|
|
34
36
|
|
|
35
|
-
const preventNavigation = (event: MouseEvent<
|
|
37
|
+
const preventNavigation = (event: MouseEvent<HTMLElement>) => event.preventDefault();
|
|
36
38
|
|
|
37
|
-
export const Button
|
|
38
|
-
variant,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
theme && `theme-${theme}`,
|
|
51
|
-
size && `btn-${size}`,
|
|
52
|
-
{ 'btn-icon': icon, 'btn-styled': styled, disabled },
|
|
53
|
-
className
|
|
54
|
-
);
|
|
39
|
+
export const Button = polymorphic<ButtonProps>(
|
|
40
|
+
({ as: RootAs, variant, theme, size, icon, styled, disabled, active, className, ...props }) => {
|
|
41
|
+
const attributes: ButtonElementAttributes = props;
|
|
42
|
+
const link = isButtonLink(attributes);
|
|
43
|
+
const Root = RootAs ?? (link ? 'a' : 'button');
|
|
44
|
+
const nativeButton = Root === 'button';
|
|
45
|
+
const classes = classNames(
|
|
46
|
+
variant === false ? undefined : variant ? `btn-${variant}` : icon ? undefined : 'btn',
|
|
47
|
+
theme && `theme-${theme}`,
|
|
48
|
+
size && `btn-${size}`,
|
|
49
|
+
{ 'btn-icon': icon, 'btn-styled': styled, disabled, active },
|
|
50
|
+
className
|
|
51
|
+
);
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
return (
|
|
54
|
+
<Root
|
|
55
|
+
{...attributes}
|
|
56
|
+
className={classes}
|
|
57
|
+
type={nativeButton ? attributes.type || 'button' : attributes.type}
|
|
58
|
+
href={disabled ? undefined : attributes.href}
|
|
59
|
+
disabled={nativeButton || typeof Root !== 'string' ? disabled : undefined}
|
|
60
|
+
aria-disabled={(!nativeButton && disabled) || undefined}
|
|
61
|
+
aria-pressed={
|
|
62
|
+
!link || attributes.role === 'button'
|
|
63
|
+
? (active ?? attributes['aria-pressed'])
|
|
64
|
+
: attributes['aria-pressed']
|
|
65
|
+
}
|
|
66
|
+
tabIndex={!nativeButton && disabled ? -1 : attributes.tabIndex}
|
|
67
|
+
onClick={!nativeButton && disabled ? preventNavigation : attributes.onClick}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
Button.displayName = 'Button';
|
|
73
|
+
|
|
74
|
+
export type ButtonInputProps = Omit<ComponentPropsWithRef<'input'>, 'size'> & ButtonStyleProps;
|
|
75
|
+
|
|
76
|
+
export const ButtonInput = polymorphic<ButtonInputProps>(
|
|
77
|
+
({
|
|
78
|
+
as: Root = 'input',
|
|
79
|
+
variant,
|
|
80
|
+
theme,
|
|
81
|
+
size,
|
|
82
|
+
icon,
|
|
83
|
+
styled,
|
|
84
|
+
active,
|
|
85
|
+
className,
|
|
86
|
+
type = 'button',
|
|
87
|
+
...props
|
|
88
|
+
}) => (
|
|
89
|
+
<Root
|
|
90
|
+
{...props}
|
|
91
|
+
type={type}
|
|
92
|
+
className={classNames(
|
|
93
|
+
variant === false ? undefined : variant ? `btn-${variant}` : 'btn',
|
|
94
|
+
theme && `theme-${theme}`,
|
|
95
|
+
size && `btn-${size}`,
|
|
96
|
+
{ 'btn-icon': icon, 'btn-styled': styled, active },
|
|
97
|
+
className
|
|
98
|
+
)}
|
|
71
99
|
/>
|
|
72
|
-
)
|
|
73
|
-
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
ButtonInput.displayName = 'ButtonInput';
|
package/source/ButtonGroup.tsx
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
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 ButtonGroupProps extends ComponentPropsWithRef<'div'> {
|
|
5
7
|
vertical?: boolean;
|
|
8
|
+
size?: 'xs' | 'sm' | 'lg';
|
|
9
|
+
divider?: boolean;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
export const ButtonGroup
|
|
9
|
-
vertical,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export const ButtonGroup = polymorphic<ButtonGroupProps>(
|
|
13
|
+
({ as: Root = 'div', vertical, size, divider, role = 'group', className, ...props }) => (
|
|
14
|
+
<Root
|
|
15
|
+
role={role}
|
|
16
|
+
{...props}
|
|
17
|
+
className={classNames(
|
|
18
|
+
vertical ? 'btn-group-vertical' : 'btn-group',
|
|
19
|
+
size && `btn-group-${size}`,
|
|
20
|
+
divider && 'btn-group-divider',
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
19
25
|
);
|
|
20
26
|
ButtonGroup.displayName = 'ButtonGroup';
|
|
21
27
|
|
|
22
|
-
export const ButtonToolbar
|
|
23
|
-
className,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
export const ButtonToolbar = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
29
|
+
({ as: Root = 'div', className, role = 'toolbar', ...props }) => (
|
|
30
|
+
<Root role={role} {...props} className={classNames('btn-toolbar', className)} />
|
|
31
|
+
)
|
|
32
|
+
);
|
|
28
33
|
ButtonToolbar.displayName = 'ButtonToolbar';
|