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/source/Tab.tsx
CHANGED
|
@@ -9,26 +9,26 @@ import {
|
|
|
9
9
|
Component,
|
|
10
10
|
ComponentPropsWithRef,
|
|
11
11
|
createRef,
|
|
12
|
-
|
|
12
|
+
ElementType,
|
|
13
13
|
isValidElement,
|
|
14
14
|
KeyboardEvent,
|
|
15
15
|
MouseEvent,
|
|
16
16
|
ReactNode
|
|
17
17
|
} from 'react';
|
|
18
18
|
|
|
19
|
+
import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
|
|
20
|
+
|
|
19
21
|
export interface TabProps extends ComponentPropsWithRef<'div'> {
|
|
20
22
|
eventKey: string;
|
|
21
23
|
label: ReactNode;
|
|
22
24
|
disabled?: boolean;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export const Tab
|
|
26
|
-
eventKey: _eventKey,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}) => <div {...props} />;
|
|
31
|
-
|
|
27
|
+
export const Tab = polymorphic<TabProps>(
|
|
28
|
+
({ as: Root = 'div', eventKey: _eventKey, label: _label, disabled: _disabled, ...props }) => (
|
|
29
|
+
<Root {...props} />
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
32
|
Tab.displayName = 'Tab';
|
|
33
33
|
|
|
34
34
|
export interface TabsProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
@@ -42,11 +42,19 @@ export interface TabsProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
@observer
|
|
45
|
-
export class Tabs extends Component<
|
|
45
|
+
export class Tabs<T extends ElementType | undefined = 'div'> extends Component<
|
|
46
|
+
PolymorphicClassProps<T, TabsProps>
|
|
47
|
+
> {
|
|
46
48
|
static displayName = 'Tabs';
|
|
47
49
|
|
|
50
|
+
declare readonly props: PolymorphicClassProps<T, TabsProps>;
|
|
51
|
+
|
|
52
|
+
protected get componentProps(): Readonly<TabsProps & AsProps> {
|
|
53
|
+
return this.props;
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
get tabs() {
|
|
49
|
-
return Children.toArray(this.
|
|
57
|
+
return Children.toArray(this.componentProps.children)
|
|
50
58
|
.filter(child => typeof child !== 'string' || child.trim())
|
|
51
59
|
.map(child => {
|
|
52
60
|
// Server component boundaries may wrap Tab in a lazy client reference.
|
|
@@ -64,13 +72,13 @@ export class Tabs extends Component<TabsProps> {
|
|
|
64
72
|
root = createRef<HTMLDivElement>();
|
|
65
73
|
|
|
66
74
|
@observable accessor selectedKey =
|
|
67
|
-
this.
|
|
75
|
+
this.componentProps.defaultActiveKey ??
|
|
68
76
|
this.tabs.find(({ props }) => !props.disabled)?.props.eventKey ??
|
|
69
77
|
this.tabs[0]?.props.eventKey ??
|
|
70
78
|
'';
|
|
71
79
|
|
|
72
80
|
get activeKey() {
|
|
73
|
-
const key = this.
|
|
81
|
+
const key = this.componentProps.activeKey ?? this.selectedKey;
|
|
74
82
|
|
|
75
83
|
return this.tabs.some(({ props }) => props.eventKey === key && !props.disabled)
|
|
76
84
|
? key
|
|
@@ -78,27 +86,29 @@ export class Tabs extends Component<TabsProps> {
|
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
handleClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
81
|
-
this.
|
|
89
|
+
this.componentProps.onClick?.(event);
|
|
90
|
+
|
|
82
91
|
if (event.defaultPrevented) return;
|
|
83
92
|
|
|
84
93
|
const button = (event.target as Element).closest<HTMLButtonElement>('[data-tab-index]');
|
|
85
94
|
const tab = button && this.tabs[Number(button.dataset.tabIndex)]?.props;
|
|
95
|
+
|
|
86
96
|
if (!tab || tab.disabled) return;
|
|
87
97
|
|
|
88
98
|
this.activate(tab.eventKey);
|
|
89
99
|
};
|
|
90
100
|
|
|
91
101
|
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
92
|
-
this.
|
|
102
|
+
this.componentProps.onKeyDown?.(event);
|
|
93
103
|
|
|
94
104
|
if (event.defaultPrevented) return;
|
|
95
105
|
|
|
96
106
|
const button = (event.target as Element).closest<HTMLButtonElement>('[data-tab-index]');
|
|
97
107
|
const index = Number(button?.dataset.tabIndex);
|
|
98
|
-
const tabs = this
|
|
108
|
+
const { tabs } = this;
|
|
99
109
|
if (!button || Number.isNaN(index)) return;
|
|
100
110
|
|
|
101
|
-
const horizontal = this.
|
|
111
|
+
const horizontal = this.componentProps.orientation !== 'vertical';
|
|
102
112
|
const previous = horizontal ? event.key === 'ArrowLeft' : event.key === 'ArrowUp';
|
|
103
113
|
const next = horizontal ? event.key === 'ArrowRight' : event.key === 'ArrowDown';
|
|
104
114
|
const enabled = tabs
|
|
@@ -128,17 +138,17 @@ export class Tabs extends Component<TabsProps> {
|
|
|
128
138
|
|
|
129
139
|
@action
|
|
130
140
|
activate = (key: string) => {
|
|
131
|
-
this.
|
|
141
|
+
this.componentProps.onChange?.(key);
|
|
132
142
|
|
|
133
|
-
if (this.
|
|
143
|
+
if (this.componentProps.activeKey === undefined) this.selectedKey = key;
|
|
134
144
|
};
|
|
135
145
|
|
|
136
|
-
tabId = (key: string) => `${this.
|
|
146
|
+
tabId = (key: string) => `${this.componentProps.id}-tab-${encodeURIComponent(key)}`;
|
|
137
147
|
|
|
138
|
-
panelId = (key: string) => `${this.
|
|
148
|
+
panelId = (key: string) => `${this.componentProps.id}-panel-${encodeURIComponent(key)}`;
|
|
139
149
|
|
|
140
150
|
renderTabs = () => {
|
|
141
|
-
const { orientation = 'horizontal', variant = 'tabs' } = this.
|
|
151
|
+
const { orientation = 'horizontal', variant = 'tabs' } = this.componentProps;
|
|
142
152
|
const listGroup = variant === 'list-group';
|
|
143
153
|
|
|
144
154
|
return (
|
|
@@ -154,7 +164,7 @@ export class Tabs extends Component<TabsProps> {
|
|
|
154
164
|
: 'flex-column')
|
|
155
165
|
)}
|
|
156
166
|
role="tablist"
|
|
157
|
-
aria-label={this.
|
|
167
|
+
aria-label={this.componentProps['aria-label'] ?? 'Tabs'}
|
|
158
168
|
aria-orientation={orientation}
|
|
159
169
|
>
|
|
160
170
|
{this.tabs.map(({ props: tab }, index) => {
|
|
@@ -187,7 +197,7 @@ export class Tabs extends Component<TabsProps> {
|
|
|
187
197
|
};
|
|
188
198
|
|
|
189
199
|
renderPanels = () => {
|
|
190
|
-
const { fade = true } = this.
|
|
200
|
+
const { fade = true } = this.componentProps;
|
|
191
201
|
|
|
192
202
|
return (
|
|
193
203
|
<div className="tab-content">
|
|
@@ -216,7 +226,10 @@ export class Tabs extends Component<TabsProps> {
|
|
|
216
226
|
};
|
|
217
227
|
|
|
218
228
|
render() {
|
|
229
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
230
|
+
|
|
219
231
|
const {
|
|
232
|
+
as: _as,
|
|
220
233
|
activeKey: _activeKey,
|
|
221
234
|
className,
|
|
222
235
|
defaultActiveKey: _defaultActiveKey,
|
|
@@ -229,20 +242,20 @@ export class Tabs extends Component<TabsProps> {
|
|
|
229
242
|
children: _children,
|
|
230
243
|
variant: _variant,
|
|
231
244
|
...props
|
|
232
|
-
} = this.
|
|
245
|
+
} = this.componentProps;
|
|
233
246
|
|
|
234
247
|
return (
|
|
235
|
-
<
|
|
248
|
+
<Root
|
|
236
249
|
{...props}
|
|
237
250
|
ref={this.root}
|
|
238
|
-
id={this.
|
|
251
|
+
id={this.componentProps.id}
|
|
239
252
|
className={className}
|
|
240
253
|
onClick={this.handleClick}
|
|
241
254
|
onKeyDown={this.handleKeyDown}
|
|
242
255
|
>
|
|
243
256
|
{this.renderTabs()}
|
|
244
257
|
{this.renderPanels()}
|
|
245
|
-
</
|
|
258
|
+
</Root>
|
|
246
259
|
);
|
|
247
260
|
}
|
|
248
261
|
}
|
package/source/Table.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 { Breakpoint } from './Grid';
|
|
5
|
+
import { polymorphic } from './Polymorphic';
|
|
5
6
|
|
|
6
7
|
export interface TableProps extends ComponentPropsWithRef<'table'> {
|
|
7
8
|
striped?: boolean;
|
|
@@ -13,47 +14,57 @@ export interface TableProps extends ComponentPropsWithRef<'table'> {
|
|
|
13
14
|
responsive?: boolean | Breakpoint;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export const Table
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
'table-striped': striped,
|
|
34
|
-
'table-striped-columns': stripedColumns,
|
|
35
|
-
'table-hover': hover,
|
|
36
|
-
'table-bordered': bordered,
|
|
37
|
-
'table-borderless': borderless,
|
|
38
|
-
'table-sm': small
|
|
39
|
-
},
|
|
40
|
-
className
|
|
41
|
-
)}
|
|
42
|
-
/>
|
|
43
|
-
);
|
|
17
|
+
export const Table = polymorphic<TableProps>(
|
|
18
|
+
({
|
|
19
|
+
as: RootAs,
|
|
20
|
+
striped,
|
|
21
|
+
stripedColumns,
|
|
22
|
+
hover,
|
|
23
|
+
bordered,
|
|
24
|
+
borderless,
|
|
25
|
+
small,
|
|
26
|
+
responsive,
|
|
27
|
+
className,
|
|
28
|
+
children,
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
31
|
+
const Root = RootAs ?? 'div';
|
|
32
|
+
const TableRoot = !responsive && RootAs ? RootAs : 'table';
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
34
|
+
const table = (
|
|
35
|
+
<TableRoot
|
|
36
|
+
{...(responsive && RootAs ? {} : props)}
|
|
37
|
+
className={classNames(
|
|
38
|
+
'table',
|
|
39
|
+
{
|
|
40
|
+
'table-striped': striped,
|
|
41
|
+
'table-striped-columns': stripedColumns,
|
|
42
|
+
'table-hover': hover,
|
|
43
|
+
'table-bordered': bordered,
|
|
44
|
+
'table-borderless': borderless,
|
|
45
|
+
'table-sm': small
|
|
46
|
+
},
|
|
47
|
+
responsive && RootAs ? undefined : className
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</TableRoot>
|
|
52
|
+
);
|
|
58
53
|
|
|
54
|
+
return !responsive ? (
|
|
55
|
+
table
|
|
56
|
+
) : (
|
|
57
|
+
<Root
|
|
58
|
+
{...(RootAs ? props : {})}
|
|
59
|
+
className={classNames(
|
|
60
|
+
'table-responsive',
|
|
61
|
+
responsive !== true && `${responsive}:table-responsive`,
|
|
62
|
+
RootAs && className
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{table}
|
|
66
|
+
</Root>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
59
70
|
Table.displayName = 'Table';
|
package/source/Toast.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { Timestamp, uniqueID } from 'web-utility';
|
|
|
8
8
|
|
|
9
9
|
import type { ComponentTheme } from './Button';
|
|
10
10
|
import { CloseButton } from './CloseButton';
|
|
11
|
+
import { polymorphic } from './Polymorphic';
|
|
11
12
|
|
|
12
13
|
export type ToastPosition =
|
|
13
14
|
| 'top-start'
|
|
@@ -53,30 +54,34 @@ export interface ToastContainerProps extends ComponentPropsWithRef<'div'> {
|
|
|
53
54
|
position?: ToastPosition | 'static';
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
export const ToastContainer
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
export const ToastContainer = polymorphic<ToastContainerProps>(
|
|
58
|
+
({
|
|
59
|
+
as: Root = 'div',
|
|
60
|
+
position = 'top-end',
|
|
61
|
+
className,
|
|
62
|
+
'aria-live': ariaLive = 'polite',
|
|
63
|
+
'aria-atomic': ariaAtomic = true,
|
|
64
|
+
...props
|
|
65
|
+
}) => {
|
|
66
|
+
const isStatic = position === 'static';
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Root
|
|
70
|
+
{...props}
|
|
71
|
+
className={classNames(
|
|
72
|
+
'toast-container',
|
|
73
|
+
!isStatic && 'position-fixed',
|
|
74
|
+
!isStatic && 'p-3',
|
|
75
|
+
isStatic ? 'position-static' : TOAST_POSITION_CLASSES[position],
|
|
76
|
+
className
|
|
77
|
+
)}
|
|
78
|
+
aria-live={ariaLive}
|
|
79
|
+
aria-atomic={ariaAtomic}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
ToastContainer.displayName = 'ToastContainer';
|
|
80
85
|
|
|
81
86
|
export interface ToastItemProps extends ComponentPropsWithRef<'div'> {
|
|
82
87
|
theme?: ComponentTheme;
|
|
@@ -85,34 +90,44 @@ export interface ToastItemProps extends ComponentPropsWithRef<'div'> {
|
|
|
85
90
|
instant?: boolean;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
export const ToastItem
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
export const ToastItem = polymorphic<ToastItemProps>(
|
|
94
|
+
({
|
|
95
|
+
as: Root = 'div',
|
|
96
|
+
theme,
|
|
97
|
+
show = true,
|
|
98
|
+
translucent,
|
|
99
|
+
instant,
|
|
100
|
+
role = 'status',
|
|
101
|
+
className,
|
|
102
|
+
...props
|
|
103
|
+
}) => (
|
|
104
|
+
<Root
|
|
105
|
+
{...props}
|
|
106
|
+
className={classNames(
|
|
107
|
+
'toast',
|
|
108
|
+
{ show, 'toast-translucent': translucent, 'toast-instant': instant },
|
|
109
|
+
theme && `theme-${theme}`,
|
|
110
|
+
className
|
|
111
|
+
)}
|
|
112
|
+
role={role}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
107
115
|
);
|
|
116
|
+
ToastItem.displayName = 'ToastItem';
|
|
108
117
|
|
|
109
|
-
export const ToastHeader
|
|
110
|
-
|
|
118
|
+
export const ToastHeader = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
119
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
120
|
+
<Root {...props} className={classNames('toast-header', className)} />
|
|
121
|
+
)
|
|
111
122
|
);
|
|
123
|
+
ToastHeader.displayName = 'ToastHeader';
|
|
112
124
|
|
|
113
|
-
export const ToastBody
|
|
114
|
-
|
|
125
|
+
export const ToastBody = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
126
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
127
|
+
<Root {...props} className={classNames('toast-body', className)} />
|
|
128
|
+
)
|
|
115
129
|
);
|
|
130
|
+
ToastBody.displayName = 'ToastBody';
|
|
116
131
|
|
|
117
132
|
export class Toast {
|
|
118
133
|
@observable
|
package/source/ToggleButton.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
|
export interface ToggleButtonProps extends Omit<ComponentPropsWithRef<'label'>, 'onChange'> {
|
|
7
8
|
type?: 'checkbox' | 'radio';
|
|
@@ -21,41 +22,43 @@ export interface ToggleButtonProps extends Omit<ComponentPropsWithRef<'label'>,
|
|
|
21
22
|
onChange?: ComponentPropsWithRef<'input'>['onChange'];
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export const ToggleButton
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
export const ToggleButton = polymorphic<ToggleButtonProps>(
|
|
26
|
+
({
|
|
27
|
+
as: Root = 'label',
|
|
28
|
+
type = 'checkbox',
|
|
29
|
+
variant = 'solid',
|
|
30
|
+
theme,
|
|
31
|
+
name,
|
|
32
|
+
value,
|
|
33
|
+
checked,
|
|
34
|
+
defaultChecked,
|
|
35
|
+
disabled,
|
|
36
|
+
required,
|
|
37
|
+
size,
|
|
38
|
+
inputProps,
|
|
39
|
+
onChange,
|
|
40
|
+
className,
|
|
41
|
+
children,
|
|
42
|
+
...props
|
|
43
|
+
}) => (
|
|
44
|
+
<Root
|
|
45
|
+
{...props}
|
|
46
|
+
className={classNames(
|
|
47
|
+
'btn-check',
|
|
48
|
+
`btn-${variant}`,
|
|
49
|
+
theme && `theme-${theme}`,
|
|
50
|
+
size && `btn-${size}`,
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
<input
|
|
55
|
+
{...inputProps}
|
|
56
|
+
{...{ type, name, value, checked, defaultChecked, disabled, required }}
|
|
57
|
+
autoComplete="off"
|
|
58
|
+
onChange={onChange}
|
|
59
|
+
/>
|
|
60
|
+
{children}
|
|
61
|
+
</Root>
|
|
62
|
+
)
|
|
59
63
|
);
|
|
60
|
-
|
|
61
64
|
ToggleButton.displayName = 'ToggleButton';
|
package/source/Toggler.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
-
import { ButtonHTMLAttributes, Component, KeyboardEvent, MouseEvent } from 'react';
|
|
4
|
+
import { ButtonHTMLAttributes, Component, ElementType, KeyboardEvent, MouseEvent } from 'react';
|
|
5
5
|
|
|
6
6
|
import { Button, ComponentTheme } from './Button';
|
|
7
|
+
import { AsProps, PolymorphicClassProps } from './Polymorphic';
|
|
7
8
|
|
|
8
9
|
export interface TogglerProps extends Omit<ButtonHTMLAttributes<HTMLElement>, 'value'> {
|
|
9
10
|
as?: 'button' | 'div' | 'span';
|
|
@@ -15,15 +16,23 @@ export interface TogglerProps extends Omit<ButtonHTMLAttributes<HTMLElement>, 'v
|
|
|
15
16
|
onToggled?: (targets: HTMLElement[]) => unknown;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export class Toggler extends Component<
|
|
19
|
+
export class Toggler<T extends ElementType | undefined = 'button'> extends Component<
|
|
20
|
+
PolymorphicClassProps<T, TogglerProps>
|
|
21
|
+
> {
|
|
19
22
|
static displayName = 'Toggler';
|
|
20
23
|
|
|
24
|
+
declare readonly props: PolymorphicClassProps<T, TogglerProps>;
|
|
25
|
+
|
|
26
|
+
protected get componentProps(): Readonly<Omit<TogglerProps, 'as'> & AsProps> {
|
|
27
|
+
return this.props;
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
handleClick = (event: MouseEvent<HTMLElement>) => {
|
|
22
|
-
this.
|
|
31
|
+
this.componentProps.onClick?.(event);
|
|
23
32
|
|
|
24
|
-
if (event.defaultPrevented || this.
|
|
33
|
+
if (event.defaultPrevented || this.componentProps.disabled) return;
|
|
25
34
|
|
|
26
|
-
const { target, attribute = 'class', value, onToggled } = this.
|
|
35
|
+
const { target, attribute = 'class', value, onToggled } = this.componentProps;
|
|
27
36
|
const targets = target
|
|
28
37
|
? [...document.querySelectorAll<HTMLElement>(target)]
|
|
29
38
|
: [event.currentTarget];
|
|
@@ -56,11 +65,11 @@ export class Toggler extends Component<TogglerProps> {
|
|
|
56
65
|
};
|
|
57
66
|
|
|
58
67
|
handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
59
|
-
this.
|
|
68
|
+
this.componentProps.onKeyDown?.(event);
|
|
60
69
|
|
|
61
70
|
if (
|
|
62
71
|
!event.defaultPrevented &&
|
|
63
|
-
!this.
|
|
72
|
+
!this.componentProps.disabled &&
|
|
64
73
|
(event.key === 'Enter' || event.key === ' ')
|
|
65
74
|
) {
|
|
66
75
|
event.preventDefault();
|
|
@@ -79,7 +88,7 @@ export class Toggler extends Component<TogglerProps> {
|
|
|
79
88
|
variant,
|
|
80
89
|
disabled,
|
|
81
90
|
...props
|
|
82
|
-
} = this.
|
|
91
|
+
} = this.componentProps;
|
|
83
92
|
|
|
84
93
|
return Tag === 'button' ? (
|
|
85
94
|
<Button
|
package/source/Tooltip.tsx
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { FC } from 'react';
|
|
3
2
|
|
|
4
3
|
import { OVERLAY_ARROW_POSITIONS, OVERLAY_DIRECTIONS, OverlayTriggerProps } from './Overlay';
|
|
4
|
+
import { polymorphic } from './Polymorphic';
|
|
5
5
|
|
|
6
6
|
export type TooltipProps = OverlayTriggerProps;
|
|
7
7
|
|
|
8
|
-
export const Tooltip
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
export const Tooltip = polymorphic<TooltipProps>(
|
|
9
|
+
({
|
|
10
|
+
as: Root = 'div',
|
|
11
|
+
placement = 'top',
|
|
12
|
+
show = true,
|
|
13
|
+
role = 'tooltip',
|
|
14
|
+
className,
|
|
15
|
+
children,
|
|
16
|
+
arrowStyle,
|
|
17
|
+
...props
|
|
18
|
+
}) => (
|
|
19
|
+
<Root
|
|
20
|
+
{...props}
|
|
21
|
+
className={classNames(
|
|
22
|
+
'tooltip',
|
|
23
|
+
{ show },
|
|
24
|
+
`bs-tooltip-${OVERLAY_DIRECTIONS[placement]}`,
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
role={role}
|
|
28
|
+
hidden={!show}
|
|
29
|
+
data-bs-placement={placement}
|
|
30
|
+
>
|
|
31
|
+
<div
|
|
32
|
+
style={arrowStyle}
|
|
33
|
+
className={classNames('tooltip-arrow', OVERLAY_ARROW_POSITIONS[placement])}
|
|
34
|
+
/>
|
|
35
|
+
<div className="tooltip-inner">{children}</div>
|
|
36
|
+
</Root>
|
|
37
|
+
)
|
|
35
38
|
);
|
|
36
|
-
|
|
37
39
|
Tooltip.displayName = 'Tooltip';
|
package/source/index.ts
CHANGED
|
@@ -25,10 +25,12 @@ export * from './NavOverflow';
|
|
|
25
25
|
export * from './Overlay';
|
|
26
26
|
export * from './Pagination';
|
|
27
27
|
export * from './Placeholder';
|
|
28
|
+
export * from './Polymorphic';
|
|
28
29
|
export * from './Popover';
|
|
29
30
|
export * from './Progress';
|
|
30
31
|
export * from './ScrollSpy';
|
|
31
32
|
export * from './Spinner';
|
|
33
|
+
export * from './Stack';
|
|
32
34
|
export * from './Stepper';
|
|
33
35
|
export * from './Tab';
|
|
34
36
|
export * from './Table';
|