Skip to content

Commit df417e5

Browse files
committed
refactor: add buttonicon and do not remove the asicon attribute of the button
1 parent f36fdec commit df417e5

File tree

6 files changed

+300
-179
lines changed

6 files changed

+300
-179
lines changed

packages/ui/src/components/button/Button.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ import { cn } from '@/lib/utils';
77
import { buttonVariants } from './button-variants';
88
import type { ButtonProps } from './types';
99

10-
export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
10+
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
1111
const {
1212
asChild = false,
13-
asIconButton,
1413
children,
1514
className,
16-
color = asIconButton ? 'carbon' : 'primary',
15+
color,
1716
disabled,
1817
fitContent,
1918
leading,
2019
loading,
2120
shadow,
22-
shape = asIconButton ? 'square' : 'auto',
21+
shape,
2322
size,
2423
trailing,
25-
variant = asIconButton ? 'ghost' : 'solid',
24+
variant,
2625
...rest
2726
} = props;
2827

2928
const isDisabled = loading || disabled;
3029

3130
const Comp = asChild ? Slot : 'button';
3231

33-
const mergedCls = cn(buttonVariants({ color, fitContent, shadow, shape, size, variant }), className);
32+
// eslint-disable-next-line sort/object-properties
33+
const mergedCls = cn(buttonVariants({ color, fitContent, shadow, size, shape, variant }), className);
3434

3535
if (asChild) {
3636
return (
@@ -58,4 +58,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
5858
</Comp>
5959
);
6060
});
61+
6162
Button.displayName = 'Button';
63+
64+
export default Button;

packages/ui/src/components/button/ButtonGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { cn } from '@/lib/utils';
55
import { buttonGroupVariants } from './button-group-variants';
66
import type { ButtonGroupProps } from './types';
77

8-
export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>((props, ref) => {
8+
const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>((props, ref) => {
99
const { children, className, orientation, ...rest } = props;
1010

1111
const mergedCls = cn(buttonGroupVariants({ orientation }), className);
@@ -22,3 +22,5 @@ export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>((props,
2222
});
2323

2424
ButtonGroup.displayName = 'ButtonGroup';
25+
26+
export default ButtonGroup;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { forwardRef } from 'react';
2+
3+
import { Icon } from '../icon';
4+
5+
import Button from './Button';
6+
import type { ButtonIconProps } from './types';
7+
8+
const ButtonIcon = forwardRef<HTMLButtonElement, ButtonIconProps>((props, ref) => {
9+
const {
10+
children,
11+
color = 'accent',
12+
fitContent = true,
13+
icon,
14+
iconProps,
15+
shape = 'square',
16+
variant = 'ghost',
17+
...rest
18+
} = props;
19+
20+
return (
21+
<Button
22+
color={color}
23+
fitContent={fitContent}
24+
ref={ref}
25+
shape={shape}
26+
variant={variant}
27+
{...rest}
28+
>
29+
{children || (
30+
<Icon
31+
icon={String(icon)}
32+
{...iconProps}
33+
/>
34+
)}
35+
</Button>
36+
);
37+
});
38+
39+
ButtonIcon.displayName = 'ButtonIcon';
40+
41+
export default ButtonIcon;

0 commit comments

Comments
 (0)