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:
parent
573814ddac
commit
765418d3d2
19 changed files with 378 additions and 59 deletions
0
client/src/components/Apps/Apps.module.css
Normal file
0
client/src/components/Apps/Apps.module.css
Normal file
17
client/src/components/Apps/Apps.tsx
Normal file
17
client/src/components/Apps/Apps.tsx
Normal 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;
|
15
client/src/components/Settings/Settings.tsx
Normal file
15
client/src/components/Settings/Settings.tsx
Normal 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;
|
27
client/src/components/Themer/ThemePreview.module.css
Normal file
27
client/src/components/Themer/ThemePreview.module.css
Normal 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;
|
||||
}
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
12
client/src/components/Themer/Themer.module.css
Normal file
12
client/src/components/Themer/Themer.module.css
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
|
7
client/src/components/UI/Headline/Headline.module.css
Normal file
7
client/src/components/UI/Headline/Headline.module.css
Normal file
|
@ -0,0 +1,7 @@
|
|||
.HeadlineTitle {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.HeadlineSubtitle {
|
||||
color: var(--color-primary);
|
||||
}
|
18
client/src/components/UI/Headline/Headline.tsx
Normal file
18
client/src/components/UI/Headline/Headline.tsx
Normal 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;
|
4
client/src/components/UI/Icon/Icon.module.css
Normal file
4
client/src/components/UI/Icon/Icon.module.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
.Icon {
|
||||
color: var(--color-primary);
|
||||
width: 90%;
|
||||
}
|
25
client/src/components/UI/Icon/Icon.tsx
Normal file
25
client/src/components/UI/Icon/Icon.tsx
Normal 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;
|
4
client/src/components/UI/Layout/Layout.module.css
Normal file
4
client/src/components/UI/Layout/Layout.module.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
.Container {
|
||||
width: 100%;
|
||||
padding: var(--space-p-x);
|
||||
}
|
9
client/src/components/UI/Layout/Layout.tsx
Normal file
9
client/src/components/UI/Layout/Layout.tsx
Normal 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>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue