1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-10-16 20:17:25 +00:00

Implement working SelectTheme

This commit is contained in:
Stefano Pigozzi 2021-04-21 18:58:14 +02:00
parent 24f70457b6
commit 3a5cfbbe8d
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01
8 changed files with 59 additions and 5 deletions

View file

@ -12,10 +12,10 @@ import PageSettings from "./routes/PageSettings"
export default function App() {
const [theme, ] = useState("ThemeDark");
const [theme, setTheme] = useState("ThemeDark");
return (
<ContextTheme.Provider value={theme}>
<ContextTheme.Provider value={[theme, setTheme]}>
<BrowserRouter>
<div className={classNames(Style.App, theme)}>

View file

@ -8,6 +8,8 @@
color: var(--fg-field-off);
background-color: var(--bg-field-off);
font-family: var(--font-regular);
}
.Input:focus {

View file

@ -5,7 +5,7 @@ import ContextTheme from "../contexts/ContextTheme"
export default function Logo({ children, className, ...props }) {
const theme = useContext(ContextTheme)
const [theme, ] = useContext(ContextTheme)
let logo;
if(theme === "ThemeDark") {

View file

@ -0,0 +1,12 @@
import React from "react"
import Style from "./Select.module.css"
import classNames from "classnames"
export default function Select({ children, className, ...props }) {
return (
<select className={classNames(Style.Select, className)} {...props}>
{children}
</select>
)
}

View file

@ -0,0 +1,23 @@
.Select {
border-radius: 25px;
border-width: 0;
min-height: 28px;
padding: 2px 10px;
margin: 2px;
color: var(--fg-field-off);
background-color: var(--bg-field-off);
font-family: var(--font-regular);
/* Non ho idea di perchè serva */
vertical-align: bottom;
}
.Select:focus {
outline: 0; /* TODO: Questo è sconsigliato dalle linee guida sull'accessibilità! */
color: var(--fg-field-on);
background-color: var(--bg-field-on);
}

View file

@ -0,0 +1,15 @@
import React, {useContext} from "react"
import Select from "./Select"
import ContextTheme from "../contexts/ContextTheme"
export default function SelectTheme({ children, ...props }) {
const [theme, setTheme] = useContext(ContextTheme);
return (
<Select value={theme} onChange={e => setTheme(e.target.value)} {...props}>
<option value={"ThemeDark"}>Dark</option>
<option value={"ThemeLight"}>Light</option>
</Select>
)
}

View file

@ -1,4 +1,4 @@
import {createContext} from "react";
const ContextTheme = createContext("ThemeDark")
const ContextTheme = createContext(["ThemeDark", undefined])
export default ContextTheme

View file

@ -3,6 +3,8 @@ import Style from "./PageSettings.module.css"
import classNames from "classnames"
import BoxHeaderOnly from "../components/BoxHeaderOnly"
import BoxWithHeader from "../components/BoxWithHeader"
import Select from "../components/Select"
import SelectTheme from "../components/SelectTheme"
export default function PageSettings({ children, className, ...props }) {
@ -12,7 +14,7 @@ export default function PageSettings({ children, className, ...props }) {
You are currently logged in as:
</BoxHeaderOnly>
<BoxHeaderOnly>
Switch theme:
Switch theme: <SelectTheme/>
</BoxHeaderOnly>
<BoxWithHeader header={"Change your email address"}>