|
1 | 1 | <script lang="ts"> |
2 | 2 | import "../app.css"; |
3 | | - import { Avatar, Navigation, Toaster, createToaster } from "@skeletonlabs/skeleton-svelte"; |
| 3 | + import { Avatar, Navigation, createToaster } from "@skeletonlabs/skeleton-svelte"; |
| 4 | + import NavigationTile from "$lib/components/navigation/NavigationTile.svelte"; |
4 | 5 | import IconHome from "lucide-svelte/icons/house"; |
5 | 6 | import IconWorkflow from "lucide-svelte/icons/workflow"; |
6 | 7 | import IconInfo from "lucide-svelte/icons/info"; |
|
12 | 13 | import { TemplateAPI } from "$lib/components/template/api"; |
13 | 14 | import { page } from "$app/state"; |
14 | 15 | import { initContext, setColorScheme, setToaster } from "$lib/context/layout_context.svelte"; |
| 16 | + import Toast from "$lib/components/ui/Toast.svelte"; |
15 | 17 |
|
16 | 18 | let expanded = $state(false); |
17 | 19 |
|
|
27 | 29 | setColorScheme(document.documentElement.className as App.ColorScheme); |
28 | 30 | } |
29 | 31 |
|
30 | | - const tileProps = { |
31 | | - "active": "bg-surface-300-700", |
32 | | - "hover": "hover:preset-filled-surface-200-800", |
33 | | - }; |
34 | | -
|
35 | 32 | const apiProps: ApiProps = { |
36 | 33 | token: data.access_token!!, |
37 | 34 | fetch: fetch |
|
45 | 42 | placement: "bottom-end" |
46 | 43 | }); |
47 | 44 | setToaster(toaster); |
| 45 | +
|
| 46 | + const tileProps = $derived({ |
| 47 | + expanded, |
| 48 | + hover: "preset-filled-surface-200-800", |
| 49 | + }); |
48 | 50 | </script> |
49 | 51 |
|
50 | 52 | <div class="card border-surface-100-900 grid h-full w-full grid-cols-[auto_1fr] border-[1px]"> |
51 | | - <Navigation.Rail value="nothing" classes="navbar overflow-y-auto" {expanded}> |
52 | | - {#snippet header()} |
53 | | - <Navigation.Tile labelExpanded="Menu" title="menu" selected={expanded} onclick={() => expanded = !expanded} {...tileProps}> |
54 | | - <IconMenu/> |
55 | | - </Navigation.Tile> |
56 | | - {/snippet} |
57 | | - {#snippet tiles()} |
58 | | - <Navigation.Tile id="home" labelExpanded="Home" label="Home" href="/" selected={activeUrl === "/"} {...tileProps}> |
59 | | - <IconHome/> |
60 | | - </Navigation.Tile> |
61 | | - {#if data.user != null} |
62 | | - <!-- matches /flows and /flow/:id --> |
63 | | - <Navigation.Tile id="flows" labelExpanded="My Flows" label="Flows" href="/flows" selected={activeUrl.startsWith("/flow")} {...tileProps}> |
64 | | - <IconWorkflow/> |
65 | | - </Navigation.Tile> |
66 | | - {/if} |
67 | | - <Navigation.Tile id="about" labelExpanded="About Snoty" label="About" href="/about" selected={activeUrl === "/about"} {...tileProps}> |
68 | | - <IconInfo/> |
69 | | - </Navigation.Tile> |
70 | | - {#if !isErrorJson(data.roles) && data.roles?.includes("admin")} |
71 | | - <Navigation.Tile id="admin" labelExpanded="Admin" label="Admin" href="/admin" selected={activeUrl === "/admin"} {...tileProps}> |
72 | | - <IconMonitorCog/> |
73 | | - </Navigation.Tile> |
74 | | - {/if} |
75 | | - {/snippet} |
76 | | - {#snippet footer()} |
77 | | - <UserMenu {apiProps} user={data.user} {tileProps}/> |
78 | | - {/snippet} |
79 | | - </Navigation.Rail> |
80 | | - <Toaster {toaster} width="min-w-md"/> |
| 53 | + <Navigation layout={expanded ? "sidebar" : "rail"} class={`p-1 overflow-y-auto ${expanded ? "grid grid-rows-[1fr_auto_1fr] gap-4" : "w-auto"}`}> |
| 54 | + <Navigation.Header> |
| 55 | + <NavigationTile labelExpanded="Menu" selected={expanded} onclick={() => expanded = !expanded} {...tileProps}> |
| 56 | + <IconMenu/> |
| 57 | + </NavigationTile> |
| 58 | + </Navigation.Header> |
| 59 | + <Navigation.Content> |
| 60 | + <Navigation.Menu class="gap-1"> |
| 61 | + <NavigationTile labelExpanded="Home" label="Home" href="/" selected={activeUrl === "/"} {...tileProps}> |
| 62 | + <IconHome/> |
| 63 | + </NavigationTile> |
| 64 | + {#if data.user != null} |
| 65 | + <!-- matches /flows and /flow/:id --> |
| 66 | + <NavigationTile labelExpanded="My Flows" label="Flows" href="/flows" selected={activeUrl.startsWith("/flow")} {...tileProps}> |
| 67 | + <IconWorkflow/> |
| 68 | + </NavigationTile> |
| 69 | + {/if} |
| 70 | + <NavigationTile labelExpanded="About Snoty" label="About" href="/about" selected={activeUrl === "/about"} {...tileProps}> |
| 71 | + <IconInfo/> |
| 72 | + </NavigationTile> |
| 73 | + {#if !isErrorJson(data.roles) && data.roles?.includes("admin")} |
| 74 | + <NavigationTile labelExpanded="Admin" label="Admin" href="/admin" selected={activeUrl === "/admin"} {...tileProps}> |
| 75 | + <IconMonitorCog/> |
| 76 | + </NavigationTile> |
| 77 | + {/if} |
| 78 | + </Navigation.Menu> |
| 79 | + </Navigation.Content> |
| 80 | + <Navigation.Footer class="flex flex-col justify-end"> |
| 81 | + <UserMenu {apiProps} user={data.user} {tileProps}/> |
| 82 | + </Navigation.Footer> |
| 83 | + </Navigation> |
| 84 | + <Toast {toaster}/> |
81 | 85 | <div class="flex flex-col gap-2 items-center justify-center h-full overflow-y-auto"> |
82 | 86 | {@render children()} |
83 | 87 | </div> |
|
0 commit comments