Skip to content

Commit 3788ef4

Browse files
committed
refactor: menu color tokens
uses a "default, low, medium, high" structure for menu backgrounds and text colors, representing different layers to stacking menu sections. Blends this with existing DS to introduce "low" "medium" and "high" background colors.
1 parent 18b7a05 commit 3788ef4

File tree

5 files changed

+52
-84
lines changed

5 files changed

+52
-84
lines changed

src/components/Nav/Menu/MenuContent.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,35 @@ export const navMenuVariants = tv({
1313
slots: {
1414
base: "text-body",
1515
item: "has-[button[data-state=open]]:rounded-s-md has-[button[data-state=open]]:rounded-e-none has-[button[data-state=open]]:-me-2 has-[button[data-state=open]]:pe-2",
16-
link: "group w-full relative py-4 hover:text-menu-active [&:hover_p]:text-menu-active focus-visible:text-menu-active [&:focus-visible_p]:text-menu-active hover:outline-0 rounded-md hover:shadow-none focus-visible:outline-0 focus-visible:rounded-md focus-visible:shadow-none",
16+
link: "group w-full relative py-4 hover:text-primary [&:hover_p]:text-primary focus-visible:text-primary [&:focus-visible_p]:text-primary hover:outline-0 rounded-md hover:shadow-none focus-visible:outline-0 focus-visible:rounded-md focus-visible:shadow-none",
1717
linkSubtext: "text-sm",
1818
submenu: "grid h-full w-full grid-cols-1",
1919
},
2020
variants: {
2121
level: {
2222
1: {
23-
submenu: "grid-cols-3 bg-menu-1-background",
24-
item: "has-[button[data-state=open]]:bg-menu-1-active-background",
25-
link: "data-[active=true]:bg-menu-1-active-background hover:bg-menu-1-active-background focus-visible:bg-menu-1-active-background",
26-
linkSubtext: "group-[data-active=true]:text-menu-1-subtext",
23+
submenu: "grid-cols-3 bg-background",
24+
item: "has-[button[data-state=open]]:bg-background-low",
25+
link: "data-[active=true]:bg-background-low hover:bg-background-low focus-visible:bg-background-low",
26+
linkSubtext: "group-[data-active=true]:text-body-menu",
2727
},
2828
2: {
29-
submenu: "grid-cols-2 bg-menu-2-background",
30-
item: "has-[button[data-state=open]]:bg-menu-2-active-background",
31-
link: "hover:bg-menu-2-active-background focus-visible:bg-menu-2-active-background data-[active=true]:bg-menu-2-active-background",
32-
linkSubtext: "group-[data-active=true]:text-menu-2-subtext",
29+
submenu: "grid-cols-2 bg-background-low",
30+
item: "has-[button[data-state=open]]:bg-background-medium",
31+
link: "hover:bg-background-medium focus-visible:bg-background-medium data-[active=true]:bg-background-medium",
32+
linkSubtext: "group-[data-active=true]:text-body-menu-low",
3333
},
3434
3: {
35-
submenu: "grid-cols-1 bg-menu-3-background",
36-
item: "has-[button[data-state=open]]:bg-menu-3-active-background",
37-
link: "data-[active=true]:bg-menu-3-active-background hover:bg-menu-3-active-background",
38-
linkSubtext: "group-[data-active=true]:text-menu-3-subtext",
35+
submenu: "grid-cols-1 bg-background-medium",
36+
item: "has-[button[data-state=open]]:bg-background-low`",
37+
link: "data-[active=true]:bg-background-low hover:bg-background-low",
38+
linkSubtext: "group-[data-active=true]:text-body-menu-medium",
3939
},
4040
4: {
41-
submenu: "grid-cols-1 bg-menu-4-background",
42-
item: "has-[button[data-state=open]]:bg-menu-4-active-background",
43-
link: "data-[active=true]:bg-menu-4-active-background hover:bg-menu-4-active-background",
44-
linkSubtext: "group-[data-active=true]:text-menu-4-subtext",
41+
submenu: "grid-cols-1 bg-background-high",
42+
item: "has-[button[data-state=open]]:bg-background-medium",
43+
link: "data-[active=true]:bg-background-medium hover:bg-background-medium",
44+
linkSubtext: "group-[data-active=true]:text-body-menu-high",
4545
},
4646
},
4747
},
@@ -62,7 +62,7 @@ const MenuContent = ({ items, isOpen, sections }: MenuContentProps) => {
6262
<Content asChild>
6363
<motion.div
6464
className={cn(
65-
"absolute inset-x-0 top-19 border border-body-light bg-menu-1-background shadow-md",
65+
"absolute inset-x-0 top-19 border border-body-light bg-background shadow-md",
6666
base()
6767
)}
6868
variants={containerVariants}

src/components/Nav/Mobile/LvlAccordion.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const subtextColorPerLevel = {
3333
}
3434

3535
const backgroundColorPerLevel = {
36-
1: "bg-menu-1-background",
37-
2: "bg-menu-2-background",
38-
3: "bg-menu-3-background",
39-
4: "bg-menu-4-background",
36+
1: "bg-background",
37+
2: "bg-background-low",
38+
3: "bg-background-medium",
39+
4: "bg-background-high",
4040
}
4141

4242
const LvlAccordion = ({

src/components/Nav/Mobile/MenuBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const MenuBody = ({ linkSections, onToggle }: MenuBodyProps) => {
6464

6565
<AccordionContent
6666
className={cn(
67-
"mt-0 bg-menu-2-background p-0",
67+
"mt-0 bg-background-low p-0",
6868
isExpanded && "border-t border-disabled"
6969
)}
7070
>

src/styles/semantic-tokens.css

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
--background: var(--white);
1616
--background-highlight: var(--gray-50);
17-
--background-medium: var(--gray-200); /* TODO: VERIFY */
17+
/* TODO: Add "low" "medium" and "high" to design system */
18+
--background-low: var(--gray-100);
19+
--background-medium: var(--gray-200);
20+
--background-high: var(--gray-300);
1821

1922
/* TODO: Add border color tokens to match DS */
2023

@@ -103,22 +106,10 @@
103106
--shadow-window-box-5: 0px -64px 120px 80px hsla(var(--purple-100), var(--shadow-window-box-5-opacity));
104107

105108
/* Menu colors */
106-
--menu: var(--body);
107-
--menu-hover: var(--gray-200);
108-
--menu-active: var(--primary);
109-
--menu-active-background: var(--primary-high-contrast);
110-
--menu-1-subtext: var(--gray-400);
111-
--menu-1-background: var(--white);
112-
--menu-1-active-background: var(--gray-150);
113-
--menu-2-subtext: var(--gray-400);
114-
--menu-2-background: var(--gray-150);
115-
--menu-2-active-background: var(--gray-200);
116-
--menu-3-subtext: var(--gray-500);
117-
--menu-3-background: var(--gray-200);
118-
--menu-3-active-background: var(--gray-100);
119-
--menu-4-subtext: var(--gray-700);
120-
--menu-4-background: var(--gray-300);
121-
--menu-4-active-background: var(--gray-200);
109+
--body-menu: var(--gray-400);
110+
--body-menu-low: var(--gray-400);
111+
--body-menu-medium: var(--gray-500);
112+
--body-menu-high: var(--gray-700);
122113
}
123114

124115
/* Dark mode token declarations */
@@ -132,7 +123,11 @@
132123

133124
--background: var(--black);
134125
--background-highlight: var(--gray-900);
135-
--background-medium: var(--gray-950); /* TODO: VERIFY */
126+
127+
/* TODO: Add "low" "medium" and "high" to design system */
128+
--background-low: var(--gray-700);
129+
--background-medium: var(--gray-600);
130+
--background-high: var(--gray-800);
136131

137132
/* TODO: Add border color tokens to match DS */
138133

@@ -188,21 +183,9 @@
188183
--shadow-window-box-5-opacity: 0.06;
189184

190185
/* Menu colors */
191-
--menu: var(--body);
192-
--menu-hover: var(--gray-200);
193-
--menu-active: var(--primary);
194-
--menu-active-background: var(--primary-high-contrast);
195-
--menu-1-subtext: var(--gray-400);
196-
--menu-1-background: var(--black);
197-
--menu-1-active-background: var(--gray-700);
198-
--menu-2-subtext: var(--gray-300);
199-
--menu-2-background: var(--gray-700);
200-
--menu-2-active-background: var(--gray-600);
201-
--menu-3-subtext: var(--gray-300);
202-
--menu-3-background: var(--gray-600);
203-
--menu-3-active-background: var(--gray-700);
204-
--menu-4-subtext: var(--gray-300);
205-
--menu-4-background: var(--gray-700);
206-
--menu-4-active-background: var(--gray-800);
186+
--body-menu: var(--gray-400);
187+
--body-menu-low: var(--gray-300);
188+
--body-menu-medium: var(--gray-300);
189+
--body-menu-high: var(--gray-300);
207190
}
208191
}

tailwind.config.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,25 @@ const config = {
136136
medium: "hsla(var(--body-medium))",
137137
light: "hsla(var(--body-light))",
138138
inverse: "hsla(var(--body-inverse))",
139+
140+
// TODO: Add "body-menu" to design system
141+
menu: {
142+
DEFAULT: "hsla(var(--body-menu))",
143+
low: "hsla(var(--body-menu-low))",
144+
medium: "hsla(var(--body-menu-medium))",
145+
high: "hsla(var(--body-menu-high))",
146+
},
139147
},
140148

141149
disabled: "hsla(var(--disabled))",
142150

143151
background: {
144152
DEFAULT: "hsla(var(--background))",
145153
highlight: "hsla(var(--background-highlight))",
154+
// TODO : Add "low" "medium" and "high" to design system
155+
low: "hsla(var(--background-low))",
156+
medium: "hsla(var(--background-medium))",
157+
high: "hsla(var(--background-high))",
146158
},
147159

148160
// TODO: Add border color tokens to match DS
@@ -192,33 +204,6 @@ const config = {
192204
light: "hsla(var(--warning-light))",
193205
},
194206

195-
menu: {
196-
DEFAULT: "hsla(var(--menu))",
197-
hover: "hsla(var(--menu-hover))",
198-
active: "hsla(var(--menu-active))",
199-
"active-background": "hsla(var(--menu-active-background))",
200-
1: {
201-
subtext: "hsla(var(--menu-1-subtext))",
202-
background: "hsla(var(--menu-1-background))",
203-
"active-background": "hsla(var(--menu-1-active-background))",
204-
},
205-
2: {
206-
subtext: "hsla(var(--menu-2-subtext))",
207-
background: "hsla(var(--menu-2-background))",
208-
"active-background": "hsla(var(--menu-2-active-background))",
209-
},
210-
3: {
211-
subtext: "hsla(var(--menu-3-subtext))",
212-
background: "hsla(var(--menu-3-background))",
213-
"active-background": "hsla(var(--menu-3-active-background))",
214-
},
215-
4: {
216-
subtext: "hsla(var(--menu-4-subtext))",
217-
background: "hsla(var(--menu-4-background))",
218-
"active-background": "hsla(var(--menu-4-active-background))",
219-
},
220-
},
221-
222207
/** @deprecated */
223208
"switch-background": "hsla(var(--switch-background))", // TODO: Migrate
224209
"tooltip-shadow": "var(--tooltip-shadow)",

0 commit comments

Comments
 (0)