@reuters-graphics/graphics-components 3.9.0 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/llm-docs/components/AdSlot.md +11 -0
- package/dist/llm-docs/components/Analytics.md +89 -0
- package/dist/llm-docs/components/Article.md +183 -0
- package/dist/llm-docs/components/BeforeAfter.md +170 -0
- package/dist/llm-docs/components/BioBox.md +74 -0
- package/dist/llm-docs/components/Block.md +211 -0
- package/dist/llm-docs/components/BlogPost.md +68 -0
- package/dist/llm-docs/components/BlogTOC.md +91 -0
- package/dist/llm-docs/components/BodyText.md +143 -0
- package/dist/llm-docs/components/Byline.md +242 -0
- package/dist/llm-docs/components/ClockWall.md +48 -0
- package/dist/llm-docs/components/DatawrapperChart.md +87 -0
- package/dist/llm-docs/components/DocumentCloud.md +47 -0
- package/dist/llm-docs/components/EmbedPreviewerLink.md +35 -0
- package/dist/llm-docs/components/EndNotes.md +79 -0
- package/dist/llm-docs/components/FeaturePhoto.md +102 -0
- package/dist/llm-docs/components/Framer.md +44 -0
- package/dist/llm-docs/components/Geocoder.md +49 -0
- package/dist/llm-docs/components/GraphicBlock.md +319 -0
- package/dist/llm-docs/components/Headline.md +248 -0
- package/dist/llm-docs/components/Headpile.md +55 -0
- package/dist/llm-docs/components/HeroHeadline.md +515 -0
- package/dist/llm-docs/components/HorizontalScroller.md +523 -0
- package/dist/llm-docs/components/InfoBox.md +196 -0
- package/dist/llm-docs/components/KinesisLogo.md +34 -0
- package/dist/llm-docs/components/LanguageButton.md +171 -0
- package/dist/llm-docs/components/Legend.md +251 -0
- package/dist/llm-docs/components/Lottie.md +464 -0
- package/dist/llm-docs/components/PaddingReset.md +78 -0
- package/dist/llm-docs/components/PhotoPack.md +237 -0
- package/dist/llm-docs/components/PymChild.md +49 -0
- package/dist/llm-docs/components/ReferralBlock.md +119 -0
- package/dist/llm-docs/components/ReutersGraphicsLogo.md +37 -0
- package/dist/llm-docs/components/ReutersLogo.md +35 -0
- package/dist/llm-docs/components/SEO.md +113 -0
- package/dist/llm-docs/components/Scroller.md +350 -0
- package/dist/llm-docs/components/ScrollerBase.md +104 -0
- package/dist/llm-docs/components/ScrollerVideo.md +576 -0
- package/dist/llm-docs/components/SearchInput.md +44 -0
- package/dist/llm-docs/components/ShareBar.md +78 -0
- package/dist/llm-docs/components/SimpleTimeline.md +141 -0
- package/dist/llm-docs/components/SiteFooter.md +77 -0
- package/dist/llm-docs/components/SiteHeader.md +55 -0
- package/dist/llm-docs/components/SiteHeadline.md +111 -0
- package/dist/llm-docs/components/Spinner.md +43 -0
- package/dist/llm-docs/components/Table.md +298 -0
- package/dist/llm-docs/components/Theme.md +266 -0
- package/dist/llm-docs/components/TileMap.md +477 -0
- package/dist/llm-docs/components/ToolsHeader.md +46 -0
- package/dist/llm-docs/components/Video.md +254 -0
- package/dist/llm-docs/components/Visible.md +54 -0
- package/dist/llm-docs/components/cssVariables.md +40 -0
- package/dist/llm-docs/components/index.md +59 -0
- package/dist/llm-docs/components/resizeObserver.md +21 -0
- package/dist/llm-docs/guides/archieml.md +406 -0
- package/dist/llm-docs/guides/colours.md +443 -0
- package/dist/llm-docs/guides/customising-with-scss.md +61 -0
- package/dist/llm-docs/guides/graphics-kit.md +25 -0
- package/dist/llm-docs/guides/index.md +16 -0
- package/dist/llm-docs/guides/intro.md +21 -0
- package/dist/llm-docs/guides/layout.md +13 -0
- package/dist/llm-docs/guides/llm-docs.md +71 -0
- package/dist/llm-docs/guides/styles.md +16 -0
- package/dist/llm-docs/guides/theming.md +100 -0
- package/dist/llm-docs/guides/tokens.md +150 -0
- package/dist/llm-docs/index.md +36 -0
- package/package.json +23 -3
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# Table
|
|
2
|
+
|
|
3
|
+
**Category:** Components/Graphics/Table
|
|
4
|
+
|
|
5
|
+
**Import:** `import { Table } from '@reuters-graphics/graphics-components'`
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Prop | Type | Default | Required | Description |
|
|
10
|
+
|------|------|---------|:--------:|-------------|
|
|
11
|
+
| `data` | `T[]` | — | ✓ | Data for the table as an array. |
|
|
12
|
+
| `title` | `string` | — | | A title that runs above the table. |
|
|
13
|
+
| `dek` | `string` | — | | A block of text that runs above the table. |
|
|
14
|
+
| `notes` | `string` | — | | A footnote that runs below the table. |
|
|
15
|
+
| `source` | `string` | — | | A source line that runs below the table. |
|
|
16
|
+
| `includedFields` | `string[]` | `Object.keys(data[0]).filter((f) => f !== 'searchStr')` | | List of the fields to include in the table. By default everything goes. |
|
|
17
|
+
| `truncated` | `boolean` | `false` | | Whether or not the table is cutoff after a set number of rows. |
|
|
18
|
+
| `truncateLength` | `number` | `5` | | If the table is truncated, how many rows to allow before the cutoff. |
|
|
19
|
+
| `paginated` | `boolean` | `false` | | Whether or not the table is paginated after a set number of rows. |
|
|
20
|
+
| `pageSize` | `number` | `25` | | The default page size. |
|
|
21
|
+
| `searchable` | `boolean` | `false` | | Whether or not searches are allowed. |
|
|
22
|
+
| `searchPlaceholder` | `string` | `'Search in table'` | | The placeholder text that appears in the search box. |
|
|
23
|
+
| `filterField` | `string` | `''` | | A field to offer uses as an interactive filter. |
|
|
24
|
+
| `filterLabel` | `string` | — | | The label to place above the filter box. |
|
|
25
|
+
| `sortable` | `boolean` | `false` | | Whether or not sorts are allowed. |
|
|
26
|
+
| `sortField` | `string` | `Object.keys(data[0])[0]` | | The column to sort by. By default it's the first header. |
|
|
27
|
+
| `sortableFields` | `string[]` | `Object.keys(data[0]).filter((f) => f !== 'searchStr')` | | The columns that are allowed to sort. It's all of them by default. |
|
|
28
|
+
| `sortDirection` | `'ascending' \| 'descending'` | `$bindable('ascending')` | | The direction of the sort. By default it's ascending. |
|
|
29
|
+
| `fieldFormatters` | `FieldFormatters<T>` | — | | Custom field formatting functions. Should be keyed to the name of the field. |
|
|
30
|
+
| `width` | `'normal' \| 'wide' \| 'wider' \| 'widest' \| 'fluid'` | `'normal'` | | Width of the component within the text well. Options: `normal`, `wide`, `wider`, `widest`, `fluid` |
|
|
31
|
+
| `id` | `string` | `''` | | Add an ID to target with SCSS. |
|
|
32
|
+
| `class` | `string` | `''` | | Add a class to target with SCSS. |
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### Demo
|
|
37
|
+
|
|
38
|
+
```svelte
|
|
39
|
+
<Table width="normal" data={/* homeRuns */} />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Text elements
|
|
43
|
+
|
|
44
|
+
```svelte
|
|
45
|
+
<Table
|
|
46
|
+
data={/* homeRuns */}
|
|
47
|
+
title="Career home run leaders"
|
|
48
|
+
dek="In baseball, a home run (also known as a "dinger" or "tater") occurs when a batter hits the ball over the outfield fence. When a home run is hit, the batter and any runners on base are able to score."
|
|
49
|
+
notes="Note: As of Opening Day 2023"
|
|
50
|
+
source="Source: Baseball Reference"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Truncated
|
|
55
|
+
|
|
56
|
+
```svelte
|
|
57
|
+
<Table data={/* homeRuns */} truncated={true} source="Source: Baseball Reference" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Paginated
|
|
61
|
+
|
|
62
|
+
```svelte
|
|
63
|
+
<Table
|
|
64
|
+
data={/* pressFreedom */}
|
|
65
|
+
paginated={true}
|
|
66
|
+
title="Press Freedom Index"
|
|
67
|
+
source="Source: Reporters Without Borders"
|
|
68
|
+
/>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Search bar
|
|
72
|
+
|
|
73
|
+
```svelte
|
|
74
|
+
<Table
|
|
75
|
+
data={/* pressFreedom */}
|
|
76
|
+
searchable={true}
|
|
77
|
+
paginated={true}
|
|
78
|
+
searchPlaceholder="Search press freedom data"
|
|
79
|
+
title="Press Freedom Index"
|
|
80
|
+
source="Source: Reporters Without Borders"
|
|
81
|
+
/>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Filter
|
|
85
|
+
|
|
86
|
+
```svelte
|
|
87
|
+
<Table
|
|
88
|
+
data={/* pressFreedom */}
|
|
89
|
+
paginated={true}
|
|
90
|
+
filterField="Region"
|
|
91
|
+
filterLabel="regions"
|
|
92
|
+
title="Press Freedom Index"
|
|
93
|
+
notes="Source: Reporters Without Borders"
|
|
94
|
+
/>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Search and filter
|
|
98
|
+
|
|
99
|
+
```svelte
|
|
100
|
+
<Table
|
|
101
|
+
data={/* pressFreedom */}
|
|
102
|
+
searchable={true}
|
|
103
|
+
paginated={true}
|
|
104
|
+
filterField="Region"
|
|
105
|
+
filterLabel="regions"
|
|
106
|
+
title="Press Freedom Index"
|
|
107
|
+
dek="Reporters Without Borders ranks countries based on their level of press freedom using criteria such as the degree of media pluralism and violence against journalists."
|
|
108
|
+
source="Source: Reporters Without Borders"
|
|
109
|
+
/>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Sort
|
|
113
|
+
|
|
114
|
+
```svelte
|
|
115
|
+
<Table
|
|
116
|
+
data={/* pressFreedom */}
|
|
117
|
+
sortable={true}
|
|
118
|
+
paginated={true}
|
|
119
|
+
sortField="Score"
|
|
120
|
+
sortDirection="descending"
|
|
121
|
+
title="Press Freedom Index"
|
|
122
|
+
notes="Note: data as of 2018"
|
|
123
|
+
source="Source: Reporters Without Borders"
|
|
124
|
+
/>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Format
|
|
128
|
+
|
|
129
|
+
```svelte
|
|
130
|
+
<Table
|
|
131
|
+
data={/* richestWomen */}
|
|
132
|
+
fieldFormatters={{
|
|
133
|
+
'Net worth (in billions)': currencyFormat as Formatter<unknown>,
|
|
134
|
+
}}
|
|
135
|
+
sortable={true}
|
|
136
|
+
sortField="Net worth (in billions)"
|
|
137
|
+
sortDirection="descending"
|
|
138
|
+
title="The Richest Women in the World"
|
|
139
|
+
source="Source: Forbes"
|
|
140
|
+
/>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Documentation
|
|
144
|
+
|
|
145
|
+
# Table
|
|
146
|
+
|
|
147
|
+
The `Table` component presents data as a table that you can make searchable, filtereable, sortable, or paginated.
|
|
148
|
+
|
|
149
|
+
```svelte
|
|
150
|
+
<script>
|
|
151
|
+
import { Table } from '@reuters-graphics/graphics-components';
|
|
152
|
+
|
|
153
|
+
import data from './data.json'; // Import your data
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<Table {data} />
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Text elements
|
|
160
|
+
|
|
161
|
+
Set the `title`, `dek`, `notes` and `source` options to add supporting metadata above and below the table.
|
|
162
|
+
|
|
163
|
+
```svelte
|
|
164
|
+
<Table
|
|
165
|
+
data={yourData}
|
|
166
|
+
title="Career home run leaders"
|
|
167
|
+
dek={`In baseball,
|
|
168
|
+
a home run (also known as a "dinger" or "tater") occurs when a batter hits the
|
|
169
|
+
ball over the outfield fence. When a home run is hit, the batter and any runners
|
|
170
|
+
on base are able to score.`}
|
|
171
|
+
notes="Note: As of Opening Day 2023"
|
|
172
|
+
source="Source: Baseball Reference"
|
|
173
|
+
/>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Truncated
|
|
177
|
+
|
|
178
|
+
When your table has 10 or more rows, consider clipping it by setting the `truncated` option. When it is enabled, the table is clipped and readers must click a button below the table to see all rows.
|
|
179
|
+
|
|
180
|
+
By default, this configuration will limit the table to 5 records. Change the cutoff point by adjusting the `truncateLength` option.
|
|
181
|
+
|
|
182
|
+
This is a good option for simple tables with between 10 and 30 rows. It works best when the table doesn't require interactivity.
|
|
183
|
+
|
|
184
|
+
```svelte
|
|
185
|
+
<Table data={yourData} truncated={true} source="Source: Baseball Reference" />
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Paginated
|
|
189
|
+
|
|
190
|
+
When your table has many rows, you should consider breaking it up into pages by setting `paginated` to `true`. When it is enabled, readers can leaf through the data using a set of buttons below the table.
|
|
191
|
+
|
|
192
|
+
By default, there are 25 records per page. Change the number by adjusting the `pageSize` option.
|
|
193
|
+
|
|
194
|
+
This is a good option when publishing large tables for readers to explore. It works well with interactive features like searching and filters.
|
|
195
|
+
|
|
196
|
+
```svelte
|
|
197
|
+
<Table
|
|
198
|
+
data={yourData}
|
|
199
|
+
paginated={true}
|
|
200
|
+
title="Press Freedom Index"
|
|
201
|
+
source="Reporters Without Borders"
|
|
202
|
+
/>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Search bar
|
|
206
|
+
|
|
207
|
+
Allow users to search the table by setting the optional `searchable` option to `true`. Modify the default text that appears in the box by setting `searchPlaceholder` to a different placeholder text.
|
|
208
|
+
|
|
209
|
+
```svelte
|
|
210
|
+
<Table
|
|
211
|
+
data={yourData}
|
|
212
|
+
searchable={true}
|
|
213
|
+
paginated={true}
|
|
214
|
+
searchPlaceholder="Search press freedom data"
|
|
215
|
+
,
|
|
216
|
+
title="Press Freedom Index"
|
|
217
|
+
notes="Source: Reporters Without Borders"
|
|
218
|
+
/>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Filter
|
|
222
|
+
|
|
223
|
+
Allow users to filter the table by providing one of the attributes as the `filterField`. This works best with categorical columns.
|
|
224
|
+
|
|
225
|
+
Set `filterLabel` to make the category name more readable. For example, if the column is `Region`, set `filterLabel` to `regions` or `regions of the world`.
|
|
226
|
+
|
|
227
|
+
```svelte
|
|
228
|
+
<Table
|
|
229
|
+
data={yourData}
|
|
230
|
+
filterField="Region"
|
|
231
|
+
filterLabel="regions"
|
|
232
|
+
paginated={true}
|
|
233
|
+
title="Press Freedom Index"
|
|
234
|
+
notes="Source: Reporters Without Borders"
|
|
235
|
+
/>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Search and filter
|
|
239
|
+
|
|
240
|
+
Feel free to both search and filter.
|
|
241
|
+
|
|
242
|
+
```svelte
|
|
243
|
+
<Table
|
|
244
|
+
data={yourData}
|
|
245
|
+
searchable={true}
|
|
246
|
+
paginated={true}
|
|
247
|
+
filterField="Region"
|
|
248
|
+
filterLabel="regions"
|
|
249
|
+
title="Press Freedom Index"
|
|
250
|
+
dek="Reporters Without Borders ranks countries based on their level of press freedom using criteria such as the degree of media pluralism and violence against journalists."
|
|
251
|
+
source="Source: Reporters Without Borders"
|
|
252
|
+
/>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
````
|
|
256
|
+
|
|
257
|
+
## Sort
|
|
258
|
+
|
|
259
|
+
Allow users to sort the table by setting `sortable` to `true`. Specify the starting order by setting `sortField` to a column name and `sortDirection` to `ascending` or `descending`.
|
|
260
|
+
|
|
261
|
+
By default, all fields are sortable. If you'd like to limit the columns where sorting is allowed, provide a list to the `sortableFields` option.
|
|
262
|
+
|
|
263
|
+
```svelte
|
|
264
|
+
<Table
|
|
265
|
+
data={yourData}
|
|
266
|
+
sortable={true}
|
|
267
|
+
paginated={true}
|
|
268
|
+
sortField="Score"
|
|
269
|
+
sortDirection="descending"
|
|
270
|
+
title="Press Freedom Index"
|
|
271
|
+
source="Source: Reporters Without Borders"
|
|
272
|
+
/>
|
|
273
|
+
````
|
|
274
|
+
|
|
275
|
+
## Format
|
|
276
|
+
|
|
277
|
+
Format column values by supplying functions keyed to field names with the `fieldFormatters` option. Columns are still sorted using the raw, underlying values.
|
|
278
|
+
|
|
279
|
+
Among other things, this feature can be used to provide a unit of measurement, such as `$` or `%`, with numeric fields.
|
|
280
|
+
|
|
281
|
+
```svelte
|
|
282
|
+
<script lang="ts">
|
|
283
|
+
const fieldFormatters = {
|
|
284
|
+
// The key must match the column name in the data exactly
|
|
285
|
+
'Net worth (in billions)': (v) => '$' + v.toFixed(1),
|
|
286
|
+
};
|
|
287
|
+
</script>
|
|
288
|
+
|
|
289
|
+
<Table
|
|
290
|
+
data={yourData}
|
|
291
|
+
{fieldFormatters}
|
|
292
|
+
sortable={true}
|
|
293
|
+
sortField="Net worth (in billions)"
|
|
294
|
+
sortDirection="descending"
|
|
295
|
+
title="The Richest Women in the World"
|
|
296
|
+
source="Source: Forbes"
|
|
297
|
+
/>
|
|
298
|
+
```
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Theme
|
|
2
|
+
|
|
3
|
+
**Category:** Components/Theming/Theme
|
|
4
|
+
|
|
5
|
+
**Import:** `import { Theme } from '@reuters-graphics/graphics-components'`
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Prop | Type | Default | Required | Description |
|
|
10
|
+
|------|------|---------|:--------:|-------------|
|
|
11
|
+
| `theme` | `CustomThemeConfig \| ThemeConfig` | `{}` | | Custom theme object. Can be a partial theme with just what you want to change. |
|
|
12
|
+
| `base` | `Base` | `'light'` | | Base theme is one of `light` or `dark` and will be merged with your custom theme to fill in any values you don't explicitly set. Options: `light`, `dark` |
|
|
13
|
+
| `children` | `Snippet` | — | ✓ | Content wrapped inside `Theme` |
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
### Demo
|
|
18
|
+
|
|
19
|
+
```svelte
|
|
20
|
+
<div class="reset-article">
|
|
21
|
+
<Theme theme={themes.light} base="light">
|
|
22
|
+
<ThemedPage />
|
|
23
|
+
</Theme>
|
|
24
|
+
</div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Custom theme
|
|
28
|
+
|
|
29
|
+
```svelte
|
|
30
|
+
<Theme
|
|
31
|
+
base="dark"
|
|
32
|
+
theme={{
|
|
33
|
+
colour: { accent: 'var(--tr-light-orange)' },
|
|
34
|
+
font: { family: { hed: '"Newsreader Text", serif' } },
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<ThemedPage />
|
|
38
|
+
</Theme>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Custom font
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<Theme
|
|
45
|
+
base="light"
|
|
46
|
+
theme={{
|
|
47
|
+
font: { family: { hed: 'Indie Flower', body: 'Indie Flower' } },
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<div class="gfont">
|
|
51
|
+
<Headline
|
|
52
|
+
hed={'Reuters Graphics Interactive'}
|
|
53
|
+
dek={'The beginning of a beautiful page'}
|
|
54
|
+
section={'Global news'}
|
|
55
|
+
/>
|
|
56
|
+
<BodyText
|
|
57
|
+
text={'Bacon ipsum dolor amet cupim porchetta chuck buffalo sirloin beef. Biltong ham brisket tenderloin hamburger doner.'}
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
</Theme>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Background patterns
|
|
64
|
+
|
|
65
|
+
```svelte
|
|
66
|
+
<div id="pattern-bg">
|
|
67
|
+
<Theme
|
|
68
|
+
base="dark"
|
|
69
|
+
theme={{
|
|
70
|
+
colour: { background: 'transparent' },
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<SiteHeader />
|
|
74
|
+
<Headline
|
|
75
|
+
hed={'Reuters Graphics Interactive'}
|
|
76
|
+
dek={'The beginning of a beautiful page'}
|
|
77
|
+
section={'Global news'}
|
|
78
|
+
/>
|
|
79
|
+
<BodyText
|
|
80
|
+
text={'Bacon ipsum dolor amet cupim porchetta chuck buffalo sirloin beef. Biltong ham brisket tenderloin hamburger doner.'}
|
|
81
|
+
/>
|
|
82
|
+
</Theme>
|
|
83
|
+
</div>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Inheritance
|
|
87
|
+
|
|
88
|
+
```svelte
|
|
89
|
+
<Theme theme={themes.light}>
|
|
90
|
+
<div class="themed">
|
|
91
|
+
<p>Theme</p>
|
|
92
|
+
<Theme theme={themes.dark}>
|
|
93
|
+
<div class="themed">
|
|
94
|
+
<p>Sub-theme</p>
|
|
95
|
+
<Theme theme={themes.light}>
|
|
96
|
+
<div class="themed">
|
|
97
|
+
<p>Sub-sub</p>
|
|
98
|
+
</div>
|
|
99
|
+
</Theme>
|
|
100
|
+
<Theme
|
|
101
|
+
theme={{
|
|
102
|
+
colour: { background: 'steelblue', 'text-primary': '#fff' },
|
|
103
|
+
font: { family: { note: '"Newsreader Text", serif' } },
|
|
104
|
+
}}
|
|
105
|
+
base="dark"
|
|
106
|
+
>
|
|
107
|
+
<div class="themed">
|
|
108
|
+
<p>Sub-sub sibling</p>
|
|
109
|
+
</div>
|
|
110
|
+
</Theme>
|
|
111
|
+
</div>
|
|
112
|
+
</Theme>
|
|
113
|
+
</div>
|
|
114
|
+
</Theme>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Documentation
|
|
118
|
+
|
|
119
|
+
# Theme
|
|
120
|
+
|
|
121
|
+
The `Theme` component wraps your page content and uses [CSS variables](../?path=/docs/scss-css-variables--page) to set major colour and typography styles for your page. All the components from this library that are added to your page will use the CSS variables set by `Theme`.
|
|
122
|
+
|
|
123
|
+
Use the [theme builder](?path=/docs/components-theming-theme-builder--docs) to test custom themes.
|
|
124
|
+
|
|
125
|
+
```svelte
|
|
126
|
+
<script>
|
|
127
|
+
import { Theme } from '@reuters-graphics/graphics-components';
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<Theme base="light">
|
|
131
|
+
<!-- Page content, now styled according to your theme! -->
|
|
132
|
+
</Theme>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> In the graphics kit, the `Theme` is set in both `pages/+page.svelte` and in `App.svelte`.
|
|
136
|
+
|
|
137
|
+
## Custom theme
|
|
138
|
+
|
|
139
|
+
You can customise your page's theme in two ways:
|
|
140
|
+
|
|
141
|
+
- Choose the `base` theme, either `light` or `dark`
|
|
142
|
+
- Pass a custom theme object to the `theme` prop, which will override styles in the `base` theme.
|
|
143
|
+
|
|
144
|
+
Use the [theme builder](?path=/docs/components-theming-theme-builder--docs) to see what properties you can customise.
|
|
145
|
+
|
|
146
|
+
```svelte
|
|
147
|
+
<Theme
|
|
148
|
+
base="dark"
|
|
149
|
+
theme={{
|
|
150
|
+
colour: { accent: 'var(--tr-light-orange)' },
|
|
151
|
+
font: { family: { hed: '"Newsreader Text", serif' } },
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<!-- Page content -->
|
|
155
|
+
</Theme>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
> **Note:** The `Theme` component only styles child components or elements, so if you're changing the background colour of your page, make sure to also set the `background-color` on your `body` element in global SCSS.
|
|
159
|
+
>
|
|
160
|
+
> ```scss
|
|
161
|
+
> // global.scss
|
|
162
|
+
> body {
|
|
163
|
+
> background-color: #2e3440;
|
|
164
|
+
> }
|
|
165
|
+
> ```
|
|
166
|
+
|
|
167
|
+
## Custom font
|
|
168
|
+
|
|
169
|
+
To use typefaces other than the defaults provided by the graphics kit, download the font files from services such as [Google Fonts](https://fonts.google.com/) or [Adobe Typekit](https://fonts.adobe.com/). Make a folder called `fonts` inside `statics/` and put the font file -- for example, `IndieFlower-Regular.ttf` downloaded from [Google Fonts](https://fonts.google.com/share?selection.family=Indie+Flower) -- in `statics/fonts/`.
|
|
170
|
+
|
|
171
|
+
Then, declare it as a `@font-face` in `global.scss`:
|
|
172
|
+
|
|
173
|
+
```scss
|
|
174
|
+
/* global.scss in the graphics kit */
|
|
175
|
+
@font-face {
|
|
176
|
+
// If you're unsure of the font-family name,
|
|
177
|
+
// click on "Get embed code" on the Google font page and check the CSS class.
|
|
178
|
+
font-family: 'Indie Flower';
|
|
179
|
+
|
|
180
|
+
// Path to the font file. Change format depending on the font file type.
|
|
181
|
+
src: url('/fonts/IndieFlower-Regular.ttf') format('truetype');
|
|
182
|
+
font-weight: normal; // Optional
|
|
183
|
+
font-style: normal; // Optional
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Finally, pass the font to the appropriate text type in `Theme`:
|
|
188
|
+
|
|
189
|
+
```svelte
|
|
190
|
+
<Theme
|
|
191
|
+
base="light"
|
|
192
|
+
theme={{
|
|
193
|
+
font: {
|
|
194
|
+
family: {
|
|
195
|
+
hed: 'IndieFlower', // Set header text font to `IndieFlower`
|
|
196
|
+
body: 'IndieFlower', // Set body text font to `IndieFlower`
|
|
197
|
+
// etc...
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
<!-- Page content -->
|
|
203
|
+
</Theme>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Background patterns
|
|
207
|
+
|
|
208
|
+
To use a background pattern or image, set the background colour property in `Theme` to `transparent`:
|
|
209
|
+
|
|
210
|
+
```svelte
|
|
211
|
+
<Theme
|
|
212
|
+
base="dark"
|
|
213
|
+
theme={{
|
|
214
|
+
colour: { background: 'transparent' },
|
|
215
|
+
}}
|
|
216
|
+
>
|
|
217
|
+
<!-- Page content -->
|
|
218
|
+
</Theme>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Then in `global.scss`, set your image, which should be stored in `statics/images/`, as `background-image`:
|
|
222
|
+
|
|
223
|
+
```scss
|
|
224
|
+
/* global.scss */
|
|
225
|
+
body {
|
|
226
|
+
background-image: url('/images/my-pattern.png');
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
You may also want to override the background on the header nav if it conflicts with your background, especially the dropdown menu:
|
|
231
|
+
|
|
232
|
+
```scss
|
|
233
|
+
/* global.scss
|
|
234
|
+
Main nav container */
|
|
235
|
+
.nav-container .inner {
|
|
236
|
+
background: darkblue !important;
|
|
237
|
+
/* Dropdown menu */
|
|
238
|
+
.dropdown {
|
|
239
|
+
background: darkblue !important;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/* Mobile nav overlay */
|
|
243
|
+
header + .overlay {
|
|
244
|
+
background: darkblue !important;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Inheritance
|
|
249
|
+
|
|
250
|
+
Styles that use `Theme`'s CSS variables will always use those set by the nearest parent `Theme`. That lets you change the theme for parts of your page by simply wrapping that bit in a new `Theme` with different styles.
|
|
251
|
+
|
|
252
|
+
The demo below shows a more complex example of nesting themes, but more likely you'll so something like this:
|
|
253
|
+
|
|
254
|
+
```svelte
|
|
255
|
+
<script>
|
|
256
|
+
import { Theme } from '@reuters-graphics/graphics-components';
|
|
257
|
+
</script>
|
|
258
|
+
|
|
259
|
+
<Theme>
|
|
260
|
+
<!-- Page content styled with the default light theme. -->
|
|
261
|
+
<Theme theme={{ colour: { background: 'lightgrey' } }}>
|
|
262
|
+
<!-- A darker background for this section. -->
|
|
263
|
+
</Theme>
|
|
264
|
+
<!-- Back to normal here... -->
|
|
265
|
+
</Theme>
|
|
266
|
+
```
|