idea-react 3.0.0-alpha.1 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/AGENTS.md +11 -2
  2. package/ReadMe.md +86 -46
  3. package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
  4. package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
  5. package/dist/index.d.mts +1069 -245
  6. package/dist/index.d.ts +1069 -245
  7. package/dist/index.js +16 -16
  8. package/dist/index.mjs +15 -15
  9. package/dist/rolldown-runtime-5iZMYShA.js +1 -0
  10. package/dist/style.css +69 -66
  11. package/package.json +4 -2
  12. package/source/Accordion.tsx +137 -0
  13. package/source/Alert.tsx +138 -0
  14. package/source/Avatar.tsx +7 -1
  15. package/source/Badge.tsx +2 -0
  16. package/source/Breadcrumb.tsx +36 -0
  17. package/source/Button.tsx +40 -5
  18. package/source/ButtonGroup.tsx +10 -1
  19. package/source/Card.tsx +73 -4
  20. package/source/Carousel/index.tsx +391 -0
  21. package/source/Carousel/model.ts +113 -0
  22. package/source/Carousel/scroll.ts +79 -0
  23. package/source/Collapse.tsx +178 -0
  24. package/source/Drawer.tsx +127 -30
  25. package/source/{CodeBlock.tsx → Extension/CodeBlock/index.tsx} +23 -5
  26. package/source/Extension/CodeBlock/style.module.css +3 -0
  27. package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
  28. package/source/{EditorHTML.tsx → Extension/EditorHTML.tsx} +1 -1
  29. package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
  30. package/source/{Icon.tsx → Extension/Icon.tsx} +1 -7
  31. package/source/{Loading.tsx → Extension/Loading.tsx} +8 -3
  32. package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +3 -3
  33. package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
  34. package/source/Extension/OverlayBox.tsx +280 -0
  35. package/source/{PageNav.tsx → Extension/PageNav.tsx} +27 -9
  36. package/source/{ScrollNav → Extension/ScrollNav}/index.tsx +1 -1
  37. package/source/Extension/Select.tsx +127 -0
  38. package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
  39. package/source/{SpinnerButton.tsx → Extension/SpinnerButton.tsx} +2 -2
  40. package/source/{TableSpinner.tsx → Extension/TableSpinner.tsx} +1 -1
  41. package/source/{Timeline → Extension/Timeline}/index.tsx +1 -1
  42. package/source/{UserRank → Extension/UserRank}/index.tsx +4 -4
  43. package/source/Extension/index.ts +27 -0
  44. package/source/Form/Adorn.tsx +59 -0
  45. package/source/Form/Checkbox.tsx +78 -0
  46. package/source/Form/ChipInput.tsx +125 -0
  47. package/source/Form/Chips.tsx +69 -0
  48. package/source/Form/Combobox.tsx +374 -0
  49. package/source/Form/Control.tsx +94 -0
  50. package/source/Form/DatePicker.tsx +280 -0
  51. package/source/Form/DatePickerPlugin.ts +37 -0
  52. package/source/Form/Feedback.tsx +35 -0
  53. package/source/Form/FloatingLabel.tsx +32 -0
  54. package/source/Form/InputGroup.tsx +173 -0
  55. package/source/Form/OTP.tsx +141 -0
  56. package/source/Form/PasswordStrength.tsx +183 -0
  57. package/source/Form/Plugin.tsx +53 -0
  58. package/source/Form/Primitives.tsx +88 -0
  59. package/source/Form/Radio.tsx +43 -0
  60. package/source/Form/Range.tsx +116 -0
  61. package/source/Form/Switch.tsx +58 -0
  62. package/source/Form/index.ts +16 -0
  63. package/source/Grid.tsx +4 -0
  64. package/source/ListGroup.tsx +28 -15
  65. package/source/Menu.tsx +226 -17
  66. package/source/NativeDialog/index.tsx +109 -5
  67. package/source/Nav.tsx +18 -2
  68. package/source/NavOverflow/index.tsx +307 -0
  69. package/source/NavOverflow/model.ts +21 -0
  70. package/source/Navbar.tsx +31 -6
  71. package/source/Overlay.ts +163 -1
  72. package/source/Pagination.tsx +92 -0
  73. package/source/Placeholder.tsx +66 -0
  74. package/source/Popover.tsx +7 -2
  75. package/source/Progress/index.tsx +76 -0
  76. package/source/Progress/style.module.css +15 -0
  77. package/source/ScrollSpy/index.tsx +365 -0
  78. package/source/ScrollSpy/model.ts +17 -0
  79. package/source/Spinner.tsx +10 -0
  80. package/source/Stepper.tsx +85 -0
  81. package/source/Tab.tsx +248 -0
  82. package/source/Toast.tsx +65 -27
  83. package/source/ToggleButton.tsx +21 -7
  84. package/source/Toggler.tsx +108 -0
  85. package/source/Tooltip.tsx +6 -1
  86. package/source/index.ts +16 -27
  87. package/source/OverlayBox.tsx +0 -208
  88. package/source/Select.tsx +0 -95
  89. /package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +0 -0
  90. /package/source/{Countdown.tsx → Extension/Countdown.tsx} +0 -0
  91. /package/source/{Editor.tsx → Extension/Editor.tsx} +0 -0
  92. /package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.tsx +0 -0
  93. /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
  94. /package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +0 -0
  95. /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
  96. /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
  97. /package/source/{TextTruncate → Extension/TextTruncate}/index.tsx +0 -0
  98. /package/source/{Time.tsx → Extension/Time.tsx} +0 -0
  99. /package/source/{TimeDistance.tsx → Extension/TimeDistance.tsx} +0 -0
  100. /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
  101. /package/source/{TypeEcho → Extension/TypeEcho}/Content.tsx +0 -0
  102. /package/source/{TypeEcho → Extension/TypeEcho}/index.tsx +0 -0
  103. /package/source/{UserRank → Extension/UserRank}/Address.tsx +0 -0
  104. /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
  105. /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
  106. /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.tsx +0 -0
  107. /package/source/{ZodiacBar.tsx → Extension/ZodiacBar.tsx} +0 -0
