forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopicTypeIcon.vue
155 lines (144 loc) · 5.1 KB
/
TopicTypeIcon.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
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2022 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>
<div
class="TopicTypeIcon"
:style="styles"
>
<OverridableAsset
v-if="imageOverride"
:imageOverride="imageOverride"
:shouldCalculateOptimalWidth="shouldCalculateOptimalWidth"
class="icon-inline"
/>
<component
v-else
:is="icon"
v-bind="iconProps"
class="icon-inline"
/>
</div>
</template>
<script>
import PathIcon from 'theme/components/Icons/PathIcon.vue';
import TechnologyIcon from 'theme/components/Icons/TechnologyIcon.vue';
import ArticleIcon from 'theme/components/Icons/ArticleIcon.vue';
import TutorialIcon from 'theme/components/Icons/TutorialIcon.vue';
import TopicFuncIcon from 'theme/components/Icons/TopicFuncIcon.vue';
import CollectionIcon from 'theme/components/Icons/CollectionIcon.vue';
import TopicFuncOpIcon from 'theme/components/Icons/TopicFuncOpIcon.vue';
import CurlyBracketsIcon from 'theme/components/Icons/CurlyBracketsIcon.vue';
import TopicSubscriptIcon from 'theme/components/Icons/TopicSubscriptIcon.vue';
import TwoLetterSymbolIcon from 'theme/components/Icons/TwoLetterSymbolIcon.vue';
import SingleLetterSymbolIcon from 'theme/components/Icons/SingleLetterSymbolIcon.vue';
import { TopicTypes, TopicTypeAliases } from 'docc-render/constants/TopicTypes';
import { HeroColorsMap } from 'docc-render/constants/HeroColors';
import SVGIcon from 'docc-render/components/SVGIcon.vue';
import OverridableAsset from 'docc-render/components/OverridableAsset.vue';
const TopicTypeIcons = {
[TopicTypes.article]: ArticleIcon,
[TopicTypes.associatedtype]: CollectionIcon,
[TopicTypes.buildSetting]: CollectionIcon,
[TopicTypes.class]: SingleLetterSymbolIcon,
[TopicTypes.collection]: CollectionIcon,
[TopicTypes.dictionarySymbol]: SingleLetterSymbolIcon,
[TopicTypes.container]: CollectionIcon,
[TopicTypes.enum]: SingleLetterSymbolIcon,
[TopicTypes.extension]: TwoLetterSymbolIcon,
[TopicTypes.func]: TopicFuncIcon,
[TopicTypes.op]: TopicFuncOpIcon,
[TopicTypes.httpRequest]: SingleLetterSymbolIcon,
[TopicTypes.languageGroup]: CollectionIcon,
[TopicTypes.learn]: PathIcon,
[TopicTypes.method]: SingleLetterSymbolIcon,
[TopicTypes.macro]: SingleLetterSymbolIcon,
[TopicTypes.module]: TechnologyIcon,
[TopicTypes.namespace]: SingleLetterSymbolIcon,
[TopicTypes.overview]: PathIcon,
[TopicTypes.protocol]: TwoLetterSymbolIcon,
[TopicTypes.property]: SingleLetterSymbolIcon,
[TopicTypes.propertyListKey]: SingleLetterSymbolIcon,
[TopicTypes.resources]: PathIcon,
[TopicTypes.sampleCode]: CurlyBracketsIcon,
[TopicTypes.struct]: SingleLetterSymbolIcon,
[TopicTypes.subscript]: TopicSubscriptIcon,
[TopicTypes.symbol]: CollectionIcon,
[TopicTypes.tutorial]: TutorialIcon,
[TopicTypes.typealias]: SingleLetterSymbolIcon,
[TopicTypes.union]: SingleLetterSymbolIcon,
[TopicTypes.var]: SingleLetterSymbolIcon,
};
const TopicTypeProps = {
[TopicTypes.class]: { symbol: 'C' },
[TopicTypes.dictionarySymbol]: { symbol: 'O' },
[TopicTypes.enum]: { symbol: 'E' },
[TopicTypes.extension]: { first: 'E', second: 'x' },
[TopicTypes.httpRequest]: { symbol: 'E' },
[TopicTypes.method]: { symbol: 'M' },
[TopicTypes.macro]: { symbol: '#' },
[TopicTypes.namespace]: { symbol: 'N' },
[TopicTypes.protocol]: { first: 'P', second: 'r' },
[TopicTypes.property]: { symbol: 'P' },
[TopicTypes.propertyListKey]: { symbol: 'K' },
[TopicTypes.struct]: { symbol: 'S' },
[TopicTypes.typealias]: { symbol: 'T' },
[TopicTypes.union]: { symbol: 'U' },
[TopicTypes.var]: { symbol: 'V' },
};
export default {
name: 'TopicTypeIcon',
components: { OverridableAsset, SVGIcon, SingleLetterSymbolIcon },
constants: { TopicTypeIcons, TopicTypeProps },
props: {
type: {
type: String,
required: true,
},
withColors: {
type: Boolean,
default: false,
},
imageOverride: {
type: Object,
default: null,
},
shouldCalculateOptimalWidth: {
type: Boolean,
default: true,
},
},
computed: {
normalisedType: ({ type }) => TopicTypeAliases[type] || type,
icon: ({ normalisedType }) => TopicTypeIcons[normalisedType] || CollectionIcon,
iconProps: ({ normalisedType }) => TopicTypeProps[normalisedType] || {},
color: ({ normalisedType }) => HeroColorsMap[normalisedType],
styles: ({
color,
withColors,
}) => (withColors && color ? { '--icon-color': `var(--color-type-icon-${color})` } : {}),
},
};
</script>
<style scoped lang='scss'>
@import 'docc-render/styles/_core.scss';
.TopicTypeIcon {
width: 1em;
height: 1em;
flex: 0 0 auto;
// use the `--icon-color` if `withColors` is true, otherwise just use gray.
color: var(--icon-color, var(--color-figure-gray-secondary));
:deep(picture) {
flex: 1;
}
svg, :deep(img) {
display: block;
width: 100%;
height: 100%;
}
}
</style>