idea-react 3.0.0-beta.1 → 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 +9 -1
- package/ReadMe.md +34 -6
- package/dist/index.d.mts +270 -186
- package/dist/index.d.ts +270 -186
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/style.css +0 -3
- package/package.json +1 -1
- 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 +43 -40
- 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 +40 -37
- package/source/Toggler.tsx +17 -8
- package/source/Tooltip.tsx +31 -29
- package/source/index.ts +2 -0
- package/source/Extension/CodeBlock/index.tsx +0 -58
- package/source/Extension/CodeBlock/style.module.css +0 -3
package/dist/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idea-react",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"author": "shiy2008@gmail.com",
|
|
6
6
|
"description": "A React advanced components library based on TypeScript & Bootstrap, built by idea2app remote developers team.",
|
package/source/Accordion.tsx
CHANGED
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { action, observable } from 'mobx';
|
|
5
5
|
import { observer } from 'mobx-react';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Component,
|
|
8
|
+
ComponentPropsWithoutRef,
|
|
9
|
+
ComponentPropsWithRef,
|
|
10
|
+
ElementType,
|
|
11
|
+
MouseEvent
|
|
12
|
+
} from 'react';
|
|
7
13
|
|
|
8
14
|
import { Button, ButtonProps, ComponentTheme } from './Button';
|
|
9
15
|
import { Icon } from './Extension/Icon';
|
|
16
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
|
|
10
17
|
|
|
11
18
|
export interface AccordionProps extends ComponentPropsWithRef<'div'> {
|
|
12
19
|
theme?: ComponentTheme;
|
|
@@ -15,46 +22,48 @@ export interface AccordionProps extends ComponentPropsWithRef<'div'> {
|
|
|
15
22
|
gap?: boolean;
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
export const Accordion
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
export const Accordion = polymorphic<AccordionProps>(
|
|
26
|
+
({ as: Root = 'div', theme, size, flush, gap, className, ...props }) => (
|
|
27
|
+
<Root
|
|
28
|
+
{...props}
|
|
29
|
+
className={classNames(
|
|
30
|
+
'accordion',
|
|
31
|
+
theme && `theme-${theme}`,
|
|
32
|
+
size && `accordion-${size}`,
|
|
33
|
+
{ 'accordion-flush': flush, 'accordion-gap': gap },
|
|
34
|
+
className
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
29
38
|
);
|
|
39
|
+
Accordion.displayName = 'Accordion';
|
|
30
40
|
|
|
31
|
-
export const AccordionItem
|
|
32
|
-
|
|
41
|
+
export const AccordionItem = polymorphic<ComponentPropsWithRef<'details'>>(
|
|
42
|
+
({ as: Root = 'details', className, ...props }) => (
|
|
43
|
+
<Root {...props} className={classNames('accordion-item', className)} />
|
|
44
|
+
)
|
|
33
45
|
);
|
|
46
|
+
AccordionItem.displayName = 'AccordionItem';
|
|
34
47
|
|
|
35
48
|
export interface AccordionHeaderProps extends ComponentPropsWithRef<'summary'> {
|
|
36
49
|
icon?: string | false;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
export const AccordionHeader
|
|
40
|
-
icon = 'chevron-down',
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{children}
|
|
47
|
-
{icon && <Icon name={icon} className="accordion-icon" aria-hidden="true" />}
|
|
48
|
-
</summary>
|
|
52
|
+
export const AccordionHeader = polymorphic<AccordionHeaderProps>(
|
|
53
|
+
({ as: Root = 'summary', icon = 'chevron-down', className, children, ...props }) => (
|
|
54
|
+
<Root {...props} className={classNames('accordion-header', className)}>
|
|
55
|
+
{children}
|
|
56
|
+
{icon && <Icon name={icon} className="accordion-icon" aria-hidden="true" />}
|
|
57
|
+
</Root>
|
|
58
|
+
)
|
|
49
59
|
);
|
|
60
|
+
AccordionHeader.displayName = 'AccordionHeader';
|
|
50
61
|
|
|
51
|
-
export const AccordionBody
|
|
52
|
-
|
|
62
|
+
export const AccordionBody = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
63
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
64
|
+
<Root {...props} className={classNames('accordion-body', className)} />
|
|
65
|
+
)
|
|
53
66
|
);
|
|
54
|
-
|
|
55
|
-
Accordion.displayName = 'Accordion';
|
|
56
|
-
AccordionItem.displayName = 'AccordionItem';
|
|
57
|
-
AccordionHeader.displayName = 'AccordionHeader';
|
|
58
67
|
AccordionBody.displayName = 'AccordionBody';
|
|
59
68
|
|
|
60
69
|
export interface AccordionToggleProps
|
|
@@ -65,7 +74,15 @@ export interface AccordionToggleProps
|
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
@observer
|
|
68
|
-
export class AccordionToggle extends Component<
|
|
77
|
+
export class AccordionToggle<T extends ElementType | undefined = 'button'> extends Component<
|
|
78
|
+
PolymorphicClassProps<T, AccordionToggleProps>
|
|
79
|
+
> {
|
|
80
|
+
declare readonly props: PolymorphicClassProps<T, AccordionToggleProps>;
|
|
81
|
+
|
|
82
|
+
protected get componentProps(): Readonly<AccordionToggleProps & AsProps> {
|
|
83
|
+
return this.props;
|
|
84
|
+
}
|
|
85
|
+
|
|
69
86
|
static displayName = 'AccordionToggle';
|
|
70
87
|
|
|
71
88
|
@observable accessor expanded = false;
|
|
@@ -75,7 +92,7 @@ export class AccordionToggle extends Component<AccordionToggleProps> {
|
|
|
75
92
|
get items() {
|
|
76
93
|
return [
|
|
77
94
|
...(document
|
|
78
|
-
.querySelector(this.
|
|
95
|
+
.querySelector(this.componentProps.target)
|
|
79
96
|
?.querySelectorAll<HTMLDetailsElement>(':scope > .accordion-item') ?? [])
|
|
80
97
|
];
|
|
81
98
|
}
|
|
@@ -86,7 +103,7 @@ export class AccordionToggle extends Component<AccordionToggleProps> {
|
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
componentDidUpdate(previous: AccordionToggleProps) {
|
|
89
|
-
if (previous.target !== this.
|
|
106
|
+
if (previous.target !== this.componentProps.target) {
|
|
90
107
|
this.restoreNames();
|
|
91
108
|
this.refresh();
|
|
92
109
|
}
|
|
@@ -109,7 +126,7 @@ export class AccordionToggle extends Component<AccordionToggleProps> {
|
|
|
109
126
|
});
|
|
110
127
|
|
|
111
128
|
handleClick = (event: MouseEvent<HTMLButtonElement>) => {
|
|
112
|
-
this.
|
|
129
|
+
this.componentProps.onClick?.(event);
|
|
113
130
|
|
|
114
131
|
if (event.defaultPrevented) return;
|
|
115
132
|
|
|
@@ -130,8 +147,15 @@ export class AccordionToggle extends Component<AccordionToggleProps> {
|
|
|
130
147
|
};
|
|
131
148
|
|
|
132
149
|
render() {
|
|
133
|
-
const { target: _target, ...props } = this.
|
|
134
|
-
|
|
135
|
-
return
|
|
150
|
+
const { target: _target, ...props } = this.componentProps;
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Button
|
|
154
|
+
as={this.componentProps.as}
|
|
155
|
+
{...props}
|
|
156
|
+
aria-expanded={this.expanded}
|
|
157
|
+
onClick={this.handleClick}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
136
160
|
}
|
|
137
161
|
}
|
package/source/Alert.tsx
CHANGED
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
ComponentPropsWithoutRef,
|
|
9
9
|
ComponentPropsWithRef,
|
|
10
10
|
createRef,
|
|
11
|
-
|
|
11
|
+
ElementType,
|
|
12
12
|
MouseEvent,
|
|
13
13
|
TransitionEvent
|
|
14
14
|
} from 'react';
|
|
15
15
|
|
|
16
16
|
import { ComponentTheme } from './Button';
|
|
17
17
|
import { CloseButton } from './CloseButton';
|
|
18
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
|
|
18
19
|
|
|
19
20
|
export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
|
|
20
21
|
theme?: ComponentTheme;
|
|
@@ -26,7 +27,15 @@ export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
@observer
|
|
29
|
-
export class Alert extends Component<
|
|
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
|
+
|
|
30
39
|
static displayName = 'Alert';
|
|
31
40
|
|
|
32
41
|
@observable accessor hiding = false;
|
|
@@ -39,7 +48,7 @@ export class Alert extends Component<AlertProps> {
|
|
|
39
48
|
componentDidUpdate() {
|
|
40
49
|
if (this.closed && !this.notified) {
|
|
41
50
|
this.notified = true;
|
|
42
|
-
this.
|
|
51
|
+
this.componentProps.onClosed?.();
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
|
|
@@ -57,9 +66,9 @@ export class Alert extends Component<AlertProps> {
|
|
|
57
66
|
close = action(() => {
|
|
58
67
|
if (this.hiding || this.closed) return;
|
|
59
68
|
|
|
60
|
-
this.
|
|
69
|
+
this.componentProps.onClose?.();
|
|
61
70
|
|
|
62
|
-
if (this.
|
|
71
|
+
if (this.componentProps.instant) return this.finishClose();
|
|
63
72
|
|
|
64
73
|
this.hiding = true;
|
|
65
74
|
|
|
@@ -81,13 +90,16 @@ export class Alert extends Component<AlertProps> {
|
|
|
81
90
|
};
|
|
82
91
|
|
|
83
92
|
handleTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {
|
|
84
|
-
this.
|
|
93
|
+
this.componentProps.onTransitionEnd?.(event);
|
|
85
94
|
|
|
86
95
|
if (event.target === event.currentTarget && this.hiding) this.finishClose();
|
|
87
96
|
};
|
|
88
97
|
|
|
89
98
|
render() {
|
|
99
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
100
|
+
|
|
90
101
|
const {
|
|
102
|
+
as: _as,
|
|
91
103
|
theme,
|
|
92
104
|
dismissible,
|
|
93
105
|
instant,
|
|
@@ -97,10 +109,10 @@ export class Alert extends Component<AlertProps> {
|
|
|
97
109
|
className,
|
|
98
110
|
children,
|
|
99
111
|
...props
|
|
100
|
-
} = this.
|
|
112
|
+
} = this.componentProps;
|
|
101
113
|
|
|
102
114
|
return this.closed ? null : (
|
|
103
|
-
<
|
|
115
|
+
<Root
|
|
104
116
|
{...props}
|
|
105
117
|
ref={this.root}
|
|
106
118
|
role={props.role ?? 'alert'}
|
|
@@ -121,18 +133,21 @@ export class Alert extends Component<AlertProps> {
|
|
|
121
133
|
onClick={this.handleClose}
|
|
122
134
|
/>
|
|
123
135
|
)}
|
|
124
|
-
</
|
|
136
|
+
</Root>
|
|
125
137
|
);
|
|
126
138
|
}
|
|
127
139
|
}
|
|
128
140
|
|
|
129
|
-
export const AlertLink
|
|
130
|
-
|
|
141
|
+
export const AlertLink = polymorphic<ComponentPropsWithRef<'a'>>(
|
|
142
|
+
({ as: Root = 'a', className, ...props }) => (
|
|
143
|
+
<Root {...props} className={classNames('alert-link', className)} />
|
|
144
|
+
)
|
|
131
145
|
);
|
|
146
|
+
AlertLink.displayName = 'AlertLink';
|
|
132
147
|
|
|
133
|
-
export const AlertHeading
|
|
134
|
-
|
|
148
|
+
export const AlertHeading = polymorphic<ComponentPropsWithRef<'h4'>>(
|
|
149
|
+
({ as: Root = 'h4', className, ...props }) => (
|
|
150
|
+
<Root {...props} className={classNames('alert-heading', className)} />
|
|
151
|
+
)
|
|
135
152
|
);
|
|
136
|
-
|
|
137
|
-
AlertLink.displayName = 'AlertLink';
|
|
138
153
|
AlertHeading.displayName = 'AlertHeading';
|
package/source/Avatar.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef, CSSProperties,
|
|
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,65 +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 AvatarImage
|
|
70
|
-
|
|
72
|
+
export const AvatarImage = polymorphic<ComponentPropsWithRef<'img'>>(
|
|
73
|
+
({ as: Root = 'img', className, ...props }) => (
|
|
74
|
+
<Root {...props} className={classNames('avatar-img', className)} />
|
|
75
|
+
)
|
|
71
76
|
);
|
|
72
|
-
|
|
73
77
|
AvatarImage.displayName = 'AvatarImage';
|
|
74
78
|
|
|
75
|
-
export const AvatarStack
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
)
|
|
82
88
|
);
|
|
83
|
-
|
|
84
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,25 +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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<a {...props} className={classes} />
|
|
31
|
-
) : (
|
|
32
|
-
<span {...props} className={classes} />
|
|
33
|
-
);
|
|
34
|
-
};
|
|
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
|
+
);
|
|
35
32
|
|
|
33
|
+
return <Root {...props} className={classes} />;
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
36
|
Badge.displayName = 'Badge';
|
package/source/Breadcrumb.tsx
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
)
|
|
6
10
|
);
|
|
11
|
+
Breadcrumb.displayName = 'Breadcrumb';
|
|
7
12
|
|
|
8
|
-
export const BreadcrumbItem
|
|
9
|
-
|
|
13
|
+
export const BreadcrumbItem = polymorphic<ComponentPropsWithRef<'li'>>(
|
|
14
|
+
({ as: Root = 'li', ...props }) => (
|
|
15
|
+
<Root {...props} className={classNames('breadcrumb-item', props.className)} />
|
|
16
|
+
)
|
|
10
17
|
);
|
|
18
|
+
BreadcrumbItem.displayName = 'BreadcrumbItem';
|
|
11
19
|
|
|
12
20
|
export interface BreadcrumbLinkProps extends ComponentPropsWithRef<'a'> {
|
|
13
21
|
active?: boolean;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
export const BreadcrumbLink
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
)
|
|
27
38
|
);
|
|
39
|
+
BreadcrumbLink.displayName = 'BreadcrumbLink';
|
|
28
40
|
|
|
29
|
-
export const BreadcrumbDivider
|
|
30
|
-
|
|
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
|
+
)
|
|
31
49
|
);
|
|
32
|
-
|
|
33
|
-
Breadcrumb.displayName = 'Breadcrumb';
|
|
34
|
-
BreadcrumbItem.displayName = 'BreadcrumbItem';
|
|
35
|
-
BreadcrumbLink.displayName = 'BreadcrumbLink';
|
|
36
50
|
BreadcrumbDivider.displayName = 'BreadcrumbDivider';
|