-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Default color mode to user's current system theme #3456
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,15 @@ interface ThemeContextProviderProps { | |
export const ThemeContextProvider: FC<ThemeContextProviderProps> = ({ | ||
children, | ||
}) => { | ||
const currentTheme = (localStorage.getItem('theme') as Theme) || Theme.LIGHT | ||
const [theme, setTheme] = useState<Theme>(currentTheme) | ||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only logic changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on moving this logic to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did consider that approach, though I ended up on preferring to have all the theme logic in one place |
||
|
||
let systemTheme = Theme.LIGHT | ||
if (prefersDark) { | ||
systemTheme = Theme.DARK | ||
} | ||
|
||
const currentTheme = localStorage.getItem('theme') as Theme | ||
const [theme, setTheme] = useState<Theme>(currentTheme ?? systemTheme) | ||
const initialRender = useRef(true) | ||
|
||
if (initialRender.current) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is uncommented now