forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChapter.vue
180 lines (157 loc) · 3.6 KB
/
Chapter.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->
<template>
<section class="chapter" :id="anchor" tabindex="-1">
<div class="info">
<Asset :identifier="image" aria-hidden="true" />
<div class="intro">
<component
:is="volumeHasName ? 'h3': 'h2'"
class="name"
:aria-label="`${name} - ${$tc('tutorials.sections.chapter', { number })}`"
>
<span class="eyebrow" aria-hidden="true">
{{ $t('tutorials.sections.chapter', { number }) }}
</span>
<span aria-hidden="true" class="name-text">{{name}}</span>
</component>
<ContentNode v-if="content" :content="content" />
</div>
</div>
<TopicList :topics="topics" />
</section>
</template>
<script>
import { anchorize } from 'docc-render/utils/strings';
import onIntersectViewport, { intersectionMargins } from 'docc-render/mixins/onIntersectViewport';
import Asset from 'docc-render/components/Asset.vue';
import ContentNode from 'docc-render/components/ContentNode.vue';
import ChapterTopicList from './ChapterTopicList.vue';
export default {
name: 'Chapter',
mixins: [onIntersectViewport],
inject: {
store: {
default: () => ({
setActiveSidebarLink() {},
setActiveVolume() {},
}),
},
},
components: {
Asset,
ContentNode,
TopicList: ChapterTopicList,
},
props: {
content: {
type: Array,
required: false,
},
image: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
number: {
type: Number,
required: true,
},
topics: {
type: Array,
required: true,
},
volumeHasName: {
type: Boolean,
default: false,
},
},
computed: {
anchor: ({ name }) => anchorize(name),
intersectionRootMargin: () => intersectionMargins.topOneThird,
},
methods: {
onIntersectViewport() {
this.store.setActiveSidebarLink(this.name);
if (!this.volumeHasName) {
// if the parent is not a Volume with a name, clear out the volume
this.store.setActiveVolume(null);
}
},
},
};
</script>
<style scoped lang="scss">
@import 'docc-render/styles/_core.scss';
.chapter {
&:focus {
outline: none !important;
}
}
.info {
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.name {
@include font-styles(tutorials-overview-chapter-title);
color: var(--color-tutorials-overview-header-text, light-color(fill-tertiary));
&-text {
word-break: break-word;
}
}
.eyebrow {
@include font-styles(body-tight);
color: var(--color-tutorials-overview-eyebrow);
display: block;
font-weight: $font-weight-semibold;
margin-bottom: 5px;
}
.content {
@include font-styles(body-reduced);
color: var(--color-tutorials-overview-content-alt);
}
.asset {
flex: 0 0 190px;
}
.intro {
flex: 0 1 360px;
}
@include breakpoint-between-medium-and-nav-medium() {
.asset {
flex: 0 0 130px;
}
.intro {
flex: 0 1 260px;
}
}
@include breakpoint(small, $scope: nav) {
.intro {
flex: 0 1 340px;
}
}
@include breakpoint(small) {
.info {
display: block;
text-align: center;
}
.asset {
margin: 0 45px;
}
.eyebrow {
margin-bottom: 7px;
}
.intro {
margin-top: 40px;
}
}
</style>