2
2
3
3
import { Fragment , useEffect , useState } from 'react'
4
4
import { useTheme } from 'next-themes'
5
- import { Menu , RadioGroup , Transition } from '@headlessui/react'
5
+ import {
6
+ Menu ,
7
+ MenuButton ,
8
+ MenuItem ,
9
+ MenuItems ,
10
+ Radio ,
11
+ RadioGroup ,
12
+ Transition ,
13
+ } from '@headlessui/react'
6
14
7
15
const Sun = ( ) => (
8
16
< svg
@@ -57,9 +65,9 @@ const ThemeSwitch = () => {
57
65
< div className = "mr-5 flex items-center" >
58
66
< Menu as = "div" className = "relative inline-block text-left" >
59
67
< div className = "flex items-center justify-center hover:text-primary-500 dark:hover:text-primary-400" >
60
- < Menu . Button aria-label = "Theme switcher" >
68
+ < MenuButton aria-label = "Theme switcher" >
61
69
{ mounted ? resolvedTheme === 'dark' ? < Moon /> : < Sun /> : < Blank /> }
62
- </ Menu . Button >
70
+ </ MenuButton >
63
71
</ div >
64
72
< Transition
65
73
as = { Fragment }
@@ -70,31 +78,29 @@ const ThemeSwitch = () => {
70
78
leaveFrom = "transform opacity-100 scale-100"
71
79
leaveTo = "transform opacity-0 scale-95"
72
80
>
73
- < Menu . Items className = "absolute right-0 z-50 mt-2 w-32 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-800" >
81
+ < MenuItems className = "absolute right-0 z-50 mt-2 w-32 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-800" >
74
82
< RadioGroup value = { theme } onChange = { setTheme } >
75
83
< div className = "p-1" >
76
- < RadioGroup . Option value = "light" >
77
- < Menu . Item >
78
- { ( { active } ) => (
84
+ < Radio value = "light" >
85
+ < MenuItem >
86
+ { ( { focus } ) => (
79
87
< 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`}
88
+ className = { `${ focus ? 'bg-primary-600 text-white' : '' } group flex w-full items-center rounded-md px-2 py-2 text-sm` }
83
89
>
84
90
< div className = "mr-2" >
85
91
< Sun />
86
92
</ div >
87
93
Light
88
94
</ button >
89
95
) }
90
- </ Menu . Item >
91
- </ RadioGroup . Option >
92
- < RadioGroup . Option value = "dark" >
93
- < Menu . Item >
94
- { ( { active } ) => (
96
+ </ MenuItem >
97
+ </ Radio >
98
+ < Radio value = "dark" >
99
+ < MenuItem >
100
+ { ( { focus } ) => (
95
101
< button
96
102
className = { `${
97
- active ? 'bg-primary-600 text-white' : ''
103
+ focus ? 'bg-primary-600 text-white' : ''
98
104
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
99
105
>
100
106
< div className = "mr-2" >
@@ -103,14 +109,14 @@ const ThemeSwitch = () => {
103
109
Dark
104
110
</ button >
105
111
) }
106
- </ Menu . Item >
107
- </ RadioGroup . Option >
108
- < RadioGroup . Option value = "system" >
109
- < Menu . Item >
110
- { ( { active } ) => (
112
+ </ MenuItem >
113
+ </ Radio >
114
+ < Radio value = "system" >
115
+ < MenuItem >
116
+ { ( { focus } ) => (
111
117
< button
112
118
className = { `${
113
- active ? 'bg-primary-600 text-white' : ''
119
+ focus ? 'bg-primary-600 text-white' : ''
114
120
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
115
121
>
116
122
< div className = "mr-2" >
@@ -119,11 +125,11 @@ const ThemeSwitch = () => {
119
125
System
120
126
</ button >
121
127
) }
122
- </ Menu . Item >
123
- </ RadioGroup . Option >
128
+ </ MenuItem >
129
+ </ Radio >
124
130
</ div >
125
131
</ RadioGroup >
126
- </ Menu . Items >
132
+ </ MenuItems >
127
133
</ Transition >
128
134
</ Menu >
129
135
</ div >
0 commit comments