idea-react 3.0.0-beta.0 → 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 (130) hide show
  1. package/AGENTS.md +19 -2
  2. package/ReadMe.md +95 -54
  3. package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
  4. package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
  5. package/dist/index.d.mts +1232 -474
  6. package/dist/index.d.ts +1232 -474
  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 +66 -66
  11. package/package.json +1 -1
  12. package/source/Accordion.tsx +161 -0
  13. package/source/Alert.tsx +153 -0
  14. package/source/Avatar.tsx +57 -46
  15. package/source/Badge.tsx +17 -15
  16. package/source/Breadcrumb.tsx +50 -0
  17. package/source/Button.tsx +69 -40
  18. package/source/ButtonGroup.tsx +23 -18
  19. package/source/Card.tsx +86 -17
  20. package/source/Carousel/index.tsx +392 -0
  21. package/source/Carousel/model.ts +113 -0
  22. package/source/Carousel/scroll.ts +79 -0
  23. package/source/CloseButton.tsx +20 -15
  24. package/source/Collapse.tsx +233 -0
  25. package/source/Drawer.tsx +158 -38
  26. package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +24 -5
  27. package/source/Extension/CodeBlock.tsx +64 -0
  28. package/source/{Countdown.tsx → Extension/Countdown.tsx} +21 -9
  29. package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
  30. package/source/Extension/Editor.tsx +78 -0
  31. package/source/Extension/EditorHTML.tsx +20 -0
  32. package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
  33. package/source/Extension/HorizontalMarquee/index.tsx +85 -0
  34. package/source/Extension/Icon.tsx +19 -0
  35. package/source/Extension/Loading.tsx +30 -0
  36. package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +29 -13
  37. package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
  38. package/source/Extension/OverlayBox.tsx +293 -0
  39. package/source/{PageNav.tsx → Extension/PageNav.tsx} +43 -16
  40. package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +21 -5
  41. package/source/Extension/ScrollNav/index.tsx +47 -0
  42. package/source/Extension/Select.tsx +128 -0
  43. package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
  44. package/source/Extension/SpinnerButton.tsx +30 -0
  45. package/source/Extension/TableSpinner.tsx +22 -0
  46. package/source/Extension/TextTruncate/index.tsx +29 -0
  47. package/source/Extension/Time.tsx +17 -0
  48. package/source/Extension/TimeDistance.tsx +45 -0
  49. package/source/Extension/Timeline/index.tsx +63 -0
  50. package/source/Extension/TypeEcho/Content.tsx +123 -0
  51. package/source/Extension/TypeEcho/index.tsx +22 -0
  52. package/source/Extension/UserRank/Address.tsx +22 -0
  53. package/source/Extension/UserRank/index.tsx +106 -0
  54. package/source/Extension/VerticalMarquee/index.tsx +23 -0
  55. package/source/Extension/ZodiacBar.tsx +59 -0
  56. package/source/Extension/index.ts +27 -0
  57. package/source/Form/Adorn.tsx +45 -26
  58. package/source/Form/Checkbox.tsx +20 -11
  59. package/source/Form/ChipInput.tsx +129 -0
  60. package/source/Form/Chips.tsx +57 -37
  61. package/source/Form/Combobox.tsx +362 -78
  62. package/source/Form/Control.tsx +72 -42
  63. package/source/Form/DatePicker.tsx +245 -45
  64. package/source/Form/DatePickerPlugin.ts +37 -0
  65. package/source/Form/Feedback.tsx +21 -16
  66. package/source/Form/FloatingLabel.tsx +21 -7
  67. package/source/Form/InputGroup.tsx +162 -11
  68. package/source/Form/OTP.tsx +156 -45
  69. package/source/Form/PasswordStrength.tsx +43 -17
  70. package/source/Form/Plugin.tsx +53 -0
  71. package/source/Form/Primitives.tsx +70 -20
  72. package/source/Form/Radio.tsx +35 -40
  73. package/source/Form/Range.tsx +125 -56
  74. package/source/Form/Switch.tsx +53 -27
  75. package/source/Form/index.ts +1 -0
  76. package/source/Grid.tsx +68 -56
  77. package/source/Image.tsx +10 -6
  78. package/source/ListGroup.tsx +59 -58
  79. package/source/Menu.tsx +317 -46
  80. package/source/NativeDialog/index.tsx +148 -22
  81. package/source/Nav.tsx +49 -33
  82. package/source/NavOverflow/index.tsx +323 -0
  83. package/source/NavOverflow/model.ts +21 -0
  84. package/source/Navbar.tsx +65 -45
  85. package/source/Overlay.ts +163 -1
  86. package/source/Pagination.tsx +86 -0
  87. package/source/Placeholder.tsx +70 -0
  88. package/source/Polymorphic.ts +57 -0
  89. package/source/Popover.tsx +34 -26
  90. package/source/Progress/index.tsx +81 -0
  91. package/source/Progress/style.module.css +15 -0
  92. package/source/ScrollSpy/index.tsx +380 -0
  93. package/source/ScrollSpy/model.ts +17 -0
  94. package/source/Spinner.tsx +31 -17
  95. package/source/Stack.tsx +25 -0
  96. package/source/Stepper.tsx +91 -0
  97. package/source/Tab.tsx +261 -0
  98. package/source/Table.tsx +53 -42
  99. package/source/Toast.tsx +93 -46
  100. package/source/ToggleButton.tsx +47 -30
  101. package/source/Toggler.tsx +117 -0
  102. package/source/Tooltip.tsx +31 -24
  103. package/source/index.ts +17 -27
  104. package/source/CodeBlock.tsx +0 -40
  105. package/source/Editor.tsx +0 -43
  106. package/source/EditorHTML.tsx +0 -16
  107. package/source/HorizontalMarquee/index.tsx +0 -61
  108. package/source/Icon.tsx +0 -24
  109. package/source/Loading.tsx +0 -22
  110. package/source/OverlayBox.tsx +0 -208
  111. package/source/ScrollNav/index.tsx +0 -22
  112. package/source/Select.tsx +0 -95
  113. package/source/SpinnerButton.tsx +0 -35
  114. package/source/TableSpinner.tsx +0 -26
  115. package/source/TextTruncate/index.tsx +0 -25
  116. package/source/Time.tsx +0 -15
  117. package/source/TimeDistance.tsx +0 -41
  118. package/source/Timeline/index.tsx +0 -60
  119. package/source/TypeEcho/Content.tsx +0 -58
  120. package/source/TypeEcho/index.tsx +0 -14
  121. package/source/UserRank/Address.tsx +0 -20
  122. package/source/UserRank/index.tsx +0 -111
  123. package/source/VerticalMarquee/index.tsx +0 -25
  124. package/source/ZodiacBar.tsx +0 -51
  125. /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
  126. /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
  127. /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
  128. /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
  129. /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
  130. /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
