Skip to content

Commit

Permalink
[fix](docs): maintain state in Accordion when changing pages
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #479
  • Loading branch information
BeeMargarida committed Dec 5, 2023
1 parent f78a84f commit 2b74eba
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 89 deletions.
22 changes: 21 additions & 1 deletion apps/docs/src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
} from 'radix-icons-svelte';
import { base } from '$app/paths';
export let pathname: string;
let accordionEl: HTMLElement;
$: {
// Sets the active link in the Sidebar when the page changes
accordionEl?.querySelectorAll('a').forEach((a) => {
if (a.getAttribute('href') === pathname) {
a.classList.add('active');
} else {
a.classList.remove('active');
}
});
}
const useStyles = createStyles(() => ({
'.svelteui-AccordionItem-panel': {
padding: '0 !important',
Expand Down Expand Up @@ -76,7 +90,13 @@

<hr />

<Accordion variant="default" chevronPosition="left" multiple class={getStyles()}>
<Accordion
bind:element={accordionEl}
variant="default"
chevronPosition="left"
multiple
class={getStyles()}
>
<Accordion.Item value="changelog">
<div slot="control"><NavigationTitle>Changelog</NavigationTitle></div>
<ul class="list">
Expand Down
69 changes: 0 additions & 69 deletions apps/docs/src/lib/theme/components/Layout.svelte

This file was deleted.

2 changes: 1 addition & 1 deletion apps/docs/src/lib/theme/utils/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { outside_click, set_active_link } from './link-actions';
export { outside_click } from './link-actions';
12 changes: 0 additions & 12 deletions apps/docs/src/lib/theme/utils/link-actions.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
// import { current_page } from '@svelte-docs/get/routes';

export function set_active_link(node, options) {
node.querySelectorAll('a').forEach((a) => {
if (a.getAttribute('href') === options.page.url.pathname) {
a.classList.add('active');
} else {
a.classList.remove('active');
}
});
}

export function outside_click(node, options) {
const { handler } = options;
console.log(node);
const HTMLCollection = node.children[1].children;
let runner;

Expand Down
7 changes: 1 addition & 6 deletions apps/docs/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { colorScheme, Burger, SvelteUIProvider } from '@svelteuidev/core';
import { page } from '$app/stores';
import { Device, Logo, PageTransition, TopBar, Sidebar } from '$lib/components';
import { set_active_link } from '$lib/theme/utils';
import '$lib/theme/style.css';
import type { PageData } from './$types';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -36,11 +35,7 @@
class="sidebar"
class:active-sidebar={show_sidebar}
>
{#key $page}
<div use:set_active_link={{ page: $page }}>
<Sidebar />
</div>
{/key}
<Sidebar pathname={$page.url.pathname} />
</div>
{/if}
<div class="topbar">
Expand Down

0 comments on commit 2b74eba

Please sign in to comment.