-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(ui): chonkify segmentedControl #89589
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
Changes from all commits
881a91b
193d398
7516449
339f364
0d625a2
0f3cf1a
523e8c8
0b3a610
bcd0d1b
02d449c
da1241a
4469f16
e74f1d0
4c010d8
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 |
---|---|---|
|
@@ -51,7 +51,9 @@ function chonkSizeMapping(size: ButtonProps['size']): ChonkButtonSize { | |
} | ||
|
||
export function getChonkButtonStyles( | ||
p: ButtonProps & {theme: DO_NOT_USE_ChonkTheme} | ||
p: Pick<ButtonProps, 'size' | 'priority' | 'busy' | 'disabled' | 'borderless'> & { | ||
theme: DO_NOT_USE_ChonkTheme; | ||
} | ||
): StrictCSSObject { | ||
const type = chonkPriorityToType(p.priority); | ||
const size = chonkSizeMapping(p.size); | ||
|
@@ -150,7 +152,7 @@ export function getChonkButtonStyles( | |
}, | ||
}, | ||
|
||
'&:active, &[aria-expanded="true"]': { | ||
'&:active, &[aria-expanded="true"], &[aria-checked="true"]': { | ||
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.
|
||
'&::after': { | ||
transform: 'translateY(0px)', | ||
}, | ||
|
@@ -159,7 +161,7 @@ export function getChonkButtonStyles( | |
}, | ||
}, | ||
|
||
'&:disabled': { | ||
'&:disabled, &[aria-disabled="true"]': { | ||
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. I’ve set |
||
'&::after': { | ||
transform: 'translateY(0px)', | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import type {DO_NOT_USE_ChonkTheme} from '@emotion/react'; | ||
|
||
import {getChonkButtonStyles} from 'sentry/components/core/button/index.chonk'; | ||
import type {FormSize} from 'sentry/utils/theme'; | ||
import {chonkStyled} from 'sentry/utils/theme/theme.chonk'; | ||
|
||
export type Priority = 'default' | 'primary'; | ||
|
||
export const ChonkStyledGroupWrap = chonkStyled('div')<{ | ||
priority: Priority; | ||
size: FormSize; | ||
}>` | ||
position: relative; | ||
display: inline-grid; | ||
grid-auto-flow: column; | ||
min-width: 0; | ||
|
||
${p => p.theme.form[p.size]} | ||
|
||
& > label:first-child { | ||
border-top-right-radius: 0; | ||
border-bottom-right-radius: 0; | ||
border-right: 0; | ||
} | ||
|
||
& > label:not(:first-child):not(:last-child) { | ||
border-radius: 0; | ||
} | ||
|
||
& > label:last-child { | ||
border-top-left-radius: 0; | ||
border-bottom-left-radius: 0; | ||
} | ||
|
||
/* don't turn off border if the 2nd element is also the last element */ | ||
& > label:last-child:not(:nth-child(2)) { | ||
border-left: 0; | ||
} | ||
`; | ||
|
||
export const ChonkStyledSegmentWrap = chonkStyled('label')<{ | ||
isSelected: boolean; | ||
priority: Priority; | ||
size: FormSize; | ||
isDisabled?: boolean; | ||
}>` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
margin: 0; | ||
cursor: ${p => (p.isDisabled ? 'default' : 'pointer')}; | ||
min-height: 0; | ||
min-width: 0; | ||
z-index: ${p => (p.isSelected ? 1 : undefined)}; | ||
|
||
${p => p.theme.buttonPadding[p.size]} | ||
font-weight: ${p => p.theme.fontWeightNormal}; | ||
|
||
${p => ({...getChonkButtonStyles({...p, disabled: p.isDisabled, priority: p.isSelected && p.priority === 'primary' ? 'primary' : 'default'})})} | ||
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. took me a while to figure out why 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. Oh my god... we really need to delete these dual props, this is a waste of time + having isDisabled and disabled is just confusing 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. I think we use let’s put it on the list to decide for one |
||
|
||
&:has(input:focus-visible) { | ||
${p => p.theme.focusRing}; | ||
|
||
/* Hide fallback ring when :has works */ | ||
span { | ||
box-shadow: none !important; | ||
} | ||
} | ||
|
||
/* Fallback ring (for Firefox, where :has doesn't work) */ | ||
input:focus-visible + span { | ||
${({theme}) => theme.focusRing}; | ||
} | ||
`; | ||
|
||
export const ChonkStyledVisibleLabel = chonkStyled('span')<{ | ||
isSelected: boolean; | ||
priority: Priority; | ||
}>` | ||
${p => p.theme.overflowEllipsis} | ||
user-select: none; | ||
font-weight: ${p => p.theme.fontWeightNormal}; | ||
text-align: center; | ||
color: ${p => getTextColor(p)}; | ||
`; | ||
|
||
function getTextColor({ | ||
isSelected, | ||
priority, | ||
theme, | ||
}: { | ||
isSelected: boolean; | ||
priority: Priority; | ||
theme: DO_NOT_USE_ChonkTheme; | ||
isDisabled?: boolean; | ||
}) { | ||
if (isSelected) { | ||
return priority === 'default' ? theme.colors.blue500 : undefined; | ||
} | ||
|
||
return theme.subText; | ||
} |
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.
changed the interface here to be as minimal as possible - only what gets really used, so that I can re-use it in the
segmentgedControl