Skip to content
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

feat: nav tooltips #29

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 32 additions & 11 deletions src/lib/layouts/Docs.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<script lang="ts" context="module">
import { navigating } from '$app/stores';
import { writable } from 'svelte/store';

export type DocsLayoutVariant = 'default' | 'expanded' | 'two-side-navs';
export type DocsLayoutState = {
showReferences: boolean;
showSidenav: boolean;
};
export const layoutState = writable<DocsLayoutState>({
showReferences: false,
showSidenav: false
});
export function toggleReferences() {
layoutState.update((state) => ({
showReferences: !state.showReferences,
showSidenav: false
}));
}
export function toggleSidenav() {
layoutState.update((state) => ({
showReferences: false,
showSidenav: !state.showSidenav
}));
}
</script>

<script lang="ts">
const handleMenuClick = () => {
const gridHugeNavs = document.querySelector('.aw-grid-huge-navs');
const gridSideNavs = document.querySelector('.aw-grid-side-nav');
const referencesMenu = document.querySelector('.aw-references-menu');

gridHugeNavs?.classList.toggle('is-open');
gridSideNavs?.classList.toggle('is-open');
referencesMenu?.classList.remove('is-open');
};

export let variant: DocsLayoutVariant = 'default';

const variantClasses: Record<DocsLayoutVariant, string> = {
default: 'aw-grid-side-nav aw-container',
expanded: 'aw-grid-huge-navs',
Expand All @@ -22,11 +36,18 @@

$: variantClass = variantClasses[variant];

navigating.subscribe(() => {
layoutState.set({
showReferences: false,
showSidenav: false
});
});
</script>

<div class="u-position-relative">
<div
class={variantClass}
class:is-open={$layoutState.showSidenav}
style:--container-size={variant === 'default' ? 'var(--container-size-large)' : undefined}
>
<section class="aw-mobile-header is-transparent">
Expand All @@ -50,7 +71,7 @@
<a href="https://cloud.appwrite.io/console" class="aw-button">
<span class="aw-sub-body-500">Go to console</span>
</a>
<button on:click={handleMenuClick} class="aw-button is-text" aria-label="open navigation">
<button on:click={toggleSidenav} class="aw-button is-text" aria-label="open navigation">
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
Expand Down
47 changes: 20 additions & 27 deletions src/lib/layouts/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@

<script lang="ts">
import { page } from '$app/stores';
import Tooltip from '$lib/components/Tooltip.svelte';
import { layoutState, toggleSidenav } from './Docs.svelte';
import SidebarNavButton from './SidebarNavButton.svelte';

export let expandable = false;
export let navigation: NavTree;
export let parent: NavParent | undefined = undefined;

const handleMenuClick = () => {
const gridHugeNavs = document.querySelector('.aw-grid-huge-navs');
const referencesMenu = document.querySelector('.aw-references-menu');

gridHugeNavs?.classList.toggle('is-open');
referencesMenu?.classList.remove('is-open');
};

function isNavLink(item: NavLink | NavGroup): item is NavLink {
return 'href' in item;
}
Expand All @@ -56,31 +51,29 @@
{#each navigation as navGroup}
<section>
{#if isNavLink(navGroup)}
<a
class="aw-side-nav-button"
href={navGroup.href}
class:is-selected={$page.url?.pathname === navGroup.href}
>
<span class={navGroup.icon} aria-hidden="true" />
<span class="aw-caption-400">{navGroup.label}</span>
</a>
{#if expandable && !$layoutState.showSidenav}
<Tooltip placement="right">
<SidebarNavButton groupItem={navGroup} />
<svelte:fragment slot="tooltip">{navGroup.label}</svelte:fragment>
</Tooltip>
{:else}
<SidebarNavButton groupItem={navGroup} />
{/if}
{:else}
{#if navGroup.label}
<h4 class="aw-side-nav-header aw-eyebrow">{navGroup.label}</h4>
{/if}
<ul>
{#each navGroup.items as groupItem}
<li>
<a
class="aw-side-nav-button"
class:is-selected={$page.url?.pathname === groupItem.href}
href={groupItem.href}
>
{#if groupItem.icon}
<span class={groupItem.icon} aria-hidden="true" />
{/if}
<span class="aw-caption-400">{groupItem.label}</span>
</a>
{#if expandable && !$layoutState.showSidenav}
<Tooltip placement="right">
<SidebarNavButton {groupItem} />
<svelte:fragment slot="tooltip">{groupItem.label}</svelte:fragment>
</Tooltip>
{:else}
<SidebarNavButton {groupItem} />
{/if}
</li>
{/each}
</ul>
Expand All @@ -90,7 +83,7 @@
</div>
{#if expandable}
<button
on:click={handleMenuClick}
on:click={toggleSidenav}
class="aw-icon-button u-margin-inline-start-auto"
aria-label="toggle nav"
>
Expand Down
17 changes: 17 additions & 0 deletions src/lib/layouts/SidebarNavButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
import { page } from '$app/stores';
import type { NavLink } from './Sidebar.svelte';

export let groupItem: NavLink;
</script>

<a
class="aw-side-nav-button"
class:is-selected={$page.url?.pathname === groupItem.href}
href={groupItem.href}
>
{#if groupItem.icon}
<span class={groupItem.icon} aria-hidden="true" />
{/if}
<span class="aw-caption-400">{groupItem.label}</span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { MainFooter } from '$lib/components';
import { layoutState, toggleReferences } from '$lib/layouts/Docs.svelte';
import { parse } from '$lib/utils/markdown';
import { Platform, platformMap, serviceMap, versions } from '$lib/utils/references.js';
import type { LayoutContext } from '$markdoc/layouts/Article.svelte';
Expand Down Expand Up @@ -29,11 +30,6 @@
}
});

function handleRefClick() {
document.querySelector('.aw-references-menu')?.classList.toggle('is-open');
document.querySelector('.aw-grid-two-side-navs')?.classList.remove('is-open');
}

function selectPlatform(event: Event & { currentTarget: EventTarget & HTMLSelectElement }) {
const { version, service } = $page.params;
goto(`/docs/references/${version}/${event.currentTarget.value}/${service}`, {
Expand Down Expand Up @@ -202,14 +198,14 @@
</section>
{/each}
</div>
<aside class="aw-references-menu">
<button class="aw-icon-button" id="refOpen" on:click={handleRefClick}>
<aside class="aw-references-menu" class:is-open={$layoutState.showReferences}>
<button class="aw-icon-button" id="refOpen" on:click={toggleReferences}>
<span class="icon-menu-alt-4" aria-hidden="true" />
</button>
<div class="aw-references-menu-content">
<div class="u-flex u-main-space-between u-cross-center u-gap-16 u-margin-block-start-24">
<h5 class="aw-references-menu-title aw-eyebrow">On This Page</h5>
<button class="aw-icon-button" id="refClose" on:click={handleRefClick}>
<button class="aw-icon-button" id="refClose" on:click={toggleReferences}>
<span class="icon-x" aria-hidden="true" />
</button>
</div>
Expand Down