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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/AGENTS.md +12 -3
  2. package/ReadMe.md +34 -6
  3. package/dist/index.d.mts +313 -230
  4. package/dist/index.d.ts +313 -230
  5. package/dist/index.js +16 -16
  6. package/dist/index.mjs +15 -15
  7. package/dist/style.css +0 -3
  8. package/package.json +13 -13
  9. package/source/Accordion.tsx +61 -37
  10. package/source/Alert.tsx +30 -15
  11. package/source/Avatar.tsx +55 -50
  12. package/source/Badge.tsx +16 -16
  13. package/source/Breadcrumb.tsx +36 -22
  14. package/source/Button.tsx +63 -69
  15. package/source/ButtonGroup.tsx +21 -25
  16. package/source/Card.tsx +67 -59
  17. package/source/Carousel/index.tsx +22 -21
  18. package/source/CloseButton.tsx +20 -15
  19. package/source/Collapse.tsx +74 -19
  20. package/source/Drawer.tsx +40 -17
  21. package/source/Extension/ClickBoundary.tsx +24 -5
  22. package/source/Extension/CodeBlock.tsx +64 -0
  23. package/source/Extension/Countdown.tsx +21 -9
  24. package/source/Extension/Editor.tsx +53 -18
  25. package/source/Extension/EditorHTML.tsx +7 -3
  26. package/source/Extension/HorizontalMarquee/index.tsx +69 -45
  27. package/source/Extension/Icon.tsx +15 -14
  28. package/source/Extension/Loading.tsx +20 -17
  29. package/source/Extension/MonthCalendar.tsx +26 -10
  30. package/source/Extension/OverlayBox.tsx +28 -15
  31. package/source/Extension/PageNav.tsx +16 -7
  32. package/source/Extension/ScrollNav/Scroller.tsx +21 -5
  33. package/source/Extension/ScrollNav/index.tsx +32 -7
  34. package/source/Extension/Select.tsx +12 -11
  35. package/source/Extension/SpinnerButton.tsx +19 -24
  36. package/source/Extension/TableSpinner.tsx +10 -14
  37. package/source/Extension/TextTruncate/index.tsx +17 -13
  38. package/source/Extension/Time.tsx +7 -5
  39. package/source/Extension/TimeDistance.tsx +22 -18
  40. package/source/Extension/Timeline/index.tsx +37 -34
  41. package/source/Extension/TypeEcho/Content.tsx +79 -14
  42. package/source/Extension/TypeEcho/index.tsx +13 -5
  43. package/source/Extension/UserRank/Address.tsx +17 -15
  44. package/source/Extension/UserRank/index.tsx +79 -84
  45. package/source/Extension/VerticalMarquee/index.tsx +14 -16
  46. package/source/Extension/ZodiacBar.tsx +40 -32
  47. package/source/Form/Adorn.tsx +30 -32
  48. package/source/Form/Checkbox.tsx +9 -5
  49. package/source/Form/ChipInput.tsx +9 -5
  50. package/source/Form/Chips.tsx +41 -39
  51. package/source/Form/Combobox.tsx +80 -61
  52. package/source/Form/Control.tsx +53 -58
  53. package/source/Form/DatePicker.tsx +74 -65
  54. package/source/Form/Feedback.tsx +18 -19
  55. package/source/Form/FloatingLabel.tsx +16 -19
  56. package/source/Form/InputGroup.tsx +27 -26
  57. package/source/Form/OTP.tsx +30 -12
  58. package/source/Form/Primitives.tsx +47 -39
  59. package/source/Form/Radio.tsx +25 -22
  60. package/source/Form/Range.tsx +30 -12
  61. package/source/Form/Switch.tsx +73 -48
  62. package/source/Form/inputProps.ts +184 -0
  63. package/source/Grid.tsx +67 -59
  64. package/source/Image.tsx +10 -6
  65. package/source/ListGroup.tsx +57 -69
  66. package/source/Menu.tsx +128 -66
  67. package/source/NativeDialog/index.tsx +51 -29
  68. package/source/Nav.tsx +46 -46
  69. package/source/NavOverflow/index.tsx +26 -10
  70. package/source/Navbar.tsx +60 -55
  71. package/source/Pagination.tsx +63 -69
  72. package/source/Placeholder.tsx +47 -43
  73. package/source/Polymorphic.ts +57 -0
  74. package/source/Popover.tsx +34 -31
  75. package/source/Progress/index.tsx +59 -54
  76. package/source/ScrollSpy/index.tsx +48 -33
  77. package/source/Spinner.tsx +27 -23
  78. package/source/Stack.tsx +25 -0
  79. package/source/Stepper.tsx +46 -40
  80. package/source/Tab.tsx +40 -27
  81. package/source/Table.tsx +53 -42
  82. package/source/Toast.tsx +62 -47
  83. package/source/ToggleButton.tsx +65 -54
  84. package/source/Toggler.tsx +17 -8
  85. package/source/Tooltip.tsx +31 -29
  86. package/source/index.ts +2 -0
  87. package/tsconfig.json +2 -2
  88. package/source/Extension/CodeBlock/index.tsx +0 -58
  89. package/source/Extension/CodeBlock/style.module.css +0 -3