@@ -1,109 +1,393 @@
1
1
  'use client';
2
2
 
3
3
  import classNames from 'classnames';
4
- import { Children, cloneElement, ComponentPropsWithRef, FC, isValidElement } from 'react';
4
+ import { action, observable } from 'mobx';
5
+ import { observer } from 'mobx-react';
6
+ import {
7
+ ChangeEvent,
8
+ Children,
9
+ cloneElement,
10
+ Component,
11
+ ComponentPropsWithRef,
12
+ createRef,
13
+ ElementType,
14
+ isValidElement,
15
+ MouseEvent,
16
+ ReactElement,
17
+ ReactNode
18
+ } from 'react';
5
19
 
6
- import { Menu } from '../Menu';
20
+ import { Icon } from '../Extension/Icon';
21
+ import { Menu, MenuHeader, MenuItemContent, MenuItemDescription } from '../Menu';
22
+ import { AsProps, polymorphic, PolymorphicClassProps } from '../Polymorphic';
23
+ import { FormValidationProps } from './Primitives';
7
24
 
8
25
  export interface ComboboxOptionProps extends ComponentPropsWithRef<'button'> {
9
26
  value: string;
27
+ description?: ReactNode;
28
+ icon?: string;
29
+ checkedIcon?: boolean;
30
+ searchText?: string;
10
31
  }
11
32
 
12
- export const ComboboxOption: FC<ComboboxOptionProps> = ({ className, value, ...props }) => (
13
- <button
14
- {...props}
15
- type="button"
16
- className={classNames('menu-item', className)}
17
- data-bs-value={value}
18
- />
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
+ )
19
68
  );
