Skip to content

Commit

Permalink
Updated bootstrap to 5.2.3.
Browse files Browse the repository at this point in the history
Removed bootstrap-dark from dependencies.
The current theme is now synchronized with the react select component.
  • Loading branch information
lupusA committed May 3, 2023
1 parent f89430f commit a3c3c67
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 65 deletions.
61 changes: 24 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@fortawesome/free-regular-svg-icons": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"bootstrap-dark-5": "^1.1.3",
"bootstrap": "^5.2.3",
"http-proxy-middleware": "^2.0.6",
"moment": "^2.29.3",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import 'bootstrap-dark-5/dist/css/bootstrap-nightshade.min.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import { React, Component } from 'react';
import { Navbar, Nav, Container} from 'react-bootstrap';
import { BrowserRouter as Router, NavLink, Redirect, Route, Switch } from 'react-router-dom';
Expand Down
18 changes: 14 additions & 4 deletions src/ThemeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ import { Theme, UIPreferencesContext } from './contexts/UIPreferencesContext';

export function ThemeSelector() {
const { theme, setTheme } = useContext(UIPreferencesContext);


//Contains all supported themes
const themes = [
{ value: 'light-theme', label: 'light' },
{ value: 'dark-theme', label: 'dark' },
{ value: 'pastel-theme', label: 'pastel' },
{ value: 'ocean-theme', label: 'ocean' }
]

//Finds the current selected theme within supported themes
const currentTheme = themes.find(o => o.value === theme);
updateTheme(theme)

/**
* Handles the theme selection by the user
* @param event
*/
const handleTheme = (event: any) => {
var selectedTheme = event.value;
// keep html class in sync with button state.
updateTheme(selectedTheme)
setTheme(selectedTheme)
};

return <Select options={themes} classNamePrefix="select" onChange={handleTheme}
return <Select options={themes} value={currentTheme} classNamePrefix="select" onChange={handleTheme}
components={{
SingleValue: ({ children, ...props }) => {
return (
Expand All @@ -32,6 +38,10 @@ export function ThemeSelector() {
}}}/>
}

/**
* Keeps the html in sync with the current selected theme
* @param theme
*/
function updateTheme(theme: Theme) {
var doc = document.querySelector("html")!;
doc.className = theme
Expand Down
21 changes: 0 additions & 21 deletions src/ToggleDarkModeButton.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion src/contexts/UIPreferencesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ export interface UIPreferenceProviderProps {
initalValue: UIPreferences | undefined
}

/**
* Returns a default theme based on the user's browser settings.
* @returns Theme
*/
function getDefaultTheme(): Theme {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
// browser supports light/dark mode and user prefers dark theme.
return "dark-theme";
}

Expand Down

0 comments on commit a3c3c67

Please sign in to comment.