floors sidebar
This commit is contained in:
parent
0738070ce1
commit
4b9620be7f
4 changed files with 62 additions and 43 deletions
|
@ -1,61 +1,51 @@
|
||||||
<script>
|
<script>
|
||||||
import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
|
import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
|
||||||
import * as Sidebar from "$lib/components/ui/sidebar/index.js";
|
import * as Sidebar from "$lib/components/ui/sidebar/index.js";
|
||||||
import { ChevronUp, ChevronDown } from "lucide-svelte";
|
import { ChevronUp } from "lucide-svelte";
|
||||||
import House from "lucide-svelte/icons/house";
|
import House from "lucide-svelte/icons/house";
|
||||||
import Inbox from "lucide-svelte/icons/inbox";
|
|
||||||
import Calendar from "lucide-svelte/icons/calendar";
|
|
||||||
import Search from "lucide-svelte/icons/search";
|
|
||||||
import Settings from "lucide-svelte/icons/settings";
|
import Settings from "lucide-svelte/icons/settings";
|
||||||
import "../../app.css";
|
import "../../app.css";
|
||||||
|
import { sidebarItems } from "@/stores/sidebarStore.ts";
|
||||||
let { children, data } = $props();
|
let { children, data } = $props();
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
title: "Home",
|
number: 1,
|
||||||
url: "/",
|
url: "/",
|
||||||
icon: House,
|
icon: House,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "Inbox",
|
|
||||||
url: "/",
|
|
||||||
icon: Inbox,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Calendar",
|
|
||||||
url: "/",
|
|
||||||
icon: Calendar,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Search",
|
|
||||||
url: "/",
|
|
||||||
icon: Search,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const settings = [
|
sidebarItems.set(items);
|
||||||
{
|
|
||||||
title: "Settings",
|
function getFloorName(n) {
|
||||||
url: "settings",
|
switch (n) {
|
||||||
icon: Settings,
|
case 1:
|
||||||
},
|
return "1st floor";
|
||||||
];
|
case 2:
|
||||||
|
return "2nd floor";
|
||||||
|
case 3:
|
||||||
|
return "3rd floor";
|
||||||
|
default:
|
||||||
|
return n + "th floor";
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Sidebar.Provider>
|
<Sidebar.Provider>
|
||||||
<Sidebar.Root>
|
<Sidebar.Root collapsible="icon">
|
||||||
<Sidebar.Content>
|
<Sidebar.Content>
|
||||||
<Sidebar.Group>
|
<Sidebar.Group>
|
||||||
<Sidebar.GroupLabel>Floors</Sidebar.GroupLabel>
|
<Sidebar.GroupLabel>Floors</Sidebar.GroupLabel>
|
||||||
<Sidebar.GroupContent>
|
<Sidebar.GroupContent>
|
||||||
<Sidebar.Menu>
|
<Sidebar.Menu>
|
||||||
{#each items as item (item.title)}
|
{#each $sidebarItems as item (item.number)}
|
||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton>
|
<Sidebar.MenuButton>
|
||||||
{#snippet child({ props })}
|
{#snippet child({ props })}
|
||||||
<a href={item.url} {...props}>
|
<a href={item.url} {...props}>
|
||||||
<item.icon />
|
<item.icon />
|
||||||
<span>{item.title}</span>
|
<span>{getFloorName(item.number)}</span>
|
||||||
</a>
|
</a>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Sidebar.MenuButton>
|
</Sidebar.MenuButton>
|
||||||
|
@ -67,18 +57,16 @@
|
||||||
<Sidebar.Group>
|
<Sidebar.Group>
|
||||||
<Sidebar.GroupContent>
|
<Sidebar.GroupContent>
|
||||||
<Sidebar.Menu>
|
<Sidebar.Menu>
|
||||||
{#each settings as item (item.title)}
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuButton>
|
||||||
<Sidebar.MenuButton>
|
{#snippet child({ props })}
|
||||||
{#snippet child({ props })}
|
<a href="/settings" {...props}>
|
||||||
<a href={item.url} {...props}>
|
<Settings />
|
||||||
<item.icon />
|
<span>Settings</span>
|
||||||
<span>{item.title}</span>
|
</a>
|
||||||
</a>
|
{/snippet}
|
||||||
{/snippet}
|
</Sidebar.MenuButton>
|
||||||
</Sidebar.MenuButton>
|
</Sidebar.MenuItem>
|
||||||
</Sidebar.MenuItem>
|
|
||||||
{/each}
|
|
||||||
</Sidebar.Menu>
|
</Sidebar.Menu>
|
||||||
</Sidebar.GroupContent>
|
</Sidebar.GroupContent>
|
||||||
</Sidebar.Group>
|
</Sidebar.Group>
|
||||||
|
|
|
@ -1 +1,23 @@
|
||||||
<h1>Settings Page</h1>
|
<script>
|
||||||
|
import { sidebarItems } from "@/stores/sidebarStore.ts";
|
||||||
|
import House from "lucide-svelte/icons/house";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
let i = 2;
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
const result = {
|
||||||
|
number: i++,
|
||||||
|
url: "/",
|
||||||
|
icon: House,
|
||||||
|
};
|
||||||
|
|
||||||
|
sidebarItems.update((item) => {
|
||||||
|
item.push(result);
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
console.log(get(sidebarItems));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={a}>a</button>
|
||||||
|
|
3
src/stores/sidebarStore.ts
Normal file
3
src/stores/sidebarStore.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { writable } from "svelte/store"
|
||||||
|
|
||||||
|
export const sidebarItems = writable([]);
|
|
@ -1,6 +1,12 @@
|
||||||
import { sveltekit } from "@sveltejs/kit/vite";
|
import { sveltekit } from "@sveltejs/kit/vite";
|
||||||
|
import { fileURLToPath, URL } from "node:url";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()],
|
plugins: [sveltekit()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": fileURLToPath(new URL("./src", import.meta.url)), // Use '@' as an alias for 'src'
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue