123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <script lang="ts" setup>
- import { useWindowScroll } from "@vueuse/core";
- import { ref, watchPostEffect } from "vue";
- import { useData } from "vitepress";
- import { useSidebar } from "vitepress/theme";
- import VPNavBarAppearance from "vitepress/dist/client/theme-default/components/VPNavBarAppearance.vue";
- import VPNavBarExtra from "vitepress/dist/client/theme-default/components/VPNavBarExtra.vue";
- import VPNavBarHamburger from "vitepress/dist/client/theme-default/components/VPNavBarHamburger.vue";
- import VPNavBarMenu from "vitepress/dist/client/theme-default/components/VPNavBarMenu.vue";
- import VPNavBarSearch from "vitepress/dist/client/theme-default/components/VPNavBarSearch.vue";
- import VPNavBarSocialLinks from "vitepress/dist/client/theme-default/components/VPNavBarSocialLinks.vue";
- import VPNavBarTitle from "vitepress/dist/client/theme-default/components/VPNavBarTitle.vue";
- import VPNavBarTranslations from "vitepress/dist/client/theme-default/components/VPNavBarTranslations.vue";
- defineProps<{
- isScreenOpen: boolean;
- }>();
- defineEmits<{
- (e: "toggle-screen"): void;
- }>();
- const { y } = useWindowScroll();
- const { hasSidebar } = useSidebar();
- const { frontmatter } = useData();
- const classes = ref<Record<string, boolean>>({});
- watchPostEffect(() => {
- classes.value = {
- "has-sidebar": hasSidebar.value,
- home: frontmatter.value.layout === "home",
- top: y.value === 0,
- };
- });
- </script>
- <template>
- <div class="VPNavBar" :class="classes">
- <div class="wrapper">
- <div class="container">
- <div class="title">
- <VPNavBarTitle>
- <template #nav-bar-title-before
- ><slot name="nav-bar-title-before"
- /></template>
- <template #nav-bar-title-after><slot name="nav-bar-title-after" /></template>
- </VPNavBarTitle>
- </div>
- <div class="content">
- <div class="content-body">
- <slot name="nav-bar-content-before" />
- <VPNavBarSearch class="search" />
- <VPNavBarMenu class="menu" />
- <VPNavBarTranslations class="translations" />
- <VPNavBarAppearance class="appearance" />
- <VPNavBarSocialLinks class="social-links" />
- <VPNavBarExtra class="extra" />
- <slot name="nav-bar-content-after" />
- <VPNavBarHamburger
- class="hamburger"
- :active="isScreenOpen"
- @click="$emit('toggle-screen')"
- />
- </div>
- </div>
- </div>
- </div>
- <div class="divider">
- <div class="divider-line" />
- </div>
- </div>
- </template>
- <style scoped>
- .VPNavBar {
- position: relative;
- height: var(--vp-nav-height);
- pointer-events: none;
- white-space: nowrap;
- transition: background-color 0.5s;
- }
- .VPNavBar:not(.home) {
- background-color: var(--vp-nav-bg-color);
- }
- @media (min-width: 960px) {
- .VPNavBar:not(.home) {
- background-color: transparent;
- }
- .VPNavBar:not(.has-sidebar):not(.home.top) {
- background-color: var(--vp-nav-bg-color);
- }
- }
- .wrapper {
- padding: 0 8px 0 24px;
- }
- @media (min-width: 768px) {
- .wrapper {
- padding: 0 32px;
- }
- }
- @media (min-width: 960px) {
- .VPNavBar.has-sidebar .wrapper {
- padding: 0;
- }
- }
- .container {
- display: flex;
- justify-content: space-between;
- margin: 0 auto;
- max-width: calc(var(--vp-layout-max-width) - 64px);
- height: var(--vp-nav-height);
- pointer-events: none;
- }
- .container > .title,
- .container > .content {
- pointer-events: none;
- }
- .container :deep(*) {
- pointer-events: auto;
- }
- @media (min-width: 960px) {
- .VPNavBar.has-sidebar .container {
- max-width: 100%;
- }
- }
- .title {
- flex-shrink: 0;
- height: calc(var(--vp-nav-height) - 1px);
- transition: background-color 0.5s;
- }
- @media (min-width: 960px) {
- .VPNavBar.has-sidebar .title {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 2;
- padding: 0 32px;
- width: var(--vp-sidebar-width);
- height: var(--vp-nav-height);
- background-color: transparent;
- }
- }
- @media (min-width: 1440px) {
- .VPNavBar.has-sidebar .title {
- padding-left: max(32px, calc((100% - (var(--vp-layout-max-width) - 64px)) / 2));
- width: calc(
- (100% - (var(--vp-layout-max-width) - 64px)) / 2 + var(--vp-sidebar-width) - 32px
- );
- }
- }
- .content {
- flex-grow: 1;
- }
- @media (min-width: 960px) {
- .VPNavBar.has-sidebar .content {
- position: relative;
- z-index: 1;
- padding-right: 32px;
- padding-left: var(--vp-sidebar-width);
- }
- }
- @media (min-width: 1440px) {
- .VPNavBar.has-sidebar .content {
- padding-right: calc((100vw - var(--vp-layout-max-width)) / 2 + 32px);
- padding-left: calc(
- (100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width)
- );
- }
- }
- .content-body {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- height: var(--vp-nav-height);
- transition: background-color 0.5s;
- }
- @media (min-width: 960px) {
- .VPNavBar:not(.home.top) .content-body {
- position: relative;
- background-color: var(--vp-nav-bg-color);
- }
- .VPNavBar:not(.has-sidebar):not(.home.top) .content-body {
- background-color: transparent;
- }
- }
- @media (max-width: 767px) {
- .content-body {
- column-gap: 0.5rem;
- }
- }
- .menu + .translations::before,
- .menu + .appearance::before,
- .menu + .social-links::before,
- .translations + .appearance::before,
- .appearance + .social-links::before {
- margin-right: 8px;
- margin-left: 8px;
- width: 1px;
- height: 24px;
- background-color: var(--vp-c-divider);
- content: "";
- }
- .menu + .appearance::before,
- .translations + .appearance::before {
- margin-right: 16px;
- }
- .appearance + .social-links::before {
- margin-left: 16px;
- }
- .social-links {
- margin-right: -8px;
- }
- .divider {
- width: 100%;
- height: 1px;
- }
- @media (min-width: 960px) {
- .VPNavBar.has-sidebar .divider {
- padding-left: var(--vp-sidebar-width);
- }
- }
- @media (min-width: 1440px) {
- .VPNavBar.has-sidebar .divider {
- padding-left: calc(
- (100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width)
- );
- }
- }
- .divider-line {
- width: 100%;
- height: 1px;
- transition: background-color 0.5s;
- }
- .VPNavBar:not(.home) .divider-line {
- background-color: var(--vp-c-gutter);
- }
- @media (min-width: 960px) {
- .VPNavBar:not(.home.top) .divider-line {
- background-color: var(--vp-c-gutter);
- }
- .VPNavBar:not(.has-sidebar):not(.home.top) .divider {
- background-color: var(--vp-c-gutter);
- }
- }
- </style>
|