@@ -31,61 +31,65 @@ const useUtilityClasses = (ownerState: IconButtonOwnerState) => {
31
31
return composedClasses ;
32
32
} ;
33
33
34
- export const IconButtonRoot = styled ( 'button' , {
34
+ export const StyledIconButton = styled ( 'button' ) < { ownerState : IconButtonOwnerState } > (
35
+ ( { theme, ownerState } ) => [
36
+ {
37
+ '--Icon-margin' : 'initial' , // reset the icon's margin.
38
+ '--CircularProgress-size' : 'var(--Icon-fontSize)' ,
39
+ ...( ownerState . size === 'sm' && {
40
+ '--Icon-fontSize' : 'calc(var(--IconButton-size, 2rem) / 1.6)' , // 1.25rem by default
41
+ minWidth : 'var(--IconButton-size, 2rem)' , // use min-width instead of height to make the button resilient to its content
42
+ minHeight : 'var(--IconButton-size, 2rem)' , // use min-height instead of height to make the button resilient to its content
43
+ fontSize : theme . vars . fontSize . sm ,
44
+ paddingInline : '2px' , // add a gap, in case the content is long, e.g. multiple icons
45
+ } ) ,
46
+ ...( ownerState . size === 'md' && {
47
+ '--Icon-fontSize' : 'calc(var(--IconButton-size, 2.5rem) / 1.667)' , // 1.5rem by default
48
+ minWidth : 'var(--IconButton-size, 2.5rem)' ,
49
+ minHeight : 'var(--IconButton-size, 2.5rem)' ,
50
+ fontSize : theme . vars . fontSize . md ,
51
+ paddingInline : '0.25rem' ,
52
+ } ) ,
53
+ ...( ownerState . size === 'lg' && {
54
+ '--Icon-fontSize' : 'calc(var(--IconButton-size, 3rem) / 1.714)' , // 1.75rem by default
55
+ minWidth : 'var(--IconButton-size, 3rem)' ,
56
+ minHeight : 'var(--IconButton-size, 3rem)' ,
57
+ fontSize : theme . vars . fontSize . lg ,
58
+ paddingInline : '0.375rem' ,
59
+ } ) ,
60
+ WebkitTapHighlightColor : 'transparent' ,
61
+ paddingBlock : 0 ,
62
+ fontFamily : theme . vars . fontFamily . body ,
63
+ fontWeight : theme . vars . fontWeight . md ,
64
+ margin : `var(--IconButton-margin)` , // to be controlled by other components, eg. Input
65
+ borderRadius : `var(--IconButton-radius, ${ theme . vars . radius . sm } )` , // to be controlled by other components, eg. Input
66
+ border : 'none' ,
67
+ boxSizing : 'border-box' ,
68
+ backgroundColor : 'transparent' ,
69
+ display : 'inline-flex' ,
70
+ alignItems : 'center' ,
71
+ justifyContent : 'center' ,
72
+ position : 'relative' ,
73
+ // TODO: discuss the transition approach in a separate PR. This value is copied from mui-material Button.
74
+ transition :
75
+ 'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms' ,
76
+ [ theme . focus . selector ] : theme . focus . default ,
77
+ } ,
78
+ theme . variants [ ownerState . variant ! ] ?. [ ownerState . color ! ] ,
79
+ { '&:hover' : theme . variants [ `${ ownerState . variant ! } Hover` ] ?. [ ownerState . color ! ] } ,
80
+ { '&:active' : theme . variants [ `${ ownerState . variant ! } Active` ] ?. [ ownerState . color ! ] } ,
81
+ {
82
+ [ `&.${ iconButtonClasses . disabled } ` ] :
83
+ theme . variants [ `${ ownerState . variant ! } Disabled` ] ?. [ ownerState . color ! ] ,
84
+ } ,
85
+ ] ,
86
+ ) ;
87
+
88
+ export const IconButtonRoot = styled ( StyledIconButton , {
35
89
name : 'JoyIconButton' ,
36
90
slot : 'Root' ,
37
91
overridesResolver : ( props , styles ) => styles . root ,
38
- } ) < { ownerState : IconButtonOwnerState } > ( ( { theme, ownerState } ) => [
39
- {
40
- '--Icon-margin' : 'initial' , // reset the icon's margin.
41
- '--CircularProgress-size' : 'var(--Icon-fontSize)' ,
42
- ...( ownerState . size === 'sm' && {
43
- '--Icon-fontSize' : 'calc(var(--IconButton-size, 2rem) / 1.6)' , // 1.25rem by default
44
- minWidth : 'var(--IconButton-size, 2rem)' , // use min-width instead of height to make the button resilient to its content
45
- minHeight : 'var(--IconButton-size, 2rem)' , // use min-height instead of height to make the button resilient to its content
46
- fontSize : theme . vars . fontSize . sm ,
47
- paddingInline : '2px' , // add a gap, in case the content is long, e.g. multiple icons
48
- } ) ,
49
- ...( ownerState . size === 'md' && {
50
- '--Icon-fontSize' : 'calc(var(--IconButton-size, 2.5rem) / 1.667)' , // 1.5rem by default
51
- minWidth : 'var(--IconButton-size, 2.5rem)' ,
52
- minHeight : 'var(--IconButton-size, 2.5rem)' ,
53
- fontSize : theme . vars . fontSize . md ,
54
- paddingInline : '0.25rem' ,
55
- } ) ,
56
- ...( ownerState . size === 'lg' && {
57
- '--Icon-fontSize' : 'calc(var(--IconButton-size, 3rem) / 1.714)' , // 1.75rem by default
58
- minWidth : 'var(--IconButton-size, 3rem)' ,
59
- minHeight : 'var(--IconButton-size, 3rem)' ,
60
- fontSize : theme . vars . fontSize . lg ,
61
- paddingInline : '0.375rem' ,
62
- } ) ,
63
- WebkitTapHighlightColor : 'transparent' ,
64
- paddingBlock : 0 ,
65
- fontFamily : theme . vars . fontFamily . body ,
66
- fontWeight : theme . vars . fontWeight . md ,
67
- margin : `var(--IconButton-margin)` , // to be controlled by other components, eg. Input
68
- borderRadius : `var(--IconButton-radius, ${ theme . vars . radius . sm } )` , // to be controlled by other components, eg. Input
69
- border : 'none' ,
70
- boxSizing : 'border-box' ,
71
- backgroundColor : 'transparent' ,
72
- display : 'inline-flex' ,
73
- alignItems : 'center' ,
74
- justifyContent : 'center' ,
75
- position : 'relative' ,
76
- // TODO: discuss the transition approach in a separate PR. This value is copied from mui-material Button.
77
- transition :
78
- 'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms' ,
79
- [ theme . focus . selector ] : theme . focus . default ,
80
- } ,
81
- theme . variants [ ownerState . variant ! ] ?. [ ownerState . color ! ] ,
82
- { '&:hover' : theme . variants [ `${ ownerState . variant ! } Hover` ] ?. [ ownerState . color ! ] } ,
83
- { '&:active' : theme . variants [ `${ ownerState . variant ! } Active` ] ?. [ ownerState . color ! ] } ,
84
- {
85
- [ `&.${ iconButtonClasses . disabled } ` ] :
86
- theme . variants [ `${ ownerState . variant ! } Disabled` ] ?. [ ownerState . color ! ] ,
87
- } ,
88
- ] ) ;
92
+ } ) ( { } ) ;
89
93
90
94
const IconButton = React . forwardRef ( function IconButton ( inProps , ref ) {
91
95
const props = useThemeProps < typeof inProps & { component ?: React . ElementType } > ( {
0 commit comments