-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored FilterButton and ThemeSwitcher
ChatGPT shared link: https://chat.openai.com/share/6a73f8aa-0e9e-4704-a469-a73e4531ef84
- Loading branch information
Showing
2 changed files
with
83 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
import React from 'react'; | ||
import React, { useContext } from 'react'; | ||
|
||
import {ThemeContext} from "../themeContext"; | ||
import { ThemeContext } from "../themeContext"; | ||
|
||
import style from './ThemeSwitcher.module.scss'; | ||
|
||
export class ThemeSwitcher extends React.Component { | ||
const ThemeSwitcher = () => { | ||
const { theme, toggleTheme } = useContext(ThemeContext); | ||
|
||
render() { | ||
const className = theme === 'dark' | ||
? [style.ThemeSwitcher, style.ThemeSwitcher_dark].join(' ') | ||
: [style.ThemeSwitcher, style.ThemeSwitcher_light].join(' '); | ||
|
||
return ( | ||
<ThemeContext.Consumer> | ||
{({theme, toggleTheme}) => ( | ||
<label htmlFor="theme" className={theme === 'dark' ? [style.ThemeSwitcher, style.ThemeSwitcher_dark].join(' ') : [style.ThemeSwitcher, style.ThemeSwitcher_light].join(' ')}> | ||
<input onChange={toggleTheme} type="checkbox" name="theme" id="theme"/> | ||
</label> | ||
)} | ||
</ThemeContext.Consumer> | ||
); | ||
} | ||
return ( | ||
<label htmlFor="theme" className={className}> | ||
<input onChange={toggleTheme} type="checkbox" name="theme" id="theme"/> | ||
</label> | ||
); | ||
} | ||
|
||
export default ThemeSwitcher; | ||
export default ThemeSwitcher; |