@guardian/interactive-component-library 0.1.0-alpha.39 → 0.1.0-alpha.41

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.
@@ -107,12 +107,12 @@
107
107
  const container$7 = "_container_jzalm_1";
108
108
  const dot = "_dot_jzalm_6";
109
109
  const circle$2 = "_circle_jzalm_13";
110
- const text$3 = "_text_jzalm_17";
110
+ const text$2 = "_text_jzalm_17";
111
111
  const defaultStyles$v = {
112
112
  container: container$7,
113
113
  dot,
114
114
  circle: circle$2,
115
- text: text$3
115
+ text: text$2
116
116
  };
117
117
  const DOT_TYPE = {
118
118
  round: "round",
@@ -504,9 +504,9 @@
504
504
  })
505
505
  });
506
506
  };
507
- const text$2 = "_text_1okyv_1";
507
+ const dateStampText = "_dateStampText_wczs5_1";
508
508
  const defaultStyles$p = {
509
- text: text$2
509
+ dateStampText
510
510
  };
511
511
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
512
512
  function getDefaultExportFromCjs(x) {
@@ -885,7 +885,7 @@
885
885
  }, styles2);
886
886
  let timeSince = dayjs(timeStamp).fromNow();
887
887
  return jsxRuntime.jsx("span", {
888
- className: styles2.text,
888
+ className: styles2.dateStampText,
889
889
  children: timeSince
890
890
  });
891
891
  };
@@ -1078,14 +1078,14 @@
1078
1078
  };
1079
1079
  function ArrowButton({
1080
1080
  direction = "right",
1081
- disabled = false,
1081
+ disabled: disabled2 = false,
1082
1082
  styles: styles2,
1083
1083
  onClick
1084
1084
  }) {
1085
1085
  styles2 = mergeStyles(defaultStyles$j, styles2);
1086
1086
  return jsxRuntime.jsx("button", {
1087
1087
  className: styles2.button,
1088
- disabled,
1088
+ disabled: disabled2,
1089
1089
  onClick,
1090
1090
  children: jsxRuntime.jsxs("svg", {
1091
1091
  className: [styles2.icon, direction].join(" "),
@@ -2080,14 +2080,15 @@
2080
2080
  })
2081
2081
  });
2082
2082
  }
2083
- const searchContainer = "_searchContainer_1px2g_1";
2084
- const input = "_input_1px2g_5";
2085
- const searchIcon = "_searchIcon_1px2g_27";
2086
- const clearButton = "_clearButton_1px2g_36";
2087
- const suggestions = "_suggestions_1px2g_42";
2088
- const suggestion = "_suggestion_1px2g_42";
2089
- const selected$1 = "_selected_1px2g_68";
2090
- const highlighted = "_highlighted_1px2g_72";
2083
+ const searchContainer = "_searchContainer_1kj0x_1";
2084
+ const input = "_input_1kj0x_5";
2085
+ const searchIcon = "_searchIcon_1kj0x_27";
2086
+ const clearButton = "_clearButton_1kj0x_36";
2087
+ const suggestions = "_suggestions_1kj0x_42";
2088
+ const suggestion = "_suggestion_1kj0x_42";
2089
+ const disabled = "_disabled_1kj0x_68";
2090
+ const selected$1 = "_selected_1kj0x_73";
2091
+ const highlighted = "_highlighted_1kj0x_77";
2091
2092
  const defaultStyles$5 = {
2092
2093
  searchContainer,
2093
2094
  input,
@@ -2095,6 +2096,7 @@
2095
2096
  clearButton,
2096
2097
  suggestions,
2097
2098
  suggestion,
2099
+ disabled,
2098
2100
  selected: selected$1,
2099
2101
  highlighted
2100
2102
  };
@@ -2114,18 +2116,34 @@
2114
2116
  const [selectedIndex, setSelectedIndex] = hooks.useState(-1);
2115
2117
  const [suggestions2, setSuggestions] = hooks.useState();
2116
2118
  const [showSuggestions, setShowSuggestions] = hooks.useState(true);
