Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ButtonColor with change of Theme #368

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
38 changes: 23 additions & 15 deletions apps/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

/* eslint-disable @typescript-eslint/no-unused-vars */

import "./App.css";
import "./themes.css";
import './App.css';
import './themes.css';

import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { Landing } from './screens/Landing';
Expand All @@ -13,8 +12,8 @@ import { RecoilRoot } from 'recoil';
import { Loader } from './components/Loader';
import { Layout } from './layout';
import { Settings } from './screens/Settings';
import { Themes } from "./components/themes";
import { ThemesProvider } from "./context/themeContext";
import { Themes } from './components/themes';
import { ThemesProvider } from './context/themeContext';

function App() {
return (
Expand All @@ -34,21 +33,30 @@ function AuthApp() {
return (
<BrowserRouter>
<Routes>
<Route
path="/"
element={<Layout><Landing /></Layout>}
/>
<Route
path="/login"
element={<Login />}
path="/"
element={
<Layout>
<Landing />
</Layout>
}
/>
<Route path="/login" element={<Login />} />
<Route
path="/game/:gameId"
element={<Layout><Game /></Layout>}
element={
<Layout>
<Game />
</Layout>
}
/>
<Route
path='/settings'
element={<Layout><Settings /></Layout>}
<Route
path="/settings"
element={
<Layout>
<Settings />
</Layout>
}
>
<Route path="themes" element={<Themes />} />
</Route>
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/components/Boardcolor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function BoardColor() {
return <div></div>;
}
35 changes: 34 additions & 1 deletion apps/frontend/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { THEMES_DATA } from '@/constants/themes';
import { ThemeContext } from '@/context/themeContext';
import { useContext, useEffect, useState } from 'react';

export const Button = ({
onClick,
children,
Expand All @@ -7,12 +11,41 @@ export const Button = ({
children: React.ReactNode;
className?: string;
}) => {
const [buttonColor, setButtonColor] = useState<string>('');
const themeContext = useContext(ThemeContext);
useEffect(() => {
if (themeContext) {
const currTheme = themeContext.theme;
const theme = THEMES_DATA.find((theme) => theme.name === currTheme);
if (theme) {
switch (theme.name) {
case 'Blue':
setButtonColor(theme.buttonColor);
break;
case 'Red':
setButtonColor(theme.buttonColor);
break;
case 'Violet':
setButtonColor(theme.buttonColor);
break;
case 'bubblegum':
setButtonColor(theme.buttonColor);
break;
case 'default':
setButtonColor(theme.buttonColor);
}
}
}
}, []);
return (
<button
style={{ backgroundColor: buttonColor }}
onClick={onClick}
className={`px-8 py-4 text-2xl bg-green-500 text-white font-bold rounded ${className}`}
className={`px-8 py-4 text-2xl text-white font-bold rounded ${className}`}
>
{children}
</button>
);
};

// Define the atom with the correct type
111 changes: 55 additions & 56 deletions apps/frontend/src/components/themes.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
import { THEMES_DATA } from "@/constants/themes";
import { useThemeContext } from "@/hooks/useThemes";

export function Themes() {
const { updateTheme } = useThemeContext();
return (
<div className="flex-1 bg-bgAuxiliary1 py-12 px-10">
<div className="grid grid-cols-1 gap-8">
{
THEMES_DATA.map(theme => {
return (
<div
key={theme.id}
className="p-4 flex items-start justify-between cursor-pointer"
style={{backgroundColor: theme.background}}
onClick={() => {
updateTheme(theme.name);
}}
>
<div>
<h2 className="text-lg capitalize">{theme.name}</h2>
</div>
<div className="grid grid-cols-2">
<img
src="/bk.png"
className="w-16 h-16"
alt="chess-piece"
style={{backgroundColor: theme["board-dark"]}}
/>
<img
src="/wn.png"
className="w-16 h-16"
alt="chess-piece"
style={{backgroundColor: theme["board-light"]}}
/>
<img
src="/br.png"
className="w-16 h-16"
alt="chess-piece"
style={{backgroundColor: theme["board-light"]}}
/>
<img
src="/wp.png"
className="w-16 h-16"
alt="chess-piece"
style={{backgroundColor: theme["board-dark"]}}
/>
</div>
</div>
)
})
}
</div>
</div>
)
}
import { THEMES_DATA } from '@/constants/themes';
import { useThemeContext } from '@/hooks/useThemes';

export function Themes() {
const { updateTheme } = useThemeContext();

return (
<div className="flex-1 bg-bgAuxiliary1 py-12 px-10">
<div className="grid grid-cols-1 gap-8">
{THEMES_DATA.map((theme) => {
return (
<div
key={theme.id}
className="p-4 flex items-start justify-between cursor-pointer"
style={{ backgroundColor: theme.background }}
onClick={() => {
updateTheme(theme.name);
}}
>
<div>
<h2 className="text-lg capitalize">{theme.name}</h2>
</div>
<div className="grid grid-cols-2">
<img
src="/bk.png"
className="w-16 h-16"
alt="chess-piece"
style={{ backgroundColor: theme['board-dark'] }}
/>
<img
src="/wn.png"
className="w-16 h-16"
alt="chess-piece"
style={{ backgroundColor: theme['board-light'] }}
/>
<img
src="/br.png"
className="w-16 h-16"
alt="chess-piece"
style={{ backgroundColor: theme['board-light'] }}
/>
<img
src="/wp.png"
className="w-16 h-16"
alt="chess-piece"
style={{ backgroundColor: theme['board-dark'] }}
/>
</div>
</div>
);
})}
</div>
</div>
);
}
92 changes: 63 additions & 29 deletions apps/frontend/src/constants/themes.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
import { THEME } from "@/context/themeContext"

type THEME_DATA = {
id: number,
name: THEME,
background: string,
"board-light": string,
"board-dark": string,
"board-image": string
}

export const THEMES_DATA: THEME_DATA[] = [
{
id: 1,
name: "default",
background: "#302E2B",
"board-light": "#EBECD0",
"board-dark": "#739552",
"board-image": "https://www.chess.com/bundles/web/images/offline-play/standardboard.1d6f9426.png",
},
{
id: 2,
name: "bubblegum",
background: "#E6455E",
"board-light": "#FEFFFE",
"board-dark": "#FBD9E1",
"board-image": "https://res.cloudinary.com/dcugqfvvg/image/upload/e_improve,e_sharpen/v1718047051/screenshot-localhost_5173-2024.06.11-00_44_01_pxwr43.png",
}
]
import { THEME } from '@/context/themeContext';

export type THEME_DATA = {
id: number;
name: THEME;
background: string;
buttonColor: string;
'board-light': string;
'board-dark': string;
'board-image': string;
};

export const THEMES_DATA: THEME_DATA[] = [
{
id: 1,
name: 'default',
background: '#302E2B',
buttonColor: '#16a34a',
'board-light': '#EBECD0',
'board-dark': '#739552',
'board-image': 'https://www.chess.com/bundles/web/images/offline-play/standardboard.1d6f9426.png',
},
{
id: 2,
name: 'bubblegum',
background: '#E6455E',
buttonColor: '#FBD9E1',
'board-light': '#FEFFFE',
'board-dark': '#FBD9E1',
'board-image':
'https://res.cloudinary.com/dcugqfvvg/image/upload/e_improve,e_sharpen/v1718047051/screenshot-localhost_5173-2024.06.11-00_44_01_pxwr43.png',
},
{
id: 3,
name: 'Blue',
background: '#030712',
buttonColor: '#164e63',
'board-light': '#cffafe',
'board-dark': '#164e63',
'board-image':
'https://thumbs.dreamstime.com/b/chess-board-blue-colors-chess-pieces-vector-illustration-241711727.jpg',
},
{
id: 4,
name: 'Violet',
background: '#6b7280',
buttonColor: '#3b0764',
'board-light': '#d8b4fe',
'board-dark': '#4338ca',
'board-image':
'https://thumbs.dreamstime.com/b/chess-board-blue-colors-chess-pieces-vector-illustration-241711727.jpg',
},
{
id: 5,
name: 'Red',
background: '#fda4af',
buttonColor: '#e11d48',
'board-light': '#fecdd3',
'board-dark': '#e11d48',
'board-image':
'https://thumbs.dreamstime.com/b/chess-board-blue-colors-chess-pieces-vector-illustration-241711727.jpg',
},
];
Loading