Skip to content

Commit

Permalink
styling light & dark modes
Browse files Browse the repository at this point in the history
  • Loading branch information
atharv02-git committed Dec 6, 2021
1 parent e8c19b4 commit baff217
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.App {
min-height: 100%;
}
.App.dark {
background: #333;
}
5 changes: 4 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./App.css";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { useTheme } from './hooks/useTheme'

// components
import Navbar from "./components/Navbar";
Expand All @@ -12,8 +13,10 @@ import Recipe from "./pages/recipe/Recipe";
import Search from "./pages/search/Search";

function App() {
const { mode } = useTheme()

return (
<div className="App">
<div className={`App ${mode}`}>
<BrowserRouter>
<Navbar />
<ThemeSelector />
Expand Down
8 changes: 8 additions & 0 deletions src/components/RecipeList.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@
border-radius: 4px;
margin: 20px auto 0;
}
.recipe-list .card.dark {
background: #555;
}
.recipe-list .card.dark p,
.recipe-list .card.dark h3,
.recipe-list .card.dark div {
color: #e4e4e4;
}
5 changes: 4 additions & 1 deletion src/components/RecipeList.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Link } from "react-router-dom";
import { useTheme } from "../hooks/useTheme";

// styles
import "./RecipeList.css";

export default function RecipeList({ recipes }) {
const { mode } = useTheme();

if (recipes.length === 0) {
return <div className="error">No recipes to load...</div>;
}

return (
<div className="recipe-list">
{recipes.map((recipe) => (
<div key={recipe.id} className="card">
<div key={recipe.id} className={`card ${mode}`}>
<h3>{recipe.title}</h3>
<p>{recipe.cookingTime} to make.</p>
<div>{recipe.method.substring(0, 100)}...</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ThemeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import modeIcon from "../assets/mode-icon.svg"
// Styles
import "./ThemeSelector.css";

const themeColors = ["#58249c", "#249c6b", "#d9534f","#f0ad4e"];
const themeColors = ["#58249c", "#249c6b", "#d9534f"];

export default function ThemeSelector() {
const { changeColor,mode,changeMode } = useTheme();

const changeModeHandler = () => {
changeMode(mode === 'dark' ? 'light' : 'dark')
}
console.log(mode)
// console.log(mode)

return (
<div className="theme-selector">
Expand Down
2 changes: 1 addition & 1 deletion src/context/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const themeReducer = (state, action) => {

export function ThemeProvider({ children }) {
const [state, dispatch] = useReducer(themeReducer, {
defaultColor: "#58249c",
defaultColor: "#555",
mode: "dark",
});

Expand Down
16 changes: 16 additions & 0 deletions src/pages/recipe/Recipe.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
padding: 40px;
box-sizing: border-box;
}
.recipe>h2{
text-decoration: underline;
}
.recipe ul {
display: flex;
padding: 0;
Expand All @@ -26,3 +29,16 @@
.method {
text-align: left;
}
/* dark mode */
.recipe.dark {
background: #555;
color: #e4e4e4;
}
.recipe.dark>h2{
color: #e4e4e4;
text-decoration: underline;
}
.recipe.dark li{
color: #e4e4e4;
}

4 changes: 3 additions & 1 deletion src/pages/recipe/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams, useNavigate } from "react-router";

// Hooks
import { useFetch } from "../../hooks/useFetch";
import { useTheme } from "../../hooks/useTheme";

// Styles
import "./Recipe.css";
Expand All @@ -12,6 +13,7 @@ export default function Recipe() {
const url = "http://localhost:3000/recipes/" + id;
const { data: recipe, isPending, error } = useFetch(url);
const navigate = useNavigate();
const {mode} = useTheme()

useEffect(() => {
if (error) {
Expand All @@ -23,7 +25,7 @@ export default function Recipe() {
}, [error, navigate]);

return (
<div className="recipe">
<div className={`recipe ${ mode }`}>
{error && <div>{error}</div>}
{isPending && <div>Loading...</div>}
{recipe && (
Expand Down

0 comments on commit baff217

Please sign in to comment.