@guardian/interactive-component-library 0.1.0-alpha.10 → 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.
- package/README.md +4 -17
- package/dist/interactive-component-library.js +207 -75
- package/dist/interactive-component-library.js.map +1 -1
- package/dist/interactive-component-library.umd.cjs +206 -74
- package/dist/interactive-component-library.umd.cjs.map +1 -1
- package/dist/style.css +82 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,21 +3,8 @@
|
|
|
3
3
|
A set of reusable components for use in interactive pages, written in Preact using [Atomic Design](https://bradfrost.com/blog/post/atomic-web-design/) principles.
|
|
4
4
|
|
|
5
5
|
## Install the component library in a new client project
|
|
6
|
-
|
|
7
|
-
From [Github Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry):
|
|
8
|
-
|
|
9
|
-
1. [Create a personal access token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) with `read:packages` scope.
|
|
10
|
-
2. Create a file called `.npmrc` in the root of your new project and add the following:
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
@guardian:registry=https://npm.pkg.github.com
|
|
14
|
-
//npm.pkg.github.com/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
3. Install using npm:
|
|
18
|
-
|
|
19
6
|
```
|
|
20
|
-
npm
|
|
7
|
+
npm install @guardian/interactive-component-library
|
|
21
8
|
```
|
|
22
9
|
|
|
23
10
|
## Contributing to this repository
|
|
@@ -76,9 +63,9 @@ npm uninstall --no-save @guardian/interactive-component-library && npm install
|
|
|
76
63
|
|
|
77
64
|
To publish a new version of the component library, follow these steps:
|
|
78
65
|
|
|
79
|
-
1.
|
|
80
|
-
2. [
|
|
81
|
-
3.
|
|
66
|
+
1. [Create a new release](https://github.com/guardian/interactive-component-library/releases/new) on GitHub (don't forget to write some release notes)
|
|
67
|
+
2. Publishing the release [triggers a workflow](https://github.com/guardian/interactive-component-library/actions) to package the library and publish it to the NPM registry. If the publish actions fails, you can also trigger it manually
|
|
68
|
+
3. The publish action also creates a pull request to bump the version number. Merge the pull request to finish the release
|
|
82
69
|
|
|
83
70
|
## Scripts
|
|
84
71
|
|
|
@@ -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 = {
|
|
@@ -1608,18 +1699,17 @@ function Tooltip({
|
|
|
1608
1699
|
}) : tooltip2, displayElement);
|
|
1609
1700
|
}
|
|
1610
1701
|
function tooltipPositionForPoint({
|
|
1611
|
-
targetRect,
|
|
1612
1702
|
positionInTarget,
|
|
1613
1703
|
tooltip: tooltip2,
|
|
1614
1704
|
displayElement
|
|
1615
1705
|
}) {
|
|
1706
|
+
const displayElementRect = displayElement.getBoundingClientRect();
|
|
1616
1707
|
const newPosition = {
|
|
1617
|
-
x: positionInTarget.x +
|
|
1618
|
-
y: positionInTarget.y +
|
|
1708
|
+
x: positionInTarget.x + displayElementRect.x,
|
|
1709
|
+
y: positionInTarget.y + displayElementRect.y
|
|
1619
1710
|
};
|
|
1620
1711
|
const tooltipWidth = tooltip2.offsetWidth;
|
|
1621
1712
|
const tooltipHeight = tooltip2.offsetHeight;
|
|
1622
|
-
const displayElementRect = displayElement.getBoundingClientRect();
|
|
1623
1713
|
if (newPosition.x + tooltipWidth > displayElementRect.right) {
|
|
1624
1714
|
newPosition.x -= tooltipWidth;
|
|
1625
1715
|
}
|
|
@@ -1686,16 +1776,20 @@ const ControlChange = ({
|
|
|
1686
1776
|
})
|
|
1687
1777
|
});
|
|
1688
1778
|
};
|
|
1689
|
-
const toplineResult = "
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
const
|
|
1693
|
-
const
|
|
1694
|
-
const
|
|
1695
|
-
const
|
|
1696
|
-
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";
|
|
1697
1789
|
const defaultStyles$7 = {
|
|
1698
1790
|
toplineResult,
|
|
1791
|
+
primaryname,
|
|
1792
|
+
secondaryname,
|
|
1699
1793
|
name,
|
|
1700
1794
|
displayNumbers,
|
|
1701
1795
|
mainNumber,
|
|
@@ -1706,6 +1800,7 @@ const defaultStyles$7 = {
|
|
|
1706
1800
|
};
|
|
1707
1801
|
const ToplineResult = ({
|
|
1708
1802
|
name: name2,
|
|
1803
|
+
secondaryName,
|
|
1709
1804
|
mainNumber: mainNumber2,
|
|
1710
1805
|
secondaryNumber: secondaryNumber2,
|
|
1711
1806
|
styles: styles2,
|
|
@@ -1719,36 +1814,70 @@ const ToplineResult = ({
|
|
|
1719
1814
|
...defaultStyles$7
|
|
1720
1815
|
}, styles2);
|
|
1721
1816
|
const displayStyle = displayRow2 ? styles2.displayRow : styles2.displayColumn;
|
|
1722
|
-
return jsxs(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
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
|
+
})]
|
|
1744
1841
|
})]
|
|
1745
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
|
+
})
|
|
1746
1875
|
});
|
|
1747
1876
|
};
|
|
1748
|
-
const section = "
|
|
1749
|
-
const borderTop = "
|
|
1750
|
-
const header = "
|
|
1751
|
-
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";
|
|
1752
1881
|
const defaultStyles$6 = {
|
|
1753
1882
|
section,
|
|
1754
1883
|
borderTop,
|
|
@@ -1758,7 +1887,8 @@ const defaultStyles$6 = {
|
|
|
1758
1887
|
const PageSection = forwardRef(({
|
|
1759
1888
|
children,
|
|
1760
1889
|
styles: styles2,
|
|
1761
|
-
borderTop: borderTop2 = false
|
|
1890
|
+
borderTop: borderTop2 = false,
|
|
1891
|
+
backgroundColor = "transparent"
|
|
1762
1892
|
}, ref) => {
|
|
1763
1893
|
styles2 = mergeStyles({
|
|
1764
1894
|
...defaultStyles$6
|
|
@@ -1766,6 +1896,9 @@ const PageSection = forwardRef(({
|
|
|
1766
1896
|
return jsxs("section", {
|
|
1767
1897
|
ref,
|
|
1768
1898
|
className: [styles2.section, borderTop2 && styles2.borderTop].join(" "),
|
|
1899
|
+
style: {
|
|
1900
|
+
"--background-color": backgroundColor
|
|
1901
|
+
},
|
|
1769
1902
|
children: [jsx("div", {
|
|
1770
1903
|
className: styles2.header,
|
|
1771
1904
|
children: children.header
|
|
@@ -1795,15 +1928,14 @@ const ColumnChart = ({
|
|
|
1795
1928
|
}) => {
|
|
1796
1929
|
styles2 = mergeStyles(defaultStyles$5, styles2);
|
|
1797
1930
|
const yScale = scaleLinear$1([maxValue, minValue], [0, chartHeight]);
|
|
1931
|
+
const totalColumnWidth = Number(columnWidth) + Number(columnPadding.left) + Number(columnPadding.right);
|
|
1798
1932
|
return jsxs("svg", {
|
|
1799
1933
|
width: chartWidth,
|
|
1800
1934
|
height: chartHeight,
|
|
1801
|
-
style: "",
|
|
1802
1935
|
children: [columns.map((column, index2) => {
|
|
1803
1936
|
const getHeight = (input2) => {
|
|
1804
1937
|
return yScale(0) - yScale(input2);
|
|
1805
1938
|
};
|
|
1806
|
-
let totalColumnWidth = Number(columnWidth) + Number(columnPadding.left) + Number(columnPadding.right);
|
|
1807
1939
|
return jsxs("g", {
|
|
1808
1940
|
children: [jsx("rect", {
|
|
1809
1941
|
x: index2 * totalColumnWidth,
|
|
@@ -1813,7 +1945,7 @@ const ColumnChart = ({
|
|
|
1813
1945
|
fill: column.color,
|
|
1814
1946
|
className: `${styles2.bar} fill-color--${column.id}`,
|
|
1815
1947
|
id: column.id
|
|
1816
|
-
}
|
|
1948
|
+
}), jsx("text", {
|
|
1817
1949
|
className: styles2.text,
|
|
1818
1950
|
x: index2 * totalColumnWidth + 2,
|
|
1819
1951
|
y: column.value < 0 ? yScale(0) - 6 : yScale(0) + 20,
|