refactor: created components for navlinks in sidebar

This commit is contained in:
Shariq Ansari 2023-07-20 20:56:52 +05:30
parent 54f298e54c
commit b01b967436
3 changed files with 49 additions and 24 deletions

View File

@ -5,30 +5,21 @@
</div>
<div class="flex-1">
<nav class="space-y-0.5 px-2">
<div v-for="link in navigations" :key="link.name">
<router-link
custom
:to="link.route"
v-slot="{ href, isActive, navigate }"
>
<a
:href="href"
@click="navigate"
class="flex items-center rounded px-2 py-1 text-gray-800 transition-all duration-300 ease-in-out"
:class="[isActive ? 'bg-gray-100 hover:bg-gray-200' : 'hover:bg-gray-50']"
>
<div class="flex w-full items-center space-x-2">
<span class="grid h-5 w-6 place-items-center">
<component
:is="link.icon"
class="h-4.5 w-4.5 text-gray-700"
/>
</span>
<span class="text-base">{{ link.name }}</span>
</div>
</a>
</router-link>
</div>
<NavLinks
:links="navigations"
class="flex items-center rounded px-2 py-1 text-gray-800 transition-all duration-300 ease-in-out"
active="bg-gray-100 hover:bg-gray-200"
inactive="hover:bg-gray-50"
>
<template v-slot="{ link }">
<div class="flex w-full items-center space-x-2">
<span class="grid h-5 w-6 place-items-center">
<component :is="link.icon" class="h-4.5 w-4.5 text-gray-700" />
</span>
<span class="text-base">{{ link.name }}</span>
</div>
</template>
</NavLinks>
</nav>
</div>
</div>
@ -39,6 +30,7 @@ import LeadsIcon from './Icons/LeadsIcon.vue'
import DealsIcon from './Icons/DealsIcon.vue'
import InboxIcon from './Icons/InboxIcon.vue'
import DashboardIcon from './Icons/DashboardIcon.vue'
import NavLinks from './NavLinks.vue'
const navigations = [
{

View File

@ -0,0 +1,16 @@
<template>
<router-link custom :to="link.route" v-slot="{ href, isActive, navigate }">
<a
:href="href"
@click="navigate"
:class="[isActive ? active : inactive, $attrs.class]"
>
<slot :link="link">
{{ link.name }}
</slot>
</a>
</router-link>
</template>
<script setup>
const props = defineProps(['link', 'active', 'inactive'])
</script>

View File

@ -0,0 +1,17 @@
<template>
<NavLink
v-for="link in links"
:key="link.name"
:class="$attrs.class"
v-bind="{ link, active, inactive }"
>
<slot :link="link">
{{ link.name }}
</slot>
</NavLink>
</template>
<script setup>
import NavLink from './NavLink.vue'
const props = defineProps(['links', 'active', 'inactive'])
</script>