add darkmode switch
This commit is contained in:
1 parent
c1345eaca7
commit
2cb39f0c55
16 files changed
+501
-323
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { Link } from "react-router";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import { useTheme } from "../theme/ThemeContext";
|
||||
import "../style/navbar.css";
|
||||
|
||||
function SharedNavbar({ variant = "light", active = "" }) {
|
||||
const { cart, openCart, openProfile, user } = useShop();
|
||||
const { isLight, toggleTheme } = useTheme();
|
||||
const cartLabel =
|
||||
cart.total_quantity > 0 ? `Cart ${cart.total_quantity}` : "Cart";
|
||||
const logoSrc =
|
||||
@@ -31,6 +33,17 @@ function SharedNavbar({ variant = "light", active = "" }) {
|
||||
<button type="button" className="nav-link nav-button" onClick={openProfile}>
|
||||
{user ? "Profile" : "Profile"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`nav-link nav-button nav-theme-switch ${isLight ? "is-light" : ""}`}
|
||||
onClick={toggleTheme}
|
||||
aria-label={isLight ? "Switch to dark mode" : "Switch to light mode"}
|
||||
aria-pressed={isLight}
|
||||
>
|
||||
<span className="nav-theme-switch__track" aria-hidden="true">
|
||||
<span className="nav-theme-switch__thumb" />
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user