Skip to content

Commit

Permalink
chore: add default theme colour from localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
shafin-deriv committed Jul 29, 2024
1 parent 5f70673 commit 27254d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/layout/main-body/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { useEffect } from 'react';
import './main-body.scss';

type TMainBodyProps = {
children: React.ReactNode;
};

const MainBody: React.FC<TMainBodyProps> = ({ children }) => {
const current_theme = localStorage.getItem('theme') ?? 'light';

useEffect(() => {
const body = document.querySelector('body');
if (!body) return;
if (current_theme === 'light') {
body.classList.remove('theme--dark');
body.classList.add('theme--light');
} else {
body.classList.remove('theme--light');
body.classList.add('theme--dark');
}
}, [current_theme]);

return <div className='main-body'>{children}</div>;
};

Expand Down
1 change: 1 addition & 0 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

body {
font-family: 'IBM Plex Sans', sans-serif;
background: var(--general-main-1);
}

0 comments on commit 27254d2

Please sign in to comment.