@guardian/interactive-component-library 0.1.0-alpha.29 → 0.1.0-alpha.31

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.
@@ -219,9 +219,7 @@ function StackedBar({
219
219
  ...defaultStyles$u
220
220
  }, styles2);
221
221
  const svgHeight = labelType === LabelType.hanging && !hideLabels ? height + 20 : height;
222
- const cleanBorderAbbr = (abbrText) => {
223
- return abbrText.split("-")[0];
224
- };
222
+ const cleanBorderAbbr = (abbrText) => abbrText.split("-")[0];
225
223
  const renderLabel = (config, i) => jsx("text", {
226
224
  ref: (element) => textElements.current[i] = element,
227
225
  "text-rendering": "optimizeLegibility",
@@ -256,7 +254,6 @@ function StackedBar({
256
254
  fill: d2.fill
257
255
  },
258
256
  "shape-rendering": "crispEdges"
259
- // stroke={border && var()}
260
257
  }), labelType === LabelType.inline && !hideLabels && renderLabel(labelConfig, index)]
261
258
  }, index);
262
259
  totalWidth += itemWidth;
@@ -444,46 +441,25 @@ const defaultStyles$s = {
444
441
  unit,
445
442
  container: container$6
446
443
  };
447
- function useWindowSize() {
448
- const [windowSize, setWindowSize] = useState(() => {
449
- if (typeof window === "undefined")
450
- return {
451
- width: 0,
452
- height: 0
453
- };
454
- return {
455
- width: window.innerWidth,
456
- height: window.innerHeight
457
- };
458
- });
459
- useEffect(() => {
460
- if (typeof window === "undefined")
461
- return;
462
- function handleResize() {
463
- setWindowSize({
464
- width: window.innerWidth,
465
- height: window.innerHeight
466
- });
467
- }
468
- window.addEventListener("resize", handleResize);
469
- return () => {
470
- window.removeEventListener("resize", handleResize);
471
- };
472
- }, []);
473
- return windowSize;
474
- }
475
444
  function useContainerSize(containerRef) {
476
- const windowSize = useWindowSize();
477
445
  const [containerSize, setContainerSize] = useState();
478
446
  useLayoutEffect(() => {
479
447
  const container2 = containerRef.current;
480
448
  if (!container2)
481
449
  return;
482
- setContainerSize({
483
- width: container2.clientWidth,
484
- height: container2.clientHeight
450
+ const observer = new ResizeObserver((entries) => {
451
+ for (let entry of entries) {
452
+ setContainerSize({
453
+ width: entry.contentRect.width,
454
+ height: entry.contentRect.height
455
+ });
456
+ }
485
457
  });
486
- }, [containerRef, windowSize]);
458
+ observer.observe(container2);
459
+ return () => {
460
+ observer.disconnect();
461
+ };
462
+ }, [containerRef]);
487
463
  return containerSize;
488
464
  }
489
465
  const WaffleType = {
@@ -1333,9 +1309,11 @@ function useTable({
1333
1309
  if (sortState.columnIndex < 0) {
1334
1310
  return data;
1335
1311
  }
1312
+ const dataCopy = new Array(...data);
1336
1313
  const column = columns[sortState.columnIndex];
1337
1314
  const sortFunction = sortState.ascending ? sortAscending(column.accessor) : sortDescending(column.accessor);
1338
- return data.toSorted(sortFunction);
1315
+ dataCopy.sort(sortFunction);
1316
+ return dataCopy;
1339
1317
  }, [columns, data, sortState]);
1340
1318
  const columnModels = useMemo(() => {
1341
1319
  return columns.map((column, columnIndex) => {
@@ -1567,17 +1545,13 @@ const SlopeChart = ({
1567
1545
  }
1568
1546
  }) => {
1569
1547
  const wrapperRef = useRef(null);
1570
- const windowSize = useWindowSize();
1571
- const [width, setWidth] = useState(0);
1548
+ const containerSize = useContainerSize(wrapperRef);
1549
+ const width = containerSize ? containerSize.width : 0;
1572
1550
  const contentWidth = Math.floor(width - padding.left - padding.right);
1573
1551
  const contentHeight = contentWidth;
1574
1552
  const height = contentHeight + padding.top + padding.bottom;
1575
1553
  const yScale = scaleLinear(domain, [contentHeight, 0]);
1576
1554
  const show = width > 0;
1577
- useLayoutEffect(() => {
1578
- const newWidth = wrapperRef.current.getBoundingClientRect().width;
1579
- setWidth(newWidth);
1580
- }, [windowSize]);
1581
1555
  const y1Labels = useMemo(() => {
1582
1556
  let labels = lines.map((d2) => ({
1583
1557
  y: yScale(d2.y1),
@@ -3881,6 +3855,8 @@ const SVGMap = forwardRef(({
3881
3855
  }, [width, height]);
3882
3856
  const organisedChildren = useOrganisedChildren(children);
3883
3857
  const renderSVG = containerSize && !config.drawToCanvas;
3858
+ const zoomControl2 = organisedChildren.controls["ZoomControl"];
3859
+ const renderZoomControl = zoomControl2 && zoom2.enabled;
3884
3860
  return jsxs("div", {
3885
3861
  ref: containerRef,
3886
3862
  className: styles$4.container,
@@ -3901,9 +3877,9 @@ const SVGMap = forwardRef(({
3901
3877
  })
3902
3878
  }), jsx("div", {
3903
3879
  className: styles$4.controls,
3904
- children: jsx("div", {
3880
+ children: renderZoomControl && jsx("div", {
3905
3881
  className: styles$4.zoomControl,
3906
- children: cloneElement(organisedChildren.controls["ZoomControl"], {
3882
+ children: cloneElement(zoomControl2, {
3907
3883
  onZoomIn: () => rendererRef.current.zoomIn(),
3908
3884
  onZoomOut: () => rendererRef.current.zoomOut()
3909
3885
  })
@@ -7429,6 +7405,34 @@ class GeoJSON {
7429
7405
  });
7430
7406
  }
7431
7407
  }
7408
+ function useWindowSize() {
7409
+ const [windowSize, setWindowSize] = useState(() => {
7410
+ if (typeof window === "undefined")
7411
+ return {
7412
+ width: 0,
7413
+ height: 0
7414
+ };
7415
+ return {
7416
+ width: window.innerWidth,
7417
+ height: window.innerHeight
7418
+ };
7419
+ });
7420
+ useEffect(() => {
7421
+ if (typeof window === "undefined")
7422
+ return;
7423
+ function handleResize() {
7424
+ setWindowSize({
7425
+ width: window.innerWidth,
7426
+ height: window.innerHeight
7427
+ });
7428
+ }
7429
+ window.addEventListener("resize", handleResize);
7430
+ return () => {
7431
+ window.removeEventListener("resize", handleResize);
7432
+ };
7433
+ }, []);
7434
+ return windowSize;
7435
+ }
7432
7436
  const coalitionsWrapper = "_coalitionsWrapper_4egbd_9";
7433
7437
  const coalitionsContainer = "_coalitionsContainer_4egbd_14";
7434
7438
  const coalition = "_coalition_4egbd_9";