1
- 'use client' ;
1
+ 'use client'
2
2
3
- import { useEffect , useState } from 'react' ;
4
- import { useTheme } from 'next-themes' ;
5
-
6
- import { IconSvgProps } from '~/types' ;
3
+ import { useEffect , useState } from 'react'
4
+ import { useTheme } from 'next-themes'
5
+ import { MoonFilledIcon , SunFilledIcon } from '@nextui-org/shared-icons'
7
6
8
7
export const ThemeSwitch = ( ) => {
8
+ const [ mounted , setMounted ] = useState ( false )
9
+ const { theme, setTheme } = useTheme ( )
9
10
10
- const [ mounted , setMounted ] = useState ( false )
11
- const { theme, setTheme } = useTheme ( )
12
-
13
- useEffect ( ( ) => {
14
- setMounted ( true )
15
- } , [ ] )
16
-
17
- if ( ! mounted ) return null
11
+ useEffect ( ( ) => {
12
+ setMounted ( true )
13
+ } , [ ] )
18
14
19
- const SunFilledIcon = ( { size = 24 , width, height, ...props } : IconSvgProps ) => (
20
- < svg
21
- aria-hidden = "true"
22
- focusable = "false"
23
- height = { size || height }
24
- role = "presentation"
25
- viewBox = "0 0 24 24"
26
- width = { size || width }
27
- { ...props }
28
- >
29
- < g fill = "currentColor" >
30
- < path d = "M19 12a7 7 0 11-7-7 7 7 0 017 7z" />
31
- < path d = "M12 22.96a.969.969 0 01-1-.96v-.08a1 1 0 012 0 1.038 1.038 0 01-1 1.04zm7.14-2.82a1.024 1.024 0 01-.71-.29l-.13-.13a1 1 0 011.41-1.41l.13.13a1 1 0 010 1.41.984.984 0 01-.7.29zm-14.28 0a1.024 1.024 0 01-.71-.29 1 1 0 010-1.41l.13-.13a1 1 0 011.41 1.41l-.13.13a1 1 0 01-.7.29zM22 13h-.08a1 1 0 010-2 1.038 1.038 0 011.04 1 .969.969 0 01-.96 1zM2.08 13H2a1 1 0 010-2 1.038 1.038 0 011.04 1 .969.969 0 01-.96 1zm16.93-7.01a1.024 1.024 0 01-.71-.29 1 1 0 010-1.41l.13-.13a1 1 0 011.41 1.41l-.13.13a.984.984 0 01-.7.29zm-14.02 0a1.024 1.024 0 01-.71-.29l-.13-.14a1 1 0 011.41-1.41l.13.13a1 1 0 010 1.41.97.97 0 01-.7.3zM12 3.04a.969.969 0 01-1-.96V2a1 1 0 012 0 1.038 1.038 0 01-1 1.04z" />
32
- </ g >
33
- </ svg >
34
- ) ;
35
- const MoonFilledIcon = ( { size = 24 , width, height, ...props } : IconSvgProps ) => (
36
- < svg
37
- aria-hidden = "true"
38
- focusable = "false"
39
- height = { size || height }
40
- role = "presentation"
41
- viewBox = "0 0 24 24"
42
- width = { size || width }
43
- { ...props }
44
- >
45
- < path
46
- d = "M21.53 15.93c-.16-.27-.61-.69-1.73-.49a8.46 8.46 0 01-1.88.13 8.409 8.409 0 01-5.91-2.82 8.068 8.068 0 01-1.44-8.66c.44-1.01.13-1.54-.09-1.76s-.77-.55-1.83-.11a10.318 10.318 0 00-6.32 10.21 10.475 10.475 0 007.04 8.99 10 10 0 002.89.55c.16.01.32.02.48.02a10.5 10.5 0 008.47-4.27c.67-.93.49-1.519.32-1.79z"
47
- fill = "currentColor"
48
- />
49
- </ svg >
50
- ) ;
15
+ if ( ! mounted ) return null
51
16
52
- return (
53
- < button onClick = { ( ) => setTheme ( theme === 'light' ? 'dark' : 'light' ) } >
54
- { theme === 'light' ? < SunFilledIcon size = { 22 } /> : < MoonFilledIcon className = "text-white" size = { 22 } /> }
55
- </ button >
56
- ) ;
17
+ return (
18
+ < button onClick = { ( ) => setTheme ( theme === 'light' ? 'dark' : 'light' ) } >
19
+ { theme === 'light' ? < SunFilledIcon height = { 24 } width = { 24 } /> : < MoonFilledIcon height = { 24 } width = { 24 } /> }
20
+ </ button >
21
+ ) ;
57
22
} ;
0 commit comments