Skip to content

Commit 6ad1979

Browse files
committed
Make menu composable
1 parent 445ecdc commit 6ad1979

File tree

7 files changed

+88
-46
lines changed

7 files changed

+88
-46
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@freenit-framework/core",
3-
"version": "0.0.46",
3+
"version": "0.0.47",
44
"private": false,
55
"author": "Goran Mekić <meka@tilda.center>",
66
"license": "BSD-2-Clause",

src/lib/LeftPane.svelte

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
11
<script lang="ts">
2-
let { open, toggle } = $props()
2+
let { children, open, toggle } = $props()
33
</script>
44

55
<div class="root" class:open>
66
<div class="relative">
7-
<button class="button close" onclick={toggle}>x</button>
8-
</div>
9-
<div class="wrapper">
10-
<a href="/">Home</a>
11-
<div class="item">
12-
Auth
13-
<a href="/login">Login</a>
14-
<a href="/register">Register</a>
15-
<a href="/verify">Verify</a>
16-
<a href="/logout">Logout</a>
17-
</div>
18-
<div class="item">
19-
Users
20-
<a href="/profile">Profile</a>
21-
<a href="/users">List</a>
22-
<a href="/users/1">Detail</a>
23-
</div>
24-
<div class="item">
25-
Role
26-
<a href="/roles">List</a>
27-
<a href="/roles/1">Detail</a>
28-
</div>
29-
<div class="item">
30-
Theme
31-
<a href="/themes">List</a>
32-
<a href="/themes/Freenit">Detail</a>
7+
<div class="wrapper">
8+
{@render children?.()}
9+
<button class="button close" onclick={toggle}>x</button>
3310
</div>
3411
</div>
3512
</div>
@@ -42,20 +19,25 @@
4219
width: 0;
4320
height: 100vh;
4421
max-width: 300px;
45-
background-color: #eee;
22+
background-color: white;
4623
display: flex;
4724
flex-direction: column;
4825
overflow-x: hidden;
4926
overflow-y: scroll;
50-
transition: width 1s;
27+
transition: width 0.5s;
5128
}
5229
5330
.wrapper {
31+
display: flex;
32+
flex-direction: column;
5433
padding: 20px;
5534
}
5635
5736
.open {
5837
width: 100%;
38+
border-right-style: solid;
39+
border-width: 1px;
40+
border-color: #eee;
5941
}
6042
6143
.relative {
@@ -67,15 +49,4 @@
6749
top: 0;
6850
right: 0;
6951
}
70-
71-
.item {
72-
color: var(--color-primary);
73-
cursor: grabbing;
74-
display: flex;
75-
flex-direction: column;
76-
}
77-
78-
.item a {
79-
margin-left: 20px;
80-
}
8152
</style>

src/lib/MenuItem.svelte

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script lang="ts">
2+
let { icon, onclick, href, children } = $props()
3+
</script>
4+
5+
<a class="item" {href}>
6+
<svg class="icon dark" {onclick} onkeyup={onclick} onkeydown={onclick} role="button" tabindex={0}>
7+
<path d={icon} />
8+
</svg>
9+
{@render children?.()}
10+
</a>
11+
12+
<style>
13+
.item {
14+
display: flex;
15+
align-items: center;
16+
justify-content: flex-start;
17+
text-align: center;
18+
}
19+
20+
.icon {
21+
width: 26px;
22+
height: 26px;
23+
fill: white;
24+
}
25+
26+
.dark {
27+
fill: black;
28+
}
29+
</style>

src/lib/MenuItems.svelte

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
import {
3+
mdiAccount,
4+
mdiAccountGroup,
5+
mdiArrowDownBoldCircleOutline,
6+
mdiCookieEditOutline,
7+
mdiFaceManProfile,
8+
mdiLoginVariant,
9+
mdiLogoutVariant,
10+
mdiStamper,
11+
} from '@mdi/js'
12+
import store from '$lib/store'
13+
import MenuItem from '$lib/MenuItem.svelte'
14+
15+
let { toggle, logout } = $props()
16+
</script>
17+
18+
{#if store.auth.loggedin()}
19+
{#if store.user.profile.admin}
20+
<MenuItem href="/users" {toggle} icon={mdiAccount}>Users</MenuItem>
21+
<MenuItem href="/roles" {toggle} icon={mdiAccountGroup}>Roles</MenuItem>
22+
<MenuItem href="/themes" {toggle} icon={mdiCookieEditOutline}>Themes</MenuItem>
23+
{/if}
24+
<MenuItem href="/profile" {toggle} icon={mdiFaceManProfile}>Profile</MenuItem>
25+
<MenuItem href="/logout" toggle={logout} icon={mdiLogoutVariant}>Logout</MenuItem>
26+
{:else}
27+
<MenuItem href="/register" {toggle} icon={mdiArrowDownBoldCircleOutline}>Register</MenuItem>
28+
<MenuItem href="/verify" {toggle} icon={mdiStamper}>Verify</MenuItem>
29+
<MenuItem href="/login" {toggle} icon={mdiLoginVariant}>Login</MenuItem>
30+
{/if}

src/lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export { default as LeftPane } from './LeftPane.svelte'
22
export { default as MenuBar } from './MenuBar.svelte'
3+
export { default as MenuItem } from './MenuItem.svelte'
4+
export { default as MenuItems } from './MenuItems.svelte'
35
export { default as Login } from './Login.svelte'
46
export { default as Modal } from './Modal.svelte'
57
export { default as Register } from './Register.svelte'

src/routes/+layout.svelte

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<script>
1+
<script lang="ts">
22
import 'chota'
33
import './app.css'
44
import { onMount } from 'svelte'
55
import { SvelteToast } from '@zerodevx/svelte-toast'
66
import store from '$lib/store'
77
import LeftPane from '$lib/LeftPane.svelte'
88
import MenuBar from '$lib/MenuBar.svelte'
9+
import MenuItems from '$lib/MenuItems.svelte'
910
1011
const options = {}
1112
let open = $state(false)
@@ -15,7 +16,14 @@
1516
open = !open
1617
}
1718
18-
onMount(async () => { await store.auth.refresh_token() })
19+
const logout = () => {
20+
open = !open
21+
store.auth.logout()
22+
}
23+
24+
onMount(async () => {
25+
await store.auth.refresh_token()
26+
})
1927
</script>
2028

2129
<svelte:head>
@@ -25,7 +33,9 @@
2533

2634
<SvelteToast {options} />
2735
<MenuBar {toggle} title="Freenit" />
28-
<LeftPane {open} {toggle} />
36+
<LeftPane {open} {toggle}>
37+
<MenuItems {toggle} {logout} />
38+
</LeftPane>
2939
<section class="root">
3040
<div class="main">
3141
{@render children?.()}

0 commit comments

Comments
 (0)