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
@@ -0,0 +1,153 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { action, observable } from 'mobx';
5
+ import { observer } from 'mobx-react';
6
+ import {
7
+ Component,
8
+ ComponentPropsWithoutRef,
9
+ ComponentPropsWithRef,
10
+ createRef,
11
+ ElementType,
12
+ MouseEvent,
13
+ TransitionEvent
14
+ } from 'react';
15
+
16
+ import { ComponentTheme } from './Button';
17
+ import { CloseButton } from './CloseButton';
18
+ import { AsProps, polymorphic, PolymorphicClassProps } from './Polymorphic';
19
+
20
+ export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
21
+ theme?: ComponentTheme;
22
+ dismissible?: boolean;
23
+ instant?: boolean;
24
+ closeLabel?: string;
25
+ onClose?: () => unknown;
26
+ onClosed?: () => unknown;
27
+ }
28
+
29
+ @observer
30
+ export class Alert<T extends ElementType | undefined = 'div'> extends Component<
31
+ PolymorphicClassProps<T, AlertProps>
32
+ > {
33
+ declare readonly props: PolymorphicClassProps<T, AlertProps>;
34
+
35
+ protected get componentProps(): Readonly<AlertProps & AsProps> {
36
+ return this.props;
37
+ }
38
+
39
+ static displayName = 'Alert';
40
+
41
+ @observable accessor hiding = false;
42
+ @observable accessor closed = false;
43
+
44
+ root = createRef<HTMLDivElement>();
45
+ timer?: ReturnType<typeof setTimeout>;
46
+ notified = false;
47
+
48
+ componentDidUpdate() {
49
+ if (this.closed && !this.notified) {
50
+ this.notified = true;
51
+ this.componentProps.onClosed?.();
52
+ }
53
+ }
54
+
55
+ componentWillUnmount() {
56
+ clearTimeout(this.timer);
57
+ }
58
+
59
+ finishClose = action(() => {
60
+ if (this.closed) return;
61
+
62
+ clearTimeout(this.timer);
63
+ this.closed = true;
64
+ });
65
+
66
+ close = action(() => {
67
+ if (this.hiding || this.closed) return;
68
+
69
+ this.componentProps.onClose?.();
70
+
71
+ if (this.componentProps.instant) return this.finishClose();
72
+
73
+ this.hiding = true;
74
+
75
+ const style = getComputedStyle(this.root.current!);
76
+ const durations = style.transitionDuration.split(',').map(Alert.milliseconds);
77
+ const delays = style.transitionDelay.split(',').map(Alert.milliseconds);
78
+ const timeout = Math.max(
79
+ 0,
80
+ ...durations.map((duration, index) => duration + (delays[index % delays.length] || 0))
81
+ );
82
+ this.timer = setTimeout(this.finishClose, timeout);
83
+ });
84
+
85
+ static milliseconds = (value: string) =>
86
+ (parseFloat(value) || 0) * (value.trim().endsWith('ms') ? 1 : 1000);
87
+
88
+ handleClose = (event: MouseEvent<HTMLButtonElement>) => {
89
+ if (!event.defaultPrevented) this.close();
90
+ };
91
+
92
+ handleTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {
93
+ this.componentProps.onTransitionEnd?.(event);
94
+
95
+ if (event.target === event.currentTarget && this.hiding) this.finishClose();
96
+ };
97
+
98
+ render() {
99
+ const Root: ElementType = this.componentProps.as ?? 'div';
100
+
101
+ const {
102
+ as: _as,
103
+ theme,
104
+ dismissible,
105
+ instant,
106
+ closeLabel = 'Close',
107
+ onClose: _onClose,
108
+ onClosed: _onClosed,
109
+ className,
110
+ children,
111
+ ...props
112
+ } = this.componentProps;
113
+
114
+ return this.closed ? null : (
115
+ <Root
116
+ {...props}
117
+ ref={this.root}
118
+ role={props.role ?? 'alert'}
119
+ className={classNames(
120
+ 'alert',
121
+ theme && `theme-${theme}`,
122
+ { 'alert-instant': instant, hiding: this.hiding },
123
+ className
124
+ )}
125
+ onTransitionEnd={this.handleTransitionEnd}
126
+ >
127
+ {children}
128
+
129
+ {dismissible && (
130
+ <CloseButton
131
+ className="ms-auto"
132
+ aria-label={closeLabel}
133
+ onClick={this.handleClose}
134
+ />
135
+ )}
136
+ </Root>
137
+ );
138
+ }
139
+ }
140
+
141
+ export const AlertLink = polymorphic<ComponentPropsWithRef<'a'>>(
142
+ ({ as: Root = 'a', className, ...props }) => (
143
+ <Root {...props} className={classNames('alert-link', className)} />
144
+ )
145
+ );
146
+ AlertLink.displayName = 'AlertLink';
147
+
148
+ export const AlertHeading = polymorphic<ComponentPropsWithRef<'h4'>>(
149
+ ({ as: Root = 'h4', className, ...props }) => (
150
+ <Root {...props} className={classNames('alert-heading', className)} />
151
+ )
152
+ );
153
+ AlertHeading.displayName = 'AlertHeading';
package/source/Avatar.tsx CHANGED
@@ -1,7 +1,8 @@
1
1
  import classNames from 'classnames';
2
- import { CSSProperties, FC, HTMLAttributes } from 'react';
2
+ import { ComponentPropsWithRef, CSSProperties, HTMLAttributes } from 'react';
3
3
 
4
4
  import type { ComponentTheme } from './Button';
5
+ import { polymorphic } from './Polymorphic';
5
6
 
6
7
  export type AvatarSize = 'xs' | 'sm' | 'lg' | 'xl';
7
8
  export type AvatarStatus = 'online' | 'offline' | 'busy' | 'away';
@@ -20,59 +21,69 @@ export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
20
21
  statusLabel?: string;
21
22
  }
22
23
 
23
- export const Avatar: FC<AvatarProps> = ({
24
- className,
25
- style,
26
- size,
27
- theme,
28
- subtle,
29
- src,
30
- alt,
31
- status,
32
- statusLabel = status,
33
- children,
34
- ...props
35
- }) => (
36
- <span
37
- className={classNames(
38
- 'avatar',
39
- typeof size === 'string' && `avatar-${size}`,
40
- theme && `theme-${theme}`,
41
- subtle && 'avatar-subtle',
42
- className
43
- )}
44
- style={
45
- typeof size === 'number'
46
- ? ({ '--bs-avatar-size': `${size}rem`, ...style } as CSSProperties)
47
- : style
48
- }
49
- {...props}
50
- >
51
- {src ? <img className="avatar-img" src={src} alt={alt} /> : children}
24
+ export const Avatar = polymorphic<AvatarProps>(
25
+ ({
26
+ as: Root = 'span',
27
+ className,
28
+ style,
29
+ size,
30
+ theme,
31
+ subtle,
32
+ src,
33
+ alt,
34
+ status,
35
+ statusLabel = status,
36
+ children,
37
+ ...props
38
+ }) => (
39
+ <Root
40
+ className={classNames(
41
+ 'avatar',
42
+ typeof size === 'string' && `avatar-${size}`,
43
+ theme && `theme-${theme}`,
44
+ subtle && 'avatar-subtle',
45
+ className
46
+ )}
47
+ style={
48
+ typeof size === 'number'
49
+ ? ({ '--bs-avatar-size': `${size}rem`, ...style } as CSSProperties)
50
+ : style
51
+ }
52
+ {...props}
53
+ >
54
+ {src ? <img className="avatar-img" src={src} alt={alt} /> : children}
52
55
 
53
- {status && (
54
- <span
55
- className={`avatar-status status-${status}`}
56
- role="img"
57
- aria-label={statusLabel}
58
- />
59
- )}
60
- </span>
56
+ {status && (
57
+ <span
58
+ className={`avatar-status status-${status}`}
59
+ role="img"
60
+ aria-label={statusLabel}
61
+ />
62
+ )}
63
+ </Root>
64
+ )
61
65
  );
62
-
63
66
  Avatar.displayName = 'Avatar';
64
67
 
65
68
  export interface AvatarStackProps extends HTMLAttributes<HTMLDivElement> {
66
69
  size?: AvatarSize;
67
70
  }
68
71
 
69
- export const AvatarStack: FC<AvatarStackProps> = ({ className, size, children, ...props }) => (
70
- <div
71
- className={classNames('avatar-stack', size && `avatar-stack-${size}`, className)}
72
- {...props}
73
- >
74
- {children}
75
- </div>
72
+ export const AvatarImage = polymorphic<ComponentPropsWithRef<'img'>>(
73
+ ({ as: Root = 'img', className, ...props }) => (
74
+ <Root {...props} className={classNames('avatar-img', className)} />
75
+ )
76
76
  );
77
+ AvatarImage.displayName = 'AvatarImage';
77
78
 
79
+ export const AvatarStack = polymorphic<AvatarStackProps>(
80
+ ({ as: Root = 'div', className, size, children, ...props }) => (
81
+ <Root
82
+ className={classNames('avatar-stack', size && `avatar-stack-${size}`, className)}
83
+ {...props}
84
+ >
85
+ {children}
86
+ </Root>
87
+ )
88
+ );
78
89
  AvatarStack.displayName = 'AvatarStack';
package/source/Badge.tsx CHANGED
@@ -1,7 +1,8 @@
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
+ import { polymorphic } from './Polymorphic';
5
6
 
6
7
  interface BadgeStyleProps {
7
8
  variant?: 'solid' | 'subtle' | 'outline';
@@ -12,23 +13,24 @@ interface BadgeStyleProps {
12
13
  type BadgeLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
13
14
  type BadgeElementAttributes =
14
15
  (ComponentPropsWithRef<'span'> & { href?: never }) | BadgeLinkAttributes;
16
+
15
17
  export type BadgeProps = BadgeStyleProps & BadgeElementAttributes;
16
18
 
17
19
  const isBadgeLink = (props: BadgeElementAttributes): props is BadgeLinkAttributes =>
18
20
  typeof props.href === 'string';
19
21
 
20
- export const Badge: FC<BadgeProps> = ({ variant = 'solid', theme, pill, className, ...props }) => {
21
- const classes = classNames(
22
- 'badge',
23
- variant !== 'solid' && `badge-${variant}`,
24
- theme && `theme-${theme}`,
25
- { 'rounded-pill': pill },
26
- className
27
- );
22
+ export const Badge = polymorphic<BadgeProps>(
23
+ ({ as: RootAs, variant = 'solid', theme, pill, className, ...props }) => {
24
+ const Root = RootAs ?? (isBadgeLink(props) ? 'a' : 'span');
25
+ const classes = classNames(
26
+ 'badge',
27
+ variant !== 'solid' && `badge-${variant}`,
28
+ theme && `theme-${theme}`,
29
+ { 'rounded-pill': pill },
30
+ className
31
+ );
28
32
 
29
- return isBadgeLink(props) ? (
30
- <a {...props} className={classes} />
31
- ) : (
32
- <span {...props} className={classes} />
33
- );
34
- };
33
+ return <Root {...props} className={classes} />;
34
+ }
35
+ );
36
+ Badge.displayName = 'Badge';
@@ -0,0 +1,50 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef } from 'react';
3
+
4
+ import { polymorphic } from './Polymorphic';
5
+
6
+ export const Breadcrumb = polymorphic<ComponentPropsWithRef<'ol'>>(
7
+ ({ as: Root = 'ol', className, ...props }) => (
8
+ <Root {...props} className={classNames('breadcrumb', className)} />
9
+ )
10
+ );
11
+ Breadcrumb.displayName = 'Breadcrumb';
12
+
13
+ export const BreadcrumbItem = polymorphic<ComponentPropsWithRef<'li'>>(
14
+ ({ as: Root = 'li', ...props }) => (
15
+ <Root {...props} className={classNames('breadcrumb-item', props.className)} />
16
+ )
17
+ );
18
+ BreadcrumbItem.displayName = 'BreadcrumbItem';
19
+
20
+ export interface BreadcrumbLinkProps extends ComponentPropsWithRef<'a'> {
21
+ active?: boolean;
22
+ }
23
+
24
+ export const BreadcrumbLink = polymorphic<BreadcrumbLinkProps>(
25
+ ({
26
+ as: Root = 'a',
27
+ active,
28
+ className,
29
+ 'aria-current': current = active ? 'page' : undefined,
30
+ ...props
31
+ }) => (
32
+ <Root
33
+ {...props}
34
+ className={classNames('breadcrumb-link', { active }, className)}
35
+ aria-current={current}
36
+ />
37
+ )
38
+ );
39
+ BreadcrumbLink.displayName = 'BreadcrumbLink';
40
+
41
+ export const BreadcrumbDivider = polymorphic<ComponentPropsWithRef<'li'>>(
42
+ ({ as: Root = 'li', className, ...props }) => (
43
+ <Root
44
+ {...props}
45
+ className={classNames('breadcrumb-divider', className)}
46
+ aria-hidden="true"
47
+ />
48
+ )
49
+ );
50
+ BreadcrumbDivider.displayName = 'BreadcrumbDivider';
package/source/Button.tsx CHANGED
@@ -1,7 +1,7 @@
1
- 'use client';
2
-
3
1
  import classNames from 'classnames';
4
- import { ComponentPropsWithRef, FC, MouseEvent } from 'react';
2
+ import { ComponentPropsWithRef, MouseEvent } from 'react';
3
+
4
+ import { polymorphic } from './Polymorphic';
5
5
 
6
6
  export type ComponentTheme =
7
7
  | 'primary'
@@ -16,58 +16,87 @@ export type ComponentTheme =
16
16
  | 'inverse';
17
17
 
18
18
  interface ButtonStyleProps {
19
- variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link';
19
+ variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link' | false;
20
20
  theme?: ComponentTheme;
21
21
  size?: 'xs' | 'sm' | 'lg';
22
22
  icon?: boolean;
23
23
  styled?: boolean;
24
24
  disabled?: boolean;
25
+ active?: boolean;
25
26
  }
26
27
 
27
28
  type ButtonLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
28
29
  type ButtonAttributes = ComponentPropsWithRef<'button'> & { href?: never };
29
30
  type ButtonElementAttributes = ButtonAttributes | ButtonLinkAttributes;
31
+
30
32
  export type ButtonProps = ButtonStyleProps & ButtonElementAttributes;
31
33
 
32
34
  const isButtonLink = (props: ButtonElementAttributes): props is ButtonLinkAttributes =>
33
35
  typeof props.href === 'string';
34
36
 
35
- const preventNavigation = (event: MouseEvent<HTMLAnchorElement>) => event.preventDefault();
37
+ const preventNavigation = (event: MouseEvent<HTMLElement>) => event.preventDefault();
36
38
 
37
- export const Button: FC<ButtonProps> = ({
38
- variant,
39
- theme,
40
- size,
41
- icon,
42
- styled,
43
- disabled,
44
- className,
45
- ...props
46
- }) => {
47
- const attributes: ButtonElementAttributes = props;
48
- const classes = classNames(
49
- variant ? `btn-${variant}` : icon ? undefined : 'btn',
50
- theme && `theme-${theme}`,
51
- size && `btn-${size}`,
52
- { 'btn-icon': icon, 'btn-styled': styled, disabled },
53
- className
54
- );
39
+ export const Button = polymorphic<ButtonProps>(
40
+ ({ as: RootAs, variant, theme, size, icon, styled, disabled, active, className, ...props }) => {
41
+ const attributes: ButtonElementAttributes = props;
42
+ const link = isButtonLink(attributes);
43
+ const Root = RootAs ?? (link ? 'a' : 'button');
44
+ const nativeButton = Root === 'button';
45
+ const classes = classNames(
46
+ variant === false ? undefined : variant ? `btn-${variant}` : icon ? undefined : 'btn',
47
+ theme && `theme-${theme}`,
48
+ size && `btn-${size}`,
49
+ { 'btn-icon': icon, 'btn-styled': styled, disabled, active },
50
+ className
51
+ );
55
52
 
56
- return isButtonLink(attributes) ? (
57
- <a
58
- {...attributes}
59
- className={classes}
60
- href={disabled ? undefined : attributes.href}
61
- aria-disabled={disabled || undefined}
62
- tabIndex={disabled ? -1 : attributes.tabIndex}
63
- onClick={disabled ? preventNavigation : attributes.onClick}
64
- />
65
- ) : (
66
- <button
67
- {...attributes}
68
- type={attributes.type || 'button'}
69
- className={classes}
70
- disabled={disabled}
53
+ return (
54
+ <Root
55
+ {...attributes}
56
+ className={classes}
57
+ type={nativeButton ? attributes.type || 'button' : attributes.type}
58
+ href={disabled ? undefined : attributes.href}
59
+ disabled={nativeButton || typeof Root !== 'string' ? disabled : undefined}
60
+ aria-disabled={(!nativeButton && disabled) || undefined}
61
+ aria-pressed={
62
+ !link || attributes.role === 'button'
63
+ ? (active ?? attributes['aria-pressed'])
64
+ : attributes['aria-pressed']
65
+ }
66
+ tabIndex={!nativeButton && disabled ? -1 : attributes.tabIndex}
67
+ onClick={!nativeButton && disabled ? preventNavigation : attributes.onClick}
68
+ />
69
+ );
70
+ }
71
+ );
72
+ Button.displayName = 'Button';
73
+
74
+ export type ButtonInputProps = Omit<ComponentPropsWithRef<'input'>, 'size'> & ButtonStyleProps;
75
+
76
+ export const ButtonInput = polymorphic<ButtonInputProps>(
77
+ ({
78
+ as: Root = 'input',
79
+ variant,
80
+ theme,
81
+ size,
82
+ icon,
83
+ styled,
84
+ active,
85
+ className,
86
+ type = 'button',
87
+ ...props
88
+ }) => (
89
+ <Root
90
+ {...props}
91
+ type={type}
92
+ className={classNames(
93
+ variant === false ? undefined : variant ? `btn-${variant}` : 'btn',
94
+ theme && `theme-${theme}`,
95
+ size && `btn-${size}`,
96
+ { 'btn-icon': icon, 'btn-styled': styled, active },
97
+ className
98
+ )}
71
99
  />
72
- );
73
- };
100
+ )
101
+ );
102
+ ButtonInput.displayName = 'ButtonInput';
@@ -1,28 +1,33 @@
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 ButtonGroupProps extends ComponentPropsWithRef<'div'> {
5
7
  vertical?: boolean;
8
+ size?: 'xs' | 'sm' | 'lg';
9
+ divider?: boolean;
6
10
  }
7
11
 
8
- export const ButtonGroup: FC<ButtonGroupProps> = ({
9
- vertical,
10
- role = 'group',
11
- className,
12
- ...props
13
- }) => (
14
- <div
15
- role={role}
16
- {...props}
17
- className={classNames(vertical ? 'btn-group-vertical' : 'btn-group', className)}
18
- />
12
+ export const ButtonGroup = polymorphic<ButtonGroupProps>(
13
+ ({ as: Root = 'div', vertical, size, divider, role = 'group', className, ...props }) => (
14
+ <Root
15
+ role={role}
16
+ {...props}
17
+ className={classNames(
18
+ vertical ? 'btn-group-vertical' : 'btn-group',
19
+ size && `btn-group-${size}`,
20
+ divider && 'btn-group-divider',
21
+ className
22
+ )}
23
+ />
24
+ )
19
25
  );
20
26
  ButtonGroup.displayName = 'ButtonGroup';
21
27
 
22
- export const ButtonToolbar: FC<ComponentPropsWithRef<'div'>> = ({
23
- className,
24
- role = 'toolbar',
25
- ...props
26
- }) => <div role={role} {...props} className={classNames('btn-toolbar', className)} />;
27
-
28
+ export const ButtonToolbar = polymorphic<ComponentPropsWithRef<'div'>>(
29
+ ({ as: Root = 'div', className, role = 'toolbar', ...props }) => (
30
+ <Root role={role} {...props} className={classNames('btn-toolbar', className)} />
31
+ )
32
+ );
28
33
  ButtonToolbar.displayName = 'ButtonToolbar';