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

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 (89) hide show
  1. package/AGENTS.md +12 -3
  2. package/ReadMe.md +34 -6
  3. package/dist/index.d.mts +313 -230
  4. package/dist/index.d.ts +313 -230
  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 +13 -13
  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 +73 -48
  62. package/source/Form/inputProps.ts +184 -0
  63. package/source/Grid.tsx +67 -59
  64. package/source/Image.tsx +10 -6
  65. package/source/ListGroup.tsx +57 -69
  66. package/source/Menu.tsx +128 -66
  67. package/source/NativeDialog/index.tsx +51 -29
  68. package/source/Nav.tsx +46 -46
  69. package/source/NavOverflow/index.tsx +26 -10
  70. package/source/Navbar.tsx +60 -55
  71. package/source/Pagination.tsx +63 -69
  72. package/source/Placeholder.tsx +47 -43
  73. package/source/Polymorphic.ts +57 -0
  74. package/source/Popover.tsx +34 -31
  75. package/source/Progress/index.tsx +59 -54
  76. package/source/ScrollSpy/index.tsx +48 -33
  77. package/source/Spinner.tsx +27 -23
  78. package/source/Stack.tsx +25 -0
  79. package/source/Stepper.tsx +46 -40
  80. package/source/Tab.tsx +40 -27
  81. package/source/Table.tsx +53 -42
  82. package/source/Toast.tsx +62 -47
  83. package/source/ToggleButton.tsx +65 -54
  84. package/source/Toggler.tsx +17 -8
  85. package/source/Tooltip.tsx +31 -29
  86. package/source/index.ts +2 -0
  87. package/tsconfig.json +2 -2
  88. package/source/Extension/CodeBlock/index.tsx +0 -58
  89. package/source/Extension/CodeBlock/style.module.css +0 -3
