parent
11d5983028
commit
6bf88714fa
15 changed files with 146 additions and 58 deletions
@ -0,0 +1,36 @@ |
||||
import React, {useState, useEffect} from "react"; |
||||
|
||||
const Appearance = ({fonts}) => { |
||||
const [font, setFont] = useState(""); |
||||
const [highlightColor, setHighlightColor] = useState(""); |
||||
|
||||
const changeFont = event => { |
||||
const value = event.target.value; |
||||
setFont(value); |
||||
window.appSettings.set("font", value); |
||||
}; |
||||
|
||||
const changeColor = event => { |
||||
const value = event.target.value; |
||||
setHighlightColor(value); |
||||
window.appSettings.set("highlightColor", value); |
||||
}; |
||||
|
||||
useEffect(() => { |
||||
(async setFont => setFont(await window.appSettings.get("font", "Iosevka")))(setFont); |
||||
(async setHighlightColor => setHighlightColor(await window.appSettings.get("highlightColor", "#e6c17b")))(setHighlightColor); |
||||
}, []); |
||||
|
||||
return ( |
||||
<section className="grid"> |
||||
<label>Font in slides:</label> |
||||
<select value={font} onChange={changeFont}> |
||||
{fonts.map(font => font.trim().replace(/(^"|"$)/g, "")).map(font => <option key={font} value={font}>{font}</option>)} |
||||
</select> |
||||
<label>Global highlight color:</label> |
||||
<input type="color" value={highlightColor} onChange={changeColor} /> |
||||
</section> |
||||
); |
||||
}; |
||||
|
||||
export default Appearance; |
@ -1,27 +1,10 @@ |
||||
import React, {useState, useEffect} from "react"; |
||||
import React from "react"; |
||||
|
||||
const General = ({fonts}) => { |
||||
const [font, setFont] = useState(""); |
||||
|
||||
const changeFont = event => { |
||||
const value = event.target.value; |
||||
setFont(value); |
||||
window.appSettings.set("font", value); |
||||
}; |
||||
|
||||
useEffect(() => { |
||||
(async setFont => setFont(await window.appSettings.get("font", "Iosevka")))(setFont); |
||||
}, []); |
||||
const General = () => { |
||||
|
||||
return ( |
||||
<section className="grid"> |
||||
<label>Font in slides:</label> |
||||
<select value={font} onChange={changeFont}> |
||||
{fonts.map(font => font.trim().replace(/(^"|"$)/g, "")).map(font => <option key={font} value={font}>{font}</option>)} |
||||
</select> |
||||
<label>Global highlight color:</label> |
||||
<input type="color" /> |
||||
</section> |
||||
<> |
||||
</> |
||||
); |
||||
}; |
||||
|
||||
|
@ -0,0 +1,22 @@ |
||||
import React, {useState, useEffect} from "react"; |
||||
|
||||
import SettingsContext from "../shared/SettingsContext"; |
||||
|
||||
const withSettings = Component => () => { |
||||
const [settings, setSettings] = useState({ |
||||
font : "Iosevka" |
||||
}); |
||||
|
||||
useEffect(() => { |
||||
(async setSettings => setSettings(await window.appSettings.all()))(setSettings); |
||||
window.appSettings.onChange(settings => setSettings(settings)); |
||||
}, []); |
||||
|
||||
return ( |
||||
<SettingsContext.Provider value={{...settings}}> |
||||
<Component /> |
||||
</SettingsContext.Provider> |
||||
); |
||||
}; |
||||
|
||||
export default withSettings; |
@ -0,0 +1,5 @@ |
||||
import {createContext} from "react"; |
||||
|
||||
const SettingsContext = createContext({}); |
||||
|
||||
export default SettingsContext; |
Loading…
Reference in new issue