feat: adjust overall layout

pull/639/head
Kia King Ishii 3 years ago
parent 190a467a10
commit 80a82be50f

@ -31,16 +31,16 @@ const { hasSidebar } = useSidebar()
<template #home-features-after><slot name="home-features-after" /></template> <template #home-features-after><slot name="home-features-after" /></template>
</VPHome> </VPHome>
<VPDoc v-else :class="{ 'has-sidebar': hasSidebar }" /> <VPDoc v-else />
</div> </div>
</template> </template>
<style scoped> <style scoped>
.VPContent { .VPContent {
flex-grow: 1; flex-grow: 1;
flex-shrink: 0;
margin: 0 auto; margin: 0 auto;
width: 100%; width: 100%;
max-width: var(--vp-layout-max-width);
} }
.VPContent.is-home { .VPContent.is-home {
@ -48,12 +48,6 @@ const { hasSidebar } = useSidebar()
max-width: 100%; max-width: 100%;
} }
@media (max-width: 768px) {
.VPContent {
overflow-x: hidden;
}
}
@media (min-width: 960px) { @media (min-width: 960px) {
.VPContent { .VPContent {
padding-top: var(--vp-nav-height); padding-top: var(--vp-nav-height);
@ -62,14 +56,13 @@ const { hasSidebar } = useSidebar()
.VPContent.has-sidebar { .VPContent.has-sidebar {
margin: 0; margin: 0;
padding-left: var(--vp-sidebar-width); padding-left: var(--vp-sidebar-width);
max-width: 100%;
} }
} }
@media (min-width: 1440px) { @media (min-width: 1440px) {
.VPContent.has-sidebar { .VPContent.has-sidebar {
padding-right: calc((100vw - var(--vp-layout-max-width)) / 2); padding-right: calc((100vw - var(--vp-layout-max-width)) / 2);
padding-left: calc((100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width) - 32px); padding-left: calc((100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width));
} }
} }
</style> </style>

@ -1,10 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue' import { computed } from 'vue'
import { useData } from 'vitepress' import { useData } from 'vitepress'
import { useSidebar } from '../composables/sidebar'
import VPDocOutline from './VPDocOutline.vue' import VPDocOutline from './VPDocOutline.vue'
import VPDocFooter from './VPDocFooter.vue' import VPDocFooter from './VPDocFooter.vue'
const { page } = useData() const { page } = useData()
const { hasSidebar } = useSidebar()
const pageName = computed(() => { const pageName = computed(() => {
return page.value.relativePath.slice(0, page.value.relativePath.indexOf('/')) return page.value.relativePath.slice(0, page.value.relativePath.indexOf('/'))
@ -12,7 +14,7 @@ const pageName = computed(() => {
</script> </script>
<template> <template>
<div class="VPDoc has-aside"> <div class="VPDoc" :class="{ 'has-sidebar': hasSidebar }">
<div class="container"> <div class="container">
<div class="aside"> <div class="aside">
<div class="aside-container"> <div class="aside-container">
@ -24,11 +26,13 @@ const pageName = computed(() => {
</div> </div>
<div class="content"> <div class="content">
<main class="main"> <div class="content-container">
<Content class="vp-doc" :class="pageName" /> <main class="main">
</main> <Content class="vp-doc" :class="pageName" />
</main>
<VPDocFooter /> <VPDocFooter />
</div>
</div> </div>
</div> </div>
</div> </div>
@ -48,60 +52,63 @@ const pageName = computed(() => {
@media (min-width: 960px) { @media (min-width: 960px) {
.VPDoc { .VPDoc {
padding: 32px 64px 96px; padding: 32px 32px 128px;
} }
}
@media (min-width: 1280px) { .VPDoc:not(.has-sidebar) .container {
.VPDoc { display: flex;
padding: 32px 0 128px 64px; justify-content: center;
max-width: 992px;
} }
.VPDoc:not(.has-sidebar.has-aside) { .VPDoc:not(.has-sidebar) .aside {
padding-left: calc((100vw - 688px) / 2); display: block;
} }
.VPDoc.has-aside:not(.has-sidebar) { .VPDoc:not(.has-sidebar) .content {
padding-left: calc((100vw - 688px - 320px) / 2); max-width: 752px;
}
}
@media (min-width: 1280px) {
.VPDoc .container {
display: flex;
justify-content: center;
} }
.VPDoc:not(.has-aside) .content { .VPDoc .aside {
min-width: 688px; display: block;
} }
} }
@media (min-width: 1440px) { @media (min-width: 1440px) {
.VPDoc { .VPDoc:not(.has-sidebar) .content {
padding: 32px 0 128px 96px; max-width: 784px;
} }
}
@media (min-width: 1280px) { .VPDoc:not(.has-sidebar) .container {
.container { max-width: 1104px;
display: flex;
} }
} }
.container {
margin: 0 auto;
width: 100%;
}
.aside { .aside {
position: relative; position: relative;
display: none; display: none;
order: 2; order: 2;
flex-shrink: 0;
flex-grow: 1; flex-grow: 1;
padding-left: 64px; flex-shrink: 0;
padding-right: 32px; padding-left: 32px;
min-width: 320px; min-width: 240px;
}
@media (min-width: 1280px) {
.aside {
display: block;
}
} }
@media (min-width: 1440px) { @media (min-width: 1440px) {
.aside { .aside {
padding-left: 96px; padding-left: 64px;
} }
} }
@ -110,7 +117,7 @@ const pageName = computed(() => {
top: var(--vp-nav-height-desktop); top: var(--vp-nav-height-desktop);
bottom: 0; bottom: 0;
padding-top: 32px; padding-top: 32px;
width: 224px; width: 208px;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
} }
@ -141,17 +148,33 @@ const pageName = computed(() => {
.content { .content {
position: relative; position: relative;
margin: 0 auto; margin: 0 auto;
max-width: 688px; }
@media (min-width: 960px) {
.content {
padding: 0 32px;
}
} }
@media (min-width: 1280px) { @media (min-width: 1280px) {
.content { .content {
order: 1; order: 1;
margin: 0; margin: 0;
min-width: 632px; min-width: 640px;
}
}
@media (min-width: 1440px) {
.content {
padding-left: 64px;
} }
} }
.content-container {
margin: 0 auto;
max-width: 688px;
}
.edit-link { .edit-link {
margin: 0 0 32px; margin: 0 0 32px;
} }

@ -1,10 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { useData } from 'vitepress' import { useData } from 'vitepress'
import { resolveHeaders, useActiveAnchor } from '../composables/outline' import {
resolveHeaders,
useOutline,
useActiveAnchor
} from '../composables/outline'
const { page, frontmatter } = useData() const { page, frontmatter } = useData()
const { hasOutline } = useOutline()
const container = ref() const container = ref()
const marker = ref() const marker = ref()
@ -22,7 +28,7 @@ function handleClick({ target: el }: Event) {
</script> </script>
<template> <template>
<div class="VPDocOutline" ref="container"> <div class="VPDocOutline" :class="{ 'has-outline': hasOutline }" ref="container">
<div class="outline-marker" ref="marker" /> <div class="outline-marker" ref="marker" />
<div class="outline-title">On this page</div> <div class="outline-title">On this page</div>
@ -56,12 +62,17 @@ function handleClick({ target: el }: Event) {
<style scoped> <style scoped>
.VPDocOutline { .VPDocOutline {
position: relative; position: relative;
display: none;
border-left: 1px solid var(--vp-c-divider-light); border-left: 1px solid var(--vp-c-divider-light);
padding-left: 16px; padding-left: 16px;
font-size: 13px; font-size: 13px;
font-weight: 500; font-weight: 500;
} }
.VPDocOutline.has-outline {
display: block;
}
.outline-marker { .outline-marker {
position: absolute; position: absolute;
top: 32px; top: 32px;

@ -66,7 +66,7 @@ defineEmits<{
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin: 0 auto; margin: 0 auto;
max-width: var(--vp-layout-max-width); max-width: calc(var(--vp-layout-max-width) - 64px);
} }
.content { .content {

@ -91,8 +91,8 @@ watchPostEffect(async () => {
@media (min-width: 1440px) { @media (min-width: 1440px) {
.VPSidebar { .VPSidebar {
padding-left: calc((100% - var(--vp-layout-max-width)) / 2); padding-left: calc((100% - (var(--vp-layout-max-width) - 64px)) / 2);
width: calc((100% - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width) - 32px); width: calc((100% - (var(--vp-layout-max-width) - 64px)) / 2 + var(--vp-sidebar-width) - 32px);
} }
} }

@ -1,5 +1,5 @@
import { Ref, onMounted, onUpdated, onUnmounted } from 'vue' import { Ref, computed, onMounted, onUpdated, onUnmounted } from 'vue'
import { Header } from 'vitepress' import { Header, useData } from 'vitepress'
import { useMediaQuery } from '@vueuse/core' import { useMediaQuery } from '@vueuse/core'
import { throttleAndDebounce } from '../support/utils' import { throttleAndDebounce } from '../support/utils'
@ -18,6 +18,18 @@ interface MenuItemWithLinkAndChildren {
// magic number to avoid repeated retrieval // magic number to avoid repeated retrieval
const PAGE_OFFSET = 56 const PAGE_OFFSET = 56
export function useOutline() {
const { page } = useData()
const hasOutline = computed(() => {
return page.value.headers.length > 0
})
return {
hasOutline
}
}
export function resolveHeaders(headers: Header[]) { export function resolveHeaders(headers: Header[]) {
return mapHeaders(groupHeaders(headers)) return mapHeaders(groupHeaders(headers))
} }

@ -13,30 +13,50 @@
background-color: var(--vp-custom-block-info-bg); background-color: var(--vp-custom-block-info-bg);
} }
.custom-block.info code {
background-color: var(--vp-custom-block-info-code-bg);
}
.custom-block.tip { .custom-block.tip {
border-color: var(--vp-custom-block-tip-border); border-color: var(--vp-custom-block-tip-border);
color: var(--vp-custom-block-tip-text); color: var(--vp-custom-block-tip-text);
background-color: var(--vp-custom-block-tip-bg); background-color: var(--vp-custom-block-tip-bg);
} }
.custom-block.tip code {
background-color: var(--vp-custom-block-tip-code-bg);
}
.custom-block.warning { .custom-block.warning {
border-color: var(--vp-custom-block-warning-border); border-color: var(--vp-custom-block-warning-border);
color: var(--vp-custom-block-warning-text); color: var(--vp-custom-block-warning-text);
background-color: var(--vp-custom-block-warning-bg); background-color: var(--vp-custom-block-warning-bg);
} }
.custom-block.warning code {
background-color: var(--vp-custom-block-warning-code-bg);
}
.custom-block.danger { .custom-block.danger {
border-color: var(--vp-custom-block-danger-border); border-color: var(--vp-custom-block-danger-border);
color: var(--vp-custom-block-danger-text); color: var(--vp-custom-block-danger-text);
background-color: var(--vp-custom-block-danger-bg); background-color: var(--vp-custom-block-danger-bg);
} }
.custom-block.danger code {
background-color: var(--vp-custom-block-danger-code-bg);
}
.custom-block.details { .custom-block.details {
border-color: var(--vp-custom-block-details-border); border-color: var(--vp-custom-block-details-border);
color: var(--vp-custom-block-details-text); color: var(--vp-custom-block-details-text);
background-color: var(--vp-custom-block-details-bg); background-color: var(--vp-custom-block-details-bg);
} }
.custom-block.details code {
background-color: var(--vp-custom-block-details-code-bg);
}
.custom-block-title { .custom-block-title {
font-weight: 700; font-weight: 700;
} }
@ -64,3 +84,7 @@
.custom-block a:hover { .custom-block a:hover {
opacity: 0.6; opacity: 0.6;
} }
.custom-block code {
font-size: var(--vp-custom-block-code-font-size);
}

@ -214,10 +214,21 @@
opacity: 0.6; opacity: 0.6;
} }
.vp-doc .custom-block code {
font-size: var(--vp-custom-block-code-font-size);
font-weight: 600;
color: inherit;
}
.vp-doc .custom-block div[class*='language-'] { .vp-doc .custom-block div[class*='language-'] {
margin: 8px 0; margin: 8px 0;
} }
.vp-doc .custom-block div[class*='language-'] code {
font-weight: 400;
background-color: var(--vp-code-block-bg);
}
/** /**
* Code * Code
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
@ -247,7 +258,7 @@
.vp-doc div[class*='language-'] { .vp-doc div[class*='language-'] {
position: relative; position: relative;
margin: 20px -24px; margin: 16px -24px;
background-color: var(--vp-code-block-bg); background-color: var(--vp-code-block-bg);
overflow-x: auto; overflow-x: auto;
transition: background-color 0.5s; transition: background-color 0.5s;
@ -256,7 +267,7 @@
@media (min-width: 640px) { @media (min-width: 640px) {
.vp-doc div[class*='language-'] { .vp-doc div[class*='language-'] {
border-radius: 8px; border-radius: 8px;
margin: 24px 0; margin: 16px 0;
} }
} }
@ -269,7 +280,7 @@
.vp-doc div[class*='language-'] + div[class*='language-'], .vp-doc div[class*='language-'] + div[class*='language-'],
.vp-doc div[class$='-api'] + div[class*='language-'], .vp-doc div[class$='-api'] + div[class*='language-'],
.vp-doc div[class*='language-'] + div[class$='-api'] > div[class*='language-'] { .vp-doc div[class*='language-'] + div[class$='-api'] > div[class*='language-'] {
margin-top: -12px; margin-top: -8px;
} }
.vp-doc [class*='language-'] pre, .vp-doc [class*='language-'] pre,

@ -176,7 +176,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
:root { :root {
--vp-layout-max-width: 1376px; --vp-layout-max-width: 1440px;
} }
/** /**
@ -261,30 +261,38 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
:root { :root {
--vp-custom-block-code-font-size: 13px;
--vp-custom-block-info-border: var(--vp-c-divider-light); --vp-custom-block-info-border: var(--vp-c-divider-light);
--vp-custom-block-info-text: var(--vp-c-text-2); --vp-custom-block-info-text: var(--vp-c-text-2);
--vp-custom-block-info-bg: var(--vp-c-white-soft); --vp-custom-block-info-bg: var(--vp-c-white-soft);
--vp-custom-block-info-code-bg: var(--vp-c-gray-light-4);
--vp-custom-block-tip-border: var(--vp-c-green); --vp-custom-block-tip-border: var(--vp-c-green);
--vp-custom-block-tip-text: var(--vp-c-green-darker); --vp-custom-block-tip-text: var(--vp-c-green-darker);
--vp-custom-block-tip-bg: var(--vp-c-green-dimm); --vp-custom-block-tip-bg: var(--vp-c-green-dimm);
--vp-custom-block-tip-code-bg: var(--vp-custom-block-tip-bg);
--vp-custom-block-warning-border: var(--vp-c-yellow); --vp-custom-block-warning-border: var(--vp-c-yellow);
--vp-custom-block-warning-text: var(--vp-c-yellow-darker); --vp-custom-block-warning-text: var(--vp-c-yellow-darker);
--vp-custom-block-warning-bg: var(--vp-c-yellow-dimm); --vp-custom-block-warning-bg: var(--vp-c-yellow-dimm);
--vp-custom-block-warning-code-bg: var(--vp-custom-block-warning-bg);
--vp-custom-block-danger-border: var(--vp-c-red); --vp-custom-block-danger-border: var(--vp-c-red);
--vp-custom-block-danger-text: var(--vp-c-red-darker); --vp-custom-block-danger-text: var(--vp-c-red-darker);
--vp-custom-block-danger-bg: var(--vp-c-red-dimm); --vp-custom-block-danger-bg: var(--vp-c-red-dimm);
--vp-custom-block-danger-code-bg: var(--vp-custom-block-danger-bg);
--vp-custom-block-details-border: var(--vp-custom-block-info-border); --vp-custom-block-details-border: var(--vp-custom-block-info-border);
--vp-custom-block-details-text: var(--vp-custom-block-info-text); --vp-custom-block-details-text: var(--vp-custom-block-info-text);
--vp-custom-block-details-bg: var(--vp-custom-block-info-bg); --vp-custom-block-details-bg: var(--vp-custom-block-info-bg);
--vp-custom-block-details-code-bg: var(--vp-custom-block-details-bg);
} }
.dark { .dark {
--vp-custom-block-info-border: var(--vp-c-divider-light); --vp-custom-block-info-border: var(--vp-c-divider-light);
--vp-custom-block-info-bg: var(--vp-c-black-mute); --vp-custom-block-info-bg: var(--vp-c-black-mute);
--vp-custom-block-info-code-bg: var(--vp-c-gray-dark-4);
--vp-custom-block-tip-text: var(--vp-c-green); --vp-custom-block-tip-text: var(--vp-c-green);

Loading…
Cancel
Save