Skip to content

Commit da2295d

Browse files
mozziusclaude
andcommitted
lighten web menus' selected colours a shade in dark themes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4b57cb6 commit da2295d

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎src/components/Menu/index.web.tsx‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ export function Outer({children, style, onCloseAutoFocus}: OuterProps) {
238238
)
239239
}
240240

241+
/**
242+
* A selected item's colours. Dark themes go a shade lighter, so the pill and
243+
* its label don't turn muddy. Their palettes run the other way, so that's a
244+
* higher number.
245+
*/
246+
function useSelectedColors() {
247+
const t = useTheme()
248+
const dark = t.scheme === 'dark'
249+
return {
250+
pill: dark ? t.palette.primary_100 : t.palette.primary_50,
251+
pillHovered: dark ? t.palette.primary_200 : t.palette.primary_100,
252+
content: dark ? t.palette.primary_600 : t.palette.primary_500,
253+
}
254+
}
255+
241256
export function Item({
242257
children,
243258
label,
@@ -247,6 +262,7 @@ export function Item({
247262
...rest
248263
}: ItemProps) {
249264
const t = useTheme()
265+
const selectedColors = useSelectedColors()
250266
const {control} = useMenuContext()
251267
const {
252268
state: hovered,
@@ -309,11 +325,11 @@ export function Item({
309325
* positional corners. Hovered items keep them.
310326
*/
311327
selected && a.rounded_sm,
312-
selected && {backgroundColor: t.palette.primary_50},
328+
selected && {backgroundColor: selectedColors.pill},
313329
highlighted && [
314330
web({outline: '0 !important'}),
315331
selected
316-
? {backgroundColor: t.palette.primary_100}
332+
? {backgroundColor: selectedColors.pillHovered}
317333
: t.name === 'light'
318334
? t.atoms.bg_contrast_50
319335
: t.atoms.bg_contrast_100,
@@ -367,6 +383,7 @@ function arrangeItemContent(children: React.ReactNode) {
367383

368384
export function ItemText({children, style}: ItemTextProps) {
369385
const t = useTheme()
386+
const selectedColors = useSelectedColors()
370387
const {disabled, destructive, selected} = useMenuItemContext()
371388
return (
372389
<Text
@@ -377,7 +394,7 @@ export function ItemText({children, style}: ItemTextProps) {
377394
a.leading_snug,
378395
t.atoms.text,
379396
style,
380-
selected && {color: t.palette.primary_500},
397+
selected && {color: selectedColors.content},
381398
destructive && {color: t.palette.negative_500},
382399
disabled && t.atoms.text_contrast_low,
383400
]}>
@@ -391,6 +408,7 @@ export function ItemText({children, style}: ItemTextProps) {
391408
*/
392409
export function ItemIcon({icon: Comp, fill}: ItemIconProps) {
393410
const t = useTheme()
411+
const selectedColors = useSelectedColors()
394412
const {disabled, destructive, selected} = useMenuItemContext()
395413
return (
396414
<Comp
@@ -404,7 +422,7 @@ export function ItemIcon({icon: Comp, fill}: ItemIconProps) {
404422
: destructive
405423
? t.palette.negative_500
406424
: selected
407-
? t.palette.primary_500
425+
? selectedColors.content
408426
: t.atoms.text.color
409427
}
410428
/>
@@ -417,14 +435,15 @@ export function ItemIcon({icon: Comp, fill}: ItemIconProps) {
417435
*/
418436
export function ItemRadio({selected}: {selected: boolean}) {
419437
const t = useTheme()
438+
const selectedColors = useSelectedColors()
420439
const {disabled} = useMenuItemContext()
421440
return (
422441
<View style={{height: 16, width: 16}}>
423442
{selected && (
424443
<Check
425444
size="sm"
426445
fill={
427-
disabled ? t.atoms.text_contrast_low.color : t.palette.primary_500
446+
disabled ? t.atoms.text_contrast_low.color : selectedColors.content
428447
}
429448
/>
430449
)}

0 commit comments

Comments
 (0)