22 <section class =" tabs" >
33
44 <header class =" header" >
5+
56 <template v-if =" $slots .banner " >
67 <slot name =" banner" ></slot >
78 </template >
9+
810 <nav class =" nav" >
9- <template v-for =" tab in tabs " :key =" tab .id " >
10- <a v-if =" !tab.disabled && !tab.stub" :href =" urlForTab(tab.id)"
11- :class =" 'textcolor ' + navLinkClass(tab.id)" @click.prevent =" navigateTo(tab.id)" >
12- <slot :name =" `${tab.id}-title`" :isActive =" currentTab == tab.id" >{{ tab.title || tab.id }}
13- </slot >
14- </a >
15- <span :class =" `nav-link ${tab.disabled ? 'disabled' : ''}`" v-else >
16- <slot :name =" `${tab.id}-title`" >{{ tab.title || tab.id }}</slot >
17- </span >
18- </template >
11+ <slot v-for =" tab in tabs" :key =" tab.id" :name =" `${tab.id}-title`" >
12+ <a v-if =" tab.disabled" class =" nav-link disabled" >{{ tab.title || tab.id }}</a >
13+ <router-link v-else class =" nav-link" :to =" { path: `${basePath}/${tab.id}`, query: route.query }" >
14+ {{ tab.title || tab.id }}
15+ </router-link >
16+ </slot >
1917 </nav >
18+
2019 </header >
2120
22- <RouterView class =" view" @navigate = " router.push " />
21+ <RouterView class =" view" />
2322 </section >
2423</template >
2524
@@ -36,67 +35,7 @@ const { basePath, tabs } = defineProps<{
3635 tabs: Tab []
3736}>()
3837
39- const currentTab = ref <string >()
4038const route = useRoute ()
41- const router = useRouter ()
42-
43- onMounted (() => {
44- if (route .path .split (" /" ).length > basePath .split (" /" ).length ) {
45- // respect the url
46- induceCurrentTab ()
47- return
48- }
49- const state = localStorage .getItem (` galahad:${basePath } ` )
50- if (state !== null && state !== undefined ) {
51- // load state from local storage
52- navigateTo (state , true )
53- } else {
54- // default
55- navigateTo (tabs [0 ].id , true )
56- }
57- })
58-
59- watch (
60- () => route ,
61- () => {
62- induceCurrentTab ()
63- }
64- )
65-
66- // --- methods ---
67- function induceCurrentTab() {
68- const last = route .path .split (" /" ).pop () as string
69- setCurrentTab (last )
70- }
71- function navigateTo(tabId : string , replace = false ) {
72- const path = ` ${basePath }/${tabId } `
73- if (! route .path .startsWith (path )) {
74- if (replace ) {
75- router .replace ({ path: path , query: route .query })
76- } else {
77- router .push ({ path: path , query: route .query })
78- }
79- }
80- setCurrentTab (tabId )
81- }
82- function navLinkClass(tabId : string ) {
83- return ` nav-link${currentTab .value === tabId ? " active" : " " } `
84- }
85- function setCurrentTab(tabId : string ) {
86- // Since the route is not reactive, we have to update the value like this
87- currentTab .value = tabId
88- if (tabId !== null && tabId !== undefined )
89- localStorage .setItem (` galahad:${basePath } ` , tabId )
90- }
91- function urlForTab(tabId : string ) {
92- const qs = Object .entries (route .query )
93- .map (
94- ([k , v ]) =>
95- ` ${k }=${encodeURIComponent (typeof v === " object" ? JSON .stringify (v ) : v )} `
96- )
97- .join (" &" )
98- return ` /galahad${basePath }/${tabId }?${qs } `
99- }
10039 </script >
10140
10241<style scoped lang="scss">
@@ -124,7 +63,7 @@ function urlForTab(tabId: string) {
12463 color : black ;
12564 user-select : none ;
12665
127- & :hover:not (.disabled ):not (.active ) {
66+ & :hover:not (.disabled ):not (.router-link- active ) {
12867 cursor : pointer ;
12968 background-color : var (--int-theme-hover );
13069 }
@@ -137,11 +76,11 @@ function urlForTab(tabId: string) {
13776 cursor : not-allowed ;
13877 }
13978
140- & .active {
79+ & .router-link- active {
14180 background-color : var (--int-theme-outline );
14281 }
14382
144- & :active:not (.disabled ):not (.active ) {
83+ & :active:not (.disabled ):not (.router-link- active ) {
14584 background-color : var (--int-theme-active );
14685 }
14786 }
0 commit comments