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,38 +1,57 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
3
-
4
- export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'> & {
5
- end?: boolean;
6
- size?: 'sm' | 'lg';
7
- htmlFor?: string;
8
- };
9
-
10
- export const FormAdornment: FC<FormAdornmentProps> = ({ className, end, size, ...props }) => (
11
- <label
12
- {...props}
13
- className={classNames(
14
- 'form-control form-adorn',
15
- end && 'form-adorn-end',
16
- size && `form-adorn-${size}`,
17
- className
18
- )}
19
- />
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { Icon, IconProps } from '../Extension/Icon';
5
+ import { polymorphic } from '../Polymorphic';
6
+ import { FormValidationProps } from './Primitives';
7
+
8
+ export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'> &
9
+ FormValidationProps & {
10
+ end?: boolean;
11
+ size?: 'sm' | 'lg';
12
+ htmlFor?: string;
13
+ };
14
+
15
+ export const FormAdornment = polymorphic<FormAdornmentProps>(
16
+ ({ as: Root = 'label', className, end, size, validation, ...props }) => (
17
+ <Root
18
+ {...props}
19
+ className={classNames(
20
+ 'form-control form-adorn',
21
+ end && 'form-adorn-end',
22
+ size && `form-control-${size}`,
23
+ validation && `is-${validation}`,
24
+ className
25
+ )}
26
+ />
27
+ )
20
28
  );
21
-
22
29
  FormAdornment.displayName = 'FormAdornment';
23
30
 
24
31
  export type FormAdornmentTextProps = ComponentPropsWithRef<'span'>;
25
32
 
26
- export const FormAdornmentText: FC<FormAdornmentTextProps> = ({ className, ...props }) => (
27
- <span {...props} className={classNames('form-adorn-text', className)} />
33
+ export const FormAdornmentText = polymorphic<FormAdornmentTextProps>(
34
+ ({ as: Root = 'span', className, ...props }) => (
35
+ <Root {...props} className={classNames('form-adorn-text', className)} />
36
+ )
28
37
  );
29
-
30
38
  FormAdornmentText.displayName = 'FormAdornmentText';
31
39
 
32
- export type FormGhostProps = ComponentPropsWithRef<'input'>;
40
+ export const FormAdornmentIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
41
+ <Icon as={RootAs} {...props} className={classNames('form-adorn-icon', className)} />
42
+ ));
33
43
 
34
- export const FormGhost: FC<FormGhostProps> = ({ className, ...props }) => (
35
- <input {...props} className={classNames('form-ghost', className)} />
36
- );
44
+ FormAdornmentIcon.displayName = 'FormAdornmentIcon';
37
45
 
46
+ export type FormGhostProps = ComponentPropsWithRef<'input'> & FormValidationProps;
47
+
48
+ export const FormGhost = polymorphic<FormGhostProps>(
49
+ ({ as: Root = 'input', className, validation, ...props }) => (
50
+ <Root
51
+ {...props}
52
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
53
+ className={classNames('form-ghost', validation && `is-${validation}`, className)}
54
+ />
55
+ )
56
+ );
38
57
  FormGhost.displayName = 'FormGhost';
@@ -4,14 +4,17 @@ import classNames from 'classnames';
4
4
  import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
5
5
 
6
6
  import type { ComponentTheme } from '../Button';
7
+ import { AsProps, polymorphic } from '../Polymorphic';
8
+ import { FormValidationProps } from './Primitives';
7
9
 
8
- export type CheckboxProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'size'> & {
9
- size?: 'sm' | 'lg';
10
- theme?: ComponentTheme;
11
- indeterminate?: boolean;
12
- };
10
+ export type CheckboxProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'size'> &
11
+ FormValidationProps & {
12
+ size?: 'sm' | 'lg';
13
+ theme?: ComponentTheme;
14
+ indeterminate?: boolean;
15
+ };
13
16
 
