@@ -64,13 +64,14 @@ export interface LinkButtonProps extends Omit<LinkProps, 'className' | 'style' |
64
64
export const ButtonContext = createContext < ContextValue < ButtonProps , FocusableRefValue < HTMLButtonElement > > > ( null ) ;
65
65
export const LinkButtonContext = createContext < ContextValue < ButtonProps , FocusableRefValue < HTMLAnchorElement > > > ( null ) ;
66
66
67
+ const iconOnly = ':has([slot=icon]):not(:has([data-rsp-slot=text]))' ;
67
68
const button = style < ButtonRenderProps & ButtonStyleProps > ( {
68
69
...focusRing ( ) ,
69
70
position : 'relative' ,
70
71
display : 'flex' ,
71
72
alignItems : {
72
73
default : 'baseline' ,
73
- ':has([slot=icon]):not(:has([data-rsp-slot=text]))' : 'center'
74
+ [ iconOnly ] : 'center'
74
75
} ,
75
76
justifyContent : 'center' ,
76
77
textAlign : 'start' ,
@@ -80,19 +81,19 @@ const button = style<ButtonRenderProps & ButtonStyleProps>({
80
81
userSelect : 'none' ,
81
82
minHeight : 'control' ,
82
83
minWidth : {
83
- ':has([slot=icon]):not(:has([data-rsp-slot=text]))' : 'control'
84
+ [ iconOnly ] : 'control'
84
85
} ,
85
86
borderRadius : 'pill' ,
86
87
boxSizing : 'border-box' ,
87
88
width : 'fit' ,
88
89
textDecoration : 'none' , // for link buttons
89
90
paddingX : {
90
91
default : 'pill' ,
91
- ':has([slot=icon]):not(:has([data-rsp-slot=text]))' : 0
92
+ [ iconOnly ] : 0
92
93
} ,
93
94
paddingY : 0 ,
94
95
aspectRatio : {
95
- ':has([slot=icon]):not(:has([data-rsp-slot=text]))' : 'square'
96
+ [ iconOnly ] : 'square'
96
97
} ,
97
98
transition : 'default' ,
98
99
borderStyle : 'solid' ,
@@ -110,7 +111,7 @@ const button = style<ButtonRenderProps & ButtonStyleProps>({
110
111
type : 'marginTop' ,
111
112
value : {
112
113
default : fontRelative ( - 2 ) ,
113
- ':has([slot=icon]):not(:has([data-rsp-slot=text]))' : 0
114
+ [ iconOnly ] : 0
114
115
}
115
116
} ,
116
117
borderColor : {
@@ -331,15 +332,18 @@ function Button(props: ButtonProps, ref: FocusableRef<HTMLButtonElement>) {
331
332
< Provider
332
333
values = { [
333
334
[ SkeletonContext , null ] ,
334
- [ TextContext , { styles : style ( {
335
- paddingY : '--labelPadding' ,
336
- order : 1 ,
337
- opacity : {
338
- default : 1 ,
339
- isProgressVisible : 0
340
- }
335
+ [ TextContext , {
336
+ styles : style ( {
337
+ paddingY : '--labelPadding' ,
338
+ order : 1 ,
339
+ opacity : {
340
+ default : 1 ,
341
+ isProgressVisible : 0
342
+ }
343
+ } ) ( { isProgressVisible} ) ,
341
344
// @ts -ignore data-attributes allowed on all JSX elements, but adding to DOMProps has been problematic in the past
342
- } ) ( { isProgressVisible} ) , 'data-rsp-slot' : 'text' } ] ,
345
+ 'data-rsp-slot' : 'text'
346
+ } ] ,
343
347
[ IconContext , {
344
348
render : centerBaseline ( { slot : 'icon' , styles : style ( { order : 0 } ) } ) ,
345
349
styles : style ( {
@@ -406,7 +410,11 @@ function LinkButton(props: LinkButtonProps, ref: FocusableRef<HTMLAnchorElement>
406
410
< Provider
407
411
values = { [
408
412
[ SkeletonContext , null ] ,
409
- [ TextContext , { styles : style ( { paddingY : '--labelPadding' , order : 1 } ) } ] ,
413
+ [ TextContext , {
414
+ styles : style ( { paddingY : '--labelPadding' , order : 1 } ) ,
415
+ // @ts -ignore data-attributes allowed on all JSX elements, but adding to DOMProps has been problematic in the past
416
+ 'data-rsp-slot' : 'text'
417
+ } ] ,
410
418
[ IconContext , {
411
419
render : centerBaseline ( { slot : 'icon' , styles : style ( { order : 0 } ) } ) ,
412
420
styles : style ( { size : fontRelative ( 20 ) , marginStart : '--iconMargin' , flexShrink : 0 } )
0 commit comments