Skip to content

Commit

Permalink
feat: main mobile menu
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix committed Jan 22, 2024
1 parent aadcd0d commit fa1bcb6
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 114 deletions.
2 changes: 1 addition & 1 deletion demo/src/lib/layout/Sample.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<button
class="btn btn-sm btn-link m-1 p-0"
aria-label="Show or hide the code"
use:tooltip={{content: 'Toogle code'}}
use:tooltip={{content: 'Toggle code'}}
on:click={() => (showCode = !showCode)}><Svg className="icon-24 align-middle" svg={codeSvg} /></button
>
<button
Expand Down
5 changes: 2 additions & 3 deletions demo/src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ export const selectedTabName$ = computed(() => {
return match?.[1] || 'examples';
});

const frameworkKeyRegExp = /\/docs\/[a-z]*\//;
const frameworkKeyRegExp = /\/docs\/[a-z]*\/(.*)$/;
export const frameworkLessUrl$ = computed(() => {
const $page = get(page);
const match = $page.url.pathname.match(frameworkKeyRegExp);
return match ? $page.url.pathname.substring($page.url.pathname.indexOf(match[0]) + match[0].length) : '/';
return $page.url.pathname.match(frameworkKeyRegExp)?.[1] ?? '/';
});

export const intersectionApi = createIntersection();
25 changes: 14 additions & 11 deletions demo/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import Svg from '$lib/layout/Svg.svelte';
import github from 'bootstrap-icons/icons/github.svg?raw';
import twitter from 'bootstrap-icons/icons/twitter-x.svg?raw';
import coneStriped from 'bootstrap-icons/icons/cone-striped.svg?raw';
import 'bootstrap/dist/css/bootstrap.css';
import {/*canonicalURL$,*/ pathToRoot$, routeLevel$} from '$lib/stores';
import './styles.scss';
import {beforeNavigate, onNavigate} from '$app/navigation';
import {updated} from '$app/stores';
import {onMount} from 'svelte';
import MobileSubMenu from './menu/MobileSubMenu.svelte';
import MobileMenu from './menu/MobileMenu.svelte';
import MainSection from '$lib/layout/MainSection.svelte';
import SideMenu from './menu/SideMenu.svelte';
Expand Down Expand Up @@ -54,11 +54,10 @@
<nav class="demo-nav-top navbar navbar-dark bg-primary bg-gradient">
<div class="container-fluid">
<a class="navbar-brand" href={$pathToRoot$}> AgnosUI </a>
<div class="d-flex align-items-center">
<span class="badge bg-warning text-bg-warning d-none d-sm-block">Work In Progress</span>
<span class="badge rounded-pill bg-warning text-bg-warning d-block d-sm-none" aria-label="Work In Progress">
<Svg className="icon-20 align-middle" svg={coneStriped} />
</span>
<div class="align-items-center d-none d-md-flex">
<div class="d-flex align-items-center"></div>
<a class="nav-link text-white ms-3" href="{$pathToRoot$}docs/angular/getting-started/installation">Documentation</a>
<a class="nav-link text-white ms-3" href="{$pathToRoot$}blog/2024-01-12">Blog</a>
<a class="nav-link text-white ms-3" href="https://github.com/AmadeusITGroup/AgnosUI" aria-label="link to GitHub repository" target="_blank">
<Svg className="icon-24 align-middle" svg={github} />
</a>
Expand All @@ -67,11 +66,16 @@
</a>
<span class="ms-3 text-white">v{import.meta.env.AGNOSUI_VERSION}</span>
</div>
<div class="d-block d-md-none">
<MobileMenu />
</div>
</div>
</nav>
<div class="demo-mobile-menu d-block d-md-none">
<MobileMenu {isMainPage} />
</div>
{#if !isMainPage}
<div class="demo-mobile-menu d-block d-md-none">
<MobileSubMenu />
</div>
{/if}
<div class="demo-main d-flex flex-column">
{#if isMainPage}
<slot />
Expand All @@ -86,7 +90,7 @@
<slot />
</MainSection>
</div>
<div class="demo-toc col-auto d-none d-lg-flex">
<div class="demo-toc col-auto d-none d-md-flex">
<TOC />
</div>
</div>
Expand Down Expand Up @@ -138,7 +142,6 @@
.demo-toc {
position: sticky;
top: 0;
display: block !important;
min-width: 250px;
height: calc(100vh - 6rem);
overflow-y: auto;
Expand Down
2 changes: 1 addition & 1 deletion demo/src/routes/blog/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const load = async () => {
menu: [
{
title: 'News 2024',
submenu: [{label: 'Reactivity with Tansu', path: '/blog/2024-01-12', subpath: ''}],
submenu: [{label: 'Reactivity with Tansu', path: 'blog/2024-01-12', subpath: ''}],
},
],
};
Expand Down
81 changes: 81 additions & 0 deletions demo/src/routes/menu/MobileDialog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script lang="ts">
import {createEventDispatcher} from 'svelte';
export let title: string;
export let open: boolean;
const dispatch = createEventDispatcher<{
close: null; // does not accept a payload
}>();
let dialog: HTMLDialogElement;
$: if (open) {
dialog?.showModal();
}
function onDialogClick(e: any) {
const tagName = (e.target as HTMLElement).tagName.toLowerCase();
if (tagName === 'button' || tagName === 'a') {
dialog.close();
}
}
function onDialogClose() {
dispatch('close');
}
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<dialog bind:this={dialog} on:close={onDialogClose} on:click={onDialogClick}>
<div class="menu-title text-center border-bottom pb-2">
<span class="menu-title-text">{title}</span>
<button type="button" class="btn-close pb-3 pe-3" aria-label="Close menu" />
</div>
<slot />
</dialog>

<style lang="scss">
$negativeMargin: -16px;
$titleHeight: 3rem;
.menu-title {
position: sticky;
top: 0;
height: $titleHeight;
background-color: var(--bs-body-bg);
margin: 0 $negativeMargin 1rem $negativeMargin;
z-index: 10;
}
.menu-title-text {
line-height: $titleHeight;
}
dialog {
width: 100vw;
max-width: 100vw;
height: 100vh;
height: 100dvh;
max-height: 100vh;
position: fixed;
padding-top: 0;
top: 0;
left: 0;
border: none;
bottom: 0;
right: 0;
background-color: var(--bs-body-bg);
z-index: 1000;
:global(.demo-links-link) {
display: block !important;
}
}
.btn-close {
position: absolute;
top: 0.3rem;
right: 10px;
}
</style>
150 changes: 52 additions & 98 deletions demo/src/routes/menu/MobileMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,112 +1,66 @@
<script lang="ts">
import menuIcon from '$resources/icons/menu.svg?raw';
import chevronRight from 'bootstrap-icons/icons/chevron-right.svg?raw';
import threeDots from 'bootstrap-icons/icons/three-dots-vertical.svg?raw';
import github from 'bootstrap-icons/icons/github.svg?raw';
import twitter from 'bootstrap-icons/icons/twitter-x.svg?raw';
import MobileDialog from './MobileDialog.svelte';
import Svg from '$lib/layout/Svg.svelte';
import SideMenu from './SideMenu.svelte';
import TOC from './TOC.svelte';
import {pathToRoot$} from '$lib/stores';
import {page} from '$app/stores';
let isMenuExpanded = false;
let isOnThisPageExpanded = false;
let dialog: HTMLDialogElement;
export let isMainPage = true;
let open = false;
$: dialogTitle = isMenuExpanded ? 'Menu' : isOnThisPageExpanded ? 'On this page' : '';
$: isOpen = isMenuExpanded || isOnThisPageExpanded;
$: if (isOpen) {
dialog?.showModal();
}
function onDialogClose() {
isMenuExpanded = isOnThisPageExpanded = false;
}
function onDialogClick(e: any) {
const tagName = (e.target as HTMLElement).tagName.toLowerCase();
if (tagName === 'button' || tagName === 'a') {
dialog.close();
}
function onClose() {
open = false;
}
</script>

<div class="d-flex align-items-center justify-content-between">
<button
class="text-dark d-flex align-items-center btn btn-link link-underline link-underline-opacity-0"
aria-expanded={isMenuExpanded}
on:click={() => {
isMenuExpanded = true;
}}
>
<Svg svg={menuIcon} className="icon-20 me-1" /><span class="menu-text">Menu</span>
</button>
{#if !isMainPage}
<button
class="text-dark d-flex align-items-center btn btn-link link-underline link-underline-opacity-0"
aria-expanded={isOnThisPageExpanded}
on:click={() => {
isOnThisPageExpanded = true;
}}
<button
class="text-white btn d-flex align-items-center pe-0"
aria-expanded={open}
on:click={() => {
open = true;
}}
>
<Svg svg={threeDots} className="icon-20 me-1" />
</button>

<MobileDialog title="AgnosUI" {open} on:close={onClose}>
<nav class="navbar navbar-light flex-column align-items-stretch">
<a
class="nav-item nav-link"
href="{$pathToRoot$}docs/angular/getting-started/installation"
class:active={$page.route.id?.startsWith('/docs/')}
aria-current={$page.route.id?.startsWith('/docs/') ? 'page' : undefined}
>
Documentation
</a>
<hr />
<a
class="nav-item nav-link"
href="{$pathToRoot$}blog/2024-01-12"
class:active={$page.route.id?.startsWith('/blog/')}
aria-current={$page.route.id?.startsWith('/blog/') ? 'page' : undefined}
>
<span class="menu-text">On this page</span>
<Svg svg={chevronRight} className="icon-20 me-1" />
</button>
{/if}
</div>
Blog
</a>
<hr />
</nav>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<dialog bind:this={dialog} on:close={onDialogClose} on:click={onDialogClick}>
<div class="menu-title text-center border-bottom pb-2">
<span class="menu-title-text">{dialogTitle}</span>
<button type="button" class="btn-close pb-3 pe-3" aria-label="Close menu" />
<div class="d-flex justify-content-center">
<a class="nav-link" href="https://github.com/AmadeusITGroup/AgnosUI" aria-label="link to GitHub repository" target="_blank">
<Svg className="icon-24 align-middle" svg={github} />
</a>
<a class="nav-link ms-3" href="https://twitter.com/AgnosUI" aria-label="link to twitter / x account" target="_blank">
<Svg className="icon-24 align-middle" svg={twitter} />
</a>
<div class="ms-3">
<span class="mt-4">v{import.meta.env.AGNOSUI_VERSION}</span>
</div>
</div>
{#if isMenuExpanded}
<SideMenu />
{:else}
<TOC />
{/if}
</dialog>
</MobileDialog>

<style lang="scss">
$negativeMargin: -16px;
$titleHeight: 3rem;
.menu-title {
position: sticky;
top: 0;
height: $titleHeight;
background-color: var(--bs-body-bg);
margin: 0 $negativeMargin 1rem $negativeMargin;
z-index: 10;
}
.menu-title-text {
line-height: $titleHeight;
}
dialog {
width: 100vw;
max-width: 100vw;
height: 100vh;
height: 100dvh;
max-height: 100vh;
position: fixed;
padding-top: 0;
top: 0;
left: 0;
border: none;
bottom: 0;
right: 0;
background-color: var(--bs-body-bg);
z-index: 1000;
:global(.demo-links-link) {
display: block !important;
}
}
.btn-close {
position: absolute;
top: 0.3rem;
right: 10px;
.nav-link.active {
font-weight: 600;
}
</style>
48 changes: 48 additions & 0 deletions demo/src/routes/menu/MobileSubMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script lang="ts">
import menuIcon from '$resources/icons/menu.svg?raw';
import chevronRight from 'bootstrap-icons/icons/chevron-right.svg?raw';
import Svg from '$lib/layout/Svg.svelte';
import SideMenu from './SideMenu.svelte';
import TOC from './TOC.svelte';
import MobileDialog from './MobileDialog.svelte';
let isMenuExpanded = false;
let isOnThisPageExpanded = false;
$: title = isMenuExpanded ? 'Menu' : isOnThisPageExpanded ? 'On this page' : '';
$: open = isMenuExpanded || isOnThisPageExpanded;
function onClose() {
isMenuExpanded = isOnThisPageExpanded = false;
}
</script>

<div class="d-flex align-items-center justify-content-between">
<button
class="text-dark d-flex align-items-center btn btn-link link-underline link-underline-opacity-0"
aria-expanded={isMenuExpanded}
on:click={() => {
isMenuExpanded = true;
}}
>
<Svg svg={menuIcon} className="icon-20 me-1" /><span class="menu-text">Menu</span>
</button>
<button
class="text-dark d-flex align-items-center btn btn-link link-underline link-underline-opacity-0"
aria-expanded={isOnThisPageExpanded}
on:click={() => {
isOnThisPageExpanded = true;
}}
>
<span class="menu-text">On this page</span>
<Svg svg={chevronRight} className="icon-20 me-1" />
</button>
</div>

<MobileDialog {title} {open} on:close={onClose}>
{#if isMenuExpanded}
<SideMenu />
{:else}
<TOC />
{/if}
</MobileDialog>
Loading

0 comments on commit fa1bcb6

Please sign in to comment.