@@ -0,0 +1,85 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ import { ComponentTheme } from './Button';
5
+ import { Breakpoint } from './Grid';
6
+
7
+ export interface StepperProps extends ComponentPropsWithRef<'ol'> {
8
+ horizontal?: boolean | Breakpoint;
9
+ }
10
+
11
+ const stepperClasses = (horizontal: StepperProps['horizontal'], className?: string) =>
12
+ classNames(
13
+ 'stepper',
14
+ horizontal === true
15
+ ? 'stepper-horizontal'
16
+ : horizontal && `${horizontal}:stepper-horizontal`,
17
+ className
18
+ );
19
+
20
+ export const Stepper: FC<StepperProps> = ({ horizontal, className, ...props }) => (
21
+ <ol {...props} className={stepperClasses(horizontal, className)} />
22
+ );
23
+
24
+ export interface StepperNavProps extends ComponentPropsWithRef<'nav'> {
25
+ horizontal?: StepperProps['horizontal'];
26
+ }
27
+
28
+ export const StepperNav: FC<StepperNavProps> = ({ horizontal, className, ...props }) => (
29
+ <nav {...props} className={stepperClasses(horizontal, className)} />
30
+ );
31
+
32
+ interface StepStyle {
33
+ active?: boolean;
34
+ theme?: ComponentTheme;
35
+ }
36
+
37
+ export type StepperItemProps = ComponentPropsWithRef<'li'> & StepStyle;
38
+
39
+ export const StepperItem: FC<StepperItemProps> = ({ active, theme, className, ...props }) => (
40
+ <li
41
+ {...props}
42
+ className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
43
+ />
44
+ );
45
+
46
+ export type StepperLinkProps = ComponentPropsWithRef<'a'> & StepStyle;
47
+
48
+ export const StepperLink: FC<StepperLinkProps> = ({ active, theme, className, ...props }) => (
49
+ <a
50
+ {...props}
51
+ className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
52
+ />
53
+ );
54
+
55
+ export type StepperButtonProps = ComponentPropsWithRef<'button'> & StepStyle;
56
+
57
+ export const StepperButton: FC<StepperButtonProps> = ({
58
+ active,
59
+ theme,
60
+ className,
61
+ type = 'button',
62
+ ...props
63
+ }) => (
64
+ <button
65
+ {...props}
66
+ type={type}
67
+ className={classNames(
68
+ 'stepper-item p-0 border-0 bg-transparent',
69
+ { active },
70
+ theme && `theme-${theme}`,
71
+ className
72
+ )}
73
+ />
74
+ );
75
+
76
+ export const StepperOverflow: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
77
+ <div {...props} className={classNames('stepper-overflow', className)} />
78
+ );
79
+
80
+ Stepper.displayName = 'Stepper';
81
+ StepperNav.displayName = 'StepperNav';
82
+ StepperItem.displayName = 'StepperItem';
83
+ StepperLink.displayName = 'StepperLink';
84
+ StepperButton.displayName = 'StepperButton';
85
+ StepperOverflow.displayName = 'StepperOverflow';
package/source/Tab.tsx ADDED
@@ -0,0 +1,248 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { action, observable } from 'mobx';
5
+ import { observer } from 'mobx-react';
6
+ import {
7
+ Children,
8
+ cloneElement,
9
+ Component,
10
+ ComponentPropsWithRef,
11
+ createRef,
12
+ FC,
13
+ isValidElement,
14
+ KeyboardEvent,
15
+ MouseEvent,
16
+ ReactNode
17
+ } from 'react';
18
+
19
+ export interface TabProps extends ComponentPropsWithRef<'div'> {
20
+ eventKey: string;
21
+ label: ReactNode;
22
+ disabled?: boolean;
23
+ }
24
+
25
+ export const Tab: FC<TabProps> = ({
26
+ eventKey: _eventKey,
27
+ label: _label,
28
+ disabled: _disabled,
29
+ ...props
30
+ }) => <div {...props} />;
31
+
32
+ Tab.displayName = 'Tab';
33
+
34
+ export interface TabsProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
35
+ activeKey?: string;
36
+ defaultActiveKey?: string;
37
+ fade?: boolean;
38
+ id: string;
39
+ onChange?: (key: string) => unknown;
40
+ orientation?: 'horizontal' | 'vertical';
41
+ variant?: 'tabs' | 'pills' | 'underline' | 'list-group';
42
+ }
43
+
44
+ @observer
45
+ export class Tabs extends Component<TabsProps> {
46
+ static displayName = 'Tabs';
47
+
48
+ get tabs() {
49
+ return Children.toArray(this.props.children)
50
+ .filter(child => typeof child !== 'string' || child.trim())
51
+ .map(child => {
52
+ // Server component boundaries may wrap Tab in a lazy client reference.
53
+ if (
54
+ !isValidElement<TabProps>(child) ||
55
+ typeof child.props.eventKey !== 'string' ||
56
+ !('label' in child.props)
57
+ )
58
+ throw new TypeError('Tabs children must be Tab elements.');
59
+
60
+ return child;
61
+ });
62
+ }
63
+
64
+ root = createRef<HTMLDivElement>();
65
+
66
+ @observable accessor selectedKey =
67
+ this.props.defaultActiveKey ??
68
+ this.tabs.find(({ props }) => !props.disabled)?.props.eventKey ??
69
+ this.tabs[0]?.props.eventKey ??
70
+ '';
71
+
72
+ get activeKey() {
73
+ const key = this.props.activeKey ?? this.selectedKey;
74
+
75
+ return this.tabs.some(({ props }) => props.eventKey === key && !props.disabled)
76
+ ? key
77
+ : (this.tabs.find(({ props }) => !props.disabled)?.props.eventKey ?? '');
78
+ }
79
+
80
+ handleClick = (event: MouseEvent<HTMLDivElement>) => {
81
+ this.props.onClick?.(event);
82
+ if (event.defaultPrevented) return;
83
+
84
+ const button = (event.target as Element).closest<HTMLButtonElement>('[data-tab-index]');
85
+ const tab = button && this.tabs[Number(button.dataset.tabIndex)]?.props;
86
+ if (!tab || tab.disabled) return;
87
+
88
+ this.activate(tab.eventKey);
89
+ };
90
+
91
+ handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
92
+ this.props.onKeyDown?.(event);
93
+
94
+ if (event.defaultPrevented) return;
95
+
96
+ const button = (event.target as Element).closest<HTMLButtonElement>('[data-tab-index]');
97
+ const index = Number(button?.dataset.tabIndex);
98
+ const tabs = this.tabs;
99
+ if (!button || Number.isNaN(index)) return;
100
+
101
+ const horizontal = this.props.orientation !== 'vertical';
102
+ const previous = horizontal ? event.key === 'ArrowLeft' : event.key === 'ArrowUp';
103
+ const next = horizontal ? event.key === 'ArrowRight' : event.key === 'ArrowDown';
104
+ const enabled = tabs
105
+ .map(({ props }, tabIndex) => (props.disabled ? -1 : tabIndex))
106
+ .filter(tabIndex => tabIndex >= 0);
107
+ const currentPosition = enabled.indexOf(index);
108
+ const destination =
109
+ event.key === 'Home'
110
+ ? enabled[0]
111
+ : event.key === 'End'
112
+ ? enabled.at(-1)
113
+ : previous
114
+ ? enabled[(currentPosition - 1 + enabled.length) % enabled.length]
115
+ : next
116
+ ? enabled[(currentPosition + 1) % enabled.length]
117
+ : undefined;
118
+ if (destination === undefined) return;
119
+
120
+ event.preventDefault();
121
+ const tab = tabs[destination];
122
+
123
+ this.activate(tab.props.eventKey);
124
+ this.root.current
125
+ ?.querySelector<HTMLButtonElement>(`[data-tab-index="${destination}"]`)
126
+ ?.focus();
127
+ };
128
+
129
+ @action
130
+ activate = (key: string) => {
131
+ this.props.onChange?.(key);
132
+
133
+ if (this.props.activeKey === undefined) this.selectedKey = key;
134
+ };
135
+
136
+ tabId = (key: string) => `${this.props.id}-tab-${encodeURIComponent(key)}`;
137
+
138
+ panelId = (key: string) => `${this.props.id}-panel-${encodeURIComponent(key)}`;
139
+
140
+ renderTabs = () => {
141
+ const { orientation = 'horizontal', variant = 'tabs' } = this.props;
142
+ const listGroup = variant === 'list-group';
143
+
144
+ return (
145
+ <div
146
+ className={classNames(
147
+ listGroup ? 'list-group' : 'nav',
148
+ !listGroup && `nav-${variant}`,
149
+ orientation === 'vertical' &&
150
+ (listGroup
151
+ ? 'flex-column'
152
+ : variant === 'pills'
153
+ ? 'nav-pills-vertical'
154
+ : 'flex-column')
155
+ )}
156
+ role="tablist"
157
+ aria-label={this.props['aria-label'] ?? 'Tabs'}
158
+ aria-orientation={orientation}
159
+ >
160
+ {this.tabs.map(({ props: tab }, index) => {
161
+ const active = tab.eventKey === this.activeKey;
162
+
163
+ return (
164
+ <button
165
+ key={tab.eventKey}
166
+ id={this.tabId(tab.eventKey)}
167
+ type="button"
168
+ role="tab"
169
+ data-tab-index={index}
170
+ aria-controls={this.panelId(tab.eventKey)}
171
+ aria-selected={active}
172
+ aria-disabled={tab.disabled || undefined}
173
+ tabIndex={active ? 0 : -1}
174
+ disabled={tab.disabled}
175
+ className={classNames(
176
+ listGroup ? 'list-group-item list-group-item-action' : 'nav-link',
177
+ { active },
178
+ tab.disabled && 'disabled'
179
+ )}
180
+ >
181
+ {tab.label}
182
+ </button>
183
+ );
184
+ })}
185
+ </div>
186
+ );
187
+ };
188
+
189
+ renderPanels = () => {
190
+ const { fade = true } = this.props;
191
+
192
+ return (
193
+ <div className="tab-content">
194
+ {this.tabs.map(tab => {
195
+ const { eventKey, className } = tab.props;
196
+ const active = eventKey === this.activeKey;
197
+
198
+ return cloneElement(tab, {
199
+ key: eventKey,
200
+ id: this.panelId(eventKey),
201
+ role: 'tabpanel',
202
+ 'aria-labelledby': this.tabId(eventKey),
203
+ 'aria-hidden': !active,
204
+ tabIndex: tab.props.tabIndex ?? 0,
205
+ className: classNames(
206
+ 'tab-pane',
207
+ { active, show: active && fade },
208
+ !fade && 'tab-pane-instant',
209
+ className
210
+ ),
211
+ hidden: !active
212
+ });
213
+ })}
214
+ </div>
215
+ );
216
+ };
217
+
218
+ render() {
219
+ const {
220
+ activeKey: _activeKey,
221
+ className,
222
+ defaultActiveKey: _defaultActiveKey,
223
+ fade: _fade,
224
+ onChange: _onChange,
225
+ onClick: _onClick,
226
+ onKeyDown: _onKeyDown,
227
+ id: _id,
228
+ orientation: _orientation,
229
+ children: _children,
230
+ variant: _variant,
231
+ ...props
232
+ } = this.props;
233
+
234
+ return (
235
+ <div
236
+ {...props}
237
+ ref={this.root}
238
+ id={this.props.id}
239
+ className={className}
240
+ onClick={this.handleClick}
241
+ onKeyDown={this.handleKeyDown}
242
+ >
243
+ {this.renderTabs()}
244
+ {this.renderPanels()}
245
+ </div>
246
+ );
247
+ }
248
+ }
package/source/Toast.tsx CHANGED
@@ -7,6 +7,7 @@ import { ComponentPropsWithRef, FC, MouseEvent, ReactNode } from 'react';
7
7
  import { Timestamp, uniqueID } from 'web-utility';