20
-
21
69
  ComboboxOption.displayName = 'ComboboxOption';
22
70
 
23
- export interface ComboboxProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
71
+ export interface ComboboxGroupProps extends ComponentPropsWithRef<'div'> {
72
+ label: ReactNode;
73
+ }
74
+
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
+ )
82
+ );
83
+ ComboboxGroup.displayName = 'ComboboxGroup';
84
+
85
+ export interface ComboboxProps
86
+ extends Omit<ComponentPropsWithRef<'div'>, 'onChange' | 'defaultValue'>, FormValidationProps {
24
87
  name: string;
25
- value: string | string[];
88
+ value?: string | string[];
89
+ defaultValue?: string | string[];
26
90
  placeholder?: string;
27
91
  multiple?: boolean;
28
92
  menuClassName?: string;
29
93
  disabled?: boolean;
94
+ controlSize?: 'sm' | 'lg';
95
+ search?: boolean;
96
+ searchNormalize?: boolean;
97
+ searchPlaceholder?: string;
98
+ noResultsText?: string;
30
99
  onChange?: (value: string | string[]) => unknown;
31
100
  }
32
101
 
33
- export const Combobox: FC<ComboboxProps> = ({
34
- className,
35
- name,
36
- value,
37
- placeholder = 'Select an item…',
38
- disabled,
39
- multiple,
40
- onChange,
41
- menuClassName,
42
- children,
43
- ...props
44
- }) => {
45
- const values = Array.isArray(value) ? value : value ? [value] : [];
46
- const options = Children.toArray(children).filter(
47
- (option): option is React.ReactElement<ComboboxOptionProps> =>
48
- isValidElement<ComboboxOptionProps>(option)
102
+ const optionText = (content: ReactNode): string =>
103
+ Children.toArray(content)
104
+ .map(child =>
105
+ isValidElement<{ children?: ReactNode }>(child)
106
+ ? optionText(child.props.children)
107
+ : String(child)
108
+ )
109
+ .join(' ');
110
+
111
+ const collectOptions = (children: ReactNode): ReactElement<ComboboxOptionProps>[] =>
112
+ Children.toArray(children).flatMap(child =>
113
+ isValidElement<ComboboxOptionProps>(child) && child.type === ComboboxOption
114
+ ? [child]
115
+ : isValidElement<{ children?: ReactNode }>(child)
116
+ ? collectOptions(child.props.children)
117
+ : []
49
118
  );
50
- const selected = options.filter(option => values.includes(option.props.value));
51
- const hasSelection = selected.length > 0;
52
119
 
53
- const handleClick: ComponentPropsWithRef<'div'>['onClick'] = ({ target }) => {
54
- if (!(target instanceof Element)) return;
120
+ @observer
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
+
130
+ static displayName = 'Combobox';
131
+
132
+ @observable accessor query = '';
133
+ @observable accessor current =
134
+ this.componentProps.defaultValue ?? (this.componentProps.multiple ? [] : '');
135
+ @observable accessor visibleOptionCount = 0;
136
+ @observable accessor selectedLabel = '';
137
+
138
+ private menu = createRef<Menu>();
139
+ private optionObserver?: MutationObserver;
140
+
141
+ get values() {
142
+ const value = this.componentProps.value ?? this.current;
143
+
144
+ return Array.isArray(value) ? value : value ? [value] : [];
145
+ }
146
+
147
+ componentDidMount() {
148
+ this.updateAccessibility();
149
+ this.optionObserver = new MutationObserver(this.updateAccessibility);
150
+
151
+ const panel = this.menu.current?.panel.current;
152
+
153
+ if (panel)
154
+ this.optionObserver.observe(panel, {
155
+ childList: true,
156
+ subtree: true,
157
+ characterData: true
158
+ });
159
+ }
160
+
161
+ componentDidUpdate() {
162
+ this.updateAccessibility();
163
+ }
164
+
165
+ componentWillUnmount() {
166
+ this.optionObserver?.disconnect();
167
+ }
168
+
169
+ @action
170
+ private updateAccessibility = () => {
171
+ const panel = this.menu.current?.panel.current;
172
+ const options = [...(panel?.querySelectorAll<HTMLButtonElement>('[data-bs-value]') ?? [])];
173
+ const selected: string[] = [];
174
+ let visible = 0;
175
+
176
+ for (const option of options) {
177
+ const value = option.dataset.bsValue ?? '';
178
+ const text = option.dataset.searchText ?? option.textContent ?? '';
179
+ const matches =
180
+ option.dataset.optionHidden !== 'true' &&
181
+ this.normalize(text).includes(this.normalize(this.query));
182
+ const isSelected = this.values.includes(value);
183
+
184
+ option.setAttribute('role', 'option');
185
+ option.setAttribute('aria-selected', String(isSelected));
186
+ option.classList.toggle('selected', isSelected);
187
+ option.hidden = !matches;
188
+ option.style.display = matches ? '' : 'none';
189
+
190
+ if (matches) visible++;
191
+ if (isSelected) selected.push(option.dataset.label ?? option.textContent ?? '');
192
+ }
193
+ for (const group of panel?.querySelectorAll<HTMLElement>('[role="group"]') ?? []) {
194
+ const matches = [...group.querySelectorAll<HTMLButtonElement>('[data-bs-value]')].some(
195
+ ({ hidden }) => !hidden
196
+ );
197
+ group.hidden = !matches;
198
+ group.style.display = matches ? '' : 'none';
199
+ }
200
+ this.visibleOptionCount = visible;
201
+ this.selectedLabel =
202
+ this.componentProps.multiple && selected.length > 1
203
+ ? `${selected.length} selected`
204
+ : (selected[0] ?? '');
205
+
206
+ panel?.setAttribute('role', 'listbox');
207
+ panel?.setAttribute('aria-multiselectable', String(Boolean(this.componentProps.multiple)));
208
+ panel?.setAttribute(
209
+ 'aria-label',
210
+ this.componentProps['aria-label'] ?? this.componentProps.placeholder ?? 'Options'
211
+ );
212
+ this.menu.current?.trigger.current?.setAttribute('aria-haspopup', 'listbox');
213
+ };
214
+
215
+ @action
216
+ private setCurrent = (value: string | string[]) => (this.current = value);
217
+
218
+ @action
219
+ private handleSearch = ({ currentTarget: { value } }: ChangeEvent<HTMLInputElement>) =>
220
+ (this.query = value);
221
+
222
+ private handleClick = (event: MouseEvent<HTMLDivElement>) => {
223
+ this.componentProps.onClick?.(event);
224
+
225
+ const { target, defaultPrevented } = event;
226
+ if (defaultPrevented || this.componentProps.disabled || !(target instanceof Element))
227
+ return;
55
228
 
56
229
  const option = target.closest<HTMLButtonElement>('[data-bs-value]');
57
- if (!option || !onChange) return;
230
+ if (!option || option.disabled || option.getAttribute('aria-disabled') === 'true') return;
58
231
 
59
- const next = option.dataset.bsValue || '';
60
- const value = multiple
61
- ? values.includes(next)
62
- ? values.filter(item => item !== next)
63
- : [...values, next]
232
+ const next = option.dataset.bsValue ?? '';
233
+ const value = this.componentProps.multiple
234
+ ? this.values.includes(next)
235
+ ? this.values.filter(item => item !== next)
236
+ : [...this.values, next]
64
237
  : next;
238
+ this.componentProps.onChange?.(value);
239
+
240
+ if (this.componentProps.value === undefined) this.setCurrent(value);
241
+ };
242
+
243
+ private normalize = (value: string) => {
244
+ const text = value.toLocaleLowerCase();
65
245
 
66
- onChange(value);
246
+ return this.componentProps.searchNormalize
247
+ ? text.normalize('NFD').replace(/\p{M}/gu, '')
248
+ : text;
67
249
  };
68
250
 
69
- return (
70
- <div {...props} className={classNames('combobox', className)}>
71
- <Menu
72
- label={
73
- <span
74
- className={classNames(
75
- 'combobox-value',
76
- !hasSelection && 'combobox-placeholder'
77
- )}
78
- >
79
- {hasSelection ? selected.map(option => option.props.children) : placeholder}
80
- </span>
81
- }
82
- toggleProps={{
83
- className: 'form-control combobox-toggle',
84
- variant: 'text',
85
- disabled,
86
- 'aria-haspopup': 'listbox',
87
- 'aria-label': placeholder
88
- }}
89
- autoClose={!multiple}
90
- menuClassName={classNames(menuClassName, 'combobox-menu')}
91
- onClick={handleClick}
92
- >
93
- {options.map(option => {
94
- const selected = values.includes(option.props.value);
95
-
96
- return cloneElement(option, {
97
- className: classNames(option.props.className, selected && 'selected'),
98
- 'aria-selected': selected
99
- });
100
- })}
101
- </Menu>
102
- {values.map(item => (
103
- <input key={item} type="hidden" name={name} value={item} />
104
- ))}
105
- </div>
251
+ private matches = (option: ReactElement<ComboboxOptionProps>) =>
252
+ this.normalize(option.props.searchText ?? optionText(option.props.children)).includes(
253
+ this.normalize(this.query)
254
+ );
255
+
256
+ private renderChild = (child: ReactNode): ReactNode => {
257
+ if (!isValidElement<{ children?: ReactNode }>(child)) return child;
258
+
259
+ if (child.type === ComboboxOption) {
260
+ const option = child as ReactElement<ComboboxOptionProps>;
261
+ const selected = this.values.includes(option.props.value);
262
+
263
+ return cloneElement(option, {
264
+ hidden: option.props.hidden || !this.matches(option),
265
+ className: classNames(option.props.className, selected && 'selected'),
266
+ 'aria-selected': selected,
267
+ role: 'option'
268
+ });
269
+ }
270
+ const options = collectOptions(child.props.children);
271
+
272
+ return cloneElement(child, {
273
+ ...(child.type === ComboboxGroup && { hidden: !options.some(this.matches) }),
274
+ children: Children.map(child.props.children, this.renderChild)
275
+ });
276
+ };
277
+
278
+ private renderHiddenInput = (value: string) => (
279
+ <input
280
+ key={value}
281
+ type="hidden"
282
+ name={this.componentProps.name}
283
+ value={value}
284
+ disabled={this.componentProps.disabled}
285
+ />
106
286
  );
107
- };
108
287
 
109
- Combobox.displayName = 'Combobox';
288
+ render() {
289
+ const Root: ElementType = this.componentProps.as ?? 'div';
290
+
291
+ const {
292
+ as: _as,
293
+ className,
294
+ id,
295
+ name: _name,
296
+ value: _value,
297
+ defaultValue: _defaultValue,
298
+ placeholder = 'Select an item…',
299
+ disabled,
300
+ multiple,
301
+ onChange: _onChange,
302
+ onClick: _onClick,
303
+ menuClassName,
304
+ children,
305
+ controlSize,
306
+ search,
307
+ searchNormalize: _searchNormalize,
308
+ searchPlaceholder = 'Search…',
309
+ noResultsText = 'No results found',
310
+ validation,
311
+ ...props
312
+ } = this.componentProps;
313
+ const options = collectOptions(children);
314
+ const selected = options.filter(option => this.values.includes(option.props.value));
315
+ const hasSelection = selected.length > 0 || Boolean(this.selectedLabel);
316
+ const label =
317
+ multiple && selected.length > 1
318
+ ? `${selected.length} selected`
319
+ : (selected[0]?.props.children ?? this.selectedLabel);
320
+ const noResults = this.visibleOptionCount === 0;
321
+
322
+ return (
323
+ <Root {...props} className={classNames('combobox', className)}>
324
+ <Menu
325
+ ref={this.menu}
326
+ className="w-100"
327
+ id={id ? `${id}-combobox` : undefined}
328
+ label={
329
+ <>
330
+ <span
331
+ className={classNames(
332
+ 'combobox-value',
333
+ !hasSelection && 'combobox-placeholder'
334
+ )}
335
+ >
336
+ {hasSelection ? label : placeholder}
337
+ </span>
338
+ <Icon
339
+ name="chevron-down"
340
+ className="combobox-caret"
341
+ aria-hidden="true"
342
+ />
343
+ </>
344
+ }
345
+ toggleProps={{
346
+ id,
347
+ className: classNames(
348
+ 'form-control combobox-toggle',
349
+ controlSize && `form-control-${controlSize}`,
350
+ validation && `is-${validation}`
351
+ ),
352
+ variant: false,
353
+ disabled,
354
+ 'aria-haspopup': 'listbox',
355
+ 'aria-label': this.componentProps['aria-label'] ?? placeholder,
356
+ 'aria-labelledby': this.componentProps['aria-labelledby'],
357
+ 'aria-describedby': this.componentProps['aria-describedby'],
358
+ 'aria-invalid': validation
359
+ ? validation === 'invalid'
360
+ : this.componentProps['aria-invalid']
361
+ }}
362
+ autoClose={!multiple}
363
+ menuClassName={classNames(menuClassName, 'combobox-menu')}
364
+ onClick={this.handleClick}
365
+ >
366
+ {search && (
367
+ <div className="combobox-search">
368
+ <input
369
+ type="search"
370
+ className="form-control combobox-search-input"
371
+ aria-label={searchPlaceholder}
372
+ placeholder={searchPlaceholder}
373
+ autoComplete="off"
374
+ value={this.query}
375
+ onChange={this.handleSearch}
376
+ />
377
+ </div>
378
+ )}
379
+ {Children.map(children, this.renderChild)}
380
+ {search && noResults && (
381
+ <div className="combobox-empty" role="status">
382
+ {noResultsText}
383
+ </div>
384
+ )}
385
+ </Menu>
386
+
387
+ {this.values.length || multiple
388
+ ? this.values.map(this.renderHiddenInput)
389
+ : this.renderHiddenInput('')}
390
+ </Root>
391
+ );
392
+ }
393
+ }
@@ -1,59 +1,89 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { polymorphic } from '../Polymorphic';
5
+ import { FormValidationProps } from './Primitives';
3
6
 
4
7
  const CONTROL_SIZES = {
5
8
  sm: 'form-control-sm',
6
9
  lg: 'form-control-lg'
7
10
  } as const;
8
11
 
9
- export type FormControlProps = ComponentPropsWithRef<'input'> & {
10
- plaintext?: boolean;
11
- ghost?: boolean;
12
- caret?: boolean;
13
- color?: boolean;
14
- controlSize?: 'sm' | 'lg';
15
- };
16
-
17
- export const FormControl: FC<FormControlProps> = ({
18
- className,
19
- plaintext,
20
- ghost,
21
- caret,
22
- color,
23
- controlSize,
24
- ...props
25
- }) => (
26
- <input
27
- {...props}
28
- className={classNames(
29
- ghost ? 'form-ghost' : plaintext ? 'form-control-plaintext' : 'form-control',
30
- !ghost && caret && 'form-control-caret',
31
- !ghost && !plaintext && color && 'form-control-color',
32
- !ghost && !plaintext && controlSize && CONTROL_SIZES[controlSize],
33
- className
34
- )}
35
- />
36
- );
12
+ export type FormControlProps = Omit<ComponentPropsWithRef<'input'>, 'color'> &
13
+ FormValidationProps & {
14
+ plaintext?: boolean;
15
+ ghost?: boolean;
16
+ caret?: boolean;
17
+ color?: boolean;
18
+ controlSize?: 'sm' | 'lg';
19
+ };
37
20
 
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
+ )
46
+ );
38
47
  FormControl.displayName = 'FormControl';
