feature(home): added feature groups & ability to set title

pull/2795/head
itsWindows11 3 years ago
parent 1f4ae02138
commit e1afc8fa95
No known key found for this signature in database
GPG Key ID: 9DAF29E736DD9717

@ -20,6 +20,8 @@ hero:
alt: VitePress alt: VitePress
features: features:
- title: Features
features:
- icon: 📝 - icon: 📝
title: Focus on Your Content title: Focus on Your Content
details: Effortlessly create beautiful documentation sites with just markdown. details: Effortlessly create beautiful documentation sites with just markdown.
@ -32,6 +34,17 @@ features:
- icon: 🚀 - icon: 🚀
title: Ship Fast Sites title: Ship Fast Sites
details: Fast initial load with static HTML, fast post-load navigation with client-side routing. details: Fast initial load with static HTML, fast post-load navigation with client-side routing.
- title: Title
features:
- icon: 📝
title: Test
details: Test
- icon: 📝
title: Test
details: Test
- icon: 📝
title: Test
details: Test
--- ---
<style> <style>
:root { :root {

@ -3,6 +3,11 @@ import type { DefaultTheme } from 'vitepress/theme'
import { computed } from 'vue' import { computed } from 'vue'
import VPFeature from './VPFeature.vue' import VPFeature from './VPFeature.vue'
export interface FeatureGroup {
title?: string,
features: Feature[]
}
export interface Feature { export interface Feature {
icon?: DefaultTheme.FeatureIcon icon?: DefaultTheme.FeatureIcon
title: string title: string
@ -13,12 +18,15 @@ export interface Feature {
} }
const props = defineProps<{ const props = defineProps<{
features: Feature[] features: FeatureGroup[]
}>() }>()
const grid = computed(() => { const grid = computed({
const length = props.features.length get() {
return (idx: number) => {
const group = props.features[idx]
if (!group) return ''
const length = group.features.length
if (!length) { if (!length) {
return return
} else if (length === 2) { } else if (length === 2) {
@ -30,18 +38,34 @@ const grid = computed(() => {
} else if (length > 3) { } else if (length > 3) {
return 'grid-4' return 'grid-4'
} }
}
}
})
const firstHeading = computed({
get() {
return (idx: number) => {
return idx === 0 ? 'first' : ''
}
}
}) })
</script> </script>
<template> <template>
<div v-if="features" class="VPFeatures"> <div v-if="features" class="VPFeatures">
<div class="section" v-for="(feature_group, feature_group_idx) in features">
<h2
class="feature-group-title"
:class="[firstHeading(feature_group_idx)]"
v-if="feature_group.title"
v-html="feature_group.title" />
<div class="container"> <div class="container">
<div class="items"> <div class="items">
<div <div
v-for="feature in features" v-for="feature in feature_group.features"
:key="feature.title" :key="feature.title"
class="item" class="item"
:class="[grid]" :class="[grid(feature_group_idx)]"
> >
<VPFeature <VPFeature
:icon="feature.icon" :icon="feature.icon"
@ -55,12 +79,16 @@ const grid = computed(() => {
</div> </div>
</div> </div>
</div> </div>
</div>
</template> </template>
<style scoped> <style scoped>
.VPFeatures { .VPFeatures {
position: relative; position: relative;
padding: 0 24px; padding: 0 24px;
display: flex;
flex-direction: column;
gap: 24px;
} }
@media (min-width: 640px) { @media (min-width: 640px) {
@ -75,8 +103,20 @@ const grid = computed(() => {
} }
} }
.container { h2.feature-group-title {
margin-top: 16px;
margin-bottom: 16px;
font-size: 24px;
font-weight: 600;
}
h2.feature-group-title.first {
margin-top: 0;
}
.section {
margin: 0 auto; margin: 0 auto;
width: 100%;
max-width: 1152px; max-width: 1152px;
} }

Loading…
Cancel
Save