1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-02 09:25:17 +02:00

Theme changing. Simple routing

This commit is contained in:
unknown 2021-05-07 18:30:06 +02:00
parent 573814ddac
commit 765418d3d2
19 changed files with 378 additions and 59 deletions

View file

@ -1,38 +0,0 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

19
client/src/App.module.css Normal file
View file

@ -0,0 +1,19 @@
.SettingsButton {
width: 35px;
height: 35px;
background-color: var(--color-accent);
border-radius: 50%;
position: absolute;
bottom: 10px;
left: 10px;
display: flex;
justify-content: center;
align-items: center;
opacity: 0.25;
transition: all 0.3s;
}
.SettingsButton:hover {
cursor: pointer;
opacity: 1;
}

View file

@ -1,10 +1,23 @@
import './App.css';
import Themer from './components/Themer/Themer';
import { BrowserRouter, Route, Switch, Link } from 'react-router-dom';
import classes from './App.module.css';
import Apps from './components/Apps/Apps';
import Settings from './components/Settings/Settings';
import Icon from './components/UI/Icon/Icon';
const App = (): JSX.Element => {
return (
<Themer />
<BrowserRouter>
<Switch>
<Route exact path='/' component={Apps} />
<Route exact path='/settings' component={Settings} />
</Switch>
<Link to='/settings' className={classes.SettingsButton}>
<Icon icon='mdiCog' />
</Link>
</BrowserRouter>
);
}

View file

@ -0,0 +1,17 @@
import { Link } from 'react-router-dom';
import classes from './Apps.module.css';
import { Container } from '../UI/Layout/Layout';
import Headline from '../UI/Headline/Headline';
const Apps = (): JSX.Element => {
return (
<Container>
<Headline title='Welcome' />
<Link to='/settings'>settings</Link>
</Container>
)
}
export default Apps;

View file

@ -0,0 +1,15 @@
import { Link } from 'react-router-dom';
import Themer from '../Themer/Themer';
const Settings = (): JSX.Element => {
return (
<div>
<h1>settings</h1>
<Link to='/'>Home</Link>
<Themer />
</div>
)
}
export default Settings;

View file

@ -0,0 +1,27 @@
.ThemePreview {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.ThemePreview:hover {
cursor: pointer;
}
.ThemePreview p {
text-transform: capitalize;
margin: 8px 0;
/* align-self: flex-start; */
}
.ColorsPreview {
display: flex;
border: 1px solid silver;
}
.ColorPreview {
width: 50px;
height: 50px;
}

View file

@ -1,10 +1,29 @@
import { Theme } from '../../interfaces/Theme';
import classes from './ThemePreview.module.css';
const ThemePreview = (theme: Theme): JSX.Element => {
interface ComponentProps {
theme: Theme;
applyTheme: Function;
}
const ThemePreview = (props: ComponentProps): JSX.Element => {
return (
<div>
<p>Theme: {theme.name}</p>
<p>{theme.colors.background}</p>
<div className={classes.ThemePreview} onClick={() => props.applyTheme(props.theme.name)}>
<div className={classes.ColorsPreview}>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.background }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.primary }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.accent }}
></div>
</div>
<p>{props.theme.name}</p>
</div>
)
}

View file

@ -0,0 +1,12 @@
.ThemerGrid {
width: 100%;
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 100px;
}
@media (min-width: 900px) {
.ThemerGrid {
grid-template-columns: 1fr 1fr 1fr;
}
}

View file

@ -1,13 +1,44 @@
import { useEffect } from 'react';
import classes from './Themer.module.css';
import { themes } from './themes.json';
import { Theme } from '../../interfaces/Theme';
import ThemePreview from './ThemePreview';
import { Container } from '../UI/Layout/Layout';
import Headline from '../UI/Headline/Headline';
const Themer = (): JSX.Element => {
useEffect((): void => {
if (localStorage.theme) {
applyTheme(localStorage.theme);
}
}, []);
const applyTheme = (themeName: string): void => {
const newTheme = themes.find((theme: Theme) => theme.name === themeName);
if (newTheme) {
for (const [key, value] of Object.entries(newTheme.colors)) {
document.body.style.setProperty(`--color-${key}`, value);
}
localStorage.setItem('theme', themeName);
}
}
return (
<div>
<h1>Themes</h1>
{themes.map((theme: Theme): JSX.Element => <ThemePreview name={theme.name} colors={theme.colors} />)}
</div>
<Container>
<div>
<Headline
title='Themes'
subtitle='Select new theme by clicking on it'
/>
<div className={classes.ThemerGrid}>
{themes.map((theme: Theme): JSX.Element => <ThemePreview theme={theme} applyTheme={applyTheme} />)}
</div>
</div>
</Container>
)
}

View file

@ -0,0 +1,7 @@
.HeadlineTitle {
color: var(--color-primary);
}
.HeadlineSubtitle {
color: var(--color-primary);
}

View file

@ -0,0 +1,18 @@
import { Fragment } from 'react';
import classes from './Headline.module.css';
interface ComponentProps {
title: string;
subtitle?: string;
}
const Headline = (props: ComponentProps): JSX.Element => {
return (
<Fragment>
<h2 className={classes.HeadlineTitle}>{props.title}</h2>
{props.subtitle && <p className={classes.HeadlineSubtitle}>{props.subtitle}</p>}
</Fragment>
)
}
export default Headline;

View file

@ -0,0 +1,4 @@
.Icon {
color: var(--color-primary);
width: 90%;
}

View file

@ -0,0 +1,25 @@
import classes from './Icon.module.css';
import { Icon as MDIcon } from '@mdi/react';
interface ComponentProps {
icon: string;
}
const Icon = (props: ComponentProps): JSX.Element => {
const MDIcons = require('@mdi/js');
let iconPath = MDIcons[props.icon];
if (!iconPath) {
console.log('icon not found');
iconPath = MDIcons.mdiCancel;
}
return (
<MDIcon className={classes.Icon}
path={iconPath}
/>
)
}
export default Icon;

View file

@ -0,0 +1,4 @@
.Container {
width: 100%;
padding: var(--space-p-x);
}

View file

@ -0,0 +1,9 @@
import classes from './Layout.module.css';
export const Container = (props: any): JSX.Element => {
return (
<div className={classes.Container}>
{props.children}
</div>
)
}

View file

@ -1,13 +1,16 @@
body {
* {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
padding: 0;
box-sizing: border-box;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
body {
--color-background: #2B2C56;
--color-primary: #EFF1FC;
--color-accent: #6677EB;
--space-p-x: 16px;
background-color: var(--color-background);
font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, Roboto, sans-serif;
}