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.
Files changed (87) hide show
  1. package/AGENTS.md +9 -1
  2. package/ReadMe.md +34 -6
  3. package/dist/index.d.mts +270 -186
  4. package/dist/index.d.ts +270 -186
  5. package/dist/index.js +16 -16
  6. package/dist/index.mjs +15 -15
  7. package/dist/style.css +0 -3
  8. package/package.json +1 -1
  9. package/source/Accordion.tsx +61 -37
  10. package/source/Alert.tsx +30 -15
  11. package/source/Avatar.tsx +55 -50
  12. package/source/Badge.tsx +16 -16
  13. package/source/Breadcrumb.tsx +36 -22
  14. package/source/Button.tsx +63 -69
  15. package/source/ButtonGroup.tsx +21 -25
  16. package/source/Card.tsx +67 -59
  17. package/source/Carousel/index.tsx +22 -21
  18. package/source/CloseButton.tsx +20 -15
  19. package/source/Collapse.tsx +74 -19
  20. package/source/Drawer.tsx +40 -17
  21. package/source/Extension/ClickBoundary.tsx +24 -5
  22. package/source/Extension/CodeBlock.tsx +64 -0
  23. package/source/Extension/Countdown.tsx +21 -9
  24. package/source/Extension/Editor.tsx +53 -18
  25. package/source/Extension/EditorHTML.tsx +7 -3
  26. package/source/Extension/HorizontalMarquee/index.tsx +69 -45
  27. package/source/Extension/Icon.tsx +15 -14
  28. package/source/Extension/Loading.tsx +20 -17
  29. package/source/Extension/MonthCalendar.tsx +26 -10
  30. package/source/Extension/OverlayBox.tsx +28 -15
  31. package/source/Extension/PageNav.tsx +16 -7
  32. package/source/Extension/ScrollNav/Scroller.tsx +21 -5
  33. package/source/Extension/ScrollNav/index.tsx +32 -7
  34. package/source/Extension/Select.tsx +12 -11
  35. package/source/Extension/SpinnerButton.tsx +19 -24
  36. package/source/Extension/TableSpinner.tsx +10 -14
  37. package/source/Extension/TextTruncate/index.tsx +17 -13
  38. package/source/Extension/Time.tsx +7 -5
  39. package/source/Extension/TimeDistance.tsx +22 -18
  40. package/source/Extension/Timeline/index.tsx +37 -34
  41. package/source/Extension/TypeEcho/Content.tsx +79 -14
  42. package/source/Extension/TypeEcho/index.tsx +13 -5
  43. package/source/Extension/UserRank/Address.tsx +17 -15
  44. package/source/Extension/UserRank/index.tsx +79 -84
  45. package/source/Extension/VerticalMarquee/index.tsx +14 -16
  46. package/source/Extension/ZodiacBar.tsx +40 -32
  47. package/source/Form/Adorn.tsx +30 -32
  48. package/source/Form/Checkbox.tsx +9 -5
  49. package/source/Form/ChipInput.tsx +9 -5
  50. package/source/Form/Chips.tsx +41 -39
  51. package/source/Form/Combobox.tsx +80 -61
  52. package/source/Form/Control.tsx +53 -58
  53. package/source/Form/DatePicker.tsx +74 -65
  54. package/source/Form/Feedback.tsx +18 -19
  55. package/source/Form/FloatingLabel.tsx +16 -19
  56. package/source/Form/InputGroup.tsx +27 -26
  57. package/source/Form/OTP.tsx +30 -12
  58. package/source/Form/Primitives.tsx +47 -39
  59. package/source/Form/Radio.tsx +25 -22
  60. package/source/Form/Range.tsx +30 -12
  61. package/source/Form/Switch.tsx +43 -40
  62. package/source/Grid.tsx +67 -59
  63. package/source/Image.tsx +10 -6
  64. package/source/ListGroup.tsx +57 -69
  65. package/source/Menu.tsx +128 -66
  66. package/source/NativeDialog/index.tsx +51 -29
  67. package/source/Nav.tsx +46 -46
  68. package/source/NavOverflow/index.tsx +26 -10
  69. package/source/Navbar.tsx +60 -55
  70. package/source/Pagination.tsx +63 -69
  71. package/source/Placeholder.tsx +47 -43
  72. package/source/Polymorphic.ts +57 -0
  73. package/source/Popover.tsx +34 -31
  74. package/source/Progress/index.tsx +59 -54
  75. package/source/ScrollSpy/index.tsx +48 -33
  76. package/source/Spinner.tsx +27 -23
  77. package/source/Stack.tsx +25 -0
  78. package/source/Stepper.tsx +46 -40
  79. package/source/Tab.tsx +40 -27
  80. package/source/Table.tsx +53 -42
  81. package/source/Toast.tsx +62 -47
  82. package/source/ToggleButton.tsx +40 -37
  83. package/source/Toggler.tsx +17 -8
  84. package/source/Tooltip.tsx +31 -29
  85. package/source/index.ts +2 -0
  86. package/source/Extension/CodeBlock/index.tsx +0 -58
  87. 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
