1+ import {
2+ ArticleDesign ,
3+ ArticleDisplay ,
4+ ArticleSpecial ,
5+ Pillar ,
6+ } from '../../lib/articleFormat' ;
17import { Available } from './available' ;
28import { descriptionLinks } from './styles' ;
39
@@ -89,6 +95,28 @@ const Examples = () => (
8995 </ >
9096) ;
9197
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+
92120const Format = ( ) => (
93121 < >
94122 < h2 > Format</ h2 >
@@ -103,23 +131,21 @@ const Format = () => (
103131 < dd >
104132 Primarily influences the content, structure and features of an
105133 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 ) } .
109136 </ dd >
110137 < dt > Display</ dt >
111138 < 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 ) } .
115141 </ dd >
116142 < dt > Theme</ dt >
117143 < dd >
118144 Primarily influences the fonts and colours of an article. It can
119145 can be thought of as a superset of "pillar", i.e. all the
120146 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 ) } .
123149 </ dd >
124150 </ dl >
125151 < p >
0 commit comments