14
- interface CheckboxComponentProps extends CheckboxProps {
17
+ interface CheckboxComponentProps extends CheckboxProps, AsProps {
15
18
  forwardedRef?: Ref<HTMLInputElement>;
16
19
  }
17
20
 
@@ -41,24 +44,28 @@ class CheckboxComponent extends Component<CheckboxComponentProps> {
41
44
 
42
45
  render() {
43
46
  const {
47
+ as: Root = 'input',
44
48
  className,
45
49
  size,
46
50
  theme,
51
+ validation,
47
52
  indeterminate,
48
53
  forwardedRef: _forwardedRef,
49
54
  ...props
50
55
  } = this.props;
51
56
 
52
57
  return (
53
- <input
58
+ <Root
54
59
  {...props}
55
60
  ref={this.setInputRef}
56
61
  type="checkbox"
57
- aria-checked={indeterminate ? 'mixed' : undefined}
62
+ aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
63
+ aria-checked={indeterminate ? 'mixed' : props['aria-checked']}
58
64
  className={classNames(
59
65
  'check',
60
66
  size && `check-${size}`,
61
67
  theme && `theme-${theme}`,
68
+ validation && `is-${validation}`,
62
69
  className
63
70
  )}
64
71
  />
@@ -66,8 +73,10 @@ class CheckboxComponent extends Component<CheckboxComponentProps> {
66
73
  }
67
74
  }
68
75
 
69
- export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, forwardedRef) => (
70
- <CheckboxComponent {...props} forwardedRef={forwardedRef} />
71
- ));
76
+ export const Checkbox = polymorphic<CheckboxProps & { ref?: Ref<HTMLInputElement> }>(
77
+ forwardRef<HTMLInputElement, CheckboxProps & AsProps>((props, forwardedRef) => (
78
+ <CheckboxComponent {...props} forwardedRef={forwardedRef} />
79
+ ))
80
+ );
72
81
 
73
82
  Checkbox.displayName = 'Checkbox';
@@ -0,0 +1,129 @@
1
+ 'use client';
2
+
3
+ import type Chips from 'bootstrap/js/src/chips.js';
4
+ import classNames from 'classnames';
5
+ import { ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
6
+ import { renderToStaticMarkup } from 'react-dom/server';
7
+
8
+ import { ComponentTheme } from '../Button';
9
+ import { Icon } from '../Extension/Icon';
10
+ import { AsProps, polymorphic } from '../Polymorphic';
11
+ import { FormPlugin } from './Plugin';
12
+ import { FormValidationProps } from './Primitives';
13
+
14
+ export type ChipInputProps = ComponentPropsWithoutRef<'div'> &
15
+ FormValidationProps & {
16
+ theme?: ComponentTheme;
17
+ separator?: string | null;
18
+ allowDuplicates?: boolean;
19
+ maxChips?: number | null;
20
+ createOnBlur?: boolean;
21
+ dismissible?: boolean;
22
+ placeholder?: string;
23
+ onValuesChange?: (values: string[]) => unknown;
24
+ };
25
+
26
+ interface ChipInputComponentProps extends ChipInputProps, AsProps {
27
+ forwardedRef?: Ref<HTMLDivElement>;
28
+ }
29
+
30
+ class ChipInputComponent extends FormPlugin<ChipInputComponentProps, Pick<Chips, 'dispose'>> {
31
+ protected configurationChanged = (previous: ChipInputComponentProps) =>
32
+ previous.separator !== this.props.separator ||
33
+ previous.allowDuplicates !== this.props.allowDuplicates ||
34
+ previous.maxChips !== this.props.maxChips ||
35
+ previous.createOnBlur !== this.props.createOnBlur ||
36
+ previous.dismissible !== this.props.dismissible ||
37
+ previous.placeholder !== this.props.placeholder;
38
+
39
+ protected load = async () => {
40
+ const [{ default: Plugin }, { default: EventHandler }] = await Promise.all([
41
+ import('bootstrap/js/src/chips.js'),
42
+ import('bootstrap/js/src/dom/event-handler.js')
43
+ ]);
44
+ const {
45
+ separator = ',',
46
+ allowDuplicates = false,
47
+ maxChips = null,
48
+ createOnBlur = true,
49
+ dismissible = true,
50
+ placeholder = ''
51
+ } = this.props;
52
+
53
+ return (element: HTMLDivElement) => {
54
+ const instance = Plugin.getOrCreateInstance(element, {
55
+ separator,
56
+ allowDuplicates,
57
+ maxChips,
58
+ createOnBlur,
59
+ dismissible,
60
+ placeholder,
61
+ dismissIcon: renderToStaticMarkup(<Icon name="x-lg" aria-hidden="true" />)
62
+ });
63
+ element.addEventListener('change.bs.chips', this.handleValuesChange);
64
+
65
+ return {
66
+ dispose: () => {
67
+ element.removeEventListener('change.bs.chips', this.handleValuesChange);
68
+ EventHandler.off(element, '.bs.chips');
69
+ instance.dispose();
70
+ }
71
+ };
72
+ };
73
+ };
74
+
75
+ private handleValuesChange = (event: Event) =>
76
+ this.props.onValuesChange?.((event as Event & { values: string[] }).values);
77
+
78
+ private setRef = (element: HTMLDivElement | null) => {
79
+ this.element.current = element;
80
+ const { forwardedRef } = this.props;
81
+
82
+ if (typeof forwardedRef === 'function') forwardedRef(element);
83
+ else if (forwardedRef) forwardedRef.current = element;
84
+ };
85
+
86
+ render() {
87
+ const {
88
+ as: Root = 'div',
89
+ className,
90
+ theme,
91
+ separator,
92
+ allowDuplicates,
93
+ maxChips,
94
+ createOnBlur,
95
+ dismissible: _dismissible,
96
+ placeholder: _placeholder,
97
+ onValuesChange: _onValuesChange,
98
+ forwardedRef: _forwardedRef,
99
+ validation,
100
+ ...props
101
+ } = this.props;
102
+
103
+ return (
104
+ <Root
105
+ {...props}
106
+ ref={this.setRef}
107
+ className={classNames(
108
+ 'chip-input',
109
+ theme && `theme-${theme}`,
110
+ validation && `is-${validation}`,
111
+ className
112
+ )}
113
+ data-bs-chips=""
114
+ data-bs-separator={separator}
115
+ data-bs-allow-duplicates={allowDuplicates}
116
+ data-bs-max-chips={maxChips}
117
+ data-bs-create-on-blur={createOnBlur}
118
+ />
119
+ );
120
+ }
121
+ }
122
+
123
+ export const ChipInput = polymorphic<ChipInputProps & { ref?: Ref<HTMLDivElement> }>(
124
+ forwardRef<HTMLDivElement, ChipInputProps & AsProps>((props, forwardedRef) => (
125
+ <ChipInputComponent {...props} forwardedRef={forwardedRef} />
126
+ ))
127
+ );
128
+
129
+ ChipInput.displayName = 'ChipInput';
@@ -1,51 +1,71 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
3
 
4
- import type { ComponentTheme } from '../Button';
4
+ import { ComponentTheme } from '../Button';
5
+ import { Icon, IconProps } from '../Extension/Icon';
6
+ import { polymorphic } from '../Polymorphic';
5
7
 
6
8
  export type ChipProps = ComponentPropsWithRef<'button'> & {
7
9
  active?: boolean;
8
10
  theme?: ComponentTheme;
9
11
  };
10
12
 
11
- export const Chip: FC<ChipProps> = ({ className, active, disabled, theme, ...props }) => (
12
- <button
13
- {...props}
14
- className={classNames('chip', active && 'active', theme && `theme-${theme}`, className)}
15
- type="button"
16
- aria-pressed={active}
17
- disabled={disabled}
18
- />
13
+ export const Chip = polymorphic<ChipProps>(
14
+ ({ as: Root = 'button', className, active, theme, ...props }) => (
15
+ <Root
16
+ {...props}
17
+ className={classNames('chip', { active }, theme && `theme-${theme}`, className)}
18
+ type="button"
19
+ aria-pressed={active}
20
+ />
21
+ )
19
22
  );
20
-
21
23
  Chip.displayName = 'Chip';
22
24
 
23
- export type ChipInputProps = ComponentPropsWithRef<'div'> & {
24
- theme?: ComponentTheme;
25
- separator?: string;
26
- allowDuplicates?: boolean;
27
- maxChips?: number;
28
- createOnBlur?: boolean;
29
- };
25
+ export const ChipIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
26
+ <Icon as={RootAs} {...props} className={classNames('chip-icon', className)} />
27
+ ));
30
28
 
31
- export const ChipInput: FC<ChipInputProps> = ({
32
- className,
33
- theme,
34
- separator,
35
- allowDuplicates,
36
- maxChips,
37
- createOnBlur,
38
- ...props
39
- }) => (
40
- <div
41
- {...props}
42
- className={classNames('chip-input', theme && `theme-${theme}`, className)}
43
- data-bs-chips=""
44
- data-bs-separator={separator}
45
- data-bs-allow-duplicates={allowDuplicates}
46
- data-bs-max-chips={maxChips}
47
- data-bs-create-on-blur={createOnBlur}
48
- />
29
+ ChipIcon.displayName = 'ChipIcon';
30
+
31
+ export const ChipImage = polymorphic<ComponentPropsWithRef<'img'>>(
32
+ ({ as: Root = 'img', className, alt = '', ...props }) => (
33
+ <Root {...props} alt={alt} className={classNames('chip-img', className)} />
34
+ )
49
35
  );
50
36
 
51
- ChipInput.displayName = 'ChipInput';
37
+ ChipImage.displayName = 'ChipImage';
38
+
39
+ export const ChipDismiss = polymorphic<ComponentPropsWithRef<'button'>>(
40
+ ({ as: Root = 'button', className, children, 'aria-label': label = 'Remove', ...props }) => (
41
+ <Root
42
+ {...props}
43
+ type="button"
44
+ aria-label={label}
45
+ className={classNames('chip-dismiss', className)}
46
+ >
47
+ {children ?? <Icon name="x-lg" aria-hidden="true" />}
48
+ </Root>
49
+ )
50
+ );
51
+ ChipDismiss.displayName = 'ChipDismiss';
52
+
53
+ export type ChipTokenProps = ComponentPropsWithRef<'span'> & Pick<ChipProps, 'active' | 'theme'>;
54
+
55
+ export const ChipToken = polymorphic<ChipTokenProps>(
56
+ ({ as: Root = 'span', className, active, theme, ...props }) => (
57
+ <Root
58
+ {...props}
59
+ tabIndex={props.tabIndex ?? 0}
60
+ className={classNames('chip', { active }, theme && `theme-${theme}`, className)}
61
+ />
62
+ )
63
+ );
64
+ ChipToken.displayName = 'ChipToken';
65
+
66
+ export const ChipInputLabel = polymorphic<ComponentPropsWithRef<'label'>>(
67
+ ({ as: Root = 'label', className, ...props }) => (
68
+ <Root {...props} className={classNames('chip-input-label', className)} />
69
+ )
70
+ );
71
+ ChipInputLabel.displayName = 'ChipInputLabel';