Skip to content

Commit fecef8b

Browse files
authored
Use new styles from Figma for the color mode switch (#2217)
## Description Ania updated the moon icon so it's not visually bigger than system and sun and I don’t have to do `isSystemIcon ? "18px" : "16px"` anymore 🙏 The text is now smaller than in what we have on prod and there's a little bit more padding. Figma: https://www.figma.com/design/aPUvZDSxJfYDJtPd7GF2sB/GraphQL.org--Working-File?node-id=6237-7449&t=C0utVsWrXtGCLTl4-4 <img width="250" height="161" alt="image" src="https://github.com/user-attachments/assets/86ca0957-a37d-4e27-818c-601941a083b4" /> <img width="278" height="157" alt="image" src="https://github.com/user-attachments/assets/86437a09-2e38-4677-b7ea-daeb5803b91a" /> <img width="137" height="141" alt="image" src="https://github.com/user-attachments/assets/8cb8ceb7-6b56-4ac3-9ba2-63882cd67c36" /> <img width="160" height="165" alt="image" src="https://github.com/user-attachments/assets/95383875-f542-4e9a-a424-864458a0e502" />
1 parent db85d33 commit fecef8b

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed
Lines changed: 1 addition & 3 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 4 additions & 2 deletions
Loading

src/components/theme-switch.tsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useMounted } from "nextra/hooks"
99
import MoonIcon from "@/app/conf/_design-system/pixelarticons/moon.svg?svgr"
1010
import SunIcon from "@/app/conf/_design-system/pixelarticons/sun.svg?svgr"
1111
import SystemIcon from "@/app/conf/_design-system/pixelarticons/system.svg?svgr"
12+
import CheckIcon from "@/app/conf/_design-system/pixelarticons/check.svg?svgr"
1213

1314
const THEME_OPTIONS = ["light", "dark", "system"] as const
1415
export type ThemeOption = (typeof THEME_OPTIONS)[number]
@@ -49,41 +50,47 @@ export function ThemeSwitch({ lite, className }: ThemeSwitchProps) {
4950
aria-label="Change theme"
5051
title="Change theme"
5152
className={clsx(
52-
"gql-focus-visible -m-2 flex cursor-pointer items-center gap-2 p-2 text-neu-800 transition-colors hover:bg-neu-50 hover:text-neu-900 focus-visible:!-outline-offset-2 dark:text-neu-700 dark:hover:bg-neu-50/50",
53+
"gql-focus-visible relative cursor-pointer text-neu-800 transition-colors before:absolute before:-inset-2 hover:bg-neu-100 hover:text-neu-900 focus-visible:!-outline-offset-2 dark:text-neu-700 dark:hover:bg-neu-50/50",
5354
className,
5455
)}
5556
>
56-
<ResolvedThemeIcon height="16" />
57-
<Select.Value
58-
className={clsx(
59-
"text-sm capitalize leading-none",
60-
lite ? "sr-only" : "text-neu-700",
61-
)}
62-
/>
57+
<div className="flex items-center gap-2 border border-transparent p-[5px] [[aria-expanded=true]>&]:border-neu-300 [[aria-expanded=true]>&]:bg-neu-0 [[aria-expanded=true]>&]:dark:border-neu-100">
58+
<ResolvedThemeIcon height="16" />
59+
<Select.Value
60+
className={clsx(
61+
"text-sm capitalize leading-none",
62+
lite ? "sr-only" : "text-neu-800",
63+
)}
64+
/>
65+
</div>
6366
</Select.Trigger>
6467
<Select.Portal>
65-
<Select.Positioner className="z-20 outline-none" sideOffset={4}>
66-
<Select.Popup className="min-w-[var(--anchor-width)] border border-neu-200 bg-[rgb(var(--nextra-bg))] p-1 text-neu-900 shadow-md outline-none dark:border-neu-100">
68+
<Select.Positioner
69+
className="z-20 outline-none"
70+
align="end"
71+
sideOffset={4}
72+
>
73+
<Select.Popup className="w-[120px] min-w-[var(--anchor-width)] border border-neu-200 bg-[rgb(var(--nextra-bg))] bg-neu-0 text-neu-900 shadow-sm outline-none dark:border-neu-100">
6774
<Select.List>
6875
{THEME_OPTIONS.map(option => {
6976
const Icon = OPTION_ICONS[option]
70-
const isSystem = Icon === SystemIcon
7177
return (
7278
<Select.Item
7379
key={option}
7480
value={option}
75-
className="mt-px flex cursor-pointer items-center gap-2 px-3 py-1.5 text-neu-800 first:mt-0 focus-visible:outline-none focus-visible:ring-0 data-[highlighted]:bg-neu-100 data-[highlighted]:text-neu-900 data-[selected]:text-neu-600 dark:text-neu-700 dark:data-[highlighted]:bg-neu-50"
81+
style={{
82+
paddingBlock: lite ? "10px" : "9px",
83+
}}
84+
className="mt-px flex cursor-pointer items-center gap-2 px-2 text-xs text-neu-800 first:mt-0 focus-visible:outline-none focus-visible:ring-0 data-[highlighted]:bg-neu-100 data-[highlighted]:text-neu-900 dark:text-neu-700 dark:data-[highlighted]:bg-neu-50/50"
7685
>
77-
<Icon
78-
height={
79-
// the icons are not fully proportional
80-
isSystem ? "18" : "16"
81-
}
82-
className={isSystem ? "-mr-0.5 -translate-x-px" : ""}
83-
/>
86+
<Icon height={14} />
8487
<Select.ItemText className="capitalize leading-none">
8588
{option}
8689
</Select.ItemText>
90+
<CheckIcon
91+
height={16}
92+
className="ml-auto hidden text-pri-base dark:text-pri-light [[data-selected]_&]:block"
93+
/>
8794
</Select.Item>
8895
)
8996
})}

0 commit comments

Comments
 (0)