@guardian/interactive-component-library 0.1.0-alpha.33 → 0.1.0-alpha.35

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.
@@ -489,7 +489,8 @@ const Waffle = ({
489
489
  },
490
490
  onClick = () => {
491
491
  },
492
- styles: styles2
492
+ styles: styles2,
493
+ svgId
493
494
  }) => {
494
495
  const containerRef = useRef();
495
496
  const containerSize = useContainerSize(containerRef);
@@ -506,6 +507,7 @@ const Waffle = ({
506
507
  children: containerSize && jsx("svg", {
507
508
  viewBox: `0 0 ${width} ${height}`,
508
509
  class: styles2.svg,
510
+ id: svgId,
509
511
  children: jsx("g", {
510
512
  children: units.map((unit2, j) => {
511
513
  let attributes;
@@ -1468,6 +1470,7 @@ function Table({
1468
1470
  children: table2.columns.map((column, index) => {
1469
1471
  var _a;
1470
1472
  return jsx("th", {
1473
+ scope: "col",
1471
1474
  className: mergeStyles(styles2.headerCell, (_a = column.styles) == null ? void 0 : _a.headerCell),
1472
1475
  children: jsx(HeaderCell, {
1473
1476
  styles: mergeStyles(styles2, column.styles),
@@ -1553,7 +1556,8 @@ const SlopeChart = ({
1553
1556
  right: 24,
1554
1557
  top: 20,
1555
1558
  bottom: 20
1556
- }
1559
+ },
1560
+ svgId
1557
1561
  }) => {
1558
1562
  const wrapperRef = useRef(null);
1559
1563
  const containerSize = useContainerSize(wrapperRef);
@@ -1584,6 +1588,7 @@ const SlopeChart = ({
1584
1588
  class: styles2.svg,
1585
1589
  width,
1586
1590
  height,
1591
+ id: svgId,
1587
1592
  children: jsxs("g", {
1588
1593
  transform: `translate(${padding.left} ${padding.top})`,
1589
1594
  children: [jsxs("g", {
@@ -1948,11 +1953,11 @@ const ToplineResult = forwardRef(({
1948
1953
  })]
1949
1954
  });
1950
1955
  });
1951
- const borderTop = "_borderTop_1b1s0_9";
1952
- const section = "_section_1b1s0_13";
1953
- const fullWidth = "_fullWidth_1b1s0_56";
1954
- const header = "_header_1b1s0_95";
1955
- const content = "_content_1b1s0_132";
1956
+ const borderTop = "_borderTop_1yz7f_9";
1957
+ const section = "_section_1yz7f_14";
1958
+ const fullWidth = "_fullWidth_1yz7f_57";
1959
+ const header = "_header_1yz7f_96";
1960
+ const content = "_content_1yz7f_133";
1956
1961
  const defaultStyles$9 = {
1957
1962
  borderTop,
1958
1963
  section,
@@ -2419,22 +2424,25 @@ var d = (E) => {
2419
2424
  return cloneElement(t, { className: i });
2420
2425
  });
2421
2426
  };
2422
- const transitionContainer = "_transitionContainer_wws3j_1";
2423
- const modalBox = "_modalBox_wws3j_13";
2424
- const enter = "_enter_wws3j_21";
2425
- const exitDone = "_exitDone_wws3j_22";
2426
- const enterActive = "_enterActive_wws3j_31";
2427
- const exit = "_exit_wws3j_22";
2427
+ const transitionContainer = "_transitionContainer_1syip_1";
2428
+ const blur = "_blur_1syip_12";
2429
+ const modalBox = "_modalBox_1syip_17";
2430
+ const enter = "_enter_1syip_26";
2431
+ const exitDone = "_exitDone_1syip_27";
2432
+ const enterActive = "_enterActive_1syip_38";
2433
+ const exitActive = "_exitActive_1syip_49";
2428
2434
  const styles$6 = {
2429
2435
  transitionContainer,
2436
+ blur,
2430
2437
  modalBox,
2431
2438
  enter,
2432
2439
  exitDone,
2433
2440
  enterActive,
2434
- exit
2441
+ exitActive
2435
2442
  };
2436
2443
  function Modal({
2437
2444
  visible = false,
2445
+ blurBackground = true,
2438
2446
  children,
2439
2447
  onClickOutside
2440
2448
  }) {
@@ -2464,11 +2472,8 @@ function Modal({
2464
2472
  duration: 300,
2465
2473
  classNames: styles$6,
2466
2474
  children: jsx("div", {
2467
- class: styles$6.transitionContainer,
2475
+ className: [styles$6.transitionContainer, blurBackground && styles$6.blur, visible && styles$6.visible].join(" "),
2468
2476
  onClick,
2469
- style: {
2470
- pointerEvents: visible ? "auto" : "none"
2471
- },
2472
2477
  children: jsx("div", {
2473
2478
  ref: modalBoxRef,
2474
2479
  class: styles$6.modalBox,
@@ -3871,7 +3876,7 @@ const SVGMap = forwardRef(({
3871
3876
  const renderSVG = containerSize && !config.drawToCanvas;
3872
3877
  const zoomControl2 = organisedChildren.controls["ZoomControl"];
3873
3878
  const renderZoomControl = zoomControl2 && zoom2.enabled;
3874
- return jsxs("div", {
3879
+ return jsxs("figure", {
3875
3880
  ref: containerRef,
3876
3881
  className: styles$4.container,
3877
3882
  style: containerStyle,
@@ -4448,7 +4453,7 @@ class MapRenderer {
4448
4453
  constructor(map) {
4449
4454
  this.map = map;
4450
4455
  this._element = document.createElement("div");
4451
- this._element.className = "gv-map";
4456
+ this._element.className = "gv-layer-container";
4452
4457
  const style2 = this._element.style;
4453
4458
  style2.position = "absolute";
4454
4459
  style2.width = "100%";
@@ -5954,6 +5959,7 @@ let Map$2 = class Map2 {
5954
5959
  this.layers = [];
5955
5960
  this.dispatcher = new Dispatcher(this);
5956
5961
  this._viewport = document.createElement("div");
5962
+ this._viewport.className = "gv-map";
5957
5963
  this._viewport.style.position = "relative";
5958
5964
  this._viewport.style.overflow = "hidden";
5959
5965
  this._viewport.style.top = 0;
@@ -5967,13 +5973,19 @@ let Map$2 = class Map2 {
5967
5973
  this.view.transform = zoomIdentity;
5968
5974
  this._zoomBypassKey = navigator.userAgent.indexOf("Mac") !== -1 ? "metaKey" : "ctrlKey";
5969
5975
  this._zoomBehaviour = zoom().scaleExtent(this.view.scaleExtent).filter((event) => {
5976
+ const filterEvent = (filter) => {
5977
+ this._filterEventCallback(filter);
5978
+ return !filter;
5979
+ };
5970
5980
  if (event.type === "wheel" && !event[this._zoomBypassKey]) {
5971
- this._filterEventCallback(this._zoomBypassKey);
5972
- return false;
5981
+ return filterEvent(true);
5973
5982
  }
5974
- if ("targetTouches" in event && event.targetTouches.length < 2) {
5975
- console.log("stop event", event);
5976
- return false;
5983
+ if ("targetTouches" in event) {
5984
+ if (event.targetTouches.length < 2) {
5985
+ return false;
5986
+ }
5987
+ event.preventDefault();
5988
+ return filterEvent(false);
5977
5989
  }
5978
5990
  return (!event.ctrlKey || event.type === "wheel") && !event.button;
5979
5991
  }).on("zoom", (event) => {
@@ -5984,6 +5996,15 @@ let Map$2 = class Map2 {
5984
5996
  });
5985
5997
  });
5986
5998
  select(this._viewport).call(this._zoomBehaviour);
5999
+ this._viewport.addEventListener("touchmove", (event) => {
6000
+ if (event.targetTouches.length < 2) {
6001
+ this._filterEventCallback(true);
6002
+ }
6003
+ });
6004
+ }
6005
+ destroy() {
6006
+ this._resizeObserver.disconnect();
6007
+ this._viewport.remove();
5987
6008
  }
5988
6009
  /** PUBLIC GETTERS */
5989
6010
  get size() {
@@ -5999,9 +6020,6 @@ let Map$2 = class Map2 {
5999
6020
  onFilterEvent(callback) {
6000
6021
  this._filterEventCallback = callback;
6001
6022
  }
6002
- onZoomEvent(callback) {
6003
- this._onZoomEventCallback = callback;
6004
- }
6005
6023
  fitObject(geoJSON) {
6006
6024
  this.view.fitObject(geoJSON);
6007
6025
  this._requestRender();
@@ -6022,7 +6040,7 @@ let Map$2 = class Map2 {
6022
6040
  if (layers === this.layers) {
6023
6041
  return;
6024
6042
  }
6025
- [...this.layers].forEach((layer) => {
6043
+ new Array(...this.layers).forEach((layer) => {
6026
6044
  if (!layers.includes(layer)) {
6027
6045
  this.removeLayer(layer);
6028
6046
  }
@@ -6048,11 +6066,32 @@ let Map$2 = class Map2 {
6048
6066
  }) {
6049
6067
  return select(this._viewport).transition().duration(options.duration).call(this._zoomBehaviour.scaleTo, zoomLevel).end();
6050
6068
  }
6051
- zoomToFeature(feature, focalPoint) {
6069
+ zoomToFeature(feature, focalPoint, padding = {
6070
+ top: 40,
6071
+ right: 40,
6072
+ bottom: 40,
6073
+ left: 40
6074
+ }) {
6052
6075
  const extent = feature.getExtent();
6053
- const [[x, y], [width, height]] = this.view.boundsForExtent(extent);
6054
- const viewPortSize = this.view.viewPortSize;
6055
- const newTransform = zoomIdentity.translate(viewPortSize[0] / 2, viewPortSize[1] / 2).scale(Math.min(this.view.maxZoom, 0.9 * Math.min(viewPortSize[0] / width, viewPortSize[1] / height))).translate(-x - width / 2, -y - height / 2);
6076
+ const [[featureX, featureY], [featureWidth, featureHeight]] = this.view.boundsForExtent(extent);
6077
+ const [viewPortWidth, viewPortHeight] = this.view.viewPortSize;
6078
+ const paddedViewPortWidth = viewPortWidth - padding.left - padding.right;
6079
+ const paddedViewPortHeight = viewPortHeight - padding.top - padding.bottom;
6080
+ const featureScale = Math.min(paddedViewPortWidth / featureWidth, paddedViewPortHeight / featureHeight);
6081
+ const zoomScale = Math.min(this.view.maxZoom, featureScale);
6082
+ const scaledPadding = {
6083
+ top: padding.top / zoomScale,
6084
+ right: padding.right / zoomScale,
6085
+ bottom: padding.bottom / zoomScale,
6086
+ left: padding.left / zoomScale
6087
+ };
6088
+ const paddedFeatureBounds = {
6089
+ x: featureX - scaledPadding.left,
6090
+ y: featureY - scaledPadding.top,
6091
+ width: featureWidth + scaledPadding.left + scaledPadding.right,
6092
+ height: featureHeight + scaledPadding.top + scaledPadding.bottom
6093
+ };
6094
+ const newTransform = zoomIdentity.translate(viewPortWidth / 2, viewPortHeight / 2).scale(zoomScale).translate(-(paddedFeatureBounds.x + paddedFeatureBounds.width / 2), -(paddedFeatureBounds.y + paddedFeatureBounds.height / 2));
6056
6095
  select(this._viewport).transition().duration(500).call(this._zoomBehaviour.transform, newTransform, focalPoint);
6057
6096
  }
6058
6097
  async resetZoom(options) {
@@ -6278,16 +6317,19 @@ class View {
6278
6317
  };
6279
6318
  }
6280
6319
  }
6281
- const mapContainer = "_mapContainer_y5eeh_9";
6282
- const helpTextContainer = "_helpTextContainer_y5eeh_15";
6283
- const helpText = "_helpText_y5eeh_15";
6284
- const highlight = "_highlight_y5eeh_40";
6320
+ const mapContainer = "_mapContainer_qlxau_9";
6321
+ const helpTextContainer = "_helpTextContainer_qlxau_15";
6322
+ const helpText = "_helpText_qlxau_15";
6323
+ const desktopHelpText = "_desktopHelpText_qlxau_40";
6324
+ const mobileHelpText$1 = "_mobileHelpText_qlxau_48";
6285
6325
  const styles$3 = {
6286
6326
  mapContainer,
6287
6327
  helpTextContainer,
6288
6328
  helpText,
6289
- highlight
6329
+ desktopHelpText,
6330
+ mobileHelpText: mobileHelpText$1
6290
6331
  };
6332
+ const mobileHelpText = "Use two fingers to zoom";
6291
6333
  const Map$1 = forwardRef(({
6292
6334
  config,
6293
6335
  onLoad,
@@ -6296,10 +6338,10 @@ const Map$1 = forwardRef(({
6296
6338
  const {
6297
6339
  layers
6298
6340
  } = children;
6341
+ const targetRef = useRef();
6299
6342
  const [map, setMap] = useState();
6300
- const [hideDefaultHelpText, setHideDefaultHelpText] = useState(false);
6301
6343
  const [zoomHelpText, setZoomHelpText] = useState("");
6302
- const [highlightHelpText, setHighlightHelpText] = useState(false);
6344
+ const [showHelpText, setShowHelpText] = useState(false);
6303
6345
  useEffect(() => {
6304
6346
  const map2 = new Map$2({
6305
6347
  view: new View(config.view),
@@ -6313,6 +6355,7 @@ const Map$1 = forwardRef(({
6313
6355
  const zoomHelpText2 = navigator.userAgent.indexOf("Mac") !== -1 ? "Use ⌘ + scroll to zoom" : "Use Ctrl + scroll to zoom";
6314
6356
  setZoomHelpText(zoomHelpText2);
6315
6357
  return () => {
6358
+ map2.destroy();
6316
6359
  if (ref)
6317
6360
  ref.current = null;
6318
6361
  setMap(null);
@@ -6322,16 +6365,15 @@ const Map$1 = forwardRef(({
6322
6365
  if (!map)
6323
6366
  return;
6324
6367
  let timeoutID;
6325
- map.onFilterEvent(() => {
6368
+ map.onFilterEvent((showHelpText2) => {
6326
6369
  if (timeoutID)
6327
6370
  clearTimeout(timeoutID);
6328
- setHighlightHelpText(true);
6329
- timeoutID = setTimeout(() => {
6330
- setHighlightHelpText();
6331
- }, 1e3);
6332
- });
6333
- map.onZoomEvent((zoomLevel) => {
6334
- setHideDefaultHelpText(zoomLevel > 1);
6371
+ setShowHelpText(showHelpText2);
6372
+ if (showHelpText2) {
6373
+ timeoutID = setTimeout(() => {
6374
+ setShowHelpText(false);
6375
+ }, 1e3);
6376
+ }
6335
6377
  });
6336
6378
  return () => {
6337
6379
  if (timeoutID)
@@ -6343,22 +6385,22 @@ const Map$1 = forwardRef(({
6343
6385
  map.setLayers(layers);
6344
6386
  }
6345
6387
  }, [map, layers]);
6346
- const targetRef = useRef();
6347
- const hideHelpText = hideDefaultHelpText && !highlightHelpText;
6348
- const helpText2 = highlightHelpText ? zoomHelpText : config.defaultHelpText;
6349
- return jsx("div", {
6388
+ return jsx("figure", {
6350
6389
  ref: targetRef,
6351
6390
  className: styles$3.mapContainer,
6352
- children: jsx("div", {
6391
+ children: jsxs("div", {
6353
6392
  className: styles$3.helpTextContainer,
6354
6393
  style: {
6355
- opacity: hideHelpText ? 0 : 1
6394
+ opacity: showHelpText ? 1 : 0
6356
6395
  },
6357
6396
  "aria-hidden": true,
6358
- children: jsx("p", {
6359
- className: [styles$3.helpText, highlightHelpText && styles$3.highlight].join(" "),
6360
- children: helpText2
6361
- })
6397
+ children: [jsx("p", {
6398
+ className: [styles$3.helpText, styles$3.desktopHelpText].join(" "),
6399
+ children: zoomHelpText
6400
+ }), jsx("p", {
6401
+ className: [styles$3.helpText, styles$3.mobileHelpText].join(" "),
6402
+ children: mobileHelpText
6403
+ })]
6362
6404
  })
6363
6405
  });
6364
6406
  });
@@ -6468,7 +6510,8 @@ class FeatureRenderer {
6468
6510
  render(frameState, feature, context) {
6469
6511
  const {
6470
6512
  projection,
6471
- transform
6513
+ transform,
6514
+ pixelRatio
6472
6515
  } = frameState.viewState;
6473
6516
  this.drawingFunction.context(context);
6474
6517
  context.beginPath();
@@ -6481,7 +6524,7 @@ class FeatureRenderer {
6481
6524
  fill
6482
6525
  } = this.style;
6483
6526
  if (stroke) {
6484
- context.lineWidth = stroke.width / transform.k;
6527
+ context.lineWidth = stroke.width * pixelRatio / transform.k;
6485
6528
  context.strokeStyle = stroke.color;
6486
6529
  context.stroke();
6487
6530
  }
@@ -6872,6 +6915,8 @@ class VectorLayerRenderer {
6872
6915
  this.featureRenderer = new FeatureRenderer();
6873
6916
  }
6874
6917
  renderFrame(frameState, targetElement) {
6918
+ if (this.layer.opacity === 0)
6919
+ return targetElement;
6875
6920
  const {
6876
6921
  projection,
6877
6922
  sizeInPixels,
@@ -6889,14 +6934,14 @@ class VectorLayerRenderer {
6889
6934
  const source = this.layer.source;
6890
6935
  const features = source.getFeaturesInExtent(visibleExtent);
6891
6936
  for (const feature of features) {
6892
- context.save();
6893
6937
  const styleFunction2 = feature.getStyleFunction() || this.layer.getStyleFunction();
6894
6938
  const featureStyle = styleFunction2(feature);
6895
- if (!featureStyle)
6896
- continue;
6897
- this.featureRenderer.setStyle(featureStyle);
6898
- this.featureRenderer.render(frameState, feature, context);
6899
- context.restore();
6939
+ if ((featureStyle == null ? void 0 : featureStyle.stroke) || (featureStyle == null ? void 0 : featureStyle.fill)) {
6940
+ context.save();
6941
+ this.featureRenderer.setStyle(featureStyle);
6942
+ this.featureRenderer.render(frameState, feature, context);
6943
+ context.restore();
6944
+ }
6900
6945
  }
6901
6946
  if (Object.prototype.hasOwnProperty.call(projection, "getCompositionBorders")) {
6902
6947
  context.beginPath();
@@ -7424,7 +7469,7 @@ function useWindowSize() {
7424
7469
  height: window.innerHeight
7425
7470
  };
7426
7471
  });
7427
- useEffect(() => {
7472
+ useLayoutEffect(() => {
7428
7473
  if (typeof window === "undefined")
7429
7474
  return;
7430
7475
  function handleResize() {
@@ -7515,7 +7560,7 @@ function CoalitionsTracker({
7515
7560
  position: "relative",
7516
7561
  zIndex: 2
7517
7562
  },
7518
- children: [jsx("h4", {
7563
+ children: [jsx("h3", {
7519
7564
  className: styles2.title,
7520
7565
  children: list.title
7521
7566
  }), jsx("p", {