Skip to content

Commit 55919f1

Browse files
committed
feat: add button icon only variation
1 parent fe8737f commit 55919f1

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

packages/components/button/src/index.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,26 @@ export const Button = ({
2929
children,
3030
className,
3131
...otherProps
32-
}: Readonly<ButtonProps>): React.ReactElement => (
33-
<button className={classNames(styles.root, styles[skin], className)} {...otherProps}>
34-
{icon && <span className={styles.icon}>{icon}</span>}
35-
{children}
36-
</button>
37-
);
32+
}: Readonly<ButtonProps>): React.ReactElement => {
33+
const isIconOnly = useMemo(
34+
() => icon !== undefined && React.Children.count(children) === 0,
35+
[children, icon],
36+
);
37+
38+
return (
39+
<button
40+
className={classNames(
41+
styles.root,
42+
styles[skin],
43+
{
44+
[`${styles["icon-only"]}`]: isIconOnly,
45+
},
46+
className,
47+
)}
48+
{...otherProps}>
49+
{icon && !isIconOnly && <span className={styles.icon}>{icon}</span>}
50+
{children}
51+
{isIconOnly && icon}
52+
</button>
53+
);
54+
};

packages/components/button/src/styles/index.module.scss

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.root {
44
@include font-base;
55

6+
@include define-css-var(button, border-radius, get-spacing(1));
7+
@include define-css-var(button, padding-y, get-spacing(1));
8+
@include define-css-var(button, padding-x, get-spacing(2));
9+
610
background-color: get-css-var(button, background-color);
711
color: get-css-var(button, color);
812
font-weight: 700;
@@ -11,13 +15,20 @@
1115
display: inline-flex;
1216
align-items: center;
1317
justify-content: center;
14-
padding: get-spacing(1) get-spacing(2);
15-
border-radius: get-spacing(1);
18+
padding: get-css-var(button, padding-y) get-css-var(button, padding-x);
19+
border-radius: get-css-var(button, border-radius);
1620
transition: background-color 0.2s ease;
1721

1822
&:disabled {
1923
cursor: not-allowed;
2024
}
25+
26+
&.icon-only {
27+
@include define-css-var(button, padding-x, get-spacing(1));
28+
@include define-css-var(button, border-radius, 50%);
29+
30+
aspect-ratio: 1/1;
31+
}
2132
}
2233

2334
.primary {

0 commit comments

Comments
 (0)