@@ -0,0 +1,184 @@
1
+ import { ComponentPropsWithRef } from 'react';
2
+
3
+ type InputProps = Partial<ComponentPropsWithRef<'input'>> & Record<string, unknown>;
4
+
5
+ const inputPropNames = new Set(
6
+ [
7
+ 'accessKey',
8
+ 'accept',
9
+ 'alt',
10
+ 'autoCapitalize',
11
+ 'autoComplete',
12
+ 'autoFocus',
13
+ 'capture',
14
+ 'checked',
15
+ 'contentEditable',
16
+ 'contextMenu',
17
+ 'defaultChecked',
18
+ 'defaultValue',
19
+ 'dir',
20
+ 'dirName',
21
+ 'disabled',
22
+ 'draggable',
23
+ 'enterKeyHint',
24
+ 'form',
25
+ 'formAction',
26
+ 'formEncType',
27
+ 'formMethod',
28
+ 'formNoValidate',
29
+ 'formTarget',
30
+ 'hidden',
31
+ 'height',
32
+ 'id',
33
+ // cspell:ignore inlist
34
+ 'inlist',
35
+ 'inputMode',
36
+ 'is',
37
+ 'itemID',
38
+ 'itemProp',
39
+ 'itemRef',
40
+ 'itemScope',
41
+ 'itemType',
42
+ 'lang',
43
+ 'list',
44
+ 'max',
45
+ 'maxLength',
46
+ 'min',
47
+ 'minLength',
48
+ 'multiple',
49
+ 'name',
50
+ 'nonce',
51
+ 'pattern',
52
+ 'part',
53
+ 'popover',
54
+ 'popoverTarget',
55
+ 'popoverTargetAction',
56
+ 'placeholder',
57
+ 'about',
58
+ 'content',
59
+ 'datatype',
60
+ 'prefix',
61
+ 'property',
62
+ 'radioGroup',
63
+ 'readOnly',
64
+ 'rel',
65
+ 'resource',
66
+ 'results',
67
+ 'rev',
68
+ 'role',
69
+ 'required',
70
+ 'slot',
71
+ 'spellCheck',
72
+ 'src',
73
+ 'step',
74
+ 'tabIndex',
75
+ 'title',
76
+ 'typeof',
77
+ 'translate',
78
+ 'value',
79
+ 'vocab',
80
+ 'width',
81
+ 'autoCorrect',
82
+ 'autoSave',
83
+ 'color',
84
+ 'security',
85
+ 'unselectable',
86
+ 'exportparts',
87
+ 'inert',
88
+ 'onAnimationEnd',
89
+ 'onAnimationIteration',
90
+ 'onAnimationStart',
91
+ 'onAbort',
92
+ 'onAuxClick',
93
+ 'onBeforeInput',
94
+ 'onBeforeToggle',
95
+ 'onBlur',
96
+ 'onCanPlay',
97
+ 'onCanPlayThrough',
98
+ 'onChange',
99
+ 'onClick',
100
+ 'onCompositionEnd',
101
+ 'onCompositionStart',
102
+ 'onCompositionUpdate',
103
+ 'onContextMenu',
104
+ 'onCopy',
105
+ 'onCut',
106
+ 'onDoubleClick',
107
+ 'onDrag',
108
+ 'onDragEnd',
109
+ 'onDragEnter',
110
+ 'onDragExit',
111
+ 'onDragLeave',
112
+ 'onDragOver',
113
+ 'onDragStart',
114
+ 'onDrop',
115
+ 'onDurationChange',
116
+ 'onEmptied',
117
+ 'onEncrypted',
118
+ 'onEnded',
119
+ 'onError',
120
+ 'onFocus',
121
+ 'onGotPointerCapture',
122
+ 'onInput',
123
+ 'onInvalid',
124
+ 'onKeyDown',
125
+ 'onKeyPress',
126
+ 'onKeyUp',
127
+ 'onLoad',
128
+ 'onLoadedData',
129
+ 'onLoadedMetadata',
130
+ 'onLoadStart',
131
+ 'onLostPointerCapture',
132
+ 'onMouseDown',
133
+ 'onMouseEnter',
134
+ 'onMouseLeave',
135
+ 'onMouseMove',
136
+ 'onMouseOut',
137
+ 'onMouseOver',
138
+ 'onMouseUp',
139
+ 'onPaste',
140
+ 'onPause',
141
+ 'onPlay',
142
+ 'onPlaying',
143
+ 'onPointerCancel',
144
+ 'onPointerDown',
145
+ 'onPointerEnter',
146
+ 'onPointerLeave',
147
+ 'onPointerMove',
148
+ 'onPointerOut',
149
+ 'onPointerOver',
150
+ 'onPointerUp',
151
+ 'onProgress',
152
+ 'onRateChange',
153
+ 'onScroll',
154
+ 'onSeeked',
155
+ 'onSeeking',
156
+ 'onSelect',
157
+ 'onScrollEnd',
158
+ 'onStalled',
159
+ 'onSuspend',
160
+ 'onTimeUpdate',
161
+ 'onToggle',
162
+ 'onTransitionCancel',
163
+ 'onTransitionEnd',
164
+ 'onTransitionRun',
165
+ 'onTransitionStart',
166
+ 'onTouchCancel',
167
+ 'onTouchEnd',
168
+ 'onTouchMove',
169
+ 'onTouchStart',
170
+ 'onVolumeChange',
171
+ 'onWaiting',
172
+ 'onWheel'
173
+ ].flatMap(name => [name, `${name}Capture`])
174
+ );
175
+
176
+ export function splitInputProps(props: Record<string, unknown>) {
177
+ const inputProps: InputProps = {};
178
+ const rootProps: Record<string, unknown> = {};
179
+
180
+ for (const [name, value] of Object.entries(props))
181
+ (inputPropNames.has(name) || name.startsWith('aria-') ? inputProps : rootProps)[name] =
182
+ value;
183
+ return { inputProps, rootProps };
184
+ }
package/source/Grid.tsx CHANGED
@@ -1,5 +1,7 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { polymorphic } from './Polymorphic';
3
5
 
