-
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 a0a056b
Showing
28 changed files
with
993 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,57 @@ | ||
/* | ||
* | ||
* THIS FILE WAS COPIED INTO THANOS FROM PROMETHEUS | ||
* (LIVING AT https://github.com/prometheus/prometheus/blob/main/web/ui/react-app/src/Theme.tsx), | ||
* THE ORIGINAL CODE WAS LICENSED UNDER AN APACHE 2.0 LICENSE, SEE | ||
* https://github.com/prometheus/prometheus/blob/main/LICENSE. | ||
* | ||
*/ | ||
|
||
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,31 @@ | ||
/* | ||
* | ||
* THIS FILE WAS COPIED INTO THANOS FROM PROMETHEUS | ||
* (LIVING AT https://github.com/prometheus/prometheus/blob/main/web/ui/react-app/src/contexts/ThemeContext.tsx), | ||
* THE ORIGINAL CODE WAS LICENSED UNDER AN APACHE 2.0 LICENSE, SEE | ||
* https://github.com/prometheus/prometheus/blob/main/LICENSE. | ||
* | ||
*/ | ||
|
||
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.