Skip to content

Commit

Permalink
test: scaffold App UI
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Dec 8, 2024
1 parent 22ffef4 commit d7158ce
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions tests/App.test.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
<script>
<script lang="ts">
import { TreeView as TreeViewNav } from "carbon-components-svelte";
import TreeView from "./TreeView/TreeView.test.svelte";
import { onMount } from "svelte";
const routes = [
{
path: "/treeview",
name: "TreeView",
component: TreeView,
},
] as const;
let currentPath = window.location.pathname;
function navigate(path: string) {
history.pushState({}, "", path);
currentPath = path;
}
onMount(() => {
const handlePopState = () => {
currentPath = window.location.pathname;
};
window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
});
</script>

<TreeView />
<div style:display="flex">
<div>
<TreeViewNav
labelText="Routes"
nodes={routes.map((route) => ({
id: route.path,
text: route.name,
}))}
on:select={(e) => {
navigate(e.detail.id.toString());
}}
/>
</div>
<div style:flex="1">
{#each routes as route (route.path)}
{#if currentPath === route.path}
<svelte:component this={route.component} />
{/if}
{/each}
</div>
</div>

0 comments on commit d7158ce

Please sign in to comment.