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