-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
badge: chonkify badge and tags #86207
Changes from 1 commit
6e2be7a
14d7026
0a8c2ed
55304f5
9a8de48
a87a325
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,93 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
import type {DO_NOT_USE_ChonkTheme} from '@emotion/react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
import type {TagProps} from 'sentry/components/core/badge/tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import {space} from 'sentry/styles/space'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import {chonkStyled} from 'sentry/utils/theme/theme.chonk'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import {unreachable} from 'sentry/utils/unreachable'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
type TagType = 'default' | 'info' | 'success' | 'warning' | 'danger' | 'promotion'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
interface ChonkTagProps extends Omit<TagProps, 'type'> { | ||||||||||||||||||||||||||||||||||||||||||||||||||
type: TagType; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export function chonkTagPropMapping(props: TagProps): ChonkTagProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
...props, | ||||||||||||||||||||||||||||||||||||||||||||||||||
type: | ||||||||||||||||||||||||||||||||||||||||||||||||||
props.type === 'highlight' | ||||||||||||||||||||||||||||||||||||||||||||||||||
? 'info' | ||||||||||||||||||||||||||||||||||||||||||||||||||
: props.type === 'error' | ||||||||||||||||||||||||||||||||||||||||||||||||||
? 'danger' | ||||||||||||||||||||||||||||||||||||||||||||||||||
: props.type === 'white' | ||||||||||||||||||||||||||||||||||||||||||||||||||
? 'default' | ||||||||||||||||||||||||||||||||||||||||||||||||||
: props.type === 'black' | ||||||||||||||||||||||||||||||||||||||||||||||||||
? 'default' | ||||||||||||||||||||||||||||||||||||||||||||||||||
: props.type === undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||
? 'default' | ||||||||||||||||||||||||||||||||||||||||||||||||||
: props.type, | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we make
|
||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export const TagPill = chonkStyled('div')<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
type: TagType; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}>` | ||||||||||||||||||||||||||||||||||||||||||||||||||
${p => ({...makeTagPillTheme(p.type, p.theme)})}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
font-size: ${p => p.theme.fontSizeSmall}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
display: inline-flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||
align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||
height: 20px; | ||||||||||||||||||||||||||||||||||||||||||||||||||
border-radius: 20px; | ||||||||||||||||||||||||||||||||||||||||||||||||||
padding: 0 ${space(1)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
max-width: 166px; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
/* @TODO(jonasbadalic): We need to override button colors because they wrongly default to a blue color... */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
button, | ||||||||||||||||||||||||||||||||||||||||||||||||||
button:hover { | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: currentColor; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
function makeTagPillTheme( | ||||||||||||||||||||||||||||||||||||||||||||||||||
type: TagType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
theme: DO_NOT_USE_ChonkTheme | ||||||||||||||||||||||||||||||||||||||||||||||||||
): React.CSSProperties { | ||||||||||||||||||||||||||||||||||||||||||||||||||
switch (type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'default': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.grayTransparent400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// Highlight maps to info badge for now, but the highlight variant should be removed | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'info': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.blue400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'success': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.green400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'warning': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.yellow400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'danger': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.red400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
case 'promotion': | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
background: theme.colors.dynamic.surface300, | ||||||||||||||||||||||||||||||||||||||||||||||||||
color: theme.colors.dynamic.pink400, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||||||||||||||||||
unreachable(type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
throw new TypeError(`Unsupported badge type: ${type}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a mapping instead 🫠
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the main reason why
no-nested-ternary
exists. Any reason it’s not turned on in sentry?