@@ -10,7 +10,7 @@ import {
10
10
  Component,
11
11
  ComponentPropsWithRef,
12
12
  createRef,
13
- FC,
13
+ ElementType,
14
14
  isValidElement,
15
15
  MouseEvent,
16
16
  ReactElement,
@@ -19,6 +19,7 @@ import {
19
19
 
20
20
  import { Icon } from '../Extension/Icon';
21
21
  import { Menu, MenuHeader, MenuItemContent, MenuItemDescription } from '../Menu';
22
+ import { AsProps, polymorphic, PolymorphicClassProps } from '../Polymorphic';
22
23
  import { FormValidationProps } from './Primitives';
23
24
 
24
25
  export interface ComboboxOptionProps extends ComponentPropsWithRef<'button'> {
@@ -29,53 +30,56 @@ export interface ComboboxOptionProps extends ComponentPropsWithRef<'button'> {
29
30
  searchText?: string;
30
31
  }
31
32
 
32
- export const ComboboxOption: FC<ComboboxOptionProps> = ({
33
- className,
34
- value,
35
- children,
36
- description,
37
- icon,
38
- checkedIcon,
39
- searchText,
40
- ...props
41
- }) => (
42
- <button
43
- {...props}
44
- type="button"
45
- role="option"
46
- aria-selected={props['aria-selected'] ?? false}
47
- className={classNames('menu-item', className)}
48
- data-bs-value={value}
49
- data-search-text={searchText}
50
- data-label={optionText(children)}
51
- data-option-hidden={props.hidden || undefined}
52
- >
53
- {icon && <Icon name={icon} className="menu-item-icon" aria-hidden="true" />}
54
- {description ? (
55
- <MenuItemContent>
56
- {children}
57
- <MenuItemDescription>{description}</MenuItemDescription>
58
- </MenuItemContent>
59
- ) : (
60
- children
61
- )}
62
- {checkedIcon && <Icon name="check-lg" className="menu-item-check" aria-hidden="true" />}
63
- </button>
33
+ export const ComboboxOption = polymorphic<ComboboxOptionProps>(
34
+ ({
35
+ as: Root = 'button',
36
+ className,
37
+ value,
38
+ children,
39
+ description,
40
+ icon,
41
+ checkedIcon,
42
+ searchText,
43
+ ...props
44
+ }) => (
45
+ <Root
46
+ {...props}
47
+ type="button"
48
+ role="option"
49
+ aria-selected={props['aria-selected'] ?? false}
50
+ className={classNames('menu-item', className)}
51
+ data-bs-value={value}
52
+ data-search-text={searchText}
53
+ data-label={optionText(children)}
54
+ data-option-hidden={props.hidden || undefined}
55
+ >
56
+ {icon && <Icon name={icon} className="menu-item-icon" aria-hidden="true" />}
57
+ {description ? (
58
+ <MenuItemContent>
59
+ {children}
60
+ <MenuItemDescription>{description}</MenuItemDescription>
61
+ </MenuItemContent>
62
+ ) : (
63
+ children
64
+ )}
65
+ {checkedIcon && <Icon name="check-lg" className="menu-item-check" aria-hidden="true" />}
66
+ </Root>
67
+ )
64
68
  );
65
-
66
69
  ComboboxOption.displayName = 'ComboboxOption';
67
70
 
68
71
  export interface ComboboxGroupProps extends ComponentPropsWithRef<'div'> {
69
72
  label: ReactNode;
70
73
  }
71
74
 
72
- export const ComboboxGroup: FC<ComboboxGroupProps> = ({ label, children, ...props }) => (
73
- <div {...props} role="group" aria-label={typeof label === 'string' ? label : undefined}>
74
- <MenuHeader>{label}</MenuHeader>
75
- {children}
76
- </div>
75
+ export const ComboboxGroup = polymorphic<ComboboxGroupProps>(
76
+ ({ as: Root = 'div', label, children, ...props }) => (
77
+ <Root {...props} role="group" aria-label={typeof label === 'string' ? label : undefined}>
78
+ <MenuHeader>{label}</MenuHeader>
79
+ {children}
80
+ </Root>
81
+ )
77
82
  );
78
-
79
83
  ComboboxGroup.displayName = 'ComboboxGroup';
80
84
 
81
85
  export interface ComboboxProps
@@ -114,11 +118,20 @@ const collectOptions = (children: ReactNode): ReactElement<ComboboxOptionProps>[
114
118
  );
115
119
 
116
120
  @observer
117
- export class Combobox extends Component<ComboboxProps> {
121
+ export class Combobox<T extends ElementType | undefined = 'div'> extends Component<
122
+ PolymorphicClassProps<T, ComboboxProps>
123
+ > {
124
+ declare readonly props: PolymorphicClassProps<T, ComboboxProps>;
125
+
126
+ protected get componentProps(): Readonly<ComboboxProps & AsProps> {
127
+ return this.props;
128
+ }
129
+
118
130
  static displayName = 'Combobox';
119
131
 
120
132
  @observable accessor query = '';
121
- @observable accessor current = this.props.defaultValue ?? (this.props.multiple ? [] : '');
133
+ @observable accessor current =
134
+ this.componentProps.defaultValue ?? (this.componentProps.multiple ? [] : '');
122
135
  @observable accessor visibleOptionCount = 0;
123
136
  @observable accessor selectedLabel = '';
124
137
 
@@ -126,7 +139,7 @@ export class Combobox extends Component<ComboboxProps> {
126
139
  private optionObserver?: MutationObserver;
127
140
 
128
141
  get values() {
129
- const value = this.props.value ?? this.current;
142
+ const value = this.componentProps.value ?? this.current;
130
143
 
131
144
  return Array.isArray(value) ? value : value ? [value] : [];
132
145
  }
@@ -186,15 +199,15 @@ export class Combobox extends Component<ComboboxProps> {
186
199
  }
187
200
  this.visibleOptionCount = visible;
188
201
  this.selectedLabel =
189
- this.props.multiple && selected.length > 1
202
+ this.componentProps.multiple && selected.length > 1
190
203
  ? `${selected.length} selected`
191
204
  : (selected[0] ?? '');
192
205
 
193
206
  panel?.setAttribute('role', 'listbox');
194
- panel?.setAttribute('aria-multiselectable', String(Boolean(this.props.multiple)));
207
+ panel?.setAttribute('aria-multiselectable', String(Boolean(this.componentProps.multiple)));
195
208
  panel?.setAttribute(
196
209
  'aria-label',
197
- this.props['aria-label'] ?? this.props.placeholder ?? 'Options'
210
+ this.componentProps['aria-label'] ?? this.componentProps.placeholder ?? 'Options'
198
211
  );
199
212
  this.menu.current?.trigger.current?.setAttribute('aria-haspopup', 'listbox');
200
213
  };
@@ -207,29 +220,32 @@ export class Combobox extends Component<ComboboxProps> {
207
220
  (this.query = value);
208
221
 
209
222
  private handleClick = (event: MouseEvent<HTMLDivElement>) => {
210
- this.props.onClick?.(event);
223
+ this.componentProps.onClick?.(event);
211
224
 
212
225
  const { target, defaultPrevented } = event;
213
- if (defaultPrevented || this.props.disabled || !(target instanceof Element)) return;
226
+ if (defaultPrevented || this.componentProps.disabled || !(target instanceof Element))
227
+ return;
214
228
 
215
229
  const option = target.closest<HTMLButtonElement>('[data-bs-value]');
216
230
  if (!option || option.disabled || option.getAttribute('aria-disabled') === 'true') return;
217
231
 
218
232
  const next = option.dataset.bsValue ?? '';
219
- const value = this.props.multiple
233
+ const value = this.componentProps.multiple
220
234
  ? this.values.includes(next)
221
235
  ? this.values.filter(item => item !== next)
222
236
  : [...this.values, next]
223
237
  : next;
224
- this.props.onChange?.(value);
238
+ this.componentProps.onChange?.(value);
225
239
 
226
- if (this.props.value === undefined) this.setCurrent(value);
240
+ if (this.componentProps.value === undefined) this.setCurrent(value);
227
241
  };
228
242
 
229
243
  private normalize = (value: string) => {
230
244
  const text = value.toLocaleLowerCase();
231
245
 
232
- return this.props.searchNormalize ? text.normalize('NFD').replace(/\p{M}/gu, '') : text;
246
+ return this.componentProps.searchNormalize
247
+ ? text.normalize('NFD').replace(/\p{M}/gu, '')
248
+ : text;
233
249
  };
234
250
 
235
251
  private matches = (option: ReactElement<ComboboxOptionProps>) =>
@@ -263,14 +279,17 @@ export class Combobox extends Component<ComboboxProps> {
263
279
  <input
264
280
  key={value}
265
281
  type="hidden"
266
- name={this.props.name}
282
+ name={this.componentProps.name}
267
283
  value={value}
268
- disabled={this.props.disabled}
284
+ disabled={this.componentProps.disabled}
269
285
  />
270
286
  );
271
287
 
272
288
  render() {
289
+ const Root: ElementType = this.componentProps.as ?? 'div';
290
+
273
291
  const {
292
+ as: _as,
274
293
  className,
275
294
  id,
276
295
  name: _name,
@@ -290,7 +309,7 @@ export class Combobox extends Component<ComboboxProps> {
290
309
  noResultsText = 'No results found',
291
310
  validation,
292
311
  ...props
293
- } = this.props;
312
+ } = this.componentProps;
294
313
  const options = collectOptions(children);
295
314
  const selected = options.filter(option => this.values.includes(option.props.value));
296
315
  const hasSelection = selected.length > 0 || Boolean(this.selectedLabel);
@@ -301,7 +320,7 @@ export class Combobox extends Component<ComboboxProps> {
301
320
  const noResults = this.visibleOptionCount === 0;
302
321
 
303
322
  return (
304
- <div {...props} className={classNames('combobox', className)}>
323
+ <Root {...props} className={classNames('combobox', className)}>
305
324
  <Menu
306
325
  ref={this.menu}
307
326
  className="w-100"
@@ -333,12 +352,12 @@ export class Combobox extends Component<ComboboxProps> {
333
352
  variant: false,
334
353
  disabled,
335
354
  'aria-haspopup': 'listbox',
336
- 'aria-label': this.props['aria-label'] ?? placeholder,
337
- 'aria-labelledby': this.props['aria-labelledby'],
338
- 'aria-describedby': this.props['aria-describedby'],
355
+ 'aria-label': this.componentProps['aria-label'] ?? placeholder,
356
+ 'aria-labelledby': this.componentProps['aria-labelledby'],
357
+ 'aria-describedby': this.componentProps['aria-describedby'],
339
358
  'aria-invalid': validation
340
359
  ? validation === 'invalid'
341
- : this.props['aria-invalid']
360
+ : this.componentProps['aria-invalid']
342
361
  }}
343
362
  autoClose={!multiple}
344
363
  menuClassName={classNames(menuClassName, 'combobox-menu')}
@@ -368,7 +387,7 @@ export class Combobox extends Component<ComboboxProps> {
368
387
  {this.values.length || multiple
369
388
  ? this.values.map(this.renderHiddenInput)
370
389
  : this.renderHiddenInput('')}
371
- </div>
390
+ </Root>
372
391
  );
373
392
  }
374
393
  }
@@ -1,6 +1,7 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
3
 
4
+ import { polymorphic } from '../Polymorphic';
4
5
  import { FormValidationProps } from './Primitives';
5
6
 
6
7
  const CONTROL_SIZES = {
@@ -17,30 +18,32 @@ export type FormControlProps = Omit<ComponentPropsWithRef<'input'>, 'color'> &
17
18
  controlSize?: 'sm' | 'lg';
18
19
  };
19
20
 
20
- export const FormControl: FC<FormControlProps> = ({
21
- className,
22
- plaintext,
23
- ghost,
24
- caret,
25
- color,
26
- controlSize,
27
- validation,
28
- ...props
29
- }) => (
30
- <input
31
- {...props}
32
- aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
33
- className={classNames(
34
- ghost ? 'form-ghost' : plaintext ? 'form-control-plaintext' : 'form-control',
35
- !ghost && caret && 'form-control-caret',
36
- !ghost && !plaintext && color && 'form-control-color',
37
- !ghost && !plaintext && controlSize && CONTROL_SIZES[controlSize],
38
- validation && `is-${validation}`,
39
- className
40
- )}
41
- />
21
+ export const FormControl = polymorphic<FormControlProps>(
22
+ ({
23
+ as: Root = 'input',
24
+ className,
25
+ plaintext,
26
+ ghost,
27
+ caret,
28
+ color,
29
+ controlSize,
30
+ validation,
31
+ ...props
32
+ }) => (
33
+ <Root
34
+ {...props}
35
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
36
+ className={classNames(
37
+ ghost ? 'form-ghost' : plaintext ? 'form-control-plaintext' : 'form-control',
38
+ !ghost && caret && 'form-control-caret',
39
+ !ghost && !plaintext && color && 'form-control-color',
40
+ !ghost && !plaintext && controlSize && CONTROL_SIZES[controlSize],
41
+ validation && `is-${validation}`,
42
+ className
43
+ )}
44
+ />
45
+ )
42
46
  );
43
-
44
47
  FormControl.displayName = 'FormControl';
45
48
 
46
49
  export type FormTextAreaProps = ComponentPropsWithRef<'textarea'> &
@@ -48,24 +51,20 @@ export type FormTextAreaProps = ComponentPropsWithRef<'textarea'> &
48
51
  controlSize?: 'sm' | 'lg';
49
52
  };
50
53
 
51
- export const FormTextArea: FC<FormTextAreaProps> = ({
52
- className,
53
- controlSize,
54
- validation,
55
- ...props
56
- }) => (
57
- <textarea
58
- {...props}
59
- aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
60
- className={classNames(
61
- 'form-control',
62
- controlSize && CONTROL_SIZES[controlSize],
63
- validation && `is-${validation}`,
64
- className
65
- )}
66
- />
54
+ export const FormTextArea = polymorphic<FormTextAreaProps>(
55
+ ({ as: Root = 'textarea', className, controlSize, validation, ...props }) => (
56
+ <Root
57
+ {...props}
58
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
59
+ className={classNames(
60
+ 'form-control',
61
+ controlSize && CONTROL_SIZES[controlSize],
62
+ validation && `is-${validation}`,
63
+ className
64
+ )}
65
+ />
66
+ )
67
67
  );
68
-
69
68
  FormTextArea.displayName = 'FormTextArea';
70
69
 
71
70
  export type FormSelectProps = ComponentPropsWithRef<'select'> &
@@ -73,22 +72,18 @@ export type FormSelectProps = ComponentPropsWithRef<'select'> &
73
72
  controlSize?: 'sm' | 'lg';
74
73
  };
75
74
 
76
- export const FormSelect: FC<FormSelectProps> = ({
77
- className,
78
- controlSize,
79
- validation,
80
- ...props
81
- }) => (
82
- <select
83
- {...props}
84
- aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
85
- className={classNames(
86
- 'form-control',
87
- controlSize && CONTROL_SIZES[controlSize],
88
- validation && `is-${validation}`,
89
- className
90
- )}
91
- />
75
+ export const FormSelect = polymorphic<FormSelectProps>(
76
+ ({ as: Root = 'select', className, controlSize, validation, ...props }) => (
77
+ <Root
78
+ {...props}
79
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
80
+ className={classNames(
81
+ 'form-control',
82
+ controlSize && CONTROL_SIZES[controlSize],
83
+ validation && `is-${validation}`,
84
+ className
85
+ )}
86
+ />
87
+ )
92
88
  );
93
-
94
89
  FormSelect.displayName = 'FormSelect';
@@ -2,10 +2,11 @@
2
2
 
3
3
  import Datepicker, { type DatepickerConfig } from 'bootstrap/js/src/datepicker.js';
4
4
  import classNames from 'classnames';
5
- import { ComponentPropsWithoutRef, FC, forwardRef, Ref } from 'react';
5
+ import { ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
6
6
 
7
7
  import { Button, ButtonProps } from '../Button';
8
8
  import { Icon } from '../Extension/Icon';
9
+ import { AsProps, polymorphic, PolymorphicComponent } from '../Polymorphic';
9
10
  import { FormPlugin } from './Plugin';
10
11
  import { FormValidationProps } from './Primitives';
11
12
 
@@ -37,7 +38,7 @@ export type DatePickerButtonProps = Extract<ButtonProps, { href?: never }> &
37
38
  };
38
39
  export type DatePickerInlineProps = ComponentPropsWithoutRef<'div'> & DatePickerSettings;
39
40
 
40
- interface DatePickerComponentProps extends DatePickerProps {
41
+ interface DatePickerComponentProps extends DatePickerProps, AsProps {
41
42
  kind?: 'input' | 'button' | 'div';
42
43
  hostProps?: DatePickerButtonProps | DatePickerInlineProps;
43
44
  leadingIcon?: string;
@@ -120,6 +121,7 @@ class DatePickerComponent extends FormPlugin<
120
121
 
121
122
  render() {
122
123
  const {
124
+ as,
123
125
  className,
124
126
  enhanced,
125
127
  inline,
@@ -142,6 +144,7 @@ class DatePickerComponent extends FormPlugin<
142
144
  forwardedRef: _forwardedRef,
143
145
  ...props
144
146
  } = this.props;
147
+ const Root = as ?? (kind === 'div' ? 'div' : 'input');
145
148
  const attributes = {
146
149
  'data-bs-toggle': enhanced || kind !== 'input' ? 'datepicker' : undefined,
147
150
  'data-bs-inline': inline || kind === 'div' || undefined,
@@ -159,7 +162,7 @@ class DatePickerComponent extends FormPlugin<
159
162
  const { children, ...buttonProps } = hostProps as ButtonProps;
160
163
 
161
164
  return (
162
- <Button {...buttonProps} {...attributes} ref={this.setRef}>
165
+ <Button as={as} {...buttonProps} {...attributes} ref={this.setRef}>
163
166
  {leadingIcon && <Icon name={leadingIcon} aria-hidden="true" />}
164
167
  <span data-bs-datepicker-display="">{children}</span>
165
168
  </Button>
@@ -167,7 +170,7 @@ class DatePickerComponent extends FormPlugin<
167
170
  }
168
171
  if (kind === 'div')
169
172
  return (
170
- <div
173
+ <Root
171
174
  {...(hostProps as ComponentPropsWithoutRef<'div'>)}
172
175
  {...attributes}
173
176
  ref={this.setRef}
@@ -175,7 +178,7 @@ class DatePickerComponent extends FormPlugin<
175
178
  );
176
179
 
177
180
  return (
178
- <input
181
+ <Root
179
182
  {...props}
180
183
  {...attributes}
181
184
  ref={this.setRef}
@@ -194,38 +197,20 @@ class DatePickerComponent extends FormPlugin<
194
197
  }
195
198
  }
196
199
 
197
- export const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>((props, forwardedRef) => (
198
- <DatePickerComponent {...props} forwardedRef={forwardedRef} />
199
- ));
200
-
200
+ export const DatePicker = polymorphic<DatePickerProps & { ref?: Ref<HTMLInputElement> }>(
201
+ forwardRef<HTMLInputElement, DatePickerProps & AsProps>((props, forwardedRef) => (
202
+ <DatePickerComponent {...props} forwardedRef={forwardedRef} />
203
+ ))
204
+ );
201
205
  DatePicker.displayName = 'DatePicker';
202
206
 
203
- export const DatePickerButton: FC<DatePickerButtonProps> = forwardRef<
204
- HTMLButtonElement,
205
- DatePickerButtonProps
206
- >(
207
- (
208
- {
209
- options,
210
- inline,
211
- selectionMode,
212
- displayMonthsCount,
213
- selectedDates,
214
- firstWeekday,
215
- placement,
216
- datepickerTheme,
217
- onDatesChange,
218
- leadingIcon,
219
- ...hostProps
220
- },
221
- forwardedRef
222
- ) => (
223
- <DatePickerComponent
224
- kind="button"
225
- leadingIcon={leadingIcon}
226
- hostProps={hostProps}
227
- forwardedRef={forwardedRef}
228
- {...{
207
+ export const DatePickerButton: PolymorphicComponent<
208
+ DatePickerButtonProps & { ref?: Ref<HTMLButtonElement> }
209
+ > = polymorphic(
210
+ forwardRef<HTMLButtonElement, DatePickerButtonProps & AsProps>(
211
+ (
212
+ {
213
+ as,
229
214
  options,
230
215
  inline,
231
216
  selectionMode,
@@ -234,47 +219,71 @@ export const DatePickerButton: FC<DatePickerButtonProps> = forwardRef<
234
219
  firstWeekday,
235
220
  placement,
236
221
  datepickerTheme,
237
- onDatesChange
238
- }}
239
- />
222
+ onDatesChange,
223
+ leadingIcon,
224
+ ...hostProps
225
+ },
226
+ forwardedRef
227
+ ) => (
228
+ <DatePickerComponent
229
+ as={as}
230
+ kind="button"
231
+ leadingIcon={leadingIcon}
232
+ hostProps={hostProps}
233
+ forwardedRef={forwardedRef}
234
+ {...{
235
+ options,
236
+ inline,
237
+ selectionMode,
238
+ displayMonthsCount,
239
+ selectedDates,
240
+ firstWeekday,
241
+ placement,
242
+ datepickerTheme,
243
+ onDatesChange
244
+ }}
245
+ />
246
+ )
240
247
  )
241
248
  );
242
-
243
249
  DatePickerButton.displayName = 'DatePickerButton';
244
250
 
245
- export const DatePickerInline = forwardRef<HTMLDivElement, DatePickerInlineProps>(
246
- (
247
- {
248
- options,
249
- selectionMode,
250
- displayMonthsCount,
251
- selectedDates,
252
- firstWeekday,
253
- placement,
254
- datepickerTheme,
255
- onDatesChange,
256
- inline = true,
257
- ...hostProps
258
- },
259
- forwardedRef
260
- ) => (
261
- <DatePickerComponent
262
- kind="div"
263
- hostProps={hostProps}
264
- forwardedRef={forwardedRef}
265
- {...{
251
+ export const DatePickerInline = polymorphic<DatePickerInlineProps & { ref?: Ref<HTMLDivElement> }>(
252
+ forwardRef<HTMLDivElement, DatePickerInlineProps & AsProps>(
253
+ (
254
+ {
255
+ as,
266
256
  options,
267
- inline,
268
257
  selectionMode,
269
258
  displayMonthsCount,
270
259
  selectedDates,
271
260
  firstWeekday,
272
261
  placement,
273
262
  datepickerTheme,
274
- onDatesChange
275
- }}
276
- />
263
+ onDatesChange,
264
+ inline = true,
265
+ ...hostProps
266
+ },
267
+ forwardedRef
268
+ ) => (
269
+ <DatePickerComponent
270
+ as={as}
271
+ kind="div"
272
+ hostProps={hostProps}
273
+ forwardedRef={forwardedRef}
274
+ {...{
275
+ options,
276
+ inline,
277
+ selectionMode,
278
+ displayMonthsCount,
279
+ selectedDates,
280
+ firstWeekday,
281
+ placement,
282
+ datepickerTheme,
283
+ onDatesChange
284
+ }}
285
+ />
286
+ )
277
287
  )
278
288
  );
279
-
280
289
  DatePickerInline.displayName = 'DatePickerInline';
@@ -1,14 +1,17 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { polymorphic } from '../Polymorphic';
3
5
 
4
6
  export type FormTextProps = ComponentPropsWithRef<'small'> & {
5
7
  block?: boolean;
6
8
  };
7
9
 
8
- export const FormText: FC<FormTextProps> = ({ className, block, ...props }) => (
9
- <small {...props} className={classNames('form-text', block && 'd-block', className)} />
10
+ export const FormText = polymorphic<FormTextProps>(
11
+ ({ as: Root = 'small', className, block, ...props }) => (
12
+ <Root {...props} className={classNames('form-text', block && 'd-block', className)} />
13
+ )
10
14
  );
11
-
12
15
  FormText.displayName = 'FormText';
13
16
 
14
17
  export type FormFeedbackProps = Omit<ComponentPropsWithRef<'div'>, 'type'> & {
@@ -16,20 +19,16 @@ export type FormFeedbackProps = Omit<ComponentPropsWithRef<'div'>, 'type'> & {
16
19
  tooltip?: boolean;
17
20
  };
18
21
 
19
- export const FormFeedback: FC<FormFeedbackProps> = ({
20
- className,
21
- type = 'invalid',
22
- tooltip,
23
- ...props
24
- }) => (
25
- <div
26
- {...props}
27
- className={classNames(
28
- tooltip && 'tooltip',
29
- tooltip ? `${type}-tooltip` : `${type}-feedback`,
30
- className
31
- )}
32
- />
22
+ export const FormFeedback = polymorphic<FormFeedbackProps>(
23
+ ({ as: Root = 'div', className, type = 'invalid', tooltip, ...props }) => (
24
+ <Root
25
+ {...props}
26
+ className={classNames(
27
+ { tooltip },
28
+ tooltip ? `${type}-tooltip` : `${type}-feedback`,
29
+ className
30
+ )}
31
+ />
32
+ )
33
33
  );
34
-
35
34
  FormFeedback.displayName = 'FormFeedback';