Skip to content

Commit ee99647

Browse files
committed
feat: Refactor menu items with { active } to use headlessui highlighting
1 parent 44b5637 commit ee99647

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

components/ThemeSwitch.tsx

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,50 @@ const ThemeSwitch = () => {
7575
<div className="p-1">
7676
<RadioGroup.Option value="light">
7777
<Menu.Item>
78-
<button className="group flex w-full items-center rounded-md px-2 py-2 text-sm">
79-
<div className="mr-2">
80-
<Sun />
81-
</div>
82-
Light
83-
</button>
78+
{({ active }) => (
79+
<button
80+
className={`${
81+
active ? 'bg-primary-600 text-white' : ''
82+
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
83+
>
84+
<div className="mr-2">
85+
<Sun />
86+
</div>
87+
Light
88+
</button>
89+
)}
8490
</Menu.Item>
8591
</RadioGroup.Option>
8692
<RadioGroup.Option value="dark">
8793
<Menu.Item>
88-
<button className="group flex w-full items-center rounded-md px-2 py-2 text-sm">
89-
<div className="mr-2">
90-
<Moon />
91-
</div>
92-
Dark
93-
</button>
94+
{({ active }) => (
95+
<button
96+
className={`${
97+
active ? 'bg-primary-600 text-white' : ''
98+
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
99+
>
100+
<div className="mr-2">
101+
<Moon />
102+
</div>
103+
Dark
104+
</button>
105+
)}
94106
</Menu.Item>
95107
</RadioGroup.Option>
96108
<RadioGroup.Option value="system">
97109
<Menu.Item>
98-
<button className="group flex w-full items-center rounded-md px-2 py-2 text-sm">
99-
<div className="mr-2">
100-
<Monitor />
101-
</div>
102-
System
103-
</button>
110+
{({ active }) => (
111+
<button
112+
className={`${
113+
active ? 'bg-primary-600 text-white' : ''
114+
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
115+
>
116+
<div className="mr-2">
117+
<Monitor />
118+
</div>
119+
System
120+
</button>
121+
)}
104122
</Menu.Item>
105123
</RadioGroup.Option>
106124
</div>

0 commit comments

Comments
 (0)