utils#themeToggler JavaScript Examples
The following examples show how to use
utils#themeToggler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sidebar.js From raster-playground with GNU General Public License v3.0 | 5 votes |
export default function Sidebar({ setTheme, theme }) {
const [colors] = useQueryParam(URL_COLORS, StringParam);
const [opacity] = useQueryParam(URL_OPACITY, StringParam);
const [text, setText] = useState('');
const [colorFormat, setColorFormat] = useState('rgba');
useEffect(() => {
const colorArray = getColorsArray(colors);
setText(
JSON.stringify(copyColor(colorArray, opacity, colorFormat), undefined, 4)
);
}, [colors, opacity, colorFormat]);
const handleColorFormatChange = event => {
setColorFormat(event.target.value);
};
return (
<ThemeProvider theme={theme === 'light' ? lightTheme : darkTheme}>
<GlobalStyles />
<div className="sidebar">
<div className="sidebar-wrapper">
<h1 className="logo">
Raster<span>Playground</span>
</h1>
<div className="theme-switch-wrapper theme-toggle">
<label
className="switch"
htmlFor="checkbox"
title="Change color scheme"
>
<input
type="checkbox"
id="checkbox"
onChange={() =>
themeToggler(theme === 'light' ? 'dark' : 'light', setTheme)
}
checked={theme === 'light' ? '' : 'checked'}
/>
<div className="slider round"></div>
<div className="toggle-sun">☀️</div>
<div className="toggle-moon">?</div>
</label>
</div>
<hr />
<ShapeInput />
<br />
<br />
<TilesInput />
<br />
<br />
<ColorsInput />
<br />
<AlphaInput />
<br />
<br />
<select
id="color-format"
defaultValue="rgba"
onChange={event => handleColorFormatChange(event)}
>
<option value="hex">HEX</option>
<option value="rgba">RGBA</option>
<option value="hsla">HSLA</option>
</select>
<CopyToClipboard text={text}>
<button className="copy-btn">Copy</button>
</CopyToClipboard>
<br />
<JSONPretty
id="json-pretty"
data={text}
theme={JSONPrettyMon}
></JSONPretty>
</div>
</div>
</ThemeProvider>
);
}
Example #2
Source File: main.js From raster-playground with GNU General Public License v3.0 | 5 votes |
export default function Main() {
const [shape, onChangeShape] = useQueryParam(URL_SHAPE, StringParam);
const [tiles, onChangeTiles] = useQueryParam(URL_TILES, StringParam);
const [colors, onChangeColors] = useQueryParam(URL_COLORS, StringParam);
const [opacity, onChangeOpacity] = useQueryParam(URL_OPACITY, StringParam);
const [theme, setTheme] = useCookie('theme-color');
useEffectOnce(() => {
if (!theme) themeToggler(THEME_DEFAULT, setTheme);
else themeToggler(theme, setTheme);
}, [theme]);
useEffect(() => {
if (!shape) {
onChangeShape(SHAPE_URL_DEFAULT, URL_UPDATE_PUSH);
}
}, [shape, onChangeShape]);
useEffect(() => {
if (!tiles) {
onChangeTiles(TILES_URL_DEFAULT, URL_UPDATE_PUSH);
}
}, [tiles, onChangeTiles]);
useEffect(() => {
if (!colors) {
onChangeColors(COLORS_DEFAULT, URL_UPDATE_PUSH);
}
}, [colors, onChangeColors]);
useEffect(() => {
if (!opacity) {
onChangeOpacity(OPACITY_DEFAULT, URL_UPDATE_PUSH);
}
}, [opacity, onChangeOpacity]);
return (
<>
<MainApp theme={theme} setTheme={setTheme} />
</>
);
}