-
Notifications
You must be signed in to change notification settings - Fork 0
/
SidebarNavItem.svelte
62 lines (59 loc) · 1.8 KB
/
SidebarNavItem.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!--
@component
a single navigation item in the mobile sidebar
-->
<script lang="ts">
import type { RouteConfig } from './configs/routes'
import SvgIcon from './SVGIcon.svelte'
import ArrowDown from './assets/icons/arrow-down.svg'
import Link from './Link.svelte'
import { __$ } from './locales'
import { config } from './configs'
import cn from 'classnames'
export let item: RouteConfig
export let className = ''
export let onRouteChange: () => void = () => {}
const subRoutes = item.subRoutes?.map(x => config.routeConfig[x]) ?? []
</script>
<Link
let:match
href={item.href}
on:click={() => onRouteChange()}
disabled={item.disabled}
className={{ element: `block relative text-lg py-3 transition-all ${className}` }}>
{#if match}
<div
class={cn(
'flex items-center space-x-2',
'before:opacity-0',
'before:content-[""]',
'before:absolute',
'before:-left-10',
'before:w-6',
'before:h-6',
'before:shadow-[theme(colors.secondary.600)_0px_0px_20px_5px]',
'before:rounded-full',
'before:bg-secondary-500',
'before:transition-all',
!subRoutes.length &&
match?.partial && ['text-secondary-500', match.exact && 'before:opacity-100'],
)}>
<SvgIcon Icon={item.icon} width={'1.375rem'} height={'1.375rem'} />
<span>{$__$?.nav[item.id]}</span>
{#if subRoutes.length}
<SvgIcon
Icon={ArrowDown}
width={'1.375rem'}
height={'1.375rem'}
className="ml-2 transition-all" />
{/if}
</div>
{#if subRoutes.length}
<div class="-ml-6 py-3 pl-12 left-0">
{#each subRoutes as sub}
<svelte:self item={sub} className="-ml-6 pl-6" {onRouteChange} />
{/each}
</div>
{/if}
{/if}
</Link>