-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebar.js
121 lines (116 loc) · 2.82 KB
/
Sidebar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React from 'react'
import logo from "../assets/comfy.png";
import { Link } from 'react-router-dom'
import { useProductsContext } from '../context/products_context'
import { FaTimes } from 'react-icons/fa'
import { links } from '../utils/constants'
import styled from "styled-components";
import CartButtons from "./CartButtons";
import { useUserContext } from "../context/user_context";
const Sidebar = () => {
const { isSidebarOpen, closeSidebar } = useProductsContext();
const { myUser } = useUserContext();
return (
<SidebarContainer>
<aside
className={`${isSidebarOpen ? "sidebar show-sidebar" : "sidebar"}`}
>
<div className="sidebar-header">
<img src={logo} className="logo" alt="comfy sloth" />
<button className="close-btn" type="button" onClick={closeSidebar}>
<FaTimes />
</button>
</div>
<ul className="links">
{links.map((link) => {
const { id, url, text } = link;
return (
<li key={id}>
<Link to={url} onClick={closeSidebar}>
{text}
</Link>
</li>
);
})}
{myUser && (
<li>
<Link to={"/checkout"} onClick={closeSidebar}>
Checkout
</Link>
</li>
)}
</ul>
<CartButtons />
</aside>
</SidebarContainer>
);
};
const SidebarContainer = styled.div`
text-align: center;
.sidebar-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
}
.close-btn {
font-size: 2rem;
background: transparent;
border-color: transparent;
color: var(--clr-primary-5);
transition: var(--transition);
cursor: pointer;
color: var(--clr-red-dark);
margin-top: 0.2rem;
}
.close-btn:hover {
color: var(--clr-red-light);
}
.logo {
justify-self: center;
height: 45px;
}
.links {
margin-bottom: 2rem;
}
.links a {
display: block;
text-align: left;
font-size: 1rem;
text-transform: capitalize;
padding: 1rem 1.5rem;
color: var(--clr-grey-3);
transition: var(--transition);
letter-spacing: var(--spacing);
}
.links a:hover {
padding: 1rem 1.5rem;
padding-left: 2rem;
background: var(--clr-grey-10);
color: var(--clr-grey-2);
}
.sidebar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--clr-white);
transition: var(--transition);
transform: translate(-100%);
z-index: -1;
}
.show-sidebar {
transform: translate(0);
z-index: 999;
}
.cart-btn-wrapper {
margin: 2rem auto;
}
@media screen and (min-width: 992px) {
.sidebar {
display: none;
}
}
`
export default Sidebar