Skip to content

Commit

Permalink
Add navbar overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
MathyouMB committed Jul 2, 2023
1 parent 9ce50c1 commit d3af6c6
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 55 deletions.
10 changes: 10 additions & 0 deletions src/components/core/CircleIcon/CircleIcon.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
import { Icon } from "astro-icon";
import "./CircleIcon.style.scss";
const { icon, colorSet, size } = Astro.props;
---

<div class={`circle-icon ${colorSet} ${size}`}>
<Icon name={icon} />
</div>
7 changes: 4 additions & 3 deletions src/components/core/CircleIcon/CircleIcon.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
}

.size-small {
width: 1.5rem;
height: 1.5rem;
padding: 0.5rem;
width: 1rem;
height: 1rem;
padding: 0.4rem;
font-size: 0.8rem;
}

.red-card {
Expand Down
2 changes: 2 additions & 0 deletions src/components/resources/Navbar/Navbar.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
position: fixed;
top: 0;
z-index: 1000;
// add shadow below
// box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);

a {
text-decoration: none !important;
Expand Down
9 changes: 9 additions & 0 deletions src/components/resources/Sidebar/Sidebar.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
export interface SidebarItem {
title: string;
path?: string;
children?: SidebarItem[];
}

export interface SidebarItemGroup {
title: string;
path?: string;
icon?: string;
color?: string;
children?: SidebarItem[];
}

export interface SidebarItemProps {
item: SidebarItem;
depth: number;
color: string;
}
69 changes: 61 additions & 8 deletions src/components/resources/Sidebar/Sidebar.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
}

.sidebar-item {
padding: 0.75em 0rem;
padding-left: 0.7rem;
display: block;
transition: background-color 0.15s;
border-radius: 5px;

i {
padding-right: 0.5rem;
}
}
.sidebar-item:hover {
background-color: rgba(169, 169, 169, 0.1);

padding: 0.5em 0.8rem;
padding-top: 0.7rem;
}

.sidebar-title {
display: flex;
font-size: 1rem;
font-size: 0.97rem;
justify-content: space-between;
align-items: center;

a {
margin: 0rem;
padding: 0rem;
}

button {
background-color: transparent;
Expand All @@ -37,26 +41,75 @@
cursor: pointer;
}
}

.sidebar-title-container {
display: flex;
justify-content: left;
align-items: center;
}

.sidebar-title span i {
display: inline-block;
width: 1.5em;
}

.sidebar-content {
padding-top: 0.25em;
height: 0;
overflow: hidden;
}

.sidebar-item.open > .sidebar-content {
.sidebar-content.open {
height: auto;
}

.sidebar-item.plain {
color: #000000;
text-decoration: none;
}

.sidebar-item.plain i {
display: inline-block;
width: 1.7em;
}

// TODO: depth classes could be a scss calc
.sidebar-depth-1 {
width: 2.9rem;
}

.sidebar-depth-2 {
width: 4rem;
}

.sidebar-depth-3 {
width: 5.2rem;
}

.sidebar-sub-item {
color: rgb(95, 95, 95);
font-size: 0.9rem;
}

.red-item-hover:hover {
background-color: #ffdddd;
}

.green-item-hover:hover {
background-color: #ddfff4;
}

.blue-item-hover:hover {
background-color: #ddf8ff;
}

.orange-item-hover:hover {
background-color: #ffddcc;
}

.purple-item-hover:hover {
background-color: #f5ddff;
}

.yellow-item-hover:hover {
background-color: #fffddd;
}
2 changes: 1 addition & 1 deletion src/components/resources/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Sidebar() {
return (
<div className="sidebar">
{items.map((item, index) => (
<SidebarItem key={index} item={item} />
<SidebarItem key={index} item={item} depth={0} color={item.colorSet} />
))}
</div>
);
Expand Down
76 changes: 53 additions & 23 deletions src/components/resources/Sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
import "./Sidebar.style.scss";
import { useState } from "react";
import { CircleIcon } from "../../core";
import type { SidebarItemProps } from "./Sidebar.model";

export default function SidebarItem(props: SidebarItemProps) {
const [open, setOpen] = useState<boolean>(false);

return props.item.children ? (
<div className={open ? "sidebar-item open" : "sidebar-item"}>
<div className="sidebar-title">
<span>{props.item.title}</span>
<button className="menu-down" onClick={() => setOpen(!open)}>
{open ? (
<i className="fa fa-chevron-up"></i>
) : (
<i className="fa fa-chevron-down"></i>
)}
</button>
</div>
<div className="sidebar-content">
{/* TODO: don't hardcode this */}
<div style={{ marginBottom: "0.5rem" }}></div>
{props.item.children.map((child, index) => (
<SidebarItem key={index} item={child} />
))}
return (
<>
<div
className={`sidebar-item ${open && "open"} ${props.color}-item-hover`}
>
<div className="sidebar-title">
{/* for group headings, display an icons and special style */}
{props.depth === 0 ? (
<a href={props.item.path || "#"} className="sidebar-item plain">
<div className="sidebar-title-container">
<CircleIcon
icon={props.item.icon}
size="size-small"
colorSet={`${props.item.colorSet}-card`}
/>
<span>{props.item.title}</span>
</div>
</a>
) : null}

{/* for items at depth === 1, they should display inline with group headings */}
{props.depth !== 0 ? (
<a href={props.item.path || "#"} className="sidebar-item plain">
<div className="sidebar-title-container">
<div className={`sidebar-depth-${props.depth}`} />
<span className="sidebar-sub-item">{props.item.title}</span>
</div>
</a>
) : null}

{/* if you have children, display a dropdown arrow */}
{props.item.children ? (
<button className="menu-down" onClick={() => setOpen(!open)}>
<i className={`fa fa-chevron-${open ? "up" : "down"}`} />
</button>
) : null}
</div>
</div>
</div>
) : (
<a href={props.item.path || "#"} className="sidebar-item plain">
{props.item.title}
</a>

{/* if you have children, display children */}
{props.item.children ? (
<div className={`sidebar-content ${open ? "open" : null}`}>
{props.item.children.map((child, index) => (
<SidebarItem
key={index}
item={child}
depth={props.depth + 1}
color={props.color}
/>
))}
</div>
) : null}
</>
);
}
57 changes: 37 additions & 20 deletions src/components/resources/Sidebar/data/SidebarData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,39 @@
{
"title": "Student Life",
"icon": "fa fa-home",
"colorSet": "red",
"children": [
{
"title": "Home",
"icon": "mdi:home",
"path": "/"
},
{
"title": "About",
"icon": "mdi:home",
"path": "/about"
},
{
"title": "Contact",
"icon": "mdi:home",
"children": [
{
"title": "Facebook",
"icon": "mdi:home"
"title": "Facebook"
},
{
"title": "Twitter",
"icon": "mdi:home"
"title": "Twitter"
},
{
"title": "Instagram",
"icon": "mdi:home"
"title": "Instagram"
}
]
},
{
"title": "FAQ",
"icon": "mdi:home"
"title": "FAQ"
}
]
},
{
"title": "Academics",
"icon": "mdi:home",
"icon": "fa fa-graduation-cap",
"colorSet": "green",
"children": [
{
"title": "Login",
Expand All @@ -61,7 +56,8 @@
},
{
"title": "Careers",
"icon": "mdi:home",
"icon": "fa fa-briefcase",
"colorSet": "blue",
"children": [
{
"title": "Profile",
Expand Down Expand Up @@ -101,7 +97,8 @@
},
{
"title": "Self Learning",
"icon": "mdi:home",
"icon": "fa fa-seedling",
"colorSet": "orange",
"children": [
{
"title": "Search",
Expand All @@ -114,13 +111,33 @@
]
},
{
"title": "Report Issue",
"icon": "mdi:home",
"path": "/support"
"title": "Courses",
"icon": "fa fa-book",
"colorSet": "purple",
"children": [
{
"title": "Search",
"path": "/search"
},
{
"title": "History",
"path": "/history"
}
]
},
{
"title": "Contribute",
"icon": "mdi:home",
"path": "/report-bug"
"title": "FAQs",
"icon": "fa fa-lightbulb",
"colorSet": "yellow",
"children": [
{
"title": "Search",
"path": "/search"
},
{
"title": "History",
"path": "/history"
}
]
}
]

0 comments on commit d3af6c6

Please sign in to comment.