Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): support links in homepage features (#984) #1404

Merged
merged 9 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/config/frontmatter-configs.md
Expand Up @@ -197,9 +197,23 @@ interface Feature {

// Details of the feature.
details: string

// Link when clicked on feature component. The link can
// be both internal or external.
//
// e.g. `guide/theme-home-page` or `htttps://example.com`
link?: string

// Link text to be shown inside feature component. Best
// used with `link` option.
//
// e.g. `Learn more`, `Visit page`, etc.
linkText?: string
}
```

You may learn more about it in [Theme: Home Page](../guide/theme-home-page).

## aside

- Type: `boolean`
Expand Down
12 changes: 12 additions & 0 deletions docs/guide/theme-home-page.md
Expand Up @@ -115,5 +115,17 @@ interface Feature {

// Details of the feature.
details: string

// Link when clicked on feature component. The link can
// be both internal or external.
//
// e.g. `guide/theme-home-page` or `htttps://example.com`
link?: string

// Link text to be shown inside feature component. Best
// used with `link` option.
//
// e.g. `Learn more`, `Visit page`, etc.
linkText?: string
}
```
71 changes: 64 additions & 7 deletions src/client/theme-default/components/VPFeature.vue
@@ -1,26 +1,56 @@
<script setup lang="ts">
import VPLink from './VPLink.vue'
import VPIconArrowRight from './icons/VPIconArrowRight.vue'

defineProps<{
icon?: string
title: string
details: string
link?: string
linkText?: string
}>()
</script>

<template>
<article class="VPFeature">
<div v-if="icon" class="icon">{{ icon }}</div>
<h2 class="title">{{ title }}</h2>
<p class="details">{{ details }}</p>
</article>
<VPLink class="VPFeature" :href="link" :no-icon="true">
<article class="box">
<div v-if="icon" class="icon">{{ icon }}</div>
<h2 class="title">{{ title }}</h2>
<p class="details">{{ details }}</p>

<div v-if="linkText" class="link-text">
<p class="link-text-value">
{{ linkText }} <VPIconArrowRight class="link-text-icon" />
</p>
</div>
</article>
</VPLink>
</template>

<style scoped>
.VPFeature {
display: block;
border: 1px solid var(--vp-c-bg-soft);
border-radius: 12px;
padding: 24px;
height: 100%;
background-color: var(--vp-c-bg-soft);
transition: border-color 0.25s, background-color 0.25s;
}

.VPFeature.link:hover {
border-color: var(--vp-c-brand);
background-color: var(--vp-c-bg);
}

.dark .VPFeature.link:hover {
background-color: var(--vp-c-bg-mute);
}

.box {
display: flex;
flex-direction: column;
padding: 24px;
height: 100%;
}

.icon {
Expand All @@ -33,10 +63,11 @@ defineProps<{
width: 48px;
height: 48px;
font-size: 24px;
transition: background-color 0.25s;
}

.dark .icon {
background-color: var(--vp-c-bg);
background-color: var(--vp-c-gray-dark-5);
}

.title {
Expand All @@ -46,10 +77,36 @@ defineProps<{
}

.details {
flex-grow: 1;
padding-top: 8px;
line-height: 24px;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-text-2);
}

.link-text {
padding-top: 8px;
}

.link-text-value {
display: flex;
align-items: center;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-brand);
transition: color 0.25s;
}

.VPFeature.link:hover .link-text-value {
color: var(--vp-c-brand-dark);
}

.link-text-icon {
display: inline-block;
margin-left: 6px;
width: 14px;
height: 14px;
fill: currentColor;
}
</style>
4 changes: 4 additions & 0 deletions src/client/theme-default/components/VPFeatures.vue
Expand Up @@ -6,6 +6,8 @@ export interface Feature {
icon?: string
title: string
details: string
link?: string
linkText?: string
}

const props = defineProps<{
Expand Down Expand Up @@ -38,6 +40,8 @@ const grid = computed(() => {
:icon="feature.icon"
:title="feature.title"
:details="feature.details"
:link="feature.link"
:link-text="feature.linkText"
/>
</div>
</div>
Expand Down