39
48
 
40
- export type FormTextAreaProps = ComponentPropsWithRef<'textarea'>;
49
+ export type FormTextAreaProps = ComponentPropsWithRef<'textarea'> &
50
+ FormValidationProps & {
51
+ controlSize?: 'sm' | 'lg';
52
+ };
41
53
 
42
- export const FormTextArea: FC<FormTextAreaProps> = ({ className, ...props }) => (
43
- <textarea {...props} className={classNames('form-control', className)} />
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
+ )
44
67
  );
45
-
46
68
  FormTextArea.displayName = 'FormTextArea';
47
69
 
48
- export type FormSelectProps = ComponentPropsWithRef<'select'> & {
49
- controlSize?: 'sm' | 'lg';
50
- };
70
+ export type FormSelectProps = ComponentPropsWithRef<'select'> &
71
+ FormValidationProps & {
72
+ controlSize?: 'sm' | 'lg';
73
+ };
51
74
 
52
- export const FormSelect: FC<FormSelectProps> = ({ className, controlSize, ...props }) => (
53
- <select
54
- {...props}
55
- className={classNames('form-control', controlSize && CONTROL_SIZES[controlSize], className)}
56
- />
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
+ )
57
88
  );
58
-
59
89
  FormSelect.displayName = 'FormSelect';