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
|
import {isExternalLinkContext} from '#external-links';
export default {
extraDependencies: ['html', 'language', 'to'],
data: (url) => ({url}),
slots: {
context: {
// This awkward syntax is because the slot descriptor validator can't
// differentiate between a function that returns a validator (the usual
// syntax) and a function that is itself a validator.
validate: () => isExternalLinkContext,
default: 'generic',
},
withText: {type: 'boolean'},
},
generate(data, slots, {html, language, to}) {
const format = style =>
language.formatExternalLink(data.url, {style, context: slots.context});
const platformText = format('platform');
const handleText = format('handle');
const iconId = format('icon-id');
return html.tag('a', {class: 'icon'},
{href: data.url},
slots.withText &&
{class: 'has-text'},
[
html.tag('svg', [
!slots.withText &&
html.tag('title', platformText),
html.tag('use', {
href: to('shared.staticIcon', iconId),
}),
]),
slots.withText &&
html.tag('span', {class: 'icon-text'},
handleText ?? platformText),
]);
},
};
|