Skip to content
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

Fix IssueLabelToken treating alternative light schemes as dark #3104

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/Token/IssueLabelToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const IssueLabelToken = forwardRef((props, forwardedRef) => {
href,
onClick,
}
const {colorScheme} = useTheme()
const {resolvedColorMode} = useTheme()
const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(onRemove) && !hideRemoveButton
const onRemoveClick: MouseEventHandler = e => {
e.stopPropagation()
Expand All @@ -68,6 +68,7 @@ const IssueLabelToken = forwardRef((props, forwardedRef) => {
const labelStyles: CSSObject = useMemo(() => {
const [r, g, b] = parseToRgba(fillColor)
const [h, s, l] = parseToHsla(fillColor)
const isLightScheme = resolvedColorMode === 'light' || resolvedColorMode === 'day'

// label hack taken from https://github.com/github/github/blob/master/app/assets/stylesheets/hacks/hx_primer-labels.scss#L43-L108
// this logic should eventually live in primer/components. Also worthy of note is that the dotcom hack code will be moving to primer/css soon.
Expand All @@ -83,13 +84,12 @@ const IssueLabelToken = forwardRef((props, forwardedRef) => {
'--lightness-switch': 'max(0, min(calc((var(--perceived-lightness) - var(--lightness-threshold)) * -1000), 1))',
paddingRight: hideRemoveButton || !onRemove ? undefined : 0,
position: 'relative',
...(colorScheme === 'light' ? lightModeStyles : darkModeStyles),
...(isLightScheme ? lightModeStyles : darkModeStyles),
...(isSelected
? {
background:
colorScheme === 'light'
? 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) - 5) * 1%))'
: darkModeStyles.background,
background: isLightScheme
? 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) - 5) * 1%))'
: darkModeStyles.background,
':focus': {
outline: 'none',
},
Expand All @@ -104,7 +104,7 @@ const IssueLabelToken = forwardRef((props, forwardedRef) => {
display: 'block',
pointerEvents: 'none',
boxShadow: `0 0 0 ${tokenBorderWidthPx * 2}px ${
colorScheme === 'light'
isLightScheme
? 'rgb(var(--label-r), var(--label-g), var(--label-b))'
: 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) + var(--lighten-by)) * 1%))'
}`,
Expand All @@ -113,7 +113,7 @@ const IssueLabelToken = forwardRef((props, forwardedRef) => {
}
: {}),
}
}, [colorScheme, fillColor, isSelected, hideRemoveButton, onRemove])
}, [fillColor, resolvedColorMode, hideRemoveButton, onRemove, isSelected])

return (
<TokenBase
Expand Down