Skip to content

Commit 84b4abc

Browse files
Jimmylxuebrc-ddkiaking
authoredOct 31, 2022
feat(theme): add link feature in homepage features (#984) (#1404)
close #984 close #1070 Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
1 parent ac8619f commit 84b4abc

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed
 

‎docs/config/frontmatter-configs.md

+14
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,23 @@ interface Feature {
197197

198198
// Details of the feature.
199199
details: string
200+
201+
// Link when clicked on feature component. The link can
202+
// be both internal or external.
203+
//
204+
// e.g. `guide/theme-home-page` or `htttps://example.com`
205+
link?: string
206+
207+
// Link text to be shown inside feature component. Best
208+
// used with `link` option.
209+
//
210+
// e.g. `Learn more`, `Visit page`, etc.
211+
linkText?: string
200212
}
201213
```
202214

215+
You may learn more about it in [Theme: Home Page](../guide/theme-home-page).
216+
203217
## aside
204218

205219
- Type: `boolean`

‎docs/guide/theme-home-page.md

+12
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,17 @@ interface Feature {
115115

116116
// Details of the feature.
117117
details: string
118+
119+
// Link when clicked on feature component. The link can
120+
// be both internal or external.
121+
//
122+
// e.g. `guide/theme-home-page` or `htttps://example.com`
123+
link?: string
124+
125+
// Link text to be shown inside feature component. Best
126+
// used with `link` option.
127+
//
128+
// e.g. `Learn more`, `Visit page`, etc.
129+
linkText?: string
118130
}
119131
```
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
11
<script setup lang="ts">
2+
import VPLink from './VPLink.vue'
3+
import VPIconArrowRight from './icons/VPIconArrowRight.vue'
4+
25
defineProps<{
36
icon?: string
47
title: string
58
details: string
9+
link?: string
10+
linkText?: string
611
}>()
712
</script>
813

914
<template>
10-
<article class="VPFeature">
11-
<div v-if="icon" class="icon">{{ icon }}</div>
12-
<h2 class="title">{{ title }}</h2>
13-
<p class="details">{{ details }}</p>
14-
</article>
15+
<VPLink class="VPFeature" :href="link" :no-icon="true">
16+
<article class="box">
17+
<div v-if="icon" class="icon">{{ icon }}</div>
18+
<h2 class="title">{{ title }}</h2>
19+
<p class="details">{{ details }}</p>
20+
21+
<div v-if="linkText" class="link-text">
22+
<p class="link-text-value">
23+
{{ linkText }} <VPIconArrowRight class="link-text-icon" />
24+
</p>
25+
</div>
26+
</article>
27+
</VPLink>
1528
</template>
1629

1730
<style scoped>
1831
.VPFeature {
32+
display: block;
1933
border: 1px solid var(--vp-c-bg-soft);
2034
border-radius: 12px;
21-
padding: 24px;
2235
height: 100%;
2336
background-color: var(--vp-c-bg-soft);
37+
transition: border-color 0.25s, background-color 0.25s;
38+
}
39+
40+
.VPFeature.link:hover {
41+
border-color: var(--vp-c-brand);
42+
background-color: var(--vp-c-bg);
43+
}
44+
45+
.dark .VPFeature.link:hover {
46+
background-color: var(--vp-c-bg-mute);
47+
}
48+
49+
.box {
50+
display: flex;
51+
flex-direction: column;
52+
padding: 24px;
53+
height: 100%;
2454
}
2555
2656
.icon {
@@ -33,10 +63,11 @@ defineProps<{
3363
width: 48px;
3464
height: 48px;
3565
font-size: 24px;
66+
transition: background-color 0.25s;
3667
}
3768
3869
.dark .icon {
39-
background-color: var(--vp-c-bg);
70+
background-color: var(--vp-c-gray-dark-5);
4071
}
4172
4273
.title {
@@ -46,10 +77,36 @@ defineProps<{
4677
}
4778
4879
.details {
80+
flex-grow: 1;
4981
padding-top: 8px;
5082
line-height: 24px;
5183
font-size: 14px;
5284
font-weight: 500;
5385
color: var(--vp-c-text-2);
5486
}
87+
88+
.link-text {
89+
padding-top: 8px;
90+
}
91+
92+
.link-text-value {
93+
display: flex;
94+
align-items: center;
95+
font-size: 14px;
96+
font-weight: 500;
97+
color: var(--vp-c-brand);
98+
transition: color 0.25s;
99+
}
100+
101+
.VPFeature.link:hover .link-text-value {
102+
color: var(--vp-c-brand-dark);
103+
}
104+
105+
.link-text-icon {
106+
display: inline-block;
107+
margin-left: 6px;
108+
width: 14px;
109+
height: 14px;
110+
fill: currentColor;
111+
}
55112
</style>

‎src/client/theme-default/components/VPFeatures.vue

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface Feature {
66
icon?: string
77
title: string
88
details: string
9+
link?: string
10+
linkText?: string
911
}
1012
1113
const props = defineProps<{
@@ -38,6 +40,8 @@ const grid = computed(() => {
3840
:icon="feature.icon"
3941
:title="feature.title"
4042
:details="feature.details"
43+
:link="feature.link"
44+
:link-text="feature.linkText"
4145
/>
4246
</div>
4347
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.