@guardian/interactive-component-library 0.1.0-alpha.11 → 0.1.0-alpha.12
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
|
|
2
|
-
import { useRef, useState, useLayoutEffect,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useRef, useState, useLayoutEffect, useCallback, useEffect, useMemo, useContext, useImperativeHandle } from "preact/hooks";
|
|
3
|
+
import { render, createElement, cloneElement, createContext, toChildArray } from "preact";
|
|
4
|
+
import { useSyncExternalStore, createPortal, forwardRef } from "preact/compat";
|
|
5
5
|
import { scaleLinear as scaleLinear$1 } from "d3-scale";
|
|
6
6
|
import { geoStream, geoAlbers, geoPath, geoMercator, geoContains } from "d3-geo";
|
|
7
7
|
const main = "";
|
|
@@ -224,50 +224,141 @@ function StackedBar({
|
|
|
224
224
|
children: content2
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
function shouldUpdate(oldState, newState) {
|
|
228
|
+
if (oldState === newState)
|
|
229
|
+
return false;
|
|
230
|
+
if (isObj(oldState) && isObj(newState)) {
|
|
231
|
+
for (let key in newState) {
|
|
232
|
+
if (oldState[key] !== newState[key])
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
function isObj(obj) {
|
|
240
|
+
return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
|
|
241
|
+
}
|
|
242
|
+
function createStore(initialStore) {
|
|
243
|
+
let store = initialStore;
|
|
244
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
245
|
+
function useStore(selectorFn = (store2) => store2) {
|
|
246
|
+
const subscribe = useCallback((updater) => {
|
|
247
|
+
const listener = {
|
|
248
|
+
updater,
|
|
249
|
+
selectorFn
|
|
250
|
+
};
|
|
251
|
+
listeners.add(listener);
|
|
252
|
+
return () => {
|
|
253
|
+
listeners.delete(listener);
|
|
254
|
+
};
|
|
255
|
+
}, []);
|
|
256
|
+
const syncedStore = useSyncExternalStore(subscribe, getStore, getServerStore);
|
|
257
|
+
return selectorFn(syncedStore);
|
|
258
|
+
}
|
|
259
|
+
function setStore(action) {
|
|
260
|
+
const oldStore = store;
|
|
261
|
+
store = action instanceof Function ? action(store) : action;
|
|
262
|
+
listeners.forEach(({
|
|
263
|
+
selectorFn,
|
|
264
|
+
updater
|
|
265
|
+
}) => {
|
|
266
|
+
const oldState = selectorFn(oldStore);
|
|
267
|
+
const newState = selectorFn(store);
|
|
268
|
+
if (shouldUpdate(oldState, newState))
|
|
269
|
+
updater(() => newState);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function getStore() {
|
|
273
|
+
return store;
|
|
274
|
+
}
|
|
275
|
+
function getServerStore() {
|
|
276
|
+
return initialStore;
|
|
277
|
+
}
|
|
278
|
+
return [useStore, setStore, getStore];
|
|
279
|
+
}
|
|
280
|
+
const [useGradients, setGradients, getGradients] = createStore({});
|
|
281
|
+
const svg$7 = "_svg_1cajk_6";
|
|
282
|
+
const previous = "_previous_1cajk_12";
|
|
283
|
+
const next = "_next_1cajk_16";
|
|
230
284
|
const defaultStyles$n = {
|
|
231
285
|
svg: svg$7,
|
|
232
286
|
previous,
|
|
233
287
|
next
|
|
234
288
|
};
|
|
235
|
-
const GradientIcon = ({
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
const
|
|
244
|
-
|
|
289
|
+
const GradientIcon = (props) => {
|
|
290
|
+
let {
|
|
291
|
+
previous: previous2,
|
|
292
|
+
next: next2,
|
|
293
|
+
styles: styles2
|
|
294
|
+
} = props;
|
|
295
|
+
styles2 = mergeStyles(defaultStyles$n, styles2);
|
|
296
|
+
const gradientId = `gv-gradient-def-${previous2}-${next2}`;
|
|
297
|
+
const gradients = useGradients();
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
setGradients((current) => {
|
|
300
|
+
current[gradientId] = {
|
|
301
|
+
id: gradientId,
|
|
302
|
+
...props
|
|
303
|
+
};
|
|
304
|
+
return current;
|
|
305
|
+
});
|
|
306
|
+
}, [gradientId, props]);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
let container2 = document.getElementById("gv-gradient-defs");
|
|
309
|
+
if (!container2) {
|
|
310
|
+
container2 = document.createElement("div");
|
|
311
|
+
container2.id = "gv-gradient-defs";
|
|
312
|
+
document.body.prepend(container2);
|
|
313
|
+
}
|
|
314
|
+
render(jsx(GradientDefs, {
|
|
315
|
+
gradients: Object.values(gradients)
|
|
316
|
+
}), container2);
|
|
317
|
+
}, [gradients]);
|
|
318
|
+
return jsx("svg", {
|
|
245
319
|
class: styles2.svg,
|
|
246
320
|
width: "24",
|
|
247
321
|
height: "11",
|
|
248
322
|
viewBox: "0 0 24 11",
|
|
249
323
|
xmlns: "http://www.w3.org/2000/svg",
|
|
250
|
-
children:
|
|
324
|
+
children: jsx("path", {
|
|
251
325
|
d: "M0 5.434C0 2.43288 2.43288 0 5.434 0H5.69626C6.85818 0 7.9797 0.426401 8.84813 1.19834C10.6456 2.79612 13.3544 2.79612 15.1519 1.19834C16.0203 0.426401 17.1418 0 18.3037 0L18.566 0C21.5671 0 24 2.43288 24 5.434V5.566C24 8.56712 21.5671 11 18.566 11H18.3037C17.1418 11 16.0203 10.5736 15.1519 9.80166C13.3544 8.20388 10.6456 8.20388 8.84813 9.80166C7.9797 10.5736 6.85818 11 5.69626 11H5.434C2.43288 11 0 8.56712 0 5.566V5.434Z",
|
|
252
326
|
fill: `url(#${gradientId})`
|
|
253
|
-
})
|
|
254
|
-
children: jsxs("linearGradient", {
|
|
255
|
-
id: gradientId,
|
|
256
|
-
x1: "5.5",
|
|
257
|
-
y1: "5.5",
|
|
258
|
-
x2: "12",
|
|
259
|
-
y2: "5.5",
|
|
260
|
-
gradientUnits: "userSpaceOnUse",
|
|
261
|
-
children: [jsx("stop", {
|
|
262
|
-
class: `${styles2.previous} stop-color--${previous2}`
|
|
263
|
-
}), jsx("stop", {
|
|
264
|
-
class: `${styles2.next} stop-color--${next2}`,
|
|
265
|
-
offset: "1"
|
|
266
|
-
})]
|
|
267
|
-
})
|
|
268
|
-
})]
|
|
327
|
+
})
|
|
269
328
|
});
|
|
270
329
|
};
|
|
330
|
+
function GradientDefs({
|
|
331
|
+
gradients
|
|
332
|
+
}) {
|
|
333
|
+
return jsx("svg", {
|
|
334
|
+
width: "24",
|
|
335
|
+
height: "11",
|
|
336
|
+
viewBox: "0 0 24 11",
|
|
337
|
+
children: jsx("defs", {
|
|
338
|
+
children: gradients.map(({
|
|
339
|
+
id,
|
|
340
|
+
previous: previous2,
|
|
341
|
+
next: next2,
|
|
342
|
+
styles: styles2
|
|
343
|
+
}) => {
|
|
344
|
+
return jsxs("linearGradient", {
|
|
345
|
+
id,
|
|
346
|
+
x1: "5.5",
|
|
347
|
+
y1: "5.5",
|
|
348
|
+
x2: "12",
|
|
349
|
+
y2: "5.5",
|
|
350
|
+
gradientUnits: "userSpaceOnUse",
|
|
351
|
+
children: [jsx("stop", {
|
|
352
|
+
class: `${styles2 == null ? void 0 : styles2.previous} stop-color--${previous2}`
|
|
353
|
+
}), jsx("stop", {
|
|
354
|
+
class: `${styles2 == null ? void 0 : styles2.next} stop-color--${next2}`,
|
|
355
|
+
offset: "1"
|
|
356
|
+
})]
|
|
357
|
+
}, id);
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
});
|
|
361
|
+
}
|
|
271
362
|
const button$4 = "_button_kpmyt_1";
|
|
272
363
|
const svg$6 = "_svg_kpmyt_14";
|
|
273
364
|
const defaultStyles$m = {
|
|
@@ -1685,16 +1776,20 @@ const ControlChange = ({
|
|
|
1685
1776
|
})
|
|
1686
1777
|
});
|
|
1687
1778
|
};
|
|
1688
|
-
const toplineResult = "
|
|
1689
|
-
const
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
const
|
|
1693
|
-
const
|
|
1694
|
-
const
|
|
1695
|
-
const
|
|
1779
|
+
const toplineResult = "_toplineResult_w8o28_9";
|
|
1780
|
+
const primaryname = "_primaryname_w8o28_12";
|
|
1781
|
+
const secondaryname = "_secondaryname_w8o28_26";
|
|
1782
|
+
const name = "_name_w8o28_32";
|
|
1783
|
+
const displayNumbers = "_displayNumbers_w8o28_45";
|
|
1784
|
+
const mainNumber = "_mainNumber_w8o28_54";
|
|
1785
|
+
const secondaryNumber = "_secondaryNumber_w8o28_58";
|
|
1786
|
+
const displayRow = "_displayRow_w8o28_65";
|
|
1787
|
+
const displayColumn = "_displayColumn_w8o28_71";
|
|
1788
|
+
const topRow = "_topRow_w8o28_75";
|
|
1696
1789
|
const defaultStyles$7 = {
|
|
1697
1790
|
toplineResult,
|
|
1791
|
+
primaryname,
|
|
1792
|
+
secondaryname,
|
|
1698
1793
|
name,
|
|
1699
1794
|
displayNumbers,
|
|
1700
1795
|
mainNumber,
|
|
@@ -1705,6 +1800,7 @@ const defaultStyles$7 = {
|
|
|
1705
1800
|
};
|
|
1706
1801
|
const ToplineResult = ({
|
|
1707
1802
|
name: name2,
|
|
1803
|
+
secondaryName,
|
|
1708
1804
|
mainNumber: mainNumber2,
|
|
1709
1805
|
secondaryNumber: secondaryNumber2,
|
|
1710
1806
|
styles: styles2,
|
|
@@ -1718,36 +1814,70 @@ const ToplineResult = ({
|
|
|
1718
1814
|
...defaultStyles$7
|
|
1719
1815
|
}, styles2);
|
|
1720
1816
|
const displayStyle = displayRow2 ? styles2.displayRow : styles2.displayColumn;
|
|
1721
|
-
return jsxs(
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1817
|
+
return !secondaryName ? jsxs(Fragment, {
|
|
1818
|
+
children: [" ", jsxs("div", {
|
|
1819
|
+
class: styles2.toplineResult,
|
|
1820
|
+
onMouseOver,
|
|
1821
|
+
children: [jsxs("div", {
|
|
1822
|
+
class: styles2.topRow,
|
|
1823
|
+
children: [jsx("span", {
|
|
1824
|
+
class: `${styles2.name} before-color--${abbreviation}`,
|
|
1825
|
+
children: name2
|
|
1826
|
+
}), " ", showInfoButton && jsx("span", {
|
|
1827
|
+
class: styles2.infoButton,
|
|
1828
|
+
children: jsx(InfoButton, {
|
|
1829
|
+
onClick: onInfoPress
|
|
1830
|
+
})
|
|
1831
|
+
})]
|
|
1832
|
+
}), jsxs("div", {
|
|
1833
|
+
class: `${styles2.displayNumbers} ${displayStyle}`,
|
|
1834
|
+
children: [jsx("div", {
|
|
1835
|
+
class: styles2.mainNumber,
|
|
1836
|
+
children: mainNumber2
|
|
1837
|
+
}), jsx("div", {
|
|
1838
|
+
class: styles2.secondaryNumber,
|
|
1839
|
+
children: secondaryNumber2
|
|
1840
|
+
})]
|
|
1743
1841
|
})]
|
|
1744
1842
|
})]
|
|
1843
|
+
}) : jsx(Fragment, {
|
|
1844
|
+
children: jsxs("div", {
|
|
1845
|
+
class: styles2.toplineResult,
|
|
1846
|
+
onMouseOver,
|
|
1847
|
+
children: [jsxs("div", {
|
|
1848
|
+
class: styles2.topRow,
|
|
1849
|
+
children: [jsx("span", {
|
|
1850
|
+
class: `${styles2.primaryname} before-color--${abbreviation}`,
|
|
1851
|
+
children: name2
|
|
1852
|
+
}), " ", showInfoButton && jsx("span", {
|
|
1853
|
+
class: styles2.infoButton,
|
|
1854
|
+
children: jsx(InfoButton, {
|
|
1855
|
+
onClick: onInfoPress
|
|
1856
|
+
})
|
|
1857
|
+
})]
|
|
1858
|
+
}), jsxs("div", {
|
|
1859
|
+
class: styles2.subhead,
|
|
1860
|
+
children: [jsx("span", {
|
|
1861
|
+
class: styles2.secondaryname,
|
|
1862
|
+
children: secondaryName
|
|
1863
|
+
}), " "]
|
|
1864
|
+
}), jsxs("div", {
|
|
1865
|
+
class: `${styles2.displayNumbers} ${displayStyle}`,
|
|
1866
|
+
children: [jsx("div", {
|
|
1867
|
+
class: styles2.mainNumber,
|
|
1868
|
+
children: mainNumber2
|
|
1869
|
+
}), jsx("div", {
|
|
1870
|
+
class: styles2.secondaryNumber,
|
|
1871
|
+
children: secondaryNumber2
|
|
1872
|
+
})]
|
|
1873
|
+
})]
|
|
1874
|
+
})
|
|
1745
1875
|
});
|
|
1746
1876
|
};
|
|
1747
|
-
const section = "
|
|
1748
|
-
const borderTop = "
|
|
1749
|
-
const header = "
|
|
1750
|
-
const content = "
|
|
1877
|
+
const section = "_section_12aiu_9";
|
|
1878
|
+
const borderTop = "_borderTop_12aiu_52";
|
|
1879
|
+
const header = "_header_12aiu_56";
|
|
1880
|
+
const content = "_content_12aiu_76";
|
|
1751
1881
|
const defaultStyles$6 = {
|
|
1752
1882
|
section,
|
|
1753
1883
|
borderTop,
|
|
@@ -1757,7 +1887,8 @@ const defaultStyles$6 = {
|
|
|
1757
1887
|
const PageSection = forwardRef(({
|
|
1758
1888
|
children,
|
|
1759
1889
|
styles: styles2,
|
|
1760
|
-
borderTop: borderTop2 = false
|
|
1890
|
+
borderTop: borderTop2 = false,
|
|
1891
|
+
backgroundColor = "transparent"
|
|
1761
1892
|
}, ref) => {
|
|
1762
1893
|
styles2 = mergeStyles({
|
|
1763
1894
|
...defaultStyles$6
|
|
@@ -1765,6 +1896,9 @@ const PageSection = forwardRef(({
|
|
|
1765
1896
|
return jsxs("section", {
|
|
1766
1897
|
ref,
|
|
1767
1898
|
className: [styles2.section, borderTop2 && styles2.borderTop].join(" "),
|
|
1899
|
+
style: {
|
|
1900
|
+
"--background-color": backgroundColor
|
|
1901
|
+
},
|
|
1768
1902
|
children: [jsx("div", {
|
|
1769
1903
|
className: styles2.header,
|
|
1770
1904
|
children: children.header
|
|
@@ -1794,15 +1928,14 @@ const ColumnChart = ({
|
|
|
1794
1928
|
}) => {
|
|
1795
1929
|
styles2 = mergeStyles(defaultStyles$5, styles2);
|
|
1796
1930
|
const yScale = scaleLinear$1([maxValue, minValue], [0, chartHeight]);
|
|
1931
|
+
const totalColumnWidth = Number(columnWidth) + Number(columnPadding.left) + Number(columnPadding.right);
|
|
1797
1932
|
return jsxs("svg", {
|
|
1798
1933
|
width: chartWidth,
|
|
1799
1934
|
height: chartHeight,
|
|
1800
|
-
style: "",
|
|
1801
1935
|
children: [columns.map((column, index2) => {
|
|
1802
1936
|
const getHeight = (input2) => {
|
|
1803
1937
|
return yScale(0) - yScale(input2);
|
|
1804
1938
|
};
|
|
1805
|
-
let totalColumnWidth = Number(columnWidth) + Number(columnPadding.left) + Number(columnPadding.right);
|
|
1806
1939
|
return jsxs("g", {
|
|
1807
1940
|
children: [jsx("rect", {
|
|
1808
1941
|
x: index2 * totalColumnWidth,
|
|
@@ -1812,7 +1945,7 @@ const ColumnChart = ({
|
|
|
1812
1945
|
fill: column.color,
|
|
1813
1946
|
className: `${styles2.bar} fill-color--${column.id}`,
|
|
1814
1947
|
id: column.id
|
|
1815
|
-
}
|
|
1948
|
+
}), jsx("text", {
|
|
1816
1949
|
className: styles2.text,
|
|
1817
1950
|
x: index2 * totalColumnWidth + 2,
|
|
1818
1951
|
y: column.value < 0 ? yScale(0) - 6 : yScale(0) + 20,
|