8
8
 
9
9
  import type { ComponentTheme } from './Button';
10
+ import { CloseButton } from './CloseButton';
10
11
 
11
12
  export type ToastPosition =
12
13
  | 'top-start'
@@ -31,11 +32,13 @@ const TOAST_POSITION_CLASSES: Record<ToastPosition, string> = {
31
32
  'bottom-end': 'bottom-0 end-0'
32
33
  };
33
34
 
34
- export interface ToastMessage {
35
+ export interface ToastMessage extends Pick<
36
+ ToastItemProps,
37
+ 'theme' | 'translucent' | 'instant' | 'role'
38
+ > {
35
39
  id?: string;
36
40
  title?: ReactNode;
37
41
  body: ReactNode;
38
- theme?: ComponentTheme;
39
42
  delay?: number;
40
43
  }
41
44
 
@@ -47,7 +50,7 @@ interface ToastEntry extends ToastMessage {
47
50
  }
48
51
 
49
52
  export interface ToastContainerProps extends ComponentPropsWithRef<'div'> {
50
- position?: ToastPosition;
53
+ position?: ToastPosition | 'static';
51
54
  }
52
55
 
53
56
  export const ToastContainer: FC<ToastContainerProps> = ({
@@ -56,27 +59,49 @@ export const ToastContainer: FC<ToastContainerProps> = ({
56
59
  'aria-live': ariaLive = 'polite',
57
60
  'aria-atomic': ariaAtomic = true,
58
61
  ...props
59
- }) => (
60
- <div
61
- {...props}
62
- className={classNames(
63
- 'toast-container position-fixed p-3',
64
- TOAST_POSITION_CLASSES[position],
65
- className
66
- )}
67
- aria-live={ariaLive}
68
- aria-atomic={ariaAtomic}
69
- />
70
- );
62
+ }) => {
63
+ const isStatic = position === 'static';
64
+
65
+ return (
66
+ <div
67
+ {...props}
68
+ className={classNames(
69
+ 'toast-container',
70
+ !isStatic && 'position-fixed',
71
+ !isStatic && 'p-3',
72
+ isStatic ? 'position-static' : TOAST_POSITION_CLASSES[position],
73
+ className
74
+ )}
75
+ aria-live={ariaLive}
76
+ aria-atomic={ariaAtomic}
77
+ />
78
+ );
79
+ };
71
80
 
72
81
  export interface ToastItemProps extends ComponentPropsWithRef<'div'> {
73
82
  theme?: ComponentTheme;
83
+ show?: boolean;
84
+ translucent?: boolean;
85
+ instant?: boolean;
74
86
  }
75
87
 
76
- export const ToastItem: FC<ToastItemProps> = ({ theme, role = 'status', className, ...props }) => (
88
+ export const ToastItem: FC<ToastItemProps> = ({
89
+ theme,
90
+ show = true,
91
+ translucent,
92
+ instant,
93
+ role = 'status',
94
+ className,
95
+ ...props
96
+ }) => (
77
97
  <div
78
98
  {...props}
79
- className={classNames('toast show', theme && `theme-${theme}`, className)}
99
+ className={classNames(
100
+ 'toast',
101
+ { show, 'toast-translucent': translucent, 'toast-instant': instant },
102
+ theme && `theme-${theme}`,
103
+ className
104
+ )}
80
105
  role={role}
81
106
  />
82
107
  );
@@ -99,22 +124,33 @@ export class Toast {
99
124
  </ToastContainer>
100
125
  ));
101
126
 
102
- renderMessage = ({ id, openedAt, title, body, theme, delay = 3000 }: ToastEntry) => {
127
+ renderMessage = ({
128
+ id,
129
+ openedAt,
130
+ title,
131
+ body,
132
+ theme,
133
+ translucent,
134
+ instant,
135
+ role,
136
+ delay = 3000
137
+ }: ToastEntry) => {
103
138
  const showHeader = !!title || delay === 0;
104
139
  const elapsed = this.TimeScalar.distanceOf<Timestamp>(Date.now(), openedAt).toShortString();
105
140
 
106
141
  return (
107
- <ToastItem key={id} theme={theme}>
142
+ <ToastItem
143
+ key={id}
144
+ theme={theme}
145
+ translucent={translucent}
146
+ instant={instant}
147
+ role={role}
148
+ >
108
149
  {showHeader && (
109
150
  <ToastHeader>
110
151
  <strong className="me-auto">{title}</strong>
111
152
  <small>{elapsed}</small>
112
- <button
113
- type="button"
114
- className="btn-close"
115
- aria-label="Close"
116
- data-toast-dismiss={id}
117
- />
153
+ <CloseButton data-toast-dismiss={id} />
118
154
  </ToastHeader>
119
155
  )}
120
156
  <ToastBody>{body}</ToastBody>
@@ -135,7 +171,9 @@ export class Toast {
135
171
 
136
172
  @action
137
173
  open(message: ToastMessage) {
138
- const id = uniqueID();
174
+ const id = message.id ?? uniqueID();
175
+ this.close(id);
176
+
139
177
  const openedAt = Date.now();
140
178
  const { promise, resolve } = Promise.withResolvers<ToastEntry>();
141
179
  const timer =
@@ -143,7 +181,7 @@ export class Toast {
143
181
  ? undefined
144
182
  : setTimeout(() => this.close(id), message.delay ?? 3000);
145
183
 
146
- const item: ToastEntry = { id, ...message, openedAt, resolve, timer };
184
+ const item: ToastEntry = { ...message, id, openedAt, resolve, timer };
147
185
 
148
186
  this.messages = [...this.messages, item];
149
187
 
@@ -12,6 +12,13 @@ export interface ToggleButtonProps extends Omit<ComponentPropsWithRef<'label'>,
12
12
  checked?: boolean;
13
13
  defaultChecked?: boolean;
14
14
  disabled?: boolean;
15
+ required?: boolean;
16
+ size?: 'xs' | 'sm' | 'lg';
17
+ inputProps?: Omit<
18
+ ComponentPropsWithRef<'input'>,
19
+ 'type' | 'name' | 'value' | 'checked' | 'defaultChecked' | 'disabled' | 'required'
20
+ >;
21
+ onChange?: ComponentPropsWithRef<'input'>['onChange'];
15
22
  }
16
23
 
17
24
  export const ToggleButton: FC<ToggleButtonProps> = ({
@@ -23,22 +30,29 @@ export const ToggleButton: FC<ToggleButtonProps> = ({
23
30
  checked,
24
31
  defaultChecked,
25
32
  disabled,
33
+ required,
34
+ size,
35
+ inputProps,
36
+ onChange,
26
37
  className,
27
38
  children,
28
39
  ...props
29
40
  }) => (
30
41
  <label
31
42
  {...props}
32
- className={classNames('btn-check', `btn-${variant}`, theme && `theme-${theme}`, className)}
43
+ className={classNames(
44
+ 'btn-check',
45
+ `btn-${variant}`,
46
+ theme && `theme-${theme}`,
47
+ size && `btn-${size}`,
48
+ className
49
+ )}
33
50
  >
34
51
  <input
35
- type={type}
36
- name={name}
37
- value={value}
38
- checked={checked}
39
- defaultChecked={defaultChecked}
40
- disabled={disabled}
52
+ {...inputProps}
53
+ {...{ type, name, value, checked, defaultChecked, disabled, required }}
41
54
  autoComplete="off"
55
+ onChange={onChange}
42
56
  />
43
57
  {children}
44
58
  </label>
@@ -0,0 +1,108 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { ButtonHTMLAttributes, Component, KeyboardEvent, MouseEvent } from 'react';
5
+
6
+ import { Button, ComponentTheme } from './Button';
7
+
8
+ export interface TogglerProps extends Omit<ButtonHTMLAttributes<HTMLElement>, 'value'> {
9
+ as?: 'button' | 'div' | 'span';
10
+ target?: string;
11
+ attribute?: string;
12
+ value?: string | number | boolean | null;
13
+ theme?: ComponentTheme;
14
+ variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link';
15
+ onToggled?: (targets: HTMLElement[]) => unknown;
16
+ }
17
+
18
+ export class Toggler extends Component<TogglerProps> {
19
+ static displayName = 'Toggler';
20
+
21
+ handleClick = (event: MouseEvent<HTMLElement>) => {
22
+ this.props.onClick?.(event);
23
+
24
+ if (event.defaultPrevented || this.props.disabled) return;
25
+
26
+ const { target, attribute = 'class', value, onToggled } = this.props;
27
+ const targets = target
28
+ ? [...document.querySelectorAll<HTMLElement>(target)]
29
+ : [event.currentTarget];
30
+ const changes = targets.map(element => ({
31
+ element,
32
+ attribute: element.dataset.bsAttribute ?? attribute,
33
+ value: element.dataset.bsValue ?? value
34
+ }));
35
+
36
+ if (changes.some(({ attribute }) => attribute.toLowerCase() === 'id'))
37
+ throw new TypeError('Toggler cannot change the id attribute');
38
+
39
+ for (const { element, attribute, value } of changes) {
40
+ if (value == null) continue;
41
+
42
+ const text = String(value);
43
+ const before = new window.CustomEvent('toggle.bs.toggler', { cancelable: true });
44
+
45
+ if (!element.dispatchEvent(before)) continue;
46
+
47
+ if (attribute === 'class') {
48
+ for (const name of text.split(/\s+/).filter(Boolean))
49
+ element.classList.toggle(name);
50
+ } else if (element.getAttribute(attribute) === text) element.removeAttribute(attribute);
51
+ else element.setAttribute(attribute, text);
52
+
53
+ element.dispatchEvent(new window.CustomEvent('toggled.bs.toggler'));
54
+ }
55
+ onToggled?.(targets);
56
+ };
57
+
58
+ handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
59
+ this.props.onKeyDown?.(event);
60
+
61
+ if (
62
+ !event.defaultPrevented &&
63
+ !this.props.disabled &&
64
+ (event.key === 'Enter' || event.key === ' ')
65
+ ) {
66
+ event.preventDefault();
67
+ event.currentTarget.click();
68
+ }
69
+ };
70
+
71
+ render() {
72
+ const {
73
+ as: Tag = 'button',
74
+ target: _target,
75
+ attribute: _attribute,
76
+ value: _value,
77
+ onToggled: _onToggled,
78
+ theme,
79
+ variant,
80
+ disabled,
81
+ ...props
82
+ } = this.props;
83
+
84
+ return Tag === 'button' ? (
85
+ <Button
86
+ {...props}
87
+ theme={theme}
88
+ variant={variant}
89
+ disabled={disabled}
90
+ onClick={this.handleClick}
91
+ />
92
+ ) : (
93
+ <Tag
94
+ {...props}
95
+ className={classNames(
96
+ theme && `theme-${theme}`,
97
+ variant && `btn-${variant}`,
98
+ props.className
99
+ )}
100
+ role={props.role ?? 'button'}
101
+ tabIndex={disabled ? -1 : (props.tabIndex ?? 0)}
102
+ aria-disabled={disabled || undefined}
103
+ onClick={this.handleClick}
104
+ onKeyDown={this.handleKeyDown}
105
+ />
106
+ );
107
+ }
108
+ }
@@ -11,6 +11,7 @@ export const Tooltip: FC<TooltipProps> = ({
11
11
  role = 'tooltip',
12
12
  className,
13
13
  children,
14
+ arrowStyle,
14
15
  ...props
15
16
  }) => (
16
17
  <div
@@ -22,9 +23,13 @@ export const Tooltip: FC<TooltipProps> = ({
22
23
  className
23
24
  )}
24
25
  role={role}
26
+ hidden={!show}
25
27
  data-bs-placement={placement}
26
28
  >
27
- <div className={classNames('tooltip-arrow', OVERLAY_ARROW_POSITIONS[placement])} />
29
+ <div
30
+ style={arrowStyle}
31
+ className={classNames('tooltip-arrow', OVERLAY_ARROW_POSITIONS[placement])}
32
+ />
28
33
  <div className="tooltip-inner">{children}</div>
29
34
  </div>
30
35
  );