Skip to content

Commit 9a760b2

Browse files
authored
button: fix adaptive chonk (#91864)
Buttons now have the adaptive chonk behavior. Fixes DE-34, DE-38, DE-45 Before ![CleanShot 2025-05-19 at 11 47 25@2x](https://github.com/user-attachments/assets/c9d4108c-ce37-4d03-b7d7-2bc966e623a3) After ![CleanShot 2025-05-19 at 11 47 33@2x](https://github.com/user-attachments/assets/727af1e1-9122-4050-9556-d768118c0c21) Before ![CleanShot 2025-05-19 at 11 47 45@2x](https://github.com/user-attachments/assets/91411249-e266-43cd-9898-fcd926728fe5) After ![CleanShot 2025-05-19 at 11 47 37@2x](https://github.com/user-attachments/assets/ea7442cd-2413-4bfb-ba2d-311df0c670a1)
1 parent 7196fc7 commit 9a760b2

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

static/app/components/core/button/styles.chonk.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {DO_NOT_USE_ChonkTheme} from '@emotion/react';
22

33
import type {DO_NOT_USE_ButtonProps as ButtonProps} from 'sentry/components/core/button/types';
44
import type {StrictCSSObject} from 'sentry/utils/theme';
5+
import {unreachable} from 'sentry/utils/unreachable';
56

67
// @TODO: remove Link type in the future
78
type ChonkButtonType =
@@ -33,8 +34,25 @@ function chonkPriorityToType(priority: ButtonProps['priority']): ChonkButtonType
3334
}
3435
}
3536

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+
3653
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']>;
3856
theme: DO_NOT_USE_ChonkTheme;
3957
}
4058
): StrictCSSObject {
@@ -56,7 +74,6 @@ export function DO_NOT_USE_getChonkButtonStyles(
5674
border: 'none',
5775
color: getChonkButtonTheme(type, p.theme).color,
5876

59-
transform: 'translateY(0px)',
6077
background: 'none',
6178

6279
height:
@@ -74,9 +91,11 @@ export function DO_NOT_USE_getChonkButtonStyles(
7491
content: '""',
7592
display: 'block',
7693
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}`,
8099
background: getChonkButtonTheme(type, p.theme).background,
81100
borderRadius: 'inherit',
82101
},
@@ -89,13 +108,16 @@ export function DO_NOT_USE_getChonkButtonStyles(
89108
background: getChonkButtonTheme(type, p.theme).surface,
90109
borderRadius: 'inherit',
91110
border: `1px solid ${getChonkButtonTheme(type, p.theme).background}`,
92-
transform: 'translateY(-2px)',
111+
transform: `translateY(-${chonkElevation(p.size)})`,
93112
transition: 'transform 0.1s ease-in-out',
94113
},
95114

96115
'&:focus-visible': {
116+
outline: 'none',
117+
97118
'&::after': {
98-
...p.theme.focusRing,
119+
border: `1px solid ${p.theme.focusBorder}`,
120+
boxShadow: `0 0 0 1px ${p.theme.focusBorder}`,
99121
},
100122
},
101123

@@ -111,18 +133,18 @@ export function DO_NOT_USE_getChonkButtonStyles(
111133
overflow: 'hidden',
112134

113135
whiteSpace: 'nowrap',
114-
transform: 'translateY(-2px)',
136+
transform: `translateY(-${chonkElevation(p.size)})`,
115137
transition: 'transform 0.06s ease-in-out',
116138
},
117139

118140
'&:hover': {
119141
color: p.disabled || p.busy ? undefined : getChonkButtonTheme(type, p.theme).color,
120142

121143
'&::after': {
122-
transform: `translateY(-3px)`,
144+
transform: `translateY(calc(-${chonkElevation(p.size)} - 2px))`,
123145
},
124146
'> span:last-child': {
125-
transform: `translateY(-3px)`,
147+
transform: `translateY(calc(-${chonkElevation(p.size)} - 2px))`,
126148
},
127149
},
128150

@@ -139,9 +161,6 @@ export function DO_NOT_USE_getChonkButtonStyles(
139161
'&::after': {
140162
transform: 'translateY(0px)',
141163
},
142-
'&::before': {
143-
transform: 'translateY(0px)',
144-
},
145164
'> span:last-child': {
146165
transform: 'translateY(0px)',
147166
},

0 commit comments

Comments
 (0)