/
feature.vue
158 lines (153 loc) · 4.35 KB
/
feature.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<v-card class="flex d-flex flex-column justify-between" min-width="240">
<v-img
v-if="image"
class="flex-grow-0"
:lazy-src="lazy"
:src="img"
:srcset="_srcset.srcset"
:sizes="_srcset.size"
cover
:aspect-ratio="16 / 9"
:style="`background-color: ${_imageBackgroundColor}`"
></v-img>
<v-card-title>
<span class="h3 text-break">
<template v-if="icon">
<font-awesome-icon
v-if="typeof icon === 'object'"
:icon="icon"
class="grey--text"
/>
<BaseIcon
v-else
:color="iconColor"
:icon="icon"
style="font-size: 1em"
></BaseIcon>
</template>
{{ name }}
<template v-if="acronym">
(<abbr :title="name">{{ acronym }}</abbr
>)</template
>
</span>
</v-card-title>
<v-card-subtitle v-if="subheading">{{
titleCase(subheading)
}}</v-card-subtitle>
<div class="flex-grow-1">
<v-card-text v-if="description" class="text--primary body-1 pt-0">
{{ description }}
</v-card-text>
<v-card-text v-if="list" class="text--primary body-1 pt-0">
<ul>
<li v-for="item in list" :key="item">{{ item }}</li>
</ul>
</v-card-text>
<v-card-text class="text--primary body-1 pt-0">
<slot></slot>
</v-card-text>
</div>
<v-card-actions>
<!-- add hidden content to set height to prevent page jank -->
<v-btn style="visibility: hidden" aria-hidden="true" icon>
<v-icon />
</v-btn>
<v-spacer></v-spacer>
<LocationButton
v-if="
location &&
(location.postcode ||
location.city ||
location.region ||
location.country)
"
v-bind="location"
></LocationButton>
<BaseTooltipButton
v-if="url"
v-bind="{
link: url,
tooltip: `Learn more about ${name}`,
size: 'small',
}"
></BaseTooltipButton>
</v-card-actions>
</v-card>
</template>
<script>
import titleCase from '@/utils/title-case';
export default {
props: {
location: { type: Object, default: null },
dark: { type: Boolean, default: false },
acronym: { type: String, default: undefined },
image: { type: String, default: undefined },
url: { type: String, default: undefined },
icon: { type: [String, Object], default: () => undefined },
name: { type: String, default: undefined },
subheading: { type: String, default: undefined },
description: { type: String, default: undefined },
list: { type: Array, default: undefined },
imageHeight: { type: Number, default: 360 },
imageWidth: { type: Number, default: 640 },
imageQuality: { type: Number, default: 100 },
imageColor: { type: String, default: '#fff' },
imageBackgroundColor: { type: String, default: null },
imageFit: {
type: String,
default: 'inside',
validator: (val) =>
['cover', 'contain', 'inside', 'outside'].includes(val),
},
iconColor: { type: String, default: 'grey' },
},
computed: {
_imageBackgroundColor() {
return this.imageBackgroundColor ?? this.imageColor;
},
lazy() {
const svg = Buffer.from(
`<svg xmlns='http://www.w3.org/2000/svg'
viewBox='00512512'>
<rect width="100%" height="100%" fill="${this._imageBackgroundColor}"/>
</svg>`,
).toString('base64');
return `data:image/svg+xml;base64,${svg}`;
},
img() {
return this.$img(this.image, {
quality: this.imageQuality,
width: this.imageWidth,
height: this.imageHeight,
enlarge: undefined,
fit: this.imageFit,
trim: undefined,
position: 'center',
format: 'png',
background: this.imageColor,
});
},
_srcset() {
return this.$img.getSizes(this.image, {
sizes: 'xs:100vw sm:50vw md:33vw lg:33vw xl:33vw',
modifiers: {
format: 'webp',
quality: this.imageQuality,
width: this.imageWidth,
height: this.imageHeight,
enlarge: undefined,
fit: this.imageFit,
trim: undefined,
position: 'center',
},
});
},
},
methods: {
titleCase,
},
};
</script>