refactor: refine global layout system

pull/793/head
Kia King Ishii 3 years ago
parent 1942418f95
commit e312f0fc93

@ -7,7 +7,7 @@ defineProps<{
</script> </script>
<template> <template>
<article class="VPBox"> <article class="VPFeature">
<div v-if="icon" class="icon">{{ icon }}</div> <div v-if="icon" class="icon">{{ icon }}</div>
<h2 class="title">{{ title }}</h2> <h2 class="title">{{ title }}</h2>
<p class="details">{{ details }}</p> <p class="details">{{ details }}</p>
@ -15,8 +15,8 @@ defineProps<{
</template> </template>
<style scoped> <style scoped>
.VPBox { .VPFeature {
border: 1px solid var(--vp-c-divider-light); border: 1px solid var(--vp-c-bg-soft);
border-radius: 12px; border-radius: 12px;
padding: 24px; padding: 24px;
height: 100%; height: 100%;

@ -0,0 +1,107 @@
<script setup lang="ts">
import { computed } from 'vue'
import VPFeature from './VPFeature.vue'
export interface Feature {
icon?: string
title: string
details: string
}
const props = defineProps<{
features: Feature[]
}>()
const grid = computed(() => {
const length = props.features.length
if (!length) {
return
} else if (length === 2) {
return 'grid-2'
} else if (length === 3) {
return 'grid-3'
} else if (length % 3 === 0) {
return 'grid-6'
} else if (length % 2 === 0) {
return 'grid-4'
}
})
</script>
<template>
<div v-if="features" class="VPFeatures">
<div class="container">
<div class="items">
<div v-for="feature in features" :key="feature.title" class="item" :class="[grid]">
<VPFeature
:icon="feature.icon"
:title="feature.title"
:details="feature.details"
/>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.VPFeatures {
position: relative;
padding: 0 24px;
}
@media (min-width: 640px) {
.VPFeatures {
padding: 0 48px;
}
}
@media (min-width: 960px) {
.VPFeatures {
padding: 0 64px;
}
}
.container {
margin: 0 auto;
max-width: 1152px;
}
.items {
display: flex;
flex-wrap: wrap;
margin: -8px;
}
.item {
padding: 8px;
width: 100%;
}
@media (min-width: 640px) {
.item.grid-2,
.item.grid-4,
.item.grid-6 {
width: calc(100% / 2);
}
}
@media (min-width: 768px) {
.item.grid-2,
.item.grid-4 {
width: calc(100% / 2);
}
.item.grid-3,
.item.grid-6 {
width: calc(100% / 3);
}
}
@media (min-width: 960px) {
.item.grid-4 {
width: calc(100% / 4);
}
}
</style>

@ -64,11 +64,17 @@ defineProps<{
} }
} }
@media (min-width: 960px) {
.VPHero {
padding: calc(var(--vp-nav-height) + 80px) 64px 64px;
}
}
.container { .container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin: 0 auto; margin: 0 auto;
max-width: 960px; max-width: 1152px;
} }
@media (min-width: 960px) { @media (min-width: 960px) {
@ -98,13 +104,11 @@ defineProps<{
@media (min-width: 960px) { @media (min-width: 960px) {
.main { .main {
order: 1; order: 1;
width: calc((100% / 3) * 2);
} }
}
@media (min-width: 960px) { .VPHero.has-image .main {
.main { max-width: 592px;
width: 100%;
max-width: calc((100% / 3) * 2);
} }
} }
@ -157,7 +161,7 @@ defineProps<{
} }
.tagline { .tagline {
padding-top: 16px; padding-top: 8px;
max-width: 392px; max-width: 392px;
line-height: 28px; line-height: 28px;
font-size: 18px; font-size: 18px;
@ -172,7 +176,7 @@ defineProps<{
@media (min-width: 640px) { @media (min-width: 640px) {
.tagline { .tagline {
padding-top: 24px; padding-top: 12px;
max-width: 576px; max-width: 576px;
line-height: 32px; line-height: 32px;
font-size: 20px; font-size: 20px;
@ -181,7 +185,6 @@ defineProps<{
@media (min-width: 960px) { @media (min-width: 960px) {
.tagline { .tagline {
padding-top: 24px;
line-height: 36px; line-height: 36px;
font-size: 24px; font-size: 24px;
} }
@ -232,9 +235,9 @@ defineProps<{
@media (min-width: 960px) { @media (min-width: 960px) {
.image { .image {
flex-grow: 1;
order: 2; order: 2;
margin: 0; margin: 0;
width: calc(100% / 3);
min-height: 100%; min-height: 100%;
} }
} }

@ -1,97 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'
import { useData } from 'vitepress' import { useData } from 'vitepress'
import VPBox from './VPBox.vue' import VPFeatures from './VPFeatures.vue'
const { frontmatter: fm } = useData() const { frontmatter: fm } = useData()
const grid = computed(() => {
const length = fm.value.features?.length
if (!length) {
return
}
if (length === 2) {
return 'grid-2'
} else if (length === 3) {
return 'grid-3'
} else if (length % 3 === 0) {
return 'grid-6'
} else if (length % 2 === 0) {
return 'grid-4'
}
})
</script> </script>
<template> <template>
<div v-if="fm.features" class="VPHomeFeatures"> <VPFeatures
<div class="container"> v-if="fm.features"
<div class="items"> class="VPHomeFeatures"
<div v-for="feature in fm.features" :key="feature.title" class="item" :class="[grid]"> :features="fm.features"
<VPBox />
:icon="feature.icon"
:title="feature.title"
:details="feature.details"
/>
</div>
</div>
</div>
</div>
</template> </template>
<style scoped>
.VPHomeFeatures {
position: relative;
padding: 0 24px;
}
@media (min-width: 640px) {
.VPHomeFeatures {
padding: 0 48px;
}
}
.container {
margin: 0 auto;
max-width: 960px;
}
.items {
display: flex;
flex-wrap: wrap;
margin: -8px;
}
.item {
padding: 8px;
width: 100%;
}
@media (min-width: 640px) {
.item.grid-2,
.item.grid-4,
.item.grid-6 {
width: calc(100% / 2);
}
}
@media (min-width: 768px) {
.item.grid-2,
.item.grid-4 {
width: calc(100% / 2);
}
.item.grid-3,
.item.grid-6 {
width: calc(100% / 3);
}
}
@media (min-width: 960px) {
.item.grid-4 {
width: calc(100% / 4);
}
}
</style>

@ -6,13 +6,13 @@ const { frontmatter: fm } = useData()
</script> </script>
<template> <template>
<div v-if="fm.hero" class="VPHomeHero"> <VPHero
<VPHero v-if="fm.hero"
:name="fm.hero.name" class="VPHomeHero"
:text="fm.hero.text" :name="fm.hero.name"
:tagline="fm.hero.tagline" :text="fm.hero.text"
:image="fm.hero.image" :tagline="fm.hero.tagline"
:actions="fm.hero.actions" :image="fm.hero.image"
/> :actions="fm.hero.actions"
</div> />
</template> </template>

@ -55,7 +55,7 @@ defineProps<{
.container { .container {
margin: 0 auto; margin: 0 auto;
max-width: 960px; max-width: 1152px;
} }
.love { .love {

Loading…
Cancel
Save