Skip to content

Commit

Permalink
🎉Nav-Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
noeypatt committed Apr 7, 2020
1 parent 7accd9f commit 807b84f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 78 deletions.
25 changes: 12 additions & 13 deletions components/layout/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react'
import NavBar from './nav'
import { useMediaQuery } from 'react-responsive'
import Sidebar from './sidebar'

const Dashboard = props => {
const Dashboard = () => {

const [status, setStatus] = useState(false)
const isSmallScreen = useMediaQuery({ maxDeviceWidth: 1023 })

const [main, setMain] = useState(
Expand All @@ -23,20 +23,19 @@ const Dashboard = props => {
]
)

const onConfirm = (order) => {
setStatus(order)

if (props.statusMain) {
props.onStatusMain(false)
}
else {
props.onStatusMain(true)
}
}
const [min, setMin] = useState(
[
{ name: "ข้อมูลทั่วไป", href: "/main" },
{ name: "ข้อมูลด้านสุขภาพ", href: "/main/hospital" },
{ name: "ข้อมูลด้านสังคม", href: "/main/social" },
{ name: "ข้อมูลด้านเศรษฐกิจ", href: "/main/economy" },
{ name: "ข้อมูลด้านการช่วยเหลือ", href: "/main/service" },
]
)

return (
<React.Fragment>
<NavBar name="main" tab={isSmallScreen ? sidebar : main} confirm={onConfirm} status={status} />
<NavBar name="main" tab={isSmallScreen ? min : main} sidebar={sidebar} />
</React.Fragment>
)
}
Expand Down
44 changes: 33 additions & 11 deletions components/layout/nav.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React, { useState, useEffect } from 'react'
import Link from 'next/link'
import { useMediaQuery } from 'react-responsive';
import Sidebar from './sidebar';
import { Drawer } from 'antd';

const NavBar = props => {

const tab = props.tab
const name = props.name
const [navbar, setNavbar] = useState("")
const [status, setStatus] = useState(false)
const [visible, setVisible] = useState(false)

const isBigScreen = useMediaQuery({ minDeviceWidth: 769 })
const isSmallScreen = useMediaQuery({ maxDeviceWidth: 768.99 })
const [visible, setVisible] = useState(false)
const [placement, setPlacement] = useState("left")


const collapsible = async () => {

Expand All @@ -27,6 +30,10 @@ const NavBar = props => {

const showDrawer = () => {
setVisible(true)
}

const onClose = () => {
setVisible(false)
};

useEffect(() => {
Expand Down Expand Up @@ -91,7 +98,22 @@ const NavBar = props => {
return (
<React.Fragment key={index}>
<p className="li-buttom-line-active" onClick={showDrawer}>{item.name}</p>
<Sidebar status={visible} />
<Drawer
title="เมนู"
placement={placement}
closable={false}
onClose={onClose}
visible={visible}
>
{
props.sidebar.map((item, index) => (
<a key={index} href={item.href}>
<p>{item.name}</p>
</a>

))
}
</Drawer>
</React.Fragment>
)
})
Expand All @@ -115,14 +137,14 @@ const NavBar = props => {
return (
<a key={index} href={item.href}>
{
item.name == "เข้าสู่หน้าหลัก" ?
<p className="li-buttom-line-active">{item.name}</p>
:
<React.Fragment>
<button className="btn">
<p>{item.name}</p>
</button>
</React.Fragment>
item.name == "เข้าสู่หน้าหลัก" ?
<p className="li-buttom-line-active">{item.name}</p>
:
<React.Fragment>
<button className="btn">
<p>{item.name}</p>
</button>
</React.Fragment>
}
</a>
)
Expand Down
37 changes: 4 additions & 33 deletions components/layout/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useState, useEffect } from 'react';
import { Drawer } from 'antd';

const Sidebar = () => {

const Sidebar = props => {

const status = props.status
const [visible, setVisible] = useState(false)
const [placement, setPlacement] = useState('left')
const [sidebar, setSidebar] = useState(
[
{ name: "ข้อมูลทั่วไป", href: "/main" },
Expand All @@ -18,36 +13,12 @@ const Sidebar = props => {
)

useEffect(() => {
if (status) {
setVisible(true)
} else {
setVisible(false)
}

}, [status])

const onClose = () => {
setVisible(false)
};

}, [])

return (
<div className="warp-sidebar">
<Drawer
title="เมนู"
placement={placement}
closable={false}
onClose={onClose}
visible={visible}
>
{
sidebar.map((item, index) => (
<a key={index} href={item.href}>
<p>{item.name}</p>
</a>

))
}
</Drawer>

</div>
)
}
Expand Down
7 changes: 2 additions & 5 deletions pages/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ const MainPage = () => {
setUserOauth(await JSON.parse(localStorage.getItem("myOauth")))
}

const statusMain = (order) => {
setStatus(order)
}

const statusToken = (token) => {
setTokenError(token)
Expand Down Expand Up @@ -97,8 +94,8 @@ const MainPage = () => {
:
userOauth != null && !tokenError ?
<React.Fragment>
<Dashboard onStatusMain={statusMain} statusMain={status} />
<Sidebar />
<Dashboard />
{/* <Sidebar /> */}
<div className="page-content-main">
<div className="container-fluid-main">
<h1 className="text-center">ข้อมูลด้านทั่วไป</h1>
Expand Down
7 changes: 1 addition & 6 deletions pages/main/economy.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ const Economy = () => {
const isTablet = useMediaQuery({ minWidth: 768 })
const isMobile = useMediaQuery({ maxDeviceWidth: 768 })

const [status, setStatus] = useState(false)
const [tokenError, setTokenError] = useState(false)

const statusMain = (order) => {
setStatus(order)
}

const statusToken = (token) => {
setTokenError(token)
}
Expand All @@ -63,7 +58,7 @@ const Economy = () => {
{
!tokenError ?
<React.Fragment>
<Dashboard onStatusMain={statusMain} statusMain={status} />
<Dashboard />
<div className="page-content-main">
<div className="container-fluid-main">
<h1 className="text-center">ข้อมูลด้านเศรษฐกิจ</h1>
Expand Down
2 changes: 1 addition & 1 deletion pages/main/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Service = () => {
<div className="warp-main">
{
!tokenError ? <React.Fragment>
<Dashboard onStatusMain={statusMain} statusMain={status} />
<Dashboard />
<div className="page-content-main">
<div className="container-fluid-main">
<h1 className="text-center">หน่วยงานภาครัฐ</h1>
Expand Down
7 changes: 1 addition & 6 deletions pages/main/social.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ const Social = () => {
const isTablet = useMediaQuery({ minWidth: 768 })
const isMobile = useMediaQuery({ maxDeviceWidth: 768 })

const [status, setStatus] = useState(false)
const [tokenError, setTokenError] = useState(false)

const statusMain = (order) => {
setStatus(order)
}

const statusToken = (token) => {
setTokenError(token)
}
Expand All @@ -59,7 +54,7 @@ const Social = () => {

!tokenError ?
<React.Fragment>
<Dashboard onStatusMain={statusMain} statusMain={status} />
<Dashboard />
<div className="page-content-main">
<div className="container-fluid-main">
<h1 className="text-center">ข้อมูลด้านสังคม</h1>
Expand Down
14 changes: 11 additions & 3 deletions styles/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ $bg-color: linear-gradient(to left, #a6d254, #83d2ae);
$border-bg-color: 1px solid #83d2ae;
$line-color: #e8e9fe;


nav {
width: 100%;
min-height: 5rem;
Expand All @@ -18,7 +17,6 @@ nav {
}
}


//Navbar-Scroll
// nav {
// position: fixed;
Expand Down Expand Up @@ -106,7 +104,6 @@ nav {
}
}
}

}

ul {
Expand Down Expand Up @@ -170,3 +167,14 @@ ul {
}
}
}

//SideBar
.ant-drawer-wrapper-body {
user-select: none;
}

.ant-drawer-body {
p:hover {
color: $primary-color;
}
}

1 comment on commit 807b84f

@vercel
Copy link

@vercel vercel bot commented on 807b84f Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.