@@ -10,9 +10,7 @@ import { useClientLayoutEffect } from '../utils/useClientLayoutEffect';
10
10
11
11
const buttonVariants = cva ( {
12
12
base : [
13
- 'inline-flex min-h-[44px] cursor-pointer items-center justify-center whitespace-nowrap rounded-lg px-4 py-2 font-medium transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2' ,
14
- // Spaccing when using the button with icons
15
- '[&>svg]:first-of-type:mr-2.5 [&>svg]:last-of-type:ml-2.5' ,
13
+ 'inline-flex min-h-[44px] cursor-pointer items-center justify-center whitespace-nowrap rounded-lg font-medium transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2' ,
16
14
] ,
17
15
variants : {
18
16
/**
@@ -34,6 +32,16 @@ const buttonVariants = cva({
34
32
mint : 'focus-visible:ring-mint focus-visible:ring-offset-green-dark' ,
35
33
white : 'focus-visible:ring-white focus-visible:ring-offset-blue' ,
36
34
} ,
35
+ /**
36
+ * When the button is without text, but with a single icon.
37
+ * @default false
38
+ */
39
+ isIconOnly : {
40
+ true : 'p-2 [&>svg]:h-7 [&>svg]:w-7' ,
41
+ false :
42
+ // The of-type classes takes care to add spacing when the button is used with icons
43
+ 'px-4 py-2 [&>svg]:first-of-type:mr-2.5 [&>svg]:last-of-type:ml-2.5' ,
44
+ } ,
37
45
} ,
38
46
compoundVariants : [
39
47
{
@@ -83,6 +91,7 @@ const buttonVariants = cva({
83
91
defaultVariants : {
84
92
variant : 'primary' ,
85
93
color : 'green' ,
94
+ isIconOnly : false ,
86
95
} ,
87
96
} ) ;
88
97
@@ -106,8 +115,16 @@ type ButtonProps = VariantProps<typeof buttonVariants> & {
106
115
} & ButtonOrLinkProps ;
107
116
108
117
function Button ( props : ButtonProps ) {
109
- const { children, className, color, loading, variant, style, ...restProps } =
110
- props ;
118
+ const {
119
+ children,
120
+ className,
121
+ color,
122
+ isIconOnly,
123
+ loading,
124
+ variant,
125
+ style,
126
+ ...restProps
127
+ } = props ;
111
128
112
129
// TODO: Merge refs when we use RAC
113
130
const buttonRef = useRef < HTMLButtonElement | HTMLAnchorElement > ( null ) ;
@@ -136,7 +153,7 @@ function Button(props: ButtonProps) {
136
153
// @ts -expect-error TS doesn't agree here taht restProps is safe to spread, because restProps for anchors aren't type compatible with restProps for buttons, but that should be okay here
137
154
< Component
138
155
aria-busy = { loading ? true : undefined }
139
- className = { buttonVariants ( { className, color, variant } ) }
156
+ className = { buttonVariants ( { className, color, isIconOnly , variant } ) }
140
157
ref = { buttonRef as never }
141
158
style = { {
142
159
...style ,
0 commit comments