Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements dark mode theme using https://github.com/ForEvolve/bootstrap-dark. User is able to set theme to: a) light - same as current theme and the default one b) dark - dark version using bootstrap-dark c) auto - either light or dark version will be used depending on browser preference, if browser doesn't support media queries for prefers-color-scheme light theme will be used To make all of this work existing CSS rules were moved into themes folder and converted to scss, both light and dark styles will import that shared CSS file but each might pass different variables to customise generated CSS. Some parts of the shared CSS file use bootstrap and bootstrap-dark variables directly, to avoid redefining what's already defined there. Signed-off-by: Łukasz Mierzwa <l.mierzwa@gmail.com>
- Loading branch information
Showing
23 changed files
with
732 additions
and
102 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
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,77 @@ | ||
import React, { FC, useEffect, lazy } from 'react'; | ||
import { Form, Button, ButtonGroup } from 'reactstrap'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faSpinner, faMoon, faSun, faAdjust } from '@fortawesome/free-solid-svg-icons'; | ||
import { useTheme } from './contexts/ThemeContext'; | ||
|
||
const DarkTheme = lazy(() => import('./themes/dark')); | ||
const LightTheme = lazy(() => import('./themes/light')); | ||
|
||
export const themeLocalStorageKey = 'user-prefers-color-scheme'; | ||
|
||
const ThemeSpinner: FC = () => ( | ||
<div | ||
style={{ | ||
zIndex: 2000, | ||
backgroundColor: '#eee', | ||
position: 'fixed', | ||
top: 0, | ||
left: 0, | ||
width: '100vw', | ||
height: '100vh', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<FontAwesomeIcon | ||
size="8x" | ||
icon={faSpinner} | ||
spin | ||
className="position-absolute" | ||
style={{ transform: 'translate(-50%, -50%)', top: '50%', left: '50%' }} | ||
/> | ||
</div> | ||
); | ||
|
||
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 <React.Suspense fallback={<ThemeSpinner />}>{theme === 'dark' ? <DarkTheme /> : <LightTheme />}</React.Suspense>; | ||
}; | ||
|
||
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} /> | ||
</Button> | ||
<Button color="secondary" title="Use dark theme" active={userPreference === 'dark'} onClick={() => setTheme('dark')}> | ||
<FontAwesomeIcon icon={faMoon} /> | ||
</Button> | ||
<Button | ||
color="secondary" | ||
title="Use browser preferred theme" | ||
active={userPreference === 'auto'} | ||
onClick={() => setTheme('auto')} | ||
> | ||
<FontAwesomeIcon icon={faAdjust} /> | ||
</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,20 @@ | ||
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; | ||
} | ||
|
||
export const ThemeContext = React.createContext<themeCtx>({ | ||
theme: 'light', | ||
userPreference: 'auto', | ||
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
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@import '~@forevolve/bootstrap-dark/dist/css/toggle-bootstrap-dark.min.css'; | ||
|
||
@import '~bootstrap/scss/functions'; | ||
@import '~bootstrap/scss/variables'; | ||
@import '~@forevolve/bootstrap-dark/scss/_dark-variables.scss'; | ||
|
||
$config-yaml-color: $white; | ||
$config-yaml-bg: $jumbotron-bg; | ||
$config-yaml-border: $gray-700; | ||
|
||
$alert_cell-color: $white; | ||
$rule_cell-bg: $gray-900; | ||
|
||
.bootstrap-dark { | ||
@import './shared.scss'; | ||
} |
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,7 @@ | ||
import { FC } from 'react'; | ||
|
||
import './dark.scss'; | ||
|
||
const DarkTheme: FC = () => null; | ||
|
||
export default DarkTheme; |
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,15 @@ | ||
@import '~@forevolve/bootstrap-dark/dist/css/toggle-bootstrap.min.css'; | ||
|
||
@import '~bootstrap/scss/functions'; | ||
@import '~bootstrap/scss/variables'; | ||
|
||
$config-yaml-color: #333; | ||
$config-yaml-bg: $jumbotron-bg; | ||
$config-yaml-border: #ccc; | ||
|
||
$alert_cell-color: inherit; | ||
$rule_cell-bg: #f5f5f5; | ||
|
||
.bootstrap { | ||
@import './shared.scss'; | ||
} |
Oops, something went wrong.