@guardian/interactive-component-library 0.5.0 → 0.5.2

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.
@@ -5,4 +5,5 @@ export type MapComponentProps = {
5
5
  onLoad?: (map: Map) => void;
6
6
  children: import('preact').ComponentChildren;
7
7
  mapRef?: import('preact').Ref<Map>;
8
+ allowZoomPan?: boolean;
8
9
  };
@@ -9,7 +9,8 @@ const Component = ({
9
9
  inModalState = false,
10
10
  onLoad,
11
11
  children,
12
- mapRef
12
+ mapRef,
13
+ allowZoomPan = true
13
14
  }) => {
14
15
  const targetRef = useRef();
15
16
  const [map, setMap] = useState(
@@ -21,11 +22,12 @@ const Component = ({
21
22
  useEffect(() => {
22
23
  var _a;
23
24
  if (!targetRef.current) return;
25
+ config.allowZoomPan = allowZoomPan;
24
26
  const map2 = new Map({
25
27
  ...config,
26
28
  target: targetRef.current
27
29
  });
28
- map2.collaborativeGesturesEnabled(true);
30
+ if (allowZoomPan) map2.collaborativeGesturesEnabled(true);
29
31
  setMap(map2);
30
32
  if (mapRef) {
31
33
  mapRef.current = map2;
@@ -50,9 +52,9 @@ const Component = ({
50
52
  mapRef.current = null;
51
53
  }
52
54
  };
53
- }, [config, onLoad, mapRef]);
55
+ }, [config, onLoad, mapRef, allowZoomPan]);
54
56
  useEffect(() => {
55
- if (!map) return;
57
+ if (!map || !allowZoomPan) return;
56
58
  let timeoutID;
57
59
  map.onFilterEvent((showHelpText2) => {
58
60
  if (timeoutID) clearTimeout(timeoutID);
@@ -66,13 +68,13 @@ const Component = ({
66
68
  return () => {
67
69
  if (timeoutID) clearTimeout(timeoutID);
68
70
  };
69
- }, [map]);
71
+ }, [map, allowZoomPan]);
70
72
  useEffect(() => {
71
- if (!map) return;
73
+ if (!map || !allowZoomPan) return;
72
74
  map.collaborativeGesturesEnabled(!inModalState);
73
- }, [map, inModalState]);
75
+ }, [map, inModalState, allowZoomPan]);
74
76
  return /* @__PURE__ */ jsxs("figure", { ref: targetRef, className: styles.mapContainer, children: [
75
- /* @__PURE__ */ jsxs(
77
+ allowZoomPan && /* @__PURE__ */ jsxs(
76
78
  "div",
77
79
  {
78
80
  className: styles.helpTextContainer,
@@ -11,16 +11,20 @@ export class Map {
11
11
  * @param {Object} config - The configuration for the map.
12
12
  * @param {Object} config.view - The view configuration for the map.
13
13
  * @param {boolean} config.debug - Whether to enable debug mode or not.
14
+ * @param {boolean} config.allowZoomPan - Whether to enable zoom and pan functionality or not.
14
15
  * @param {HTMLElement} config.target - The target element to render the map into.
15
16
  */
16
17
  constructor(config: {
17
18
  view: any;
18
19
  debug: boolean;
20
+ allowZoomPan: boolean;
19
21
  target: HTMLElement;
20
22
  });
23
+ allowZoomPan: boolean;
21
24
  options: {
22
25
  view: any;
23
26
  debug: boolean;
27
+ allowZoomPan: boolean;
24
28
  target: HTMLElement;
25
29
  };
26
30
  view: View;
@@ -15,12 +15,14 @@ class Map {
15
15
  * @param {Object} config - The configuration for the map.
16
16
  * @param {Object} config.view - The view configuration for the map.
17
17
  * @param {boolean} config.debug - Whether to enable debug mode or not.
18
+ * @param {boolean} config.allowZoomPan - Whether to enable zoom and pan functionality or not.
18
19
  * @param {HTMLElement} config.target - The target element to render the map into.
19
20
  */
20
21
  constructor(config) {
21
22
  if (config.debug) {
22
23
  console.log("Map config", config);
23
24
  }
25
+ this.allowZoomPan = config.allowZoomPan;
24
26
  this.options = config;
25
27
  this.view = new View(config.view, config.debug);
26
28
  this.target = config.target;
@@ -236,6 +238,9 @@ class Map {
236
238
  }
237
239
  return (!event.ctrlKey || event.type === "wheel") && !event.button;
238
240
  }).on("zoom", (event) => {
241
+ if (!this.allowZoomPan) {
242
+ return;
243
+ }
239
244
  this.view.transform = event.transform;
240
245
  this._requestRender();
241
246
  this.dispatcher.dispatch(MapEvent.ZOOM, {
@@ -1,6 +1,7 @@
1
- export function Ticker({ maxItems, onStateChange, verticalAtMobile, children, }: {
1
+ export function Ticker({ maxItems, onStateChange, verticalAtMobile, styles, children, }: {
2
2
  maxItems?: number;
3
3
  onStateChange: any;
4
4
  verticalAtMobile?: boolean;
5
+ styles: any;
5
6
  children: any;
6
7
  }): import("preact").JSX.Element;
@@ -5,13 +5,16 @@ import { useContainerSize } from "../../../shared/hooks/useContainerSize.js";
5
5
  import { TickerControlsDesktop } from "./lib/TickerControlsDesktop.js";
6
6
  import { TickerControlsMobileVertical } from "./lib/TickerControlsMobileVertical.js";
7
7
  import { getOffsetDistance } from "./lib/helpers/tickerHelper.js";
8
- import styles from "./style.module.scss.js";
8
+ import { mergeStyles } from "../../../styles/helpers/mergeStyles.js";
9
+ import defaultStyles from "./style.module.scss.js";
9
10
  function Ticker({
10
11
  maxItems = 20,
11
12
  onStateChange,
12
13
  verticalAtMobile = false,
14
+ styles,
13
15
  children
14
16
  }) {
17
+ styles = mergeStyles({ ...defaultStyles }, styles);
15
18
  const [pageIndex, setPageIndex] = useState(0);
16
19
  const [scrollElWidth, setScrollElWidth] = useState(0);
17
20
  const [numberOfPages, setNumberOfPages] = useState(0);
@@ -4,7 +4,7 @@ import "preact/hooks";
4
4
  import "../../../particles/info-button/index.js";
5
5
  import "../../../particles/relative-time-sentence/index.js";
6
6
  import { ArrowButton } from "../../../particles/arrow-button/index.js";
7
- import styles from "../style.module.scss.js";
7
+ import defaultStyles from "../style.module.scss.js";
8
8
  const TickerControlsDesktop = ({
9
9
  hideButtons,
10
10
  controlsRef,
@@ -22,11 +22,11 @@ const TickerControlsDesktop = ({
22
22
  "div",
23
23
  {
24
24
  ref: controlsRef,
25
- className: styles.controls,
25
+ className: defaultStyles.controls,
26
26
  style: hideButtons && { display: "none" },
27
27
  children: [
28
- /* @__PURE__ */ jsx("div", { className: styles.gradient, children: /* @__PURE__ */ jsx(Gradient, {}) }),
29
- /* @__PURE__ */ jsxs("div", { className: styles.buttons, children: [
28
+ /* @__PURE__ */ jsx("div", { className: defaultStyles.gradient, children: /* @__PURE__ */ jsx(Gradient, {}) }),
29
+ /* @__PURE__ */ jsxs("div", { className: defaultStyles.buttons, children: [
30
30
  /* @__PURE__ */ jsx(
31
31
  ArrowButton,
32
32
  {
@@ -4,7 +4,7 @@ import "preact/hooks";
4
4
  import "../../../particles/info-button/index.js";
5
5
  import "../../../particles/relative-time-sentence/index.js";
6
6
  import { Button } from "../../../particles/button/index.js";
7
- import styles from "../style.module.scss.js";
7
+ import defaultStyles from "../style.module.scss.js";
8
8
  const TickerControlsMobileVertical = ({
9
9
  hideButtons,
10
10
  controlsRef,
@@ -15,15 +15,15 @@ const TickerControlsMobileVertical = ({
15
15
  "div",
16
16
  {
17
17
  ref: controlsRef,
18
- className: styles.controls,
18
+ className: defaultStyles.controls,
19
19
  style: hideButtons && { display: "none" },
20
20
  children: [
21
- /* @__PURE__ */ jsx("div", { className: styles.gradient, children: /* @__PURE__ */ jsx(Gradient, {}) }),
22
- /* @__PURE__ */ jsx("div", { className: styles.button, children: /* @__PURE__ */ jsx(
21
+ /* @__PURE__ */ jsx("div", { className: defaultStyles.gradient, children: /* @__PURE__ */ jsx(Gradient, {}) }),
22
+ /* @__PURE__ */ jsx("div", { className: defaultStyles.button, children: /* @__PURE__ */ jsx(
23
23
  Button,
24
24
  {
25
25
  type: "regular",
26
- styles: { buttonInner: styles.buttonInner },
26
+ styles: { buttonInner: defaultStyles.buttonInner },
27
27
  onClick: toggleExpandedState,
28
28
  children: buttonText
29
29
  }
@@ -10,7 +10,7 @@ const gradientHorizontal = "_gradientHorizontal_1at7j_103";
10
10
  const buttons = "_buttons_1at7j_118";
11
11
  const button = "_button_1at7j_118";
12
12
  const buttonInner = "_buttonInner_1at7j_144";
13
- const styles = {
13
+ const defaultStyles = {
14
14
  tickerVertical,
15
15
  ticker,
16
16
  tickerItems,
@@ -29,7 +29,7 @@ export {
29
29
  buttonInner,
30
30
  buttons,
31
31
  controls,
32
- styles as default,
32
+ defaultStyles as default,
33
33
  gradient,
34
34
  gradientHorizontal,
35
35
  ticker,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@guardian/interactive-component-library",
3
3
  "private": false,
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "packageManager": "pnpm@8.4.0",
6
6
  "repository": {
7
7
  "type": "git",