2117
- function onKeyDown(event) {
2119
+ async function updateSelectedIndex(diff) {
2120
+ setSelectedIndex((currentIndex) => {
2121
+ const newIndex = Math.max(Math.min(currentIndex + diff, suggestions2.length - 1), -1);
2122
+ if (newIndex >= 0 && suggestions2[newIndex].disabled) {
2123
+ return currentIndex;
2124
+ }
2125
+ return newIndex;
2126
+ });
2127
+ }
2128
+ async function onKeyDown(event) {
2118
2129
  if (event.key === "ArrowDown") {
2119
2130
  event.preventDefault();
2120
- setSelectedIndex((currentIndex) => Math.min(currentIndex + 1, suggestions2.length - 1));
2131
+ updateSelectedIndex(1);
2121
2132
  } else if (event.key === "ArrowUp") {
2122
2133
  event.preventDefault();
2123
- setSelectedIndex((currentIndex) => Math.max(currentIndex - 1, -1));
2134
+ updateSelectedIndex(-1);
2124
2135
  } else if (event.key === "Enter" && selectedIndex >= 0) {
2125
2136
  event.preventDefault();
2126
2137
  onSelectSuggestion(suggestions2[selectedIndex]);
2127
2138
  } else if (event.key === "Enter") {
2128
- onSubmit(inputRef.current.value);
2139
+ event.preventDefault();
2140
+ if (onSubmit) {
2141
+ const shouldBlur = await onSubmit(inputRef.current.value);
2142
+ if (shouldBlur) {
2143
+ inputRef.current.blur();
2144
+ }
2145
+ }
2146
+ } else if (event.key === "Escape") {
2129
2147
  inputRef.current.blur();
2130
2148
  }
2131
2149
  }
@@ -2203,18 +2221,19 @@
2203
2221
  className: styles2.suggestions,
2204
2222
  "aria-label": "Search suggestions",
2205
2223
  children: suggestions2.map((d2, index) => {
2206
- return jsxRuntime.jsx("li", {
2224
+ const shouldHighlight = !d2.disabled;
2225
+ return jsxRuntime.jsxs("li", {
2207
2226
  "aria-label": d2.text,
2208
- className: [styles2.suggestion, index === selectedIndex && styles2.selected].join(" "),
2227
+ className: [styles2.suggestion, index === selectedIndex && styles2.selected, d2.disabled && styles2.disabled].join(" "),
2209
2228
  onMouseDown: (e) => e.preventDefault(),
2210
2229
  onMouseOver: () => onMouseOver(d2, index),
2211
2230
  onClick: () => {
2212
2231
  onSelect(d2);
2213
2232
  },
2214
- children: d2.text.split(new RegExp(`(${highlightText})`, "ig")).map((part, i) => i % 2 === 1 ? jsxRuntime.jsx("span", {
2233
+ children: [shouldHighlight && d2.text.split(new RegExp(`(${highlightText})`, "ig")).map((part, i) => i % 2 === 1 ? jsxRuntime.jsx("span", {
2215
2234
  className: styles2.highlighted,
2216
2235
  children: part
2217
- }, i) : part)
2236
+ }, i) : part), !shouldHighlight && d2.text]
2218
2237
  }, index);
2219
2238
  })
2220
2239
  });
@@ -7612,7 +7631,7 @@
7612
7631
  const offsetWidth = hooks.useMemo(() => {
7613
7632
  return -pageIndex * (pageWidth || 0);
7614
7633
  }, [pageIndex, pageWidth]);
7615
- const windowSize = useWindowSize();
7634
+ useWindowSize();
7616
7635
  const tickerRef = hooks.useRef();
7617
7636
  const tickerItemsRef = hooks.useRef();
7618
7637
  const tickerScrollRef = hooks.useRef();
@@ -7628,10 +7647,9 @@
7628
7647
  setNumberOfPages(numberOfPages2);
7629
7648
  }, []);
7630
7649
  hooks.useLayoutEffect(() => {
7631
- const tickerItemsContainer = tickerItemsRef.current;
7632
- const hideButtons2 = windowSize.width >= 480 ? tickerScrollRef.current.scrollWidth <= tickerItemsContainer.clientWidth : childArray.length < 3;
7650
+ const hideButtons2 = childArray.length < 4;
7633
7651
  setHideButtons(hideButtons2);
7634
- }, [windowSize, setHideButtons]);
7652
+ }, [childArray]);
7635
7653
  function toggleExpandedState() {
7636
7654
  setExpanded((expanded2) => {
7637
7655
  const newState = !expanded2;