@@ -2,6 +2,7 @@ import type {DO_NOT_USE_ChonkTheme} from '@emotion/react';
2
2
3
3
import type { DO_NOT_USE_ButtonProps as ButtonProps } from 'sentry/components/core/button/types' ;
4
4
import type { StrictCSSObject } from 'sentry/utils/theme' ;
5
+ import { unreachable } from 'sentry/utils/unreachable' ;
5
6
6
7
// @TODO : remove Link type in the future
7
8
type ChonkButtonType =
@@ -33,8 +34,25 @@ function chonkPriorityToType(priority: ButtonProps['priority']): ChonkButtonType
33
34
}
34
35
}
35
36
37
+ function chonkElevation ( size : NonNullable < ButtonProps [ 'size' ] > ) : string {
38
+ switch ( size ) {
39
+ case 'md' :
40
+ return '3px' ;
41
+ case 'sm' :
42
+ return '2px' ;
43
+ case 'xs' :
44
+ return '1px' ;
45
+ case 'zero' :
46
+ return '0px' ;
47
+ default :
48
+ unreachable ( size ) ;
49
+ throw new Error ( `Unknown button size: ${ size } ` ) ;
50
+ }
51
+ }
52
+
36
53
export function DO_NOT_USE_getChonkButtonStyles (
37
- p : Pick < ButtonProps , 'size' | 'priority' | 'busy' | 'disabled' | 'borderless' > & {
54
+ p : Pick < ButtonProps , 'priority' | 'busy' | 'disabled' | 'borderless' > & {
55
+ size : NonNullable < ButtonProps [ 'size' ] > ;
38
56
theme : DO_NOT_USE_ChonkTheme ;
39
57
}
40
58
) : StrictCSSObject {
@@ -56,7 +74,6 @@ export function DO_NOT_USE_getChonkButtonStyles(
56
74
border : 'none' ,
57
75
color : getChonkButtonTheme ( type , p . theme ) . color ,
58
76
59
- transform : 'translateY(0px)' ,
60
77
background : 'none' ,
61
78
62
79
height :
@@ -74,9 +91,11 @@ export function DO_NOT_USE_getChonkButtonStyles(
74
91
content : '""' ,
75
92
display : 'block' ,
76
93
position : 'absolute' ,
77
- inset : '0px' ,
78
- bottom : '2px' ,
79
- boxShadow : `0 3px 0 0px ${ getChonkButtonTheme ( type , p . theme ) . background } ` ,
94
+ inset : '0' ,
95
+ height : `calc(100% - ${ chonkElevation ( p . size ) } )` ,
96
+ top : `${ chonkElevation ( p . size ) } ` ,
97
+ transform : `translateY(-${ chonkElevation ( p . size ) } )` ,
98
+ boxShadow : `0 ${ chonkElevation ( p . size ) } 0 0px ${ getChonkButtonTheme ( type , p . theme ) . background } ` ,
80
99
background : getChonkButtonTheme ( type , p . theme ) . background ,
81
100
borderRadius : 'inherit' ,
82
101
} ,
@@ -89,13 +108,16 @@ export function DO_NOT_USE_getChonkButtonStyles(
89
108
background : getChonkButtonTheme ( type , p . theme ) . surface ,
90
109
borderRadius : 'inherit' ,
91
110
border : `1px solid ${ getChonkButtonTheme ( type , p . theme ) . background } ` ,
92
- transform : ' translateY(-2px)' ,
111
+ transform : ` translateY(-${ chonkElevation ( p . size ) } )` ,
93
112
transition : 'transform 0.1s ease-in-out' ,
94
113
} ,
95
114
96
115
'&:focus-visible' : {
116
+ outline : 'none' ,
117
+
97
118
'&::after' : {
98
- ...p . theme . focusRing ,
119
+ border : `1px solid ${ p . theme . focusBorder } ` ,
120
+ boxShadow : `0 0 0 1px ${ p . theme . focusBorder } ` ,
99
121
} ,
100
122
} ,
101
123
@@ -111,18 +133,18 @@ export function DO_NOT_USE_getChonkButtonStyles(
111
133
overflow : 'hidden' ,
112
134
113
135
whiteSpace : 'nowrap' ,
114
- transform : ' translateY(-2px)' ,
136
+ transform : ` translateY(-${ chonkElevation ( p . size ) } )` ,
115
137
transition : 'transform 0.06s ease-in-out' ,
116
138
} ,
117
139
118
140
'&:hover' : {
119
141
color : p . disabled || p . busy ? undefined : getChonkButtonTheme ( type , p . theme ) . color ,
120
142
121
143
'&::after' : {
122
- transform : `translateY(-3px )` ,
144
+ transform : `translateY(calc(- ${ chonkElevation ( p . size ) } - 2px) )` ,
123
145
} ,
124
146
'> span:last-child' : {
125
- transform : `translateY(-3px )` ,
147
+ transform : `translateY(calc(- ${ chonkElevation ( p . size ) } - 2px) )` ,
126
148
} ,
127
149
} ,
128
150
@@ -139,9 +161,6 @@ export function DO_NOT_USE_getChonkButtonStyles(
139
161
'&::after' : {
140
162
transform : 'translateY(0px)' ,
141
163
} ,
142
- '&::before' : {
143
- transform : 'translateY(0px)' ,
144
- } ,
145
164
'> span:last-child' : {
146
165
transform : 'translateY(0px)' ,
147
166
} ,
0 commit comments