4
6
  export type Breakpoint = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
5
7
  export type ColSize = number | 'auto';
@@ -10,15 +12,18 @@ export interface ContainerProps extends ComponentPropsWithRef<'div'> {
10
12
  breakpoint?: Breakpoint;
11
13
  }
12
14
 
13
- export const Container: FC<ContainerProps> = ({ fluid, breakpoint, className, ...props }) => (
14
- <div
15
- {...props}
16
- className={classNames(
17
- breakpoint ? `${breakpoint}:container` : fluid ? 'container-fluid' : 'container',
18
- className
19
- )}
20
- />
15
+ export const Container = polymorphic<ContainerProps>(
16
+ ({ as: Root = 'div', fluid, breakpoint, className, ...props }) => (
17
+ <Root
18
+ {...props}
19
+ className={classNames(
20
+ breakpoint ? `${breakpoint}:container` : fluid ? 'container-fluid' : 'container',
21
+ className
22
+ )}
23
+ />
24
+ )
21
25
  );
26
+ Container.displayName = 'Container';
22
27
 
23
28
  export type RowCols = number | 'auto';
24
29
 
@@ -31,29 +36,33 @@ export interface RowProps extends ComponentPropsWithRef<'div'> {
31
36
  '2xl'?: RowCols;
32
37
  }
33
38
 
34
- export const Row: FC<RowProps> = ({ cols, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
35
- const sizes: [Breakpoint, RowCols | undefined][] = [
36
- ['sm', sm],
37
- ['md', md],
38
- ['lg', lg],
39
- ['xl', xl],
40
- ['2xl', xxl]
41
- ];
39
+ export const Row = polymorphic<RowProps>(
40
+ ({ as: Root = 'div', cols, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
41
+ const sizes: [Breakpoint, RowCols | undefined][] = [
42
+ ['sm', sm],
43
+ ['md', md],
44
+ ['lg', lg],
45
+ ['xl', xl],
46
+ ['2xl', xxl]
47
+ ];
42
48
 
43
- return (
44
- <div
45
- {...props}
46
- className={classNames(
47
- 'row',
48
- cols !== undefined && `row-cols-${cols}`,
49
- sizes.map(
50
- ([breakpoint, size]) => size !== undefined && `${breakpoint}:row-cols-${size}`
51
- ),
52
- className
53
- )}
54
- />
55
- );
56
- };
49
+ return (
50
+ <Root
51
+ {...props}
52
+ className={classNames(
53
+ 'row',
54
+ cols !== undefined && `row-cols-${cols}`,
55
+ sizes.map(
56
+ ([breakpoint, size]) =>
57
+ size !== undefined && `${breakpoint}:row-cols-${size}`
58
+ ),
59
+ className
60
+ )}
61
+ />
62
+ );
63
+ }
64
+ );
65
+ Row.displayName = 'Row';
57
66
 
58
67
  export interface ColProps extends ComponentPropsWithRef<'div'> {
59
68
  span?: ColSize;
@@ -64,33 +73,32 @@ export interface ColProps extends ComponentPropsWithRef<'div'> {
64
73
  '2xl'?: BreakpointColSize;
65
74
  }
66
75
 
67
- export const Col: FC<ColProps> = ({ span, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
68
- const sizes: [Breakpoint, BreakpointColSize | undefined][] = [
69
- ['sm', sm],
70
- ['md', md],
71
- ['lg', lg],
72
- ['xl', xl],
73
- ['2xl', xxl]
74
- ];
75
- const sized = sizes.some(([, size]) => size !== undefined);
76
+ export const Col = polymorphic<ColProps>(
77
+ ({ as: Root = 'div', span, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
78
+ const sizes: [Breakpoint, BreakpointColSize | undefined][] = [
79
+ ['sm', sm],
80
+ ['md', md],
81
+ ['lg', lg],
82
+ ['xl', xl],
83
+ ['2xl', xxl]
84
+ ];
85
+ const sized = sizes.some(([, size]) => size !== undefined);
76
86
 
77
- return (
78
- <div
79
- {...props}
80
- className={classNames(
81
- !span && !sized && 'col',
82
- span !== undefined && `col-${span}`,
83
- sizes.map(
84
- ([breakpoint, size]) =>
85
- size !== undefined &&
86
- (size === true ? `${breakpoint}:col` : `${breakpoint}:col-${size}`)
87
- ),
88
- className
89
- )}
90
- />
91
- );
92
- };
93
-
94
- Container.displayName = 'Container';
95
- Row.displayName = 'Row';
87
+ return (
88
+ <Root
89
+ {...props}
90
+ className={classNames(
91
+ !span && !sized && 'col',
92
+ span !== undefined && `col-${span}`,
93
+ sizes.map(
94
+ ([breakpoint, size]) =>
95
+ size !== undefined &&
96
+ (size === true ? `${breakpoint}:col` : `${breakpoint}:col-${size}`)
97
+ ),
98
+ className
99
+ )}
100
+ />
101
+ );
102
+ }
103
+ );
96
104
  Col.displayName = 'Col';
package/source/Image.tsx CHANGED
@@ -1,15 +1,19 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { polymorphic } from './Polymorphic';
3
5
 
4
6
  export interface ImageProps extends ComponentPropsWithRef<'img'> {
5
7
  fluid?: boolean;
6
8
  thumbnail?: boolean;
7
9
  }
8
10
 
9
- export const Image: FC<ImageProps> = ({ fluid, thumbnail, className, ...props }) => (
10
- <img
11
- {...props}
12
- className={classNames({ 'img-fluid': fluid, 'img-thumbnail': thumbnail }, className)}
13
- />
11
+ export const Image = polymorphic<ImageProps>(
12
+ ({ as: Root = 'img', fluid, thumbnail, className, ...props }) => (
13
+ <Root
14
+ {...props}
15
+ className={classNames({ 'img-fluid': fluid, 'img-thumbnail': thumbnail }, className)}
16
+ />
17
+ )
14
18
  );
15
19
  Image.displayName = 'Image';
@@ -1,8 +1,9 @@
1
1
  import classNames from 'classnames';
2
- import { ComponentPropsWithRef, FC } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
3
 
4
4
  import type { ComponentTheme } from './Button';
5
5
  import type { Breakpoint } from './Grid';
6
+ import { polymorphic } from './Polymorphic';
6
7
 
7
8
  export type ListGroupHorizontal = boolean | Breakpoint;
8
9
 
@@ -19,32 +20,22 @@ export type ListGroupProps = ListGroupStyleProps &
19
20
  | (ComponentPropsWithRef<'div'> & { as: 'div' })
20
21
  );
21
22
 
22
- export const ListGroup: FC<ListGroupProps> = ({
23
- flush,
24
- numbered,
25
- horizontal,
26
- className,
27
- ...props
28
- }) => {
29
- const classes = classNames(
30
- 'list-group',
31
- { 'list-group-flush': flush, 'list-group-numbered': numbered },
32
- horizontal &&
33
- (horizontal === true ? 'list-group-horizontal' : `${horizontal}:list-group-horizontal`),
34
- className
35
- );
23
+ export const ListGroup = polymorphic<ListGroupStyleProps & ComponentPropsWithRef<'ul'>>(
24
+ ({ as: Root = 'ul', flush, numbered, horizontal, className, ...props }) => {
25
+ const classes = classNames(
26
+ 'list-group',
27
+ { 'list-group-flush': flush, 'list-group-numbered': numbered },
28
+ horizontal &&
29
+ (horizontal === true
30
+ ? 'list-group-horizontal'
31
+ : `${horizontal}:list-group-horizontal`),
32
+ className
33
+ );
36
34
 
37
- if (props.as === 'ol') {
38
- const { as: _as, ...attributes } = props;
39
- return <ol {...attributes} className={classes} />;
40
- }
41
- if (props.as === 'div') {
42
- const { as: _as, ...attributes } = props;
43
- return <div {...attributes} className={classes} />;
35
+ return <Root {...props} className={classes} />;
44
36
  }
45
- const { as: _as, ...attributes } = props;
46
- return <ul {...attributes} className={classes} />;
47
- };
37
+ );
38
+ ListGroup.displayName = 'ListGroup';
48
39
 
49
40
  interface ListGroupItemStyleProps {
50
41
  theme?: ComponentTheme;
@@ -67,50 +58,47 @@ const isLink = (props: ListGroupItemElementAttributes): props is ListGroupItemLi
67
58
  const isButton = (props: ListGroupItemElementAttributes): props is ListGroupItemButtonAttributes =>
68
59
  typeof props.type === 'string';
69
60
 
70
- export const ListGroupItem: FC<ListGroupItemProps> = ({
71
- theme,
72
- action,
73
- active,
74
- disabled,
75
- className,
76
- ...props
77
- }) => {
78
- const classes = classNames(
79
- 'list-group-item',
80
- theme && `theme-${theme}`,
81
- action && 'list-group-item-action',
82
- { active, disabled },
83
- disabled && 'pe-none',
84
- className
85
- );
61
+ export const ListGroupItem = polymorphic<ListGroupItemProps>(
62
+ ({ as: RootAs, theme, action, active, disabled, className, ...props }) => {
63
+ const Root = RootAs ?? 'a';
64
+ const Root1 = RootAs ?? 'button';
65
+ const Root2 = RootAs ?? 'li';
86
66
 
87
- return isLink(props) ? (
88
- <a
89
- {...props}
90
- className={classes}
91
- href={disabled ? undefined : props.href}
92
- aria-current={active ? 'true' : undefined}
93
- aria-disabled={disabled || undefined}
94
- tabIndex={disabled ? -1 : props.tabIndex}
95
- onClick={disabled ? undefined : props.onClick}
96
- />
97
- ) : isButton(props) ? (
98
- <button
99
- {...props}
100
- type={props.type || 'button'}
101
- className={classes}
102
- aria-current={active ? 'true' : undefined}
103
- disabled={disabled}
104
- />
105
- ) : (
106
- <li
107
- {...(props as ListGroupItemAttributes)}
108
- className={classes}
109
- aria-current={active ? 'true' : undefined}
110
- aria-disabled={disabled || undefined}
111
- />
112
- );
113
- };
67
+ const classes = classNames(
68
+ 'list-group-item',
69
+ theme && `theme-${theme}`,
70
+ action && 'list-group-item-action',
71
+ { active, disabled },
72
+ disabled && 'pe-none',
73
+ className
74
+ );
114
75
 
115
- ListGroup.displayName = 'ListGroup';
76
+ return isLink(props) ? (
77
+ <Root
78
+ {...props}
79
+ className={classes}
80
+ href={disabled ? undefined : props.href}
81
+ aria-current={active ? 'true' : undefined}
82
+ aria-disabled={disabled || undefined}
83
+ tabIndex={disabled ? -1 : props.tabIndex}
84
+ onClick={disabled ? undefined : props.onClick}
85
+ />
86
+ ) : isButton(props) ? (
87
+ <Root1
88
+ {...props}
89
+ type={props.type || 'button'}
90
+ className={classes}
91
+ aria-current={active ? 'true' : undefined}
92
+ disabled={disabled}
93
+ />
94
+ ) : (
95
+ <Root2
96
+ {...(props as ListGroupItemAttributes)}
97
+ className={classes}
98
+ aria-current={active ? 'true' : undefined}
99
+ aria-disabled={disabled || undefined}
100
+ />
101
+ );
102
+ }
103
+ );
116
104
  ListGroupItem.displayName = 'ListGroupItem';