Skip to content

Commit

Permalink
feat: Use Zustand #33
Browse files Browse the repository at this point in the history
  • Loading branch information
imadatyatalah committed Oct 2, 2021
1 parent ab5ff40 commit 2d31c79
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
19 changes: 10 additions & 9 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { h } from 'preact';
import { h } from 'preact'
import Home from './components/home'
import { useDarkModeState } from './hooks/useDarkMode'
import { useDarkMode } from './stores/useDarkMode'
import './styles/main.css'

function App() {
const [isDark, setIsDark] = useDarkModeState()

const onChangeTheme = (arg) => {
setIsDark(arg)
}
const { theme, setTheme } = useDarkMode(({ theme, setTheme }) => ({
theme,
setTheme,
}))

const currentTheme = theme === 'dark' ? true : false

return (
<div className={`main-container ${isDark && 'dark-mode'}`}>
<Home isDark={isDark} toggleDarkMode={onChangeTheme} />
<div className={`main-container ${currentTheme && 'dark-mode'}`}>
<Home isDark={currentTheme} toggleDarkMode={setTheme} />
</div>
)
}
Expand Down
1 change: 0 additions & 1 deletion src/components/gradientPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { TwitterPicker } from 'react-color'

import './../styles/sideBar.css'
import { useDarkModeState } from './../hooks/useDarkMode'

function GradientPicker({ gradColors, onGradColorsChange, isDark }) {
const [colorOne, setColorOne] = useState(gradColors.colorOne)
Expand Down
17 changes: 0 additions & 17 deletions src/hooks/useDarkMode.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/stores/useDarkMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import create from 'zustand'
import { persist } from 'zustand/middleware'

const DARK = 'dark'
const LIGHT = 'light'

export const useDarkMode = create(
persist(
(set, get) => ({
// default theme
theme: LIGHT,

setTheme: () => set({ theme: get().theme === DARK ? LIGHT : DARK }),
}),
{ name: 'theme' },
),
)
20 changes: 16 additions & 4 deletions src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,6 @@ video {
margin: 0.75rem;
}

.m-5 {
margin: 1.25rem;
}

.m-6 {
margin: 1.5rem;
}
Expand Down Expand Up @@ -1561,6 +1557,14 @@ video {
flex-direction: row;
}

.md\:h-10 {
height: 2.5rem;
}

.md\:w-10 {
width: 2.5rem;
}

.md\:w-1\/5 {
width: 20%;
}
Expand Down Expand Up @@ -1604,6 +1608,14 @@ video {
max-width: 1280px;
}
}

.lg\:h-12 {
height: 3rem;
}

.lg\:w-12 {
width: 3rem;
}
}

@media (min-width: 1280px) {
Expand Down

0 comments on commit 2d31c79

Please sign in to comment.