-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aman Dwivedi <[email protected]>
- Loading branch information
1 parent
eacc686
commit 895fd18
Showing
28 changed files
with
937 additions
and
234 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { FC, useEffect } from 'react'; | ||
import { Form, Button, ButtonGroup } from 'reactstrap'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faMoon, faSun, faAdjust } from '@fortawesome/free-solid-svg-icons'; | ||
import { useTheme } from './contexts/ThemeContext'; | ||
|
||
export const themeLocalStorageKey = 'user-prefers-color-scheme'; | ||
|
||
export const Theme: FC = () => { | ||
const { theme } = useTheme(); | ||
|
||
useEffect(() => { | ||
document.body.classList.toggle('bootstrap-dark', theme === 'dark'); | ||
document.body.classList.toggle('bootstrap', theme === 'light'); | ||
}, [theme]); | ||
|
||
return null; | ||
}; | ||
|
||
export const ThemeToggle: FC = () => { | ||
const { userPreference, setTheme } = useTheme(); | ||
|
||
return ( | ||
<Form className="ml-auto" inline> | ||
<ButtonGroup size="sm"> | ||
<Button | ||
color="secondary" | ||
title="Use light theme" | ||
active={userPreference === 'light'} | ||
onClick={() => setTheme('light')} | ||
> | ||
<FontAwesomeIcon icon={faSun} className={userPreference === 'light' ? 'text-white' : 'text-dark'} /> | ||
</Button> | ||
<Button color="secondary" title="Use dark theme" active={userPreference === 'dark'} onClick={() => setTheme('dark')}> | ||
<FontAwesomeIcon icon={faMoon} className={userPreference === 'dark' ? 'text-white' : 'text-dark'} /> | ||
</Button> | ||
<Button | ||
color="secondary" | ||
title="Use browser-preferred theme" | ||
active={userPreference === 'auto'} | ||
onClick={() => setTheme('auto')} | ||
> | ||
<FontAwesomeIcon icon={faAdjust} className={userPreference === 'auto' ? 'text-white' : 'text-dark'} /> | ||
</Button> | ||
</ButtonGroup> | ||
</Form> | ||
); | ||
}; |
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,22 @@ | ||
import React from 'react'; | ||
|
||
export type themeName = 'light' | 'dark'; | ||
export type themeSetting = themeName | 'auto'; | ||
|
||
export interface ThemeCtx { | ||
theme: themeName; | ||
userPreference: themeSetting; | ||
setTheme: (t: themeSetting) => void; | ||
} | ||
|
||
// defaults, will be overriden in App.tsx | ||
export const ThemeContext = React.createContext<ThemeCtx>({ | ||
theme: 'light', | ||
userPreference: 'auto', | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
setTheme: (s: themeSetting) => {}, | ||
}); | ||
|
||
export const useTheme = () => { | ||
return React.useContext(ThemeContext); | ||
}; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.