Skip to content

Commit baaf872

Browse files
author
Dobromir Hristov
committed
feat: add support for @TopicsVisualStyle
1 parent f9ec758 commit baaf872

File tree

13 files changed

+573
-5
lines changed

13 files changed

+573
-5
lines changed

src/components/DocumentationTopic.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@
7171
/>
7272
</div>
7373
<Topics
74-
v-if="topicSections"
74+
v-if="shouldRenderTopicSection"
7575
:sections="topicSections"
7676
:isSymbolDeprecated="isSymbolDeprecated"
7777
:isSymbolBeta="isSymbolBeta"
78+
:topicStyle="topicSectionsStyle"
7879
/>
7980
<DefaultImplementations
8081
v-if="defaultImplementationsSections"
@@ -106,6 +107,7 @@ import BetaLegalText from 'theme/components/DocumentationTopic/BetaLegalText.vue
106107
import LanguageSwitcher from 'theme/components/DocumentationTopic/Summary/LanguageSwitcher.vue';
107108
import DocumentationHero from 'docc-render/components/DocumentationTopic/DocumentationHero.vue';
108109
import WordBreak from 'docc-render/components/WordBreak.vue';
110+
import { TopicStyles } from 'docc-render/constants/TopicStyles';
109111
import Abstract from './DocumentationTopic/Description/Abstract.vue';
110112
import ContentNode from './DocumentationTopic/ContentNode.vue';
111113
import CallToActionButton from './CallToActionButton.vue';
@@ -227,6 +229,10 @@ export default {
227229
type: Array,
228230
required: false,
229231
},
232+
topicSectionsStyle: {
233+
type: String,
234+
default: TopicStyles.list,
235+
},
230236
sampleCodeDownload: {
231237
type: Object,
232238
required: false,
@@ -355,6 +361,10 @@ export default {
355361
|| (primaryContentSections && primaryContentSections.length)
356362
),
357363
tagName: ({ isSymbolDeprecated }) => (isSymbolDeprecated ? 'Deprecated' : 'Beta'),
364+
shouldRenderTopicSection: ({
365+
topicSectionsStyle,
366+
topicSections,
367+
}) => topicSections && topicSectionsStyle !== TopicStyles.hidden,
358368
},
359369
methods: {
360370
normalizePath(path) {

src/components/DocumentationTopic/Topics.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,39 @@
1010

1111
<template>
1212
<TopicsTable
13+
v-if="shouldRenderList"
1314
anchor="topics"
1415
title="Topics"
1516
:isSymbolDeprecated="isSymbolDeprecated"
1617
:isSymbolBeta="isSymbolBeta"
1718
:sections="sections"
1819
/>
20+
<TopicsGrid
21+
v-else
22+
:sections="sections"
23+
:topicStyle="topicStyle"
24+
/>
1925
</template>
2026

2127
<script>
28+
import { TopicStyles } from 'docc-render/constants/TopicStyles';
29+
import TopicsGrid from './TopicsGrid.vue';
2230
import TopicsTable from './TopicsTable.vue';
2331
2432
export default {
2533
name: 'Topics',
26-
components: { TopicsTable },
34+
components: { TopicsGrid, TopicsTable },
2735
props: {
2836
isSymbolDeprecated: Boolean,
2937
isSymbolBeta: Boolean,
3038
sections: TopicsTable.props.sections,
39+
topicStyle: {
40+
type: String,
41+
required: true,
42+
},
43+
},
44+
computed: {
45+
shouldRenderList: ({ topicStyle }) => topicStyle === TopicStyles.list,
3146
},
3247
};
3348
</script>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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="TopicsGrid">
13+
<OnThisPageSection
14+
v-for="(section, i) in sections"
15+
:key="i"
16+
:title="section.title || ''"
17+
:anchor="anchorize(section.title || '')"
18+
:level="3"
19+
class="topic-grid"
20+
>
21+
<div class="container">
22+
<h3 class="title" v-if="section.title">
23+
{{ section.title }}
24+
</h3>
25+
<TopicsLinkCardGrid :identifiers="section.identifiers" :topicStyle="topicStyle" />
26+
</div>
27+
</OnThisPageSection>
28+
</div>
29+
</template>
30+
31+
<script>
32+
import { anchorize } from 'docc-render/utils/strings';
33+
34+
import TopicsLinkCardGrid from 'docc-render/components/DocumentationTopic/TopicsLinkCardGrid.vue';
35+
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
36+
37+
export default {
38+
name: 'TopicsGrid',
39+
components: { OnThisPageSection, TopicsLinkCardGrid },
40+
props: {
41+
sections: {
42+
type: Array,
43+
required: true,
44+
},
45+
topicStyle: {
46+
type: String,
47+
required: true,
48+
},
49+
},
50+
methods: {
51+
anchorize,
52+
},
53+
};
54+
</script>
55+
56+
<style scoped lang='scss'>
57+
@import 'docc-render/styles/_core.scss';
58+
59+
.container {
60+
@include dynamic-content-container
61+
}
62+
63+
.title {
64+
@include font-styles(label);
65+
}
66+
67+
.topic-grid + .topic-grid {
68+
margin-top: $stacked-margin-large;
69+
}
70+
</style>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
<Grid :columns="compactCards ? 3 : 2">
14+
<Column
15+
v-for="(item, index) in items"
16+
:key="index"
17+
>
18+
<TopicsLinkCardGridItem :item="item" :compact="compactCards" />
19+
</Column>
20+
</Grid>
21+
</div>
22+
</template>
23+
24+
<script>
25+
import Grid from 'docc-render/components/ContentNode/Grid.vue';
26+
import Column from 'docc-render/components/ContentNode/Column.vue';
27+
import { TopicStyles } from 'docc-render/constants/TopicStyles';
28+
import TopicsLinkCardGridItem from './TopicsLinkCardGridItem.vue';
29+
30+
export default {
31+
name: 'TopicsLinkCardGrid',
32+
components: { TopicsLinkCardGridItem, Column, Grid },
33+
inject: ['references'],
34+
props: {
35+
identifiers: {
36+
type: Array,
37+
required: true,
38+
},
39+
topicStyle: {
40+
type: String,
41+
default: TopicStyles.compactGrid,
42+
},
43+
},
44+
computed: {
45+
items() {
46+
return this.identifiers.map(i => this.references[i]);
47+
},
48+
compactCards: ({ topicStyle }) => topicStyle === TopicStyles.compactGrid,
49+
},
50+
};
51+
</script>
52+
53+
<style scoped lang='scss'>
54+
@import '@/styles/_core.scss';
55+
56+
.grid {
57+
grid-gap: 20px;
58+
}
59+
</style>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
:content="compact ? []: item.abstract"
18+
floating-style
19+
:size="compact ? undefined: 'large'"
20+
:link-text="compact? '': 'Visit page'"
21+
>
22+
<template #cover="{ classes }" v-if="!imageReferences.card">
23+
<div :class="classes" class="reference-card-grid-item__image">
24+
<TopicTypeIcon
25+
:type="item.role"
26+
:image-override="references[imageReferences.icon]"
27+
class="reference-card-grid-item__icon"
28+
/>
29+
</div>
30+
</template>
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+
38+
export default {
39+
name: 'TopicsLinkCardGridItem',
40+
components: { TopicTypeIcon, Card },
41+
inject: ['references'],
42+
props: {
43+
item: {
44+
type: Object,
45+
required: true,
46+
},
47+
compact: {
48+
type: Boolean,
49+
default: true,
50+
},
51+
},
52+
computed: {
53+
imageReferences: ({ item }) => (item.images || []).reduce((all, current) => {
54+
// eslint-disable-next-line no-param-reassign
55+
all[current.type] = current.reference;
56+
return all;
57+
}, { icon: null, card: null }),
58+
},
59+
};
60+
</script>
61+
62+
<style scoped lang='scss'>
63+
@import 'docc-render/styles/_core.scss';
64+
65+
.reference-card-grid-item {
66+
&__image {
67+
display: flex;
68+
align-items: center;
69+
justify-content: center;
70+
font-size: 80px;
71+
background-color: var(--color-fill-gray-quaternary);
72+
}
73+
74+
&__icon {
75+
display: flex;
76+
margin: 0;
77+
}
78+
}
79+
</style>

src/constants/TopicStyles.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 TopicStyles = {
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
@@ -186,6 +186,7 @@ export default {
186186
relationshipsSections,
187187
references = {},
188188
sampleCodeDownload,
189+
topicSectionsStyle,
189190
topicSections,
190191
seeAlsoSections,
191192
variantOverrides,
@@ -211,6 +212,7 @@ export default {
211212
sampleCodeDownload,
212213
title,
213214
topicSections,
215+
topicSectionsStyle,
214216
seeAlsoSections,
215217
variantOverrides,
216218
symbolKind,

tests/unit/components/DocumentationTopic.spec.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import DocumentationTopic from 'docc-render/components/DocumentationTopic.vue';
1313
import Language from 'docc-render/constants/Language';
1414
import { TopicTypes } from '@/constants/TopicTypes';
1515
import DocumentationHero from '@/components/DocumentationTopic/DocumentationHero.vue';
16+
import { TopicStyles } from '@/constants/TopicStyles';
1617

1718
const {
1819
Abstract,
@@ -445,7 +446,7 @@ describe('DocumentationTopic', () => {
445446
});
446447
});
447448

448-
it('renders `Topics` if there are topic sections', () => {
449+
it('renders `Topics` if there are topic sections, passing the `topicSectionStyles` over', () => {
449450
expect(wrapper.contains(Topics)).toBe(false);
450451

451452
const topicSections = [
@@ -461,11 +462,23 @@ describe('DocumentationTopic', () => {
461462
identifiers: ['baz'],
462463
},
463464
];
464-
wrapper.setProps({ topicSections });
465+
wrapper.setProps({ topicSections, topicSectionsStyle: TopicStyles.detailedGrid });
465466

466467
const topics = wrapper.find(Topics);
467468
expect(topics.exists()).toBe(true);
468469
expect(topics.props('sections')).toBe(topicSections);
470+
expect(topics.props('topicStyle')).toBe(TopicStyles.detailedGrid);
471+
});
472+
473+
it('does not render the `Topics` if the `topicSectionsStyle` is `hidden`', () => {
474+
const topicSections = [
475+
{
476+
title: 'Baz',
477+
identifiers: ['baz'],
478+
},
479+
];
480+
wrapper.setProps({ topicSections, topicSectionsStyle: 'hidden' });
481+
expect(wrapper.find(Topics).exists()).toBe(false);
469482
});
470483

471484
it('renders `SeeAlso` if there are see also sections', () => {

0 commit comments

Comments
 (0)