App.jsx Component
import { useState } from 'react'
import './App.css'
import Header from './Header'
import Sidebar from './Sidebar'
import Home from './Home'
function App() {
const [openSidebarToggle, setOpenSidebarToggle] = useState(false)
const OpenSidebar = () => {
setOpenSidebarToggle(!openSidebarToggle)
}
return (
<div className='grid-container'>
<Header OpenSidebar={OpenSidebar}/>
<Sidebar openSidebarToggle={openSidebarToggle} OpenSidebar={OpenSidebar}/>
<Home />
</div>
)
}
export default App
Header.jsx Component:
import React from 'react'
import
{BsFillBellFill, BsFillEnvelopeFill, BsPersonCircle, BsSearch, BsJustify}
from 'react-icons/bs'
function Header({OpenSidebar}) {
return (
<header className='header'>
<div className='menu-icon'>
<BsJustify className='icon' onClick={OpenSidebar}/>
</div>
<div className='header-left'>
<BsSearch className='icon'/>
</div>
<div className='header-right'>
<BsFillBellFill className='icon'/>
<BsFillEnvelopeFill className='icon'/>
<BsPersonCircle className='icon'/>
</div>
</header>
)
}
export default Header
Sidebar.jsx Component:
import React from 'react'
import
{BsCart3, BsGrid1X2Fill, BsFillArchiveFill, BsFillGrid3X3GapFill, BsPeopleFill,
BsListCheck, BsMenuButtonWideFill, BsFillGearFill}
from 'react-icons/bs'
function Sidebar({openSidebarToggle, OpenSidebar}) {
return (
<aside id="sidebar" className={openSidebarToggle ? "sidebar-responsive": ""}>
<div className='sidebar-title'>
<div className='sidebar-brand'>
<BsCart3 className='icon_header'/> SHOP
</div>
<span className='icon close_icon' onClick={OpenSidebar}>X</span>
</div>
<ul className='sidebar-list'>
<li className='sidebar-list-item'>
<a href="">
<BsGrid1X2Fill className='icon'/> Dashboard
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsFillArchiveFill className='icon'/> Products
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsFillGrid3X3GapFill className='icon'/> Categories
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsPeopleFill className='icon'/> Customers
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsListCheck className='icon'/> Inventory
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsMenuButtonWideFill className='icon'/> Reports
</a>
</li>
<li className='sidebar-list-item'>
<a href="">
<BsFillGearFill className='icon'/> Setting
</a>
</li>
</ul>
</aside>
)
}
export default Sidebar
Home.jsx Component:
import React from 'react'
import
{ BsFillArchiveFill, BsFillGrid3X3GapFill, BsPeopleFill, BsFillBellFill}
from 'react-icons/bs'
import
{ BarChart, Bar, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, LineChart, Line }
from 'recharts';
function Home() {
const data = [
{
name: 'Page A',
uv: 4000,
pv: 2400,
amt: 2400,
},
{
name: 'Page B',
uv: 3000,
pv: 1398,
amt: 2210,
},
{
name: 'Page C',
uv: 2000,
pv: 9800,
amt: 2290,
},
{
name: 'Page D',
uv: 2780,
pv: 3908,
amt: 2000,
},
{
name: 'Page E',
uv: 1890,
pv: 4800,
amt: 2181,
},
{
name: 'Page F',
uv: 2390,
pv: 3800,
amt: 2500,
},
{
name: 'Page G',
uv: 3490,
pv: 4300,
amt: 2100,
},
];
return (
<main className='main-container'>
<div className='main-title'>
<h3>DASHBOARD</h3>
</div>
<div className='main-cards'>
<div className='card'>
<div className='card-inner'>
<h3>PRODUCTS</h3>
<BsFillArchiveFill className='card_icon'/>
</div>
<h1>300</h1>
</div>
<div className='card'>
<div className='card-inner'>
<h3>CATEGORIES</h3>
<BsFillGrid3X3GapFill className='card_icon'/>
</div>
<h1>12</h1>
</div>
<div className='card'>
<div className='card-inner'>
<h3>CUSTOMERS</h3>
<BsPeopleFill className='card_icon'/>
</div>
<h1>33</h1>
</div>
<div className='card'>
<div className='card-inner'>
<h3>ALERTS</h3>
<BsFillBellFill className='card_icon'/>
</div>
<h1>42</h1>
</div>
</div>
<div className='charts'>
<ResponsiveContainer width="100%" height="100%">
<BarChart
width={500}
height={300}
data={data}
margin={{
top: 5,
right: 30,
left: 20,
bottom: 5,
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Legend />
<Bar dataKey="pv" fill="#8884d8" />
<Bar dataKey="uv" fill="#82ca9d" />
</BarChart>
</ResponsiveContainer>
<ResponsiveContainer width="100%" height="100%">
<LineChart
width={500}
height={300}
data={data}
margin={{
top: 5,
right: 30,
left: 20,
bottom: 5,
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
<Line type="monotone" dataKey="uv" stroke="#82ca9d" />
</LineChart>
</ResponsiveContainer>
</div>
</main>
)
}
export default Home
CSS file:
body {
margin: 0;
padding: 0;
background-color: #1d2634;
color: #9e9ea4;
font-family: 'Montserrat', sans-serif;
}
.icon {
vertical-align: middle;
line-height: 1px;
font-size: 20px;
}
.icon_header {
vertical-align: middle;
line-height: 1px;
font-size: 26px;
}
.icon, .icon_header {
margin-right: 5px;
}
.close_icon {
color: red;
margin-left: 30px;
margin-top: 10px;
cursor: pointer;
}
.grid-container {
display: grid;
grid-template-columns: 260px 1fr 1fr 1fr;
grid-template-rows: 0.2fr 3fr;
grid-template-areas:
'sidebar header header header'
'sidebar main main main';
height: 100vh;
}
/* Header */
.header {
grid-area: header;
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 30px 0 30px;
box-shadow: 0 6px 7px -3px rgba(0, 0, 0, 0.35);
}
.menu-icon {
display: none;
}
/* End Header */
/* Sidebar */
#sidebar {
grid-area: sidebar;
height: 100%;
background-color: #263043;
overflow-y: auto;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.sidebar-title {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 30px 0px 30px;
margin-bottom: 30px;
}
.sidebar-title > span {
display: none;
}
.sidebar-brand {
margin-top: 15px;
font-size: 20px;
font-weight: 700;
}
.sidebar-list {
padding: 0;
list-style-type: none;
}
.sidebar-list-item {
padding: 20px 20px 20px 20px;
font-size: 18px;
}
.sidebar-list-item:hover {
background-color: rgba(255, 255, 255, 0.2);
cursor: pointer;
}
.sidebar-list-item > a {
text-decoration: none;
color: #9e9ea4;
}
.sidebar-responsive {
display: inline !important;
position: absolute;
/*
we want the z-index of the sidebar higher so that
the charts are not showing over the sidebar
on small screens
*/
z-index: 12 !important;
}
/* End Sidebar */
/* Main */
.main-container {
grid-area: main;
overflow-y: auto;
padding: 20px 20px;
color: rgba(255, 255, 255, 0.95);
}
.main-title {
display: flex;
justify-content: space-between;
}
.main-cards {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 20px;
margin: 15px 0;
}
.card {
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 8px 15px;
border-radius: 5px;
}
.card:first-child {
background-color: #2962ff;
}
.card:nth-child(2) {
background-color: #ff6d00;
}
.card:nth-child(3) {
background-color: #2e7d32;
}
.card:nth-child(4) {
background-color: #d50000;
}
.card-inner {
display: flex;
align-items: center;
justify-content: space-between;
}
.card-inner > .card_icon {
font-size: 25px;
}
.charts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 60px;
height: 300px;
}
/* End Main */
/* Medium <= 992px */
@media screen and (max-width: 992px) {
.grid-container {
grid-template-columns: 1fr;
grid-template-rows: 0.2fr 3fr;
grid-template-areas:
'header'
'main';
}
#sidebar {
display: none;
}
.menu-icon {
display: inline;
}
.sidebar-title > span {
display: inline;
}
}
/* Small <= 768px */
@media screen and (max-width: 768px) {
.main-cards {
grid-template-columns: 1fr;
gap: 10px;
margin-bottom: 0;
}
.charts {
grid-template-columns: 1fr;
margin-top: 30px;
}
}
/* Extra Small <= 576px */
@media screen and (max-width: 576px) {
.hedaer-left {
display: none;
}
}
Github Repository:
1 Comments
Thank you for this, it has solve my issues.
ReplyDelete