Skip to content

feat: add sidebar for easy navigation #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions app/components/sidebar-nav.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
.sidebar {
position: sticky;
top: 0;
width: 20%;
height: 100vh;
background-color: #f8f9fa;
border-right: 1px solid #e9ecef;
padding: 1rem 1rem 1.5rem 1rem;
overflow-y: auto;
}

.sidebar-content {
padding-top: 0.5rem;
}

.sidebar-title {
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 1rem;
color: #212529;
}

.nav-list {
list-style: none;
padding: 0;
margin: 0;
}

.nav-item {
display: block;
width: 90%;
text-align: left;
padding: 0.25rem 0.5rem;
margin-bottom: 0.1rem;
color: #212529;
text-decoration: none;
border-radius: 4px;
transition: all 0.2s ease;
font-size: 1.1rem;
}

li > .nav-item {
color: #212529;
font-weight: 500;
}

li > .nav-item:hover {
background-color: #f1f3f5;
}

.sub-nav-list {
list-style: none;
padding-left: 1rem;
margin: 0.15rem 0;
}

.sub-nav-item {
font-size: 1rem;
padding: 0.1rem 0;
}

.sub-nav-item .nav-item {
color: #E04E39;
padding: 0.2rem 0.5rem;
}

.sub-nav-item .nav-item:hover {
background-color: #fff1ef;
}

.menu-toggle:focus {
outline: 2px solid #E04E39;
outline-offset: 2px;
}

.sub-nav-item .nav-item {
color: #c43e2d;
}

.nav-item[aria-current="true"] {
background-color: #f1f3f5;
font-weight: bold;
}

.sub-nav-item .nav-item[aria-current="true"] {
background-color: #fff1ef;
font-weight: bold;
}

@media (max-width: 768px) {
.sidebar {
position: fixed;
top: 0;
left: 0;
width: 85%;
height: 100vh;
z-index: 1000;
transform: translateX(-100%);
transition: transform 0.3s ease;
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

.sidebar.open {
transform: translateX(0);
}

.menu-toggle {
position: fixed;
top: 1rem;
right: 1rem;
z-index: 1001;
width: 44px;
height: 44px;
border-radius: 50%;
background: #E04E39;
border: none;
color: white;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.menu-toggle:hover {
background: #c43e2d;
}

.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
backdrop-filter: blur(2px);
}

.overlay.open {
display: block;
}
}
69 changes: 69 additions & 0 deletions app/components/sidebar-nav.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{#if this.isMobile}}
<button
type="button"
local-class="menu-toggle"
{{on "click" this.toggleMenu}}
aria-label={{t "component.sidebar-nav.toggle-menu"}}
>
{{t "component.sidebar-nav.menu-icon"}}
</button>
<button
type="button"
local-class="overlay {{if this.isMenuOpen 'open'}}"
{{on "click" this.closeMenu}}
aria-label={{t "component.sidebar-nav.close-menu"}}
></button>
{{/if}}

<nav
local-class="sidebar {{if this.isMenuOpen 'open'}}"
id="sidebar-nav"
aria-label={{t "component.sidebar-nav.table-of-contents"}}
>
<div local-class="sidebar-content">
<h2
local-class="sidebar-title"
id="nav-title"
>
{{t "component.sidebar-nav.contents"}}
</h2>
<ul
local-class="nav-list"
role="list"
aria-labelledby="nav-title"
>
{{#each @model as |section|}}
<li>
<a
href="#{{section.id}}"
local-class="nav-item"
{{on "click" this.closeMenu}}
aria-current={{if (eq this.currentSection section.id) "true"}}
>
{{t (concat section.id ".title")}}
</a>
{{#if section.subsections}}
<ul
local-class="sub-nav-list"
role="list"
aria-label={{t "component.sidebar-nav.subsections-of" sectionTitle=(t (concat section.id ".title"))}}
>
{{#each section.subsections as |subsection|}}
<li local-class="sub-nav-item">
<a
href="#{{section.id}}__{{subsection.id}}"
local-class="nav-item"
{{on "click" this.closeMenu}}
aria-current={{if (eq this.currentSection (concat section.id "__" subsection.id)) "true"}}
>
{{t (concat section.id "." subsection.id ".title")}}
</a>
</li>
{{/each}}
</ul>
{{/if}}
</li>
{{/each}}
</ul>
</div>
</nav>
52 changes: 52 additions & 0 deletions app/components/sidebar-nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class SidebarNavComponent extends Component {
@service scroll;
@service intl;

@tracked activeSection = '';
@tracked isMenuOpen = false;
@tracked isMobile = false;

constructor() {
super(...arguments);
if (typeof window !== 'undefined') {
this.checkMobile();
window.addEventListener('resize', this.checkMobile);
}
}

willDestroy() {
super.willDestroy();
if (typeof window !== 'undefined') {
window.removeEventListener('resize', this.checkMobile);
}
}

get currentSection() {
return this.scroll?.activeSection || '';
}

@action
scrollToSection(sectionId) {
this.scroll.scrollToSection(sectionId);
}

@action
checkMobile() {
this.isMobile = window.innerWidth <= 768;
}

@action
toggleMenu() {
this.isMenuOpen = !this.isMenuOpen;
}

@action
closeMenu() {
this.isMenuOpen = false;
}
}
11 changes: 11 additions & 0 deletions app/styles/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
margin-top: 4rem;
}

.content-wrapper {
display: flex;
width: 100%;
}

.main-content {
flex: 1;
padding: 2rem;
overflow-y: auto;
}

@media screen and (min-width: 30rem) {
.header,
.main {
Expand Down
43 changes: 25 additions & 18 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,31 @@
</div>
</header>

<main local-class="main">
<h1 local-class="title">
{{t "layout.application.title"}}
</h1>
<div local-class="content-wrapper">
<SidebarNav @model={{@model}} />

<p>
{{t "layout.application.description-1" htmlSafe=true}}
</p>
<main local-class="main main-content">
<h1 local-class="title">
{{t "layout.application.title"}}
</h1>

<p>
{{t "layout.application.description-2" htmlSafe=true}}
</p>
<p>
{{t "layout.application.description-1" htmlSafe=true}}
</p>

{{#each @model as |section|}}
<div local-class="guide-section-container">
<GuideSection
@section={{section}}
/>
</div>
{{/each}}
</main>
<p>
{{t "layout.application.description-2" htmlSafe=true}}
</p>

{{#each @model as |section|}}
<div
id="section-{{section.id}}"
local-class="guide-section-container"
>
<GuideSection
@section={{section}}
/>
</div>
{{/each}}
</main>
</div>
Loading