File tree Expand file tree Collapse file tree 2 files changed +36
-8
lines changed
packages/components/button/src Expand file tree Collapse file tree 2 files changed +36
-8
lines changed Original file line number Diff line number Diff 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+ } ;
Original file line number Diff line number Diff line change 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 ;
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 {
You can’t perform that action at this time.
0 commit comments