Skip to content

Commit 3c2d601

Browse files
author
Dobromir Hristov
authored
Add support for @TopicsVisualStyle (#419)
closes rdar://97716047
1 parent 437098f commit 3c2d601

17 files changed

+517
-22
lines changed

src/components/DocumentationTopic.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@
7373
/>
7474
</div>
7575
<Topics
76-
v-if="topicSections"
76+
v-if="shouldRenderTopicSection"
7777
:sections="topicSections"
7878
:isSymbolDeprecated="isSymbolDeprecated"
7979
:isSymbolBeta="isSymbolBeta"
80+
:topicStyle="topicSectionsStyle"
8081
/>
8182
<DefaultImplementations
8283
v-if="defaultImplementationsSections"
@@ -113,6 +114,7 @@ import BetaLegalText from 'theme/components/DocumentationTopic/BetaLegalText.vue
113114
import LanguageSwitcher from 'theme/components/DocumentationTopic/Summary/LanguageSwitcher.vue';
114115
import DocumentationHero from 'docc-render/components/DocumentationTopic/DocumentationHero.vue';
115116
import WordBreak from 'docc-render/components/WordBreak.vue';
117+
import { TopicSectionsStyle } from '@/constants/TopicSectionsStyle';
116118
import OnThisPageNav from 'theme/components/OnThisPageNav.vue';
117119
import Abstract from './DocumentationTopic/Description/Abstract.vue';
118120
import ContentNode from './DocumentationTopic/ContentNode.vue';
@@ -238,6 +240,10 @@ export default {
238240
type: Array,
239241
required: false,
240242
},
243+
topicSectionsStyle: {
244+
type: String,
245+
default: TopicSectionsStyle.list,
246+
},
241247
sampleCodeDownload: {
242248
type: Object,
243249
required: false,
@@ -376,6 +382,10 @@ export default {
376382
const icon = pageImages.find(({ type }) => type === 'icon');
377383
return icon ? icon.identifier : null;
378384
},
385+
shouldRenderTopicSection: ({
386+
topicSectionsStyle,
387+
topicSections,
388+
}) => topicSections && topicSectionsStyle !== TopicSectionsStyle.hidden,
379389
},
380390
methods: {
381391
normalizePath(path) {

src/components/DocumentationTopic/ContentTableSection.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<template>
1212
<div class="contenttable-section">
1313
<div class="section-title">
14-
<slot name="title">
14+
<slot name="title" :className="className">
1515
<LinkableHeading
1616
:level="3"
17-
class="title"
17+
:class="className"
1818
:anchor="anchorComputed"
1919
:register-on-this-page="false"
2020
>{{ title }}</LinkableHeading>
@@ -32,6 +32,8 @@
3232
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
3333
import { anchorize } from 'docc-render/utils/strings';
3434

35+
export const TITLE_CLASS_NAME = 'contenttable-title';
36+
3537
export default {
3638
name: 'ContentTableSection',
3739
components: { LinkableHeading },
@@ -47,6 +49,7 @@ export default {
4749
},
4850
computed: {
4951
anchorComputed: ({ title, anchor }) => anchor || anchorize(title),
52+
className: () => TITLE_CLASS_NAME,
5053
},
5154
};
5255
</script>
@@ -67,7 +70,7 @@ export default {
6770
}
6871
}
6972

70-
/deep/ .title {
73+
/deep/ .contenttable-title {
7174
@include font-styles(label);
7275
}
7376

@@ -86,7 +89,7 @@ export default {
8689
}
8790
}
8891

89-
/deep/ .title {
92+
/deep/ .contenttable-title {
9093
margin: 0 0 $contenttable-spacing-single-side 0;
9194
padding-bottom: 0.5rem;
9295
}

src/components/DocumentationTopic/Topics.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
:isSymbolDeprecated="isSymbolDeprecated"
1616
:isSymbolBeta="isSymbolBeta"
1717
:sections="sections"
18+
:topicStyle="topicStyle"
1819
/>
1920
</template>
2021

2122
<script>
23+
import { TopicSectionsStyle } from '@/constants/TopicSectionsStyle';
2224
import TopicsTable from './TopicsTable.vue';
2325

2426
export default {
@@ -28,6 +30,11 @@ export default {
2830
isSymbolDeprecated: Boolean,
2931
isSymbolBeta: Boolean,
3032
sections: TopicsTable.props.sections,
33+
topicStyle: {
34+
type: String,
35+
required: true,
36+
validator: v => Object.hasOwnProperty.call(TopicSectionsStyle, v),
37+
},
3138
},
3239
};
3340
</script>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
-->
10+
11+
<template>
12+
<div class="TopicsLinkCardGrid">
13+
<Row :columns="compactCards ? 3 : 2">
14+
<Column
15+
v-for="item in items"
16+
:key="item.title"
17+
>
18+
<TopicsLinkCardGridItem :item="item" :compact="compactCards" />
19+
</Column>
20+
</Row>
21+
</div>
22+
</template>
23+
24+
<script>
25+
import Row from 'docc-render/components/ContentNode/Row.vue';
26+
import Column from 'docc-render/components/ContentNode/Column.vue';
27+
import { TopicSectionsStyle } from '@/constants/TopicSectionsStyle';
28+
import TopicsLinkCardGridItem from './TopicsLinkCardGridItem.vue';
29+
30+
export default {
31+
name: 'TopicsLinkCardGrid',
32+
components: { TopicsLinkCardGridItem, Column, Row },
33+
props: {
34+
items: {
35+
type: Array,
36+
required: true,
37+
},
38+
topicStyle: {
39+
type: String,
40+
default: TopicSectionsStyle.compactGrid,
41+
validator: v => v === TopicSectionsStyle.compactGrid || v === TopicSectionsStyle.detailedGrid,
42+
},
43+
},
44+
computed: {
45+
compactCards: ({ topicStyle }) => topicStyle === TopicSectionsStyle.compactGrid,
46+
},
47+
};
48+
</script>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
-->
10+
11+
<template>
12+
<Card
13+
class="reference-card-grid-item"
14+
:url="item.url"
15+
:image="imageReferences.card"
16+
:title="item.title"
17+
floating-style
18+
:size="cardSize"
19+
:link-text="linkText"
20+
>
21+
<template v-if="!imageReferences.card" #cover="{ classes }">
22+
<div :class="classes" class="reference-card-grid-item__image">
23+
<TopicTypeIcon
24+
:type="item.role"
25+
:image-override="references[imageReferences.icon]"
26+
class="reference-card-grid-item__icon"
27+
/>
28+
</div>
29+
</template>
30+
<ContentNode v-if="!compact" :content="item.abstract" />
31+
</Card>
32+
</template>
33+
34+
<script>
35+
import Card from 'docc-render/components/Card.vue';
36+
import TopicTypeIcon from 'docc-render/components/TopicTypeIcon.vue';
37+
import { TopicRole } from 'docc-render/constants/roles';
38+
import CardSize from 'docc-render/constants/CardSize';
39+
40+
export const ROLE_LINK_TEXT = {
41+
[TopicRole.article]: 'Read article',
42+
[TopicRole.overview]: 'Start tutorial',
43+
[TopicRole.collection]: 'View API collection',
44+
[TopicRole.symbol]: 'View symbol',
45+
[TopicRole.sampleCode]: 'View sample code',
46+
};
47+
48+
export default {
49+
name: 'TopicsLinkCardGridItem',
50+
components: {
51+
TopicTypeIcon,
52+
Card,
53+
ContentNode: () => import('docc-render/components/ContentNode.vue'),
54+
},
55+
inject: ['references'],
56+
props: {
57+
item: {
58+
type: Object,
59+
required: true,
60+
},
61+
compact: {
62+
type: Boolean,
63+
default: true,
64+
},
65+
},
66+
computed: {
67+
imageReferences: ({ item }) => (item.images || []).reduce((all, current) => {
68+
// eslint-disable-next-line no-param-reassign
69+
all[current.type] = current.identifier;
70+
return all;
71+
}, { icon: null, card: null }),
72+
linkText: ({ compact, item }) => (compact ? '' : (ROLE_LINK_TEXT[item.role] || 'Learn more')),
73+
cardSize: ({ compact }) => (compact ? undefined : CardSize.large),
74+
},
75+
};
76+
</script>
77+
78+
<style scoped lang='scss'>
79+
@import 'docc-render/styles/_core.scss';
80+
81+
.reference-card-grid-item {
82+
&__image {
83+
display: flex;
84+
align-items: center;
85+
justify-content: center;
86+
font-size: 80px;
87+
background-color: var(--color-fill-gray-quaternary);
88+
}
89+
90+
&__icon {
91+
display: flex;
92+
margin: 0;
93+
}
94+
}
95+
</style>

src/components/DocumentationTopic/TopicsTable.vue

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
:title="section.title"
1717
:anchor="section.anchor"
1818
>
19-
<template v-if="wrapTitle" slot="title">
19+
<template v-if="wrapTitle" #title="{ className }">
2020
<LinkableHeading
2121
:level="3"
2222
:anchor="section.anchor"
23-
class="title"
23+
:class="className"
2424
:register-on-this-page="false"
2525
>
2626
<WordBreak>{{ section.title }}</WordBreak>
@@ -32,13 +32,21 @@
3232
<template v-if="section.discussion" slot="discussion">
3333
<ContentNode :content="section.discussion.content" />
3434
</template>
35-
<TopicsLinkBlock
36-
v-for="topic in section.topics"
35+
<template v-if="shouldRenderList">
36+
<TopicsLinkBlock
37+
v-for="topic in section.topics"
38+
class="topic"
39+
:key="topic.identifier"
40+
:topic="topic"
41+
:isSymbolDeprecated="isSymbolDeprecated"
42+
:isSymbolBeta="isSymbolBeta"
43+
/>
44+
</template>
45+
<TopicsLinkCardGrid
46+
v-else
47+
:items="section.topics"
48+
:topicStyle="topicStyle"
3749
class="topic"
38-
:key="topic.identifier"
39-
:topic="topic"
40-
:isSymbolDeprecated="isSymbolDeprecated"
41-
:isSymbolBeta="isSymbolBeta"
4250
/>
4351
</ContentTableSection>
4452
</ContentTable>
@@ -47,6 +55,8 @@
4755
<script>
4856
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
4957
import WordBreak from 'docc-render/components/WordBreak.vue';
58+
import { TopicSectionsStyle } from '@/constants/TopicSectionsStyle';
59+
import TopicsLinkCardGrid from 'docc-render/components/DocumentationTopic/TopicsLinkCardGrid.vue';
5060
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
5161
import ContentTable from './ContentTable.vue';
5262
import ContentTableSection from './ContentTableSection.vue';
@@ -62,6 +72,7 @@ export default {
6272
},
6373
},
6474
components: {
75+
TopicsLinkCardGrid,
6576
WordBreak,
6677
ContentTable,
6778
TopicsLinkBlock,
@@ -94,8 +105,13 @@ export default {
94105
type: Boolean,
95106
default: false,
96107
},
108+
topicStyle: {
109+
type: String,
110+
default: TopicSectionsStyle.list,
111+
},
97112
},
98113
computed: {
114+
shouldRenderList: ({ topicStyle }) => topicStyle === TopicSectionsStyle.list,
99115
sectionsWithTopics() {
100116
return this.sections.map(section => ({
101117
...section,

src/constants/TopicSectionsStyle.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* This source file is part of the Swift.org open source project
3+
*
4+
* Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
* Licensed under Apache License v2.0 with Runtime Library Exception
6+
*
7+
* See https://swift.org/LICENSE.txt for license information
8+
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
/* eslint-disable import/prefer-default-export */
12+
export const TopicSectionsStyle = {
13+
list: 'list',
14+
compactGrid: 'compactGrid',
15+
detailedGrid: 'detailedGrid',
16+
hidden: 'hidden',
17+
};

src/views/DocumentationTopic.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export default {
187187
relationshipsSections,
188188
references = {},
189189
sampleCodeDownload,
190+
topicSectionsStyle,
190191
topicSections,
191192
seeAlsoSections,
192193
variantOverrides,
@@ -212,6 +213,7 @@ export default {
212213
sampleCodeDownload,
213214
title,
214215
topicSections,
216+
topicSectionsStyle,
215217
seeAlsoSections,
216218
variantOverrides,
217219
symbolKind,

0 commit comments

Comments
 (0)