1
+ import {
2
+ ArticleDesign ,
3
+ ArticleDisplay ,
4
+ ArticleSpecial ,
5
+ Pillar ,
6
+ } from '../../lib/articleFormat' ;
1
7
import { Available } from './available' ;
2
8
import { descriptionLinks } from './styles' ;
3
9
@@ -89,6 +95,28 @@ const Examples = () => (
89
95
</ >
90
96
) ;
91
97
98
+ /**
99
+ * Joins all the `string` values of an enum into a single, comma-separated
100
+ * `string`.
101
+ *
102
+ * `ArticleDesign`, `ArticleDisplay` and the two variants of `ArticleTheme` are
103
+ * TypeScript enums. Their values contain both the `string` and `number`
104
+ * representations of the enum, but here we just want the `string`s, so we
105
+ * filter out the `number`s.
106
+ *
107
+ * https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
108
+ */
109
+ const formatValues = (
110
+ a :
111
+ | typeof ArticleDesign
112
+ | typeof ArticleDisplay
113
+ | typeof Pillar
114
+ | typeof ArticleSpecial ,
115
+ ) : string =>
116
+ Object . values ( a )
117
+ . filter ( ( v ) => typeof v !== 'number' )
118
+ . join ( ', ' ) ;
119
+
92
120
const Format = ( ) => (
93
121
< >
94
122
< h2 > Format</ h2 >
@@ -103,23 +131,21 @@ const Format = () => (
103
131
< dd >
104
132
Primarily influences the content, structure and features of an
105
133
article. It's the most important of the three, and is often used
106
- as a shorthand to describe the "kind" of article. Examples
107
- include < code > Liveblog</ code > , < code > Feature</ code > and{ ' ' }
108
- < code > Gallery</ code > .
134
+ as a shorthand to describe the "kind" of article. The values
135
+ are: { formatValues ( ArticleDesign ) } .
109
136
</ dd >
110
137
< dt > Display</ dt >
111
138
< dd >
112
- Primarily influences the layout of an article. Examples include{ ' ' }
113
- < code > Immersive</ code > , < code > Showcase</ code > and{ ' ' }
114
- < code > NumberedList</ code > .
139
+ Primarily influences the layout of an article. The values are:{ ' ' }
140
+ { formatValues ( ArticleDisplay ) } .
115
141
</ dd >
116
142
< dt > Theme</ dt >
117
143
< dd >
118
144
Primarily influences the fonts and colours of an article. It can
119
145
can be thought of as a superset of "pillar", i.e. all the
120
146
pillars are considered themes, but there are some additional
121
- themes that are not pillars. Examples include < code > News </ code > , { ' ' }
122
- < code > Sport </ code > and < code > Labs </ code > .
147
+ themes that are not pillars. The values are: { ' ' }
148
+ { formatValues ( Pillar ) } , { formatValues ( ArticleSpecial ) } .
123
149
</ dd >
124
150
</ dl >
125
151
< p >
0 commit comments