Skip to content

Commit

Permalink
feat(applet): show name on pinia panel nav
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Mar 20, 2024
1 parent c386c66 commit ac59853
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/applet/src/composables/virtual-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { Component, InjectionKey, Ref } from 'vue'
import { computed, defineComponent, h, inject, provide, ref } from 'vue'

const VirtualRouteKey: InjectionKey<Ref<{ path: string }>> = Symbol('VirtualRouteKey')
const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string }[]> = Symbol('VirtualRoutesKey')
const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string, name?: string }[]> = Symbol('VirtualRoutesKey')

export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string }[]) {
export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string, name?: string }[]) {
const route = ref<{ path: string, icon?: string }>({
path: '/',
})
Expand Down Expand Up @@ -38,8 +38,11 @@ export function useVirtualRouter() {
}

export function useVirtualRoute() {
const route = inject(VirtualRoutesKey)!
const routes = inject(VirtualRoutesKey)!
const route = inject(VirtualRouteKey)!

return {
routes: route,
routes,
currentRoute: route,
}
}
9 changes: 6 additions & 3 deletions packages/applet/src/pinia/components/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useVirtualRoute, useVirtualRouter } from '~/composables/virtual-router'
const { routes } = useVirtualRoute()
const { routes, currentRoute } = useVirtualRoute()
const router = useVirtualRouter()
</script>

Expand All @@ -10,10 +10,13 @@ const router = useVirtualRouter()
<li
v-for="(item, index) in routes"
:key="index"
cursor-pointer op70 hover:op100
cursor-pointer hover:op100
:style="{
opacity: currentRoute.path === item.path ? 1 : 0.7,
}"
@click="router.push(item.path)"
>
<i :class="item.icon" />
{{ item.name }}
</li>
</ul>
</template>
3 changes: 3 additions & 0 deletions packages/applet/src/pinia/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ createDevToolsConnectStateContext()
const { VirtualRouterView } = registerVirtualRouter([
{
path: '/',
name: 'Home',
component: Home,
icon: 'i-logos-pinia',
},
{
path: '/store',
name: 'Store',
component: Store,
icon: 'i-carbon-tree-view-alt',
},
{
path: '/timeline',
name: 'Timeline',
component: Timeline,
icon: 'i-mdi:timeline-clock-outline',
},
Expand Down

0 comments on commit ac59853

Please sign in to comment.