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,55 +1,121 @@
1
1
  'use client';
2
2
 
3
+ import Datepicker, { type DatepickerConfig } from 'bootstrap/js/src/datepicker.js';
3
4
  import classNames from 'classnames';
4
- import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
5
+ import { ComponentPropsWithoutRef, FC, forwardRef, Ref } from 'react';
5
6
 
6
- export type DatePickerProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> & {
7
- enhanced?: boolean;
8
- inline?: boolean;
9
- selectionMode?: 'single' | 'multiple' | 'multiple-ranged';
10
- };
7
+ import { Button, ButtonProps } from '../Button';
8
+ import { Icon } from '../Extension/Icon';
9
+ import { FormPlugin } from './Plugin';
10
+ import { FormValidationProps } from './Primitives';
11
11
 
12
- interface DatePickerComponentProps extends DatePickerProps {
13
- forwardedRef?: Ref<HTMLInputElement>;
14
- }
12
+ export type DatePickerOptions = Partial<DatepickerConfig>;
15
13
 
16
- interface DatepickerInstance {
17
- dispose(): void;
14
+ interface DatePickerSettings {
15
+ options?: DatePickerOptions;
16
+ inline?: boolean;
17
+ selectionMode?: DatepickerConfig['selectionMode'];
18
+ displayMonthsCount?: DatepickerConfig['displayMonthsCount'];
19
+ selectedDates?: string[];
20
+ firstWeekday?: DatepickerConfig['firstWeekday'];
21
+ placement?: DatepickerConfig['placement'];
22
+ datepickerTheme?: string;
23
+ onDatesChange?: (dates: string[]) => unknown;
18
24
  }
19
25
 
20
- class DatePickerComponent extends Component<DatePickerComponentProps> {
21
- private input?: HTMLInputElement;
22
- private instance?: DatepickerInstance;
23
- private mounted = false;
26
+ export type DatePickerProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> &
27
+ DatePickerSettings &
28
+ FormValidationProps & {
29
+ enhanced?: boolean;
30
+ ghost?: boolean;
31
+ controlSize?: 'sm' | 'lg';
32
+ };
24
33
 
25
- componentDidMount() {
26
- this.mounted = true;
27
- this.initialize();
28
- }
34
+ export type DatePickerButtonProps = Extract<ButtonProps, { href?: never }> &
35
+ DatePickerSettings & {
36
+ leadingIcon?: string;
37
+ };
38
+ export type DatePickerInlineProps = ComponentPropsWithoutRef<'div'> & DatePickerSettings;
29
39
 
30
- componentWillUnmount() {
31
- this.mounted = false;
32
- const { instance } = this;
33
- this.instance = undefined;
40
+ interface DatePickerComponentProps extends DatePickerProps {
41
+ kind?: 'input' | 'button' | 'div';
42
+ hostProps?: DatePickerButtonProps | DatePickerInlineProps;
43
+ leadingIcon?: string;
44
+ forwardedRef?: Ref<HTMLElement>;
45
+ }
34
46
 
35
- queueMicrotask(() => instance?.dispose());
36
- }
47
+ class DatePickerComponent extends FormPlugin<
48
+ DatePickerComponentProps,
49
+ Pick<Datepicker, 'dispose'>,
50
+ HTMLElement
51
+ > {
52
+ protected configurationChanged = (previous: DatePickerComponentProps) =>
53
+ previous.options !== this.props.options ||
54
+ previous.enhanced !== this.props.enhanced ||
55
+ previous.inline !== this.props.inline ||
56
+ previous.selectionMode !== this.props.selectionMode ||
57
+ previous.displayMonthsCount !== this.props.displayMonthsCount ||
58
+ previous.firstWeekday !== this.props.firstWeekday ||
59
+ previous.placement !== this.props.placement ||
60
+ previous.datepickerTheme !== this.props.datepickerTheme ||
61
+ previous.min !== this.props.min ||
62
+ previous.max !== this.props.max ||
63
+ JSON.stringify(previous.selectedDates) !== JSON.stringify(this.props.selectedDates);
37
64
 
38
- private initialize = async () => {
39
- if (!this.props.enhanced) return;
65
+ protected load = async () => {
66
+ const { enhanced, kind = 'input' } = this.props;
67
+ if (!enhanced && kind === 'input') return () => ({ dispose: () => undefined });
68
+
69
+ const { ReactDatepicker } = await import('./DatePickerPlugin');
70
+ const {
71
+ options,
72
+ inline,
73
+ selectionMode,
74
+ min,
75
+ max,
76
+ displayMonthsCount,
77
+ selectedDates,
78
+ firstWeekday,
79
+ placement,
80
+ datepickerTheme
81
+ } = this.props;
82
+ const config: DatePickerOptions = {
83
+ ...options,
84
+ ...(inline !== undefined && { inline }),
85
+ ...(selectionMode !== undefined && { selectionMode }),
86
+ ...(min !== undefined && { dateMin: String(min) as DatepickerConfig['dateMin'] }),
87
+ ...(max !== undefined && { dateMax: String(max) as DatepickerConfig['dateMax'] }),
88
+ ...(displayMonthsCount !== undefined && { displayMonthsCount }),
89
+ ...(selectedDates !== undefined && { selectedDates }),
90
+ ...(firstWeekday !== undefined && { firstWeekday }),
91
+ ...(placement !== undefined && { placement }),
92
+ ...(datepickerTheme !== undefined && { datepickerTheme })
93
+ };
40
94
 
41
- const { default: Datepicker } = await import('bootstrap/js/src/datepicker.js');
95
+ return (element: HTMLElement) => {
96
+ const children = [...element.childNodes];
97
+ const instance = ReactDatepicker.getOrCreateInstance(element, config);
98
+ element.addEventListener('change.bs.datepicker', this.handleDatesChange);
42
99
 
43
- if (this.mounted && this.input) this.instance = Datepicker.getOrCreateInstance(this.input);
100
+ return {
101
+ dispose: () => {
102
+ element.removeEventListener('change.bs.datepicker', this.handleDatesChange);
103
+ instance.dispose();
104
+ if (this.props.kind === 'div') element.replaceChildren(...children);
105
+ }
106
+ };
107
+ };
44
108
  };
45
109
 
46
- private setInputRef = (input: HTMLInputElement | null) => {
47
- this.input = input || undefined;
110
+ private handleDatesChange = (event: Event) =>
111
+ this.props.onDatesChange?.((event as Event & { dates: string[] }).dates);
48
112
 
113
+ private setRef = (element: HTMLElement | null) => {
114
+ this.element.current = element;
49
115
  const { forwardedRef } = this.props;
50
116
 
51
- if (typeof forwardedRef === 'function') forwardedRef(input);
52
- else if (forwardedRef) forwardedRef.current = input;
117
+ if (typeof forwardedRef === 'function') forwardedRef(element);
118
+ else if (forwardedRef) forwardedRef.current = element;
53
119
  };
54
120
 
55
121
  render() {
@@ -60,23 +126,69 @@ class DatePickerComponent extends Component<DatePickerComponentProps> {
60
126
  selectionMode,
61
127
  min,
62
128
  max,
129
+ options: _options,
130
+ displayMonthsCount,
131
+ selectedDates,
132
+ firstWeekday,
133
+ placement,
134
+ datepickerTheme,
135
+ onDatesChange: _onDatesChange,
136
+ ghost,
137
+ controlSize,
138
+ validation,
139
+ kind = 'input',
140
+ hostProps,
141
+ leadingIcon,
63
142
  forwardedRef: _forwardedRef,
64
143
  ...props
65
144
  } = this.props;
145
+ const attributes = {
146
+ 'data-bs-toggle': enhanced || kind !== 'input' ? 'datepicker' : undefined,
147
+ 'data-bs-inline': inline || kind === 'div' || undefined,
148
+ 'data-bs-selection-mode': selectionMode,
149
+ 'data-bs-display-months-count': displayMonthsCount,
150
+ 'data-bs-selected-dates': selectedDates ? JSON.stringify(selectedDates) : undefined,
151
+ 'data-bs-first-weekday': firstWeekday,
152
+ 'data-bs-placement': placement,
153
+ 'data-bs-datepicker-theme': datepickerTheme,
154
+ 'data-bs-date-min': enhanced ? min : undefined,
155
+ 'data-bs-date-max': enhanced ? max : undefined
156
+ };
157
+
158
+ if (kind === 'button') {
159
+ const { children, ...buttonProps } = hostProps as ButtonProps;
160
+
161
+ return (
162
+ <Button {...buttonProps} {...attributes} ref={this.setRef}>
163
+ {leadingIcon && <Icon name={leadingIcon} aria-hidden="true" />}
164
+ <span data-bs-datepicker-display="">{children}</span>
165
+ </Button>
166
+ );
167
+ }
168
+ if (kind === 'div')
169
+ return (
170
+ <div
171
+ {...(hostProps as ComponentPropsWithoutRef<'div'>)}
172
+ {...attributes}
173
+ ref={this.setRef}
174
+ />
175
+ );
66
176
 
67
177
  return (
68
178
  <input
69
179
  {...props}
70
- ref={this.setInputRef}
71
- className={classNames('form-control', className)}
180
+ {...attributes}
181
+ ref={this.setRef}
182
+ className={classNames(
183
+ ghost ? 'form-ghost' : 'form-control',
184
+ controlSize && `form-control-${controlSize}`,
185
+ validation && `is-${validation}`,
186
+ className
187
+ )}
188
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
72
189
  type={enhanced ? 'text' : 'date'}
73
190
  min={min}
74
191
  max={max}
75
- data-bs-toggle={enhanced ? 'datepicker' : undefined}
76
- data-bs-date-min={enhanced ? min : undefined}
77
- data-bs-date-max={enhanced ? max : undefined}
78
- data-bs-inline={enhanced ? inline || undefined : undefined}
79
- data-bs-selection-mode={enhanced ? selectionMode : undefined}
80
192
  />
81
193
  );
82
194
  }
@@ -87,3 +199,82 @@ export const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>((props,
87
199
  ));
88
200
 
89
201
  DatePicker.displayName = 'DatePicker';
202
+
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
+ {...{
229
+ options,
230
+ inline,
231
+ selectionMode,
232
+ displayMonthsCount,
233
+ selectedDates,
234
+ firstWeekday,
235
+ placement,
236
+ datepickerTheme,
237
+ onDatesChange
238
+ }}
239
+ />
240
+ )
241
+ );
242
+
243
+ DatePickerButton.displayName = 'DatePickerButton';
244
+
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
+ {...{
266
+ options,
267
+ inline,
268
+ selectionMode,
269
+ displayMonthsCount,
270
+ selectedDates,
271
+ firstWeekday,
272
+ placement,
273
+ datepickerTheme,
274
+ onDatesChange
275
+ }}
276
+ />
277
+ )
278
+ );
279
+
280
+ DatePickerInline.displayName = 'DatePickerInline';
@@ -0,0 +1,37 @@
1
+ import Datepicker from 'bootstrap/js/src/datepicker.js';
2
+
3
+ export class ReactDatepicker extends Datepicker {
4
+ private changingVisibility = false;
5
+
6
+ async show() {
7
+ if (this.changingVisibility) return;
8
+
9
+ this.changingVisibility = true;
10
+ try {
11
+ await super.show();
12
+ } finally {
13
+ this.changingVisibility = false;
14
+ }
15
+ }
16
+
17
+ async hide() {
18
+ if (this.changingVisibility) return;
19
+
20
+ this.changingVisibility = true;
21
+ try {
22
+ await super.hide();
23
+ } finally {
24
+ this.changingVisibility = false;
25
+ }
26
+ }
27
+
28
+ dispose() {
29
+ // Calendar Pro normally replaces its trigger with a clone on destroy.
30
+ // Keep React's original node and its ref/event bindings intact.
31
+ const element = this._positionElement;
32
+ const replacement = this._calendar?.context.originalElement;
33
+
34
+ super.dispose();
35
+ replacement?.replaceWith(element);
36
+ }
37
+ }
@@ -1,10 +1,12 @@
1
1
  import classNames from 'classnames';
2
2
  import { ComponentPropsWithRef, FC } from 'react';
3
3
 
4
- export type FormTextProps = ComponentPropsWithRef<'small'>;
4
+ export type FormTextProps = ComponentPropsWithRef<'small'> & {
5
+ block?: boolean;
6
+ };
5
7
 
6
- export const FormText: FC<FormTextProps> = ({ className, ...props }) => (
7
- <small {...props} className={classNames('form-text', className)} />
8
+ export const FormText: FC<FormTextProps> = ({ className, block, ...props }) => (
9
+ <small {...props} className={classNames('form-text', block && 'd-block', className)} />
8
10
  );
9
11
 
10
12
  FormText.displayName = 'FormText';
@@ -22,7 +24,11 @@ export const FormFeedback: FC<FormFeedbackProps> = ({
22
24
  }) => (
23
25
  <div
24
26
  {...props}
25
- className={classNames(tooltip ? `${type}-tooltip` : `${type}-feedback`, className)}
27
+ className={classNames(
28
+ tooltip && 'tooltip',
29
+ tooltip ? `${type}-tooltip` : `${type}-feedback`,
30
+ className
31
+ )}
26
32
  />
27
33
  );
28
34
 
@@ -1,15 +1,32 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { Children, ComponentPropsWithRef, FC, isValidElement, ReactNode } from 'react';
3
+
4
+ import { FormLabel } from './Primitives';
3
5
 
4
6
  export type FormFloatingLabelProps = ComponentPropsWithRef<'div'> & {
5
7
  always?: boolean;
6
8
  };
7
9
 
8
- export const FormFloatingLabel: FC<FormFloatingLabelProps> = ({ className, always, ...props }) => (
9
- <div
10
- {...props}
11
- className={classNames('form-floating', always && 'form-floating-always', className)}
12
- />
13
- );
10
+ const isLabel = (child: ReactNode) =>
11
+ isValidElement(child) && (child.type === 'label' || child.type === FormLabel);
12
+
13
+ export const FormFloatingLabel: FC<FormFloatingLabelProps> = ({
14
+ className,
15
+ always,
16
+ children,
17
+ ...props
18
+ }) => {
19
+ const items = Children.toArray(children);
20
+
21
+ return (
22
+ <div
23
+ {...props}
24
+ className={classNames('form-floating', always && 'form-floating-always', className)}
25
+ >
26
+ {items.filter(isLabel)}
27
+ {items.filter(item => !isLabel(item))}
28
+ </div>
29
+ );
30
+ };
14
31
 
15
32
  FormFloatingLabel.displayName = 'FormFloatingLabel';
@@ -1,5 +1,18 @@
1
+ 'use client';
2
+
1
3
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
4
+ import { observer } from 'mobx-react';
5
+ import {
6
+ cloneElement,
7
+ ComponentPropsWithRef,
8
+ FC,
9
+ FocusEvent,
10
+ KeyboardEventHandler,
11
+ ReactElement
12
+ } from 'react';
13
+
14
+ import { Button, ButtonProps } from '../Button';
15
+ import { Menu, MenuProps } from '../Menu';
3
16
 
4
17
  export type InputGroupProps = ComponentPropsWithRef<'div'> & {
5
18
  size?: 'sm' | 'lg';
@@ -14,10 +27,147 @@ export const InputGroup: FC<InputGroupProps> = ({ className, size, ...props }) =
14
27
 
15
28
  InputGroup.displayName = 'InputGroup';
16
29
 
17
- export type InputGroupTextProps = ComponentPropsWithRef<'span'>;
30
+ export type InputGroupTextProps =
31
+ | (ComponentPropsWithRef<'span'> & { htmlFor?: never })
32
+ | (ComponentPropsWithRef<'label'> & { htmlFor: string });
18
33
 
19
- export const InputGroupText: FC<InputGroupTextProps> = ({ className, ...props }) => (
20
- <span {...props} className={classNames('input-group-text', className)} />
21
- );
34
+ const isLabelAddon = (
35
+ props: InputGroupTextProps
36
+ ): props is ComponentPropsWithRef<'label'> & { htmlFor: string } =>
37
+ typeof props.htmlFor === 'string';
38
+
39
+ export const InputGroupText: FC<InputGroupTextProps> = ({ className, ...props }) => {
40
+ const addonClassName = classNames('input-group-text', className);
41
+
42
+ return isLabelAddon(props) ? (
43
+ <label {...props} className={addonClassName} />
44
+ ) : (
45
+ <span {...props} className={addonClassName} />
46
+ );
47
+ };
22
48
 
23
49
  InputGroupText.displayName = 'InputGroupText';
50
+
51
+ export type InputGroupButtonProps = ButtonProps;
52
+
53
+ export const InputGroupButton: FC<InputGroupButtonProps> = ({ className, ...props }) => (
54
+ <Button {...props} className={classNames('input-group-btn', className)} />
55
+ );
56
+
57
+ InputGroupButton.displayName = 'InputGroupButton';
58
+
59
+ export interface InputGroupIgnoreProps {
60
+ children: ReactElement<{ className?: string }>;
61
+ }
62
+
63
+ export const InputGroupIgnore: FC<InputGroupIgnoreProps> = ({ children }) =>
64
+ cloneElement(children, {
65
+ className: classNames('input-group-ignore', children.props.className)
66
+ });
67
+
68
+ InputGroupIgnore.displayName = 'InputGroupIgnore';
69
+
70
+ export interface InputGroupMenuProps extends MenuProps {
71
+ split?: boolean;
72
+ }
73
+
74
+ export class InputGroupMenu extends Menu {
75
+ declare props: InputGroupMenuProps;
76
+
77
+ static displayName = 'InputGroupMenu';
78
+
79
+ componentDidMount() {
80
+ this.root.current = this.trigger.current?.closest<HTMLDivElement>('.input-group') ?? null;
81
+ super.componentDidMount();
82
+ }
83
+
84
+ handlePanelClick: ComponentPropsWithRef<'div'>['onClick'] = event => {
85
+ this.props.onClick?.(event);
86
+
87
+ if (!event.defaultPrevented) this.handleSelect(event);
88
+ };
89
+
90
+ handleTriggerKeyDown: KeyboardEventHandler<HTMLElement> = this.handleKeyDown;
91
+
92
+ handleBlur = (event: FocusEvent<HTMLElement>) => {
93
+ this.props.onBlur?.(event as FocusEvent<HTMLDivElement>);
94
+
95
+ const { autoClose = true } = this.props;
96
+ if (
97
+ !event.defaultPrevented &&
98
+ autoClose !== false &&
99
+ autoClose !== 'inside' &&
100
+ !this.root.current?.contains(event.relatedTarget)
101
+ )
102
+ this.setOpen(false);
103
+ };
104
+
105
+ render() {
106
+ return <InputGroupMenuView {...this.props} owner={this} />;
107
+ }
108
+ }
109
+
110
+ const InputGroupMenuView = observer<FC<InputGroupMenuProps & { owner: InputGroupMenu }>>(
111
+ ({
112
+ owner: {
113
+ open,
114
+ trigger,
115
+ panel,
116
+ handleToggle,
117
+ handleTriggerKeyDown,
118
+ handleBlur,
119
+ handlePanelClick,
120
+ handleKeyDown
121
+ },
122
+ id,
123
+ label,
124
+ split,
125
+ toggleProps,
126
+ className,
127
+ children,
128
+ align = 'end',
129
+ menuClassName
130
+ }) => (
131
+ <>
132
+ <Button
133
+ {...toggleProps}
134
+ ref={trigger}
135
+ className={classNames(
136
+ 'input-group-btn',
137
+ split && 'menu-toggle-split',
138
+ toggleProps?.className,
139
+ className
140
+ )}
141
+ aria-label={
142
+ split
143
+ ? (toggleProps?.['aria-label'] ?? 'Toggle menu')
144
+ : toggleProps?.['aria-label']
145
+ }
146
+ aria-expanded={open}
147
+ aria-controls={id ? `${id}-menu` : undefined}
148
+ onClick={handleToggle}
149
+ onKeyDown={handleTriggerKeyDown}
150
+ onBlur={handleBlur}
151
+ >
152
+ {label}
153
+ </Button>
154
+
155
+ <div
156
+ ref={panel}
157
+ id={id ? `${id}-menu` : undefined}
158
+ className={classNames(
159
+ 'menu top-100',
160
+ align === 'end' ? 'end-0' : 'start-0',
161
+ open && 'show',
162
+ menuClassName
163
+ )}
164
+ hidden={!open}
165
+ onClick={handlePanelClick}
166
+ onKeyDown={handleKeyDown}
167
+ onBlur={handleBlur}
168
+ >
169
+ {children}
170
+ </div>
171
+ </>
172
+ )
173
+ );