- FC,
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: FC<TabProps> = ({
26
- eventKey: _eventKey,
27
- label: _label,
28
- disabled: _disabled,
29
- ...props
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<TabsProps> {
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.props.children)
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.props.defaultActiveKey ??
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.props.activeKey ?? this.selectedKey;
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.props.onClick?.(event);
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.props.onKeyDown?.(event);
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.tabs;
108
+ const { tabs } = this;
99
109
  if (!button || Number.isNaN(index)) return;
100
110
 
101
- const horizontal = this.props.orientation !== 'vertical';
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.props.onChange?.(key);
141
+ this.componentProps.onChange?.(key);
132
142
 
133
- if (this.props.activeKey === undefined) this.selectedKey = key;
143
+ if (this.componentProps.activeKey === undefined) this.selectedKey = key;
134
144
  };
135
145
 
136
- tabId = (key: string) => `${this.props.id}-tab-${encodeURIComponent(key)}`;
146
+ tabId = (key: string) => `${this.componentProps.id}-tab-${encodeURIComponent(key)}`;
137
147
 
138
- panelId = (key: string) => `${this.props.id}-panel-${encodeURIComponent(key)}`;
148
+ panelId = (key: string) => `${this.componentProps.id}-panel-${encodeURIComponent(key)}`;
139
149
 
140
150
  renderTabs = () => {
141
- const { orientation = 'horizontal', variant = 'tabs' } = this.props;
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.props['aria-label'] ?? 'Tabs'}
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.props;
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.props;
245
+ } = this.componentProps;
233
246
 
234
247
  return (
235
- <div
248
+ <Root
236
249
  {...props}
237
250
  ref={this.root}
238
- id={this.props.id}
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
- </div>
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, FC } from 'react';
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: FC<TableProps> = ({
17
- striped,
18
- stripedColumns,
19
- hover,
20
- bordered,
21
- borderless,
22
- small,
23
- responsive,
24
- className,
25
- ...props
26
- }) => {
27
- const table = (
28
- <table
29
- {...props}
30
- className={classNames(
31
- 'table',
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
- return !responsive ? (
46
- table
47
- ) : (
48
- <div
49
- className={classNames(
50
- 'table-responsive',
51
- responsive !== true && `${responsive}:table-responsive`
52
- )}
53
- >
54
- {table}
55
- </div>
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: FC<ToastContainerProps> = ({
57
- position = 'top-end',
58
- className,
59
- 'aria-live': ariaLive = 'polite',
60
- 'aria-atomic': ariaAtomic = true,
61
- ...props
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
- };
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: FC<ToastItemProps> = ({
89
- theme,
90
- show = true,
91
- translucent,
92
- instant,
93
- role = 'status',
94
- className,
95
- ...props
96
- }) => (
97
- <div
98
- {...props}
99
- className={classNames(
100
- 'toast',
101
- { show, 'toast-translucent': translucent, 'toast-instant': instant },
102
- theme && `theme-${theme}`,
103
- className
104
- )}
105
- role={role}
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: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
110
- <div {...props} className={classNames('toast-header', className)} />
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: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
114
- <div {...props} className={classNames('toast-body', className)} />
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
@@ -1,7 +1,8 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
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: FC<ToggleButtonProps> = ({
25
- type = 'checkbox',
26
- variant = 'solid',
27
- theme,
28
- name,
29
- value,
30
- checked,
31
- defaultChecked,
32
- disabled,
33
- required,
34
- size,
35
- inputProps,
36
- onChange,
37
- className,
38
- children,
39
- ...props
40
- }) => (
41
- <label
42
- {...props}
43
- className={classNames(
44
- 'btn-check',
45
- `btn-${variant}`,
46
- theme && `theme-${theme}`,
47
- size && `btn-${size}`,
48
- className
49
- )}
50
- >
51
- <input
52
- {...inputProps}
53
- {...{ type, name, value, checked, defaultChecked, disabled, required }}
54
- autoComplete="off"
55
- onChange={onChange}
56
- />
57
- {children}
58
- </label>
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';
@@ -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<TogglerProps> {
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.props.onClick?.(event);
31
+ this.componentProps.onClick?.(event);
23
32
 
24
- if (event.defaultPrevented || this.props.disabled) return;
33
+ if (event.defaultPrevented || this.componentProps.disabled) return;
25
34
 
26
- const { target, attribute = 'class', value, onToggled } = this.props;
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.props.onKeyDown?.(event);
68
+ this.componentProps.onKeyDown?.(event);
60
69
 
61
70
  if (
62
71
  !event.defaultPrevented &&
63
- !this.props.disabled &&
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.props;
91
+ } = this.componentProps;
83
92
 
84
93
  return Tag === 'button' ? (
85
94
  <Button
@@ -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: FC<TooltipProps> = ({
9
- placement = 'top',
10
- show = true,
11
- role = 'tooltip',
12
- className,
13
- children,
14
- arrowStyle,
15
- ...props
16
- }) => (
17
- <div
18
- {...props}
19
- className={classNames(
20
- 'tooltip',
21
- { show },
22
- `bs-tooltip-${OVERLAY_DIRECTIONS[placement]}`,
23
- className
24
- )}
25
- role={role}
26
- hidden={!show}
27
- data-bs-placement={placement}
28
- >
29
- <div
30
- style={arrowStyle}
31
- className={classNames('tooltip-arrow', OVERLAY_ARROW_POSITIONS[placement])}
32
- />
33
- <div className="tooltip-inner">{children}</div>
34
- </div>
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';