1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-24 21:39:36 +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

@ -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>
)
}