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
|
import {stitchArrays} from '#sugar';
export default {
extraDependencies: ['html', 'language'],
slots: {
scopes: {
validate: v => v.strictArrayOf(v.isStringNonEmpty),
},
contents: {
validate: v => v.strictArrayOf(v.isHTML),
},
open: {
type: 'boolean',
default: true,
},
},
generate(slots, {html, language}) {
// TODO: Manual [html.onlyIfContent]-alike here is a bit unfortunate.
// We can't use a normal [html.onlyIfContent] because the summary counts
// as content - we'd need to encode that we want to exclude it from the
// content check (for the <details> element), somehow.
if (slots.contents.every(content => html.isBlank(content))) {
return html.blank();
}
const summary =
html.tag('summary',
{class: 'underline-white'},
html.tag('span',
language.encapsulate('trackPage.nav.chronology.scope', capsule =>
language.$(capsule, 'title', {
scope:
slots.scopes.map((scope, index) =>
html.tag('a', {class: 'switcher-link'},
{href: '#'},
(index === 0
? {style: 'display: inline'}
: {style: 'display: none'}),
language.$(capsule, scope))),
}))));
const scopeContents =
stitchArrays({
scope: slots.scopes,
content: slots.contents,
}).map(({scope, content}, index) =>
html.tag('div', {class: 'scope-' + scope},
(index === 0
? {style: 'display: block'}
: {style: 'display: none'}),
content));
return (
html.tag('details', {class: 'scoped-chronology-switcher'},
slots.open &&
{open: true},
[summary, scopeContents]));
},
};
|