@guardian/interactive-component-library 0.5.2 → 0.5.4
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/components/molecules/canvas-map/lib/Feature.d.ts +4 -1
- package/dist/components/molecules/canvas-map/lib/Feature.js +3 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +65 -16
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +28 -4
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +36 -10
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +6 -3
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +0 -2
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +14 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +52 -8
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +61 -5
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +224 -26
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +13 -6
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +12 -42
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +24 -6
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +18 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +42 -11
- package/dist/components/molecules/canvas-map/lib/styles/Style.js +7 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +184 -11
- package/dist/components/molecules/canvas-map/lib/styles/Text.js +18 -3
- package/dist/components/molecules/result-summary/index.d.ts +3 -1
- package/dist/components/molecules/result-summary/index.js +38 -5
- package/dist/components/molecules/result-summary/style.module.css.js +12 -3
- package/dist/style.css +21 -2
- package/package.json +1 -1
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: add leader 'style' option, e.g. kink, direct, manhattan, etc.
|
|
3
|
+
*
|
|
4
|
+
* @typedef CalloutOptions
|
|
5
|
+
* @property {{ x: number, y: number }} offsetBy { x, y } offset in pixels, relative to the text position.
|
|
6
|
+
*
|
|
7
|
+
* E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
|
|
8
|
+
* @property {number} [leaderGap=5] Distance in pixels between the leader line and the text
|
|
9
|
+
* @property {string} [leaderColor="#121212"] Hex colour of the leader line
|
|
10
|
+
* @property {number} [leaderWidth=1] Stroke width of the leader line
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @typedef IconOptions
|
|
14
|
+
*
|
|
15
|
+
* @property {"circle"} [shape="circle"]
|
|
16
|
+
* Shape of the icon.
|
|
17
|
+
*
|
|
18
|
+
* TODO: add more shapes?
|
|
19
|
+
* @property {"left" | "right" | "center" } [position="left"] Position of the icon relative to the text.
|
|
20
|
+
*
|
|
21
|
+
* If "center", the icon is placed exactly on the text's coordinates. Use the `anchor` and
|
|
22
|
+
* `radialOffset` properties of `Text` to place the text relative to the icon.
|
|
23
|
+
* place the text relative to the icon.
|
|
24
|
+
* Position of the icon relative to the text
|
|
25
|
+
* @property {number} [size=10]
|
|
26
|
+
* Size of the icon in pixels
|
|
27
|
+
* @property {number} [padding]
|
|
28
|
+
* Distance in pixels between the icon and the text
|
|
29
|
+
* @property {string} [color]
|
|
30
|
+
* Hex colour of the icon, e.g. "#ff0000"
|
|
31
|
+
*
|
|
32
|
+
* For more advanced styling, use the `style` property.
|
|
33
|
+
* @property {import('../styles/Style').Style} [style]
|
|
34
|
+
* Style of the icon.
|
|
35
|
+
*
|
|
36
|
+
* Note that `stroke.position: "inside"` is not currently supported.
|
|
37
|
+
*/
|
|
1
38
|
/**
|
|
2
39
|
* @typedef TextStyle
|
|
3
40
|
* @property {string} content - The text to render
|
|
@@ -10,28 +47,36 @@
|
|
|
10
47
|
* @property {string} [fontSize="17px"] - The font size of the text
|
|
11
48
|
* @property {string} [fontWeight="400"] - The font weight of the text
|
|
12
49
|
* @property {number} [radialOffset=0] - The radial offset of the text in ems
|
|
50
|
+
* @property {CalloutOptions} [callout] Options for offsetting the text and drawing a leader line.
|
|
51
|
+
*
|
|
52
|
+
* If not provided, no leader line is drawn.
|
|
53
|
+
* @property {IconOptions} [icon] Options for a simple icon displayed next to the text.
|
|
54
|
+
*
|
|
55
|
+
* If not provided, no icon is drawn.
|
|
13
56
|
*/
|
|
14
57
|
/**
|
|
15
58
|
* Class that represents a text style
|
|
16
|
-
* @
|
|
59
|
+
* @class
|
|
17
60
|
* @implements {TextStyle}
|
|
18
61
|
*/
|
|
19
62
|
export class Text implements TextStyle {
|
|
20
63
|
/**
|
|
21
64
|
* Create a text element style
|
|
22
65
|
* @constructor
|
|
23
|
-
* @param {TextStyle} [options]
|
|
66
|
+
* @param {TextStyle} [options] Style options
|
|
24
67
|
*/
|
|
25
68
|
constructor(options?: TextStyle);
|
|
26
|
-
content:
|
|
27
|
-
anchor:
|
|
28
|
-
fontFamily:
|
|
29
|
-
fontSize:
|
|
30
|
-
fontWeight:
|
|
31
|
-
lineHeight:
|
|
32
|
-
color:
|
|
33
|
-
textShadow:
|
|
34
|
-
radialOffset:
|
|
69
|
+
content: string;
|
|
70
|
+
anchor: string;
|
|
71
|
+
fontFamily: string;
|
|
72
|
+
fontSize: string;
|
|
73
|
+
fontWeight: string;
|
|
74
|
+
lineHeight: number;
|
|
75
|
+
color: string;
|
|
76
|
+
textShadow: string;
|
|
77
|
+
radialOffset: number;
|
|
78
|
+
callout: CalloutOptions;
|
|
79
|
+
icon: IconOptions;
|
|
35
80
|
/**
|
|
36
81
|
* Get the relative translation for the text element based on its anchor. The translation does not take `radialOffset` into account
|
|
37
82
|
* @private
|
|
@@ -56,6 +101,112 @@ export class Text implements TextStyle {
|
|
|
56
101
|
*/
|
|
57
102
|
getTransform(elementWidth: number, elementHeight: number): string;
|
|
58
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* TODO: add leader 'style' option, e.g. kink, direct, manhattan, etc.
|
|
106
|
+
*/
|
|
107
|
+
export type CalloutOptions = {
|
|
108
|
+
/**
|
|
109
|
+
* { x, y } offset in pixels, relative to the text position.
|
|
110
|
+
*
|
|
111
|
+
* E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* { x, y } offset in pixels, relative to the text position.
|
|
115
|
+
*
|
|
116
|
+
* E.g. { x: 10, y: 20 } will move the callout 10 pixels to the right and 20 pixels down.
|
|
117
|
+
*/
|
|
118
|
+
offsetBy: {
|
|
119
|
+
x: number;
|
|
120
|
+
y: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Distance in pixels between the leader line and the text
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Distance in pixels between the leader line and the text
|
|
127
|
+
*/
|
|
128
|
+
leaderGap?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Hex colour of the leader line
|
|
131
|
+
*/
|
|
132
|
+
/**
|
|
133
|
+
* Hex colour of the leader line
|
|
134
|
+
*/
|
|
135
|
+
leaderColor?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Stroke width of the leader line
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* Stroke width of the leader line
|
|
141
|
+
*/
|
|
142
|
+
leaderWidth?: number;
|
|
143
|
+
};
|
|
144
|
+
export type IconOptions = {
|
|
145
|
+
/**
|
|
146
|
+
* Shape of the icon.
|
|
147
|
+
*
|
|
148
|
+
* TODO: add more shapes?
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Shape of the icon.
|
|
152
|
+
*
|
|
153
|
+
* TODO: add more shapes?
|
|
154
|
+
*/
|
|
155
|
+
shape?: "circle";
|
|
156
|
+
/**
|
|
157
|
+
* Position of the icon relative to the text.
|
|
158
|
+
*
|
|
159
|
+
* If "center", the icon is placed exactly on the text's coordinates. Use the `anchor` and
|
|
160
|
+
* `radialOffset` properties of `Text` to place the text relative to the icon.
|
|
161
|
+
* place the text relative to the icon.
|
|
162
|
+
* Position of the icon relative to the text
|
|
163
|
+
*/
|
|
164
|
+
/**
|
|
165
|
+
* Position of the icon relative to the text.
|
|
166
|
+
*
|
|
167
|
+
* If "center", the icon is placed exactly on the text's coordinates. Use the `anchor` and
|
|
168
|
+
* `radialOffset` properties of `Text` to place the text relative to the icon.
|
|
169
|
+
* place the text relative to the icon.
|
|
170
|
+
* Position of the icon relative to the text
|
|
171
|
+
*/
|
|
172
|
+
position?: "left" | "right" | "center";
|
|
173
|
+
/**
|
|
174
|
+
* Size of the icon in pixels
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Size of the icon in pixels
|
|
178
|
+
*/
|
|
179
|
+
size?: number;
|
|
180
|
+
/**
|
|
181
|
+
* Distance in pixels between the icon and the text
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Distance in pixels between the icon and the text
|
|
185
|
+
*/
|
|
186
|
+
padding?: number;
|
|
187
|
+
/**
|
|
188
|
+
* Hex colour of the icon, e.g. "#ff0000"
|
|
189
|
+
*
|
|
190
|
+
* For more advanced styling, use the `style` property.
|
|
191
|
+
*/
|
|
192
|
+
/**
|
|
193
|
+
* Hex colour of the icon, e.g. "#ff0000"
|
|
194
|
+
*
|
|
195
|
+
* For more advanced styling, use the `style` property.
|
|
196
|
+
*/
|
|
197
|
+
color?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Style of the icon.
|
|
200
|
+
*
|
|
201
|
+
* Note that `stroke.position: "inside"` is not currently supported.
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* Style of the icon.
|
|
205
|
+
*
|
|
206
|
+
* Note that `stroke.position: "inside"` is not currently supported.
|
|
207
|
+
*/
|
|
208
|
+
style?: import('../styles/Style').Style;
|
|
209
|
+
};
|
|
59
210
|
export type TextStyle = {
|
|
60
211
|
/**
|
|
61
212
|
* - The text to render
|
|
@@ -127,6 +278,28 @@ export type TextStyle = {
|
|
|
127
278
|
* - The radial offset of the text in ems
|
|
128
279
|
*/
|
|
129
280
|
radialOffset?: number;
|
|
281
|
+
/**
|
|
282
|
+
* Options for offsetting the text and drawing a leader line.
|
|
283
|
+
*
|
|
284
|
+
* If not provided, no leader line is drawn.
|
|
285
|
+
*/
|
|
286
|
+
/**
|
|
287
|
+
* Options for offsetting the text and drawing a leader line.
|
|
288
|
+
*
|
|
289
|
+
* If not provided, no leader line is drawn.
|
|
290
|
+
*/
|
|
291
|
+
callout?: CalloutOptions;
|
|
292
|
+
/**
|
|
293
|
+
* Options for a simple icon displayed next to the text.
|
|
294
|
+
*
|
|
295
|
+
* If not provided, no icon is drawn.
|
|
296
|
+
*/
|
|
297
|
+
/**
|
|
298
|
+
* Options for a simple icon displayed next to the text.
|
|
299
|
+
*
|
|
300
|
+
* If not provided, no icon is drawn.
|
|
301
|
+
*/
|
|
302
|
+
icon?: IconOptions;
|
|
130
303
|
};
|
|
131
304
|
/**
|
|
132
305
|
* *
|
|
@@ -13,9 +13,10 @@ class Text {
|
|
|
13
13
|
/**
|
|
14
14
|
* Create a text element style
|
|
15
15
|
* @constructor
|
|
16
|
-
* @param {TextStyle} [options]
|
|
16
|
+
* @param {TextStyle} [options] Style options
|
|
17
17
|
*/
|
|
18
18
|
constructor(options) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
19
20
|
this.content = options == null ? void 0 : options.content;
|
|
20
21
|
this.anchor = (options == null ? void 0 : options.anchor) || TextAnchor.CENTER;
|
|
21
22
|
this.fontFamily = (options == null ? void 0 : options.fontFamily) || "var(--text-sans)";
|
|
@@ -23,8 +24,22 @@ class Text {
|
|
|
23
24
|
this.fontWeight = (options == null ? void 0 : options.fontWeight) || "400";
|
|
24
25
|
this.lineHeight = (options == null ? void 0 : options.lineHeight) || 1.3;
|
|
25
26
|
this.color = (options == null ? void 0 : options.color) || "#121212";
|
|
26
|
-
this.textShadow = (options == null ? void 0 : options.textShadow)
|
|
27
|
+
this.textShadow = (options == null ? void 0 : options.textShadow) ?? "1px 1px 0px #f6f6f6, -1px -1px 0px #f6f6f6, -1px 1px 0px #f6f6f6, 1px -1px #f6f6f6";
|
|
27
28
|
this.radialOffset = (options == null ? void 0 : options.radialOffset) || 0;
|
|
29
|
+
if (options.callout) {
|
|
30
|
+
this.callout = options.callout;
|
|
31
|
+
(_a = this.callout).offsetBy ?? (_a.offsetBy = { x: 0, y: 0 });
|
|
32
|
+
(_b = this.callout).leaderGap ?? (_b.leaderGap = 5);
|
|
33
|
+
(_c = this.callout).leaderColor ?? (_c.leaderColor = "#121212");
|
|
34
|
+
(_d = this.callout).leaderWidth ?? (_d.leaderWidth = 1);
|
|
35
|
+
}
|
|
36
|
+
if (options.icon) {
|
|
37
|
+
this.icon = options.icon;
|
|
38
|
+
(_e = this.icon).shape ?? (_e.shape = "circle");
|
|
39
|
+
(_f = this.icon).position ?? (_f.position = "left");
|
|
40
|
+
(_g = this.icon).size ?? (_g.size = 10);
|
|
41
|
+
(_h = this.icon).padding ?? (_h.padding = 5);
|
|
42
|
+
}
|
|
28
43
|
}
|
|
29
44
|
/**
|
|
30
45
|
* Get the relative translation for the text element based on its anchor. The translation does not take `radialOffset` into account
|
|
@@ -65,7 +80,7 @@ class Text {
|
|
|
65
80
|
const translate = this._getRelativeTranslation();
|
|
66
81
|
let x = translate.x / 100 * elementWidth;
|
|
67
82
|
let y = translate.y / 100 * elementHeight;
|
|
68
|
-
const radialOffsetInPixels = this.radialOffset * this.fontSize.replace("px", "");
|
|
83
|
+
const radialOffsetInPixels = this.radialOffset * parseInt(this.fontSize.replace("px", ""));
|
|
69
84
|
switch (this.anchor) {
|
|
70
85
|
case TextAnchor.TOP:
|
|
71
86
|
y += radialOffsetInPixels;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export function ResultSummary({ previous, next, title, text, timestamp, styles, }: {
|
|
1
|
+
export function ResultSummary({ previous, next, title, text, timestamp, onClick, isSlim, styles, }: {
|
|
2
2
|
previous: any;
|
|
3
3
|
next: any;
|
|
4
4
|
title: any;
|
|
5
5
|
text: any;
|
|
6
6
|
timestamp: any;
|
|
7
|
+
onClick: any;
|
|
8
|
+
isSlim?: boolean;
|
|
7
9
|
styles: any;
|
|
8
10
|
}): import("preact").JSX.Element;
|
|
@@ -6,7 +6,9 @@ import { ControlChange } from "../control-change/index.js";
|
|
|
6
6
|
import "../topline-result/index.js";
|
|
7
7
|
import "../page-section/index.js";
|
|
8
8
|
import "d3-scale";
|
|
9
|
+
import { GradientIcon } from "../../particles/gradient-icon/index.js";
|
|
9
10
|
import "../../particles/info-button/index.js";
|
|
11
|
+
import { CircleIcon } from "../../particles/circle-icon/index.js";
|
|
10
12
|
import { RelativeTimeSentence } from "../../particles/relative-time-sentence/index.js";
|
|
11
13
|
import defaultStyles from "./style.module.css.js";
|
|
12
14
|
import "preact";
|
|
@@ -26,14 +28,45 @@ function ResultSummary({
|
|
|
26
28
|
title,
|
|
27
29
|
text,
|
|
28
30
|
timestamp,
|
|
31
|
+
onClick,
|
|
32
|
+
isSlim = false,
|
|
29
33
|
styles
|
|
30
34
|
}) {
|
|
31
35
|
styles = mergeStyles({ ...defaultStyles }, styles);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/* @__PURE__ */
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (isSlim) {
|
|
37
|
+
let hasChanged = next !== previous;
|
|
38
|
+
return /* @__PURE__ */ jsxs(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
className: `${styles.container} ${styles.containerSlim}`,
|
|
42
|
+
onClick,
|
|
43
|
+
children: [
|
|
44
|
+
hasChanged ? /* @__PURE__ */ jsx(
|
|
45
|
+
GradientIcon,
|
|
46
|
+
{
|
|
47
|
+
previous,
|
|
48
|
+
next,
|
|
49
|
+
styles: {
|
|
50
|
+
previous: styles.previous,
|
|
51
|
+
next: styles.next
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
) : /* @__PURE__ */ jsx(CircleIcon, { styles: { circle: `fill-color--${next}` } }),
|
|
55
|
+
/* @__PURE__ */ jsxs("p", { className: styles.titleSlim, children: [
|
|
56
|
+
title,
|
|
57
|
+
" "
|
|
58
|
+
] }),
|
|
59
|
+
/* @__PURE__ */ jsx(RelativeTimeSentence, { timeStamp: timestamp })
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.container, children: [
|
|
65
|
+
/* @__PURE__ */ jsx(ControlChange, { previous, next, text: title }),
|
|
66
|
+
/* @__PURE__ */ jsx("p", { className: styles.paragraph, children: text }),
|
|
67
|
+
/* @__PURE__ */ jsx(RelativeTimeSentence, { timeStamp: timestamp })
|
|
68
|
+
] });
|
|
69
|
+
}
|
|
37
70
|
}
|
|
38
71
|
export {
|
|
39
72
|
ResultSummary
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
const container = "
|
|
2
|
-
const
|
|
1
|
+
const container = "_container_14h9i_1";
|
|
2
|
+
const containerSlim = "_containerSlim_14h9i_12";
|
|
3
|
+
const titleSlim = "_titleSlim_14h9i_17";
|
|
4
|
+
const dateStampLinePosition = "_dateStampLinePosition_14h9i_27";
|
|
5
|
+
const paragraph = "_paragraph_14h9i_31";
|
|
3
6
|
const defaultStyles = {
|
|
4
7
|
container,
|
|
8
|
+
containerSlim,
|
|
9
|
+
titleSlim,
|
|
10
|
+
dateStampLinePosition,
|
|
5
11
|
paragraph
|
|
6
12
|
};
|
|
7
13
|
export {
|
|
8
14
|
container,
|
|
15
|
+
containerSlim,
|
|
16
|
+
dateStampLinePosition,
|
|
9
17
|
defaultStyles as default,
|
|
10
|
-
paragraph
|
|
18
|
+
paragraph,
|
|
19
|
+
titleSlim
|
|
11
20
|
};
|
package/dist/style.css
CHANGED
|
@@ -2443,7 +2443,7 @@ body ._header_1xpz0_150._fullWidth_1xpz0_39 {
|
|
|
2443
2443
|
color: var(--primary-text-color);
|
|
2444
2444
|
margin-top: var(--space-2);
|
|
2445
2445
|
}
|
|
2446
|
-
.
|
|
2446
|
+
._container_14h9i_1 {
|
|
2447
2447
|
background-color: var(--quaternary-bg-color);
|
|
2448
2448
|
border-radius: 4px;
|
|
2449
2449
|
padding: 4px 8px 6px 8px;
|
|
@@ -2454,7 +2454,26 @@ body ._header_1xpz0_150._fullWidth_1xpz0_39 {
|
|
|
2454
2454
|
height: 100%;
|
|
2455
2455
|
}
|
|
2456
2456
|
|
|
2457
|
-
.
|
|
2457
|
+
._containerSlim_14h9i_12 {
|
|
2458
|
+
min-width: 260px;
|
|
2459
|
+
display: inline-block;
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
._titleSlim_14h9i_17 {
|
|
2463
|
+
display: inline;
|
|
2464
|
+
color: var(--primary-text-color) !important;
|
|
2465
|
+
font-family: var(--text-sans) !important;
|
|
2466
|
+
font-size: var(--sans-small) !important;
|
|
2467
|
+
line-height: var(--sans-line-height) !important;
|
|
2468
|
+
font-weight: 700 !important;
|
|
2469
|
+
margin-left: var(--space-1) !important;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
._dateStampLinePosition_14h9i_27 {
|
|
2473
|
+
display: block;
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
._paragraph_14h9i_31 {
|
|
2458
2477
|
font-family: var(--text-sans);
|
|
2459
2478
|
font-size: var(--sans-xsmall);
|
|
2460
2479
|
line-height: var(--sans-line-height);
|