diff --git a/src/client/theme-default/components/NavBar.ts b/src/client/theme-default/components/NavBar.ts index e64fc5fce1e1..a5fba6f24d54 100644 --- a/src/client/theme-default/components/NavBar.ts +++ b/src/client/theme-default/components/NavBar.ts @@ -1,10 +1,12 @@ import { computed } from 'vue' import { useSiteData } from 'vitepress' import NavBarLink from './NavBarLink.vue' +import NavDropdownLink from './NavDropdownLink.vue' export default { components: { - NavBarLink + NavBarLink, + NavDropdownLink }, setup() { diff --git a/src/client/theme-default/components/NavBar.vue b/src/client/theme-default/components/NavBar.vue index 5c34229d4422..5f43c8f8528e 100644 --- a/src/client/theme-default/components/NavBar.vue +++ b/src/client/theme-default/components/NavBar.vue @@ -13,11 +13,10 @@ {{ $site.title }} diff --git a/src/client/theme-default/components/NavDropdownLink.ts b/src/client/theme-default/components/NavDropdownLink.ts new file mode 100644 index 000000000000..f9bc242d5a72 --- /dev/null +++ b/src/client/theme-default/components/NavDropdownLink.ts @@ -0,0 +1,42 @@ +import NavBarLink from './NavBarLink.vue' +import { defineComponent, ref, watch, PropType } from 'vue' +import { useRoute } from 'vitepress' +import { DefaultTheme } from '../config' + +export default defineComponent({ + name: 'DropdownLink', + components: { + NavBarLink + }, + props: { + item: { + type: Object as PropType, + required: true + } + }, + setup(props) { + const open = ref(false) + const route = useRoute() + + watch( + () => route.path, + () => { + open.value = false + } + ) + + const setOpen = (value: boolean) => { + open.value = value + } + + const isLastItemOfArray = (item: T, array: T[]) => { + return array.length && array.indexOf(item) === array.length - 1 + } + + return { + open, + setOpen, + isLastItemOfArray + } + } +}) diff --git a/src/client/theme-default/components/NavDropdownLink.vue b/src/client/theme-default/components/NavDropdownLink.vue new file mode 100644 index 000000000000..fb17a53321c4 --- /dev/null +++ b/src/client/theme-default/components/NavDropdownLink.vue @@ -0,0 +1,161 @@ + + + + + \ No newline at end of file