-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from boostcampwm-2024/Design/379
[Design] 멀티 테마 구현 (라이트 모드/ 다크 모드 전환)
- Loading branch information
Showing
16 changed files
with
137 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Button } from '@components/ui/button'; | ||
import { ThemeIcon } from '@components/Icons'; | ||
import { useTheme } from '@/hooks/useTheme'; | ||
|
||
function FloatingButton() { | ||
const { convertTheme } = useTheme(); | ||
|
||
return ( | ||
<div className="fixed bottom-3 right-5"> | ||
<Button | ||
onClick={convertTheme} | ||
className="h-10 w-10 rounded rounded-circle p-0 bg-surface-brand-default hover:bg-surface-brand-alt" | ||
> | ||
<ThemeIcon size={48} /> | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
export default FloatingButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
interface IconProps { | ||
size?: number; | ||
className?: string; | ||
} | ||
|
||
function ThemeIcon({ size = 36, className = '' }: IconProps) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
viewBox="0 0 24 24" | ||
width={size} | ||
height={size} | ||
className={className} | ||
> | ||
<path d="M0,9c0-.552,.448-1,1-1H3.108c.147-.874,.472-1.721,1.006-2.471l-1.478-1.478c-.391-.391-.391-1.023,0-1.414s1.023-.391,1.414,0l1.478,1.478c.751-.534,1.598-.859,2.471-1.006V1c0-.552,.448-1,1-1s1,.448,1,1V3.108c.874,.147,1.725,.466,2.477,1.001l1.473-1.473c.391-.391,1.023-.391,1.414,0s.391,1.023,0,1.414l-2.121,2.121c-.391,.391-1.023,.391-1.414,0-1.56-1.56-4.098-1.56-5.657,0s-1.56,4.098,0,5.657c.188,.188,.293,.442,.293,.707s-.105,.52-.293,.708l-2.208,2.207c-.195,.195-.451,.293-.707,.293s-.512-.098-.707-.293c-.391-.391-.391-1.023,0-1.414l1.56-1.56c-.535-.751-.854-1.602-1.001-2.477H1c-.552,0-1-.448-1-1ZM23.707,.293c-.391-.391-1.023-.391-1.414,0L.293,22.293c-.391,.391-.391,1.023,0,1.414,.195,.195,.451,.293,.707,.293s.512-.098,.707-.293L23.707,1.707c.391-.391,.391-1.023,0-1.414Zm-.283,10.954c.32-.15,.538-.458,.572-.811,.034-.352-.121-.696-.408-.904-1.017-.739-2.203-1.234-3.429-1.432-.541-.09-1.059,.283-1.146,.829-.088,.545,.283,1.058,.829,1.146,.41,.066,.813,.176,1.203,.328-1.65,1.36-2.653,3.41-2.653,5.597s1.003,4.238,2.655,5.598c-.683,.266-1.41,.402-2.155,.402-2.967,0-5.52-2.21-5.939-5.142-.078-.547-.586-.924-1.131-.849-.547,.078-.927,.585-.848,1.132,.559,3.91,3.964,6.858,7.919,6.858,1.695,0,3.32-.53,4.697-1.533,.286-.208,.441-.553,.407-.904-.034-.353-.251-.66-.572-.811-1.842-.861-3.033-2.727-3.033-4.752s1.19-3.891,3.033-4.753Z" /> | ||
</svg> | ||
); | ||
} | ||
|
||
export default ThemeIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createContext, useState } from 'react'; | ||
|
||
type Theme = 'light' | 'dark' | null; | ||
|
||
interface ThemeContextInterface { | ||
theme: Theme; | ||
setTheme: React.Dispatch<React.SetStateAction<Theme>>; | ||
} | ||
|
||
const currentTheme = localStorage.getItem('theme') ?? null; | ||
|
||
export const ThemeContext = createContext<ThemeContextInterface>({ | ||
theme: currentTheme as Theme, | ||
setTheme: () => null, | ||
}); | ||
|
||
export function ThemeProvider({ children }: { children: React.ReactNode }) { | ||
const [theme, setTheme] = useState<Theme>(() => (localStorage.getItem('theme') as Theme) ?? null); | ||
return <ThemeContext.Provider value={{ theme, setTheme }}>{children}</ThemeContext.Provider>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ThemeContext } from '@/contexts/ThemeContext'; | ||
import { useContext, useLayoutEffect } from 'react'; | ||
|
||
export const useTheme = () => { | ||
const { theme, setTheme } = useContext(ThemeContext); | ||
|
||
useLayoutEffect(() => { | ||
if (theme === 'dark') { | ||
localStorage.setItem('theme', 'dark'); | ||
document.querySelector('html')?.removeAttribute('data-theme'); | ||
} else { | ||
localStorage.setItem('theme', 'light'); | ||
document.querySelector('html')?.setAttribute('data-theme', 'light'); | ||
} | ||
}, [theme]); | ||
|
||
const convertTheme = () => { | ||
if (theme === 'light') { | ||
setTheme('dark'); | ||
} else { | ||
setTheme('light'); | ||
} | ||
}; | ||
|
||
return { theme, convertTheme }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters