@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.
@@ -111,12 +111,12 @@ function LargeChevron({
111
111
  const container$7 = "_container_jzalm_1";
112
112
  const dot = "_dot_jzalm_6";
113
113
  const circle$2 = "_circle_jzalm_13";
114
- const text$3 = "_text_jzalm_17";
114
+ const text$2 = "_text_jzalm_17";
115
115
  const defaultStyles$v = {
116
116
  container: container$7,
117
117
  dot,
118
118
  circle: circle$2,
119
- text: text$3
119
+ text: text$2
120
120
  };
121
121
  const DOT_TYPE = {
122
122
  round: "round",
@@ -508,9 +508,9 @@ const CircleIcon = ({
508
508
  })
509
509
  });
510
510
  };
511
- const text$2 = "_text_1okyv_1";
511
+ const dateStampText = "_dateStampText_wczs5_1";
512
512
  const defaultStyles$p = {
513
- text: text$2
513
+ dateStampText
514
514
  };
515
515
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
516
516
  function getDefaultExportFromCjs(x) {
@@ -889,7 +889,7 @@ const RelativeTimeSentence = ({
889
889
  }, styles2);
890
890
  let timeSince = dayjs(timeStamp).fromNow();
891
891
  return jsx("span", {
892
- className: styles2.text,
892
+ className: styles2.dateStampText,
893
893
  children: timeSince
894
894
  });
895
895
  };
@@ -1082,14 +1082,14 @@ const defaultStyles$j = {
1082
1082
  };
1083
1083
  function ArrowButton({
1084
1084
  direction = "right",
1085
- disabled = false,
1085
+ disabled: disabled2 = false,
1086
1086
  styles: styles2,
1087
1087
  onClick
1088
1088
  }) {
1089
1089
  styles2 = mergeStyles(defaultStyles$j, styles2);
1090
1090
  return jsx("button", {
1091
1091
  className: styles2.button,
1092
- disabled,
1092
+ disabled: disabled2,
1093
1093
  onClick,
1094
1094
  children: jsxs("svg", {
1095
1095
  className: [styles2.icon, direction].join(" "),
@@ -2084,14 +2084,15 @@ function SearchIcon() {
2084
2084
  })
2085
2085
  });
2086
2086
  }
2087
- const searchContainer = "_searchContainer_1px2g_1";
2088
- const input = "_input_1px2g_5";
2089
- const searchIcon = "_searchIcon_1px2g_27";
2090
- const clearButton = "_clearButton_1px2g_36";
2091
- const suggestions = "_suggestions_1px2g_42";
2092
- const suggestion = "_suggestion_1px2g_42";
2093
- const selected$1 = "_selected_1px2g_68";
2094
- const highlighted = "_highlighted_1px2g_72";
2087
+ const searchContainer = "_searchContainer_1kj0x_1";
2088
+ const input = "_input_1kj0x_5";
2089
+ const searchIcon = "_searchIcon_1kj0x_27";
2090
+ const clearButton = "_clearButton_1kj0x_36";
2091
+ const suggestions = "_suggestions_1kj0x_42";
2092
+ const suggestion = "_suggestion_1kj0x_42";
2093
+ const disabled = "_disabled_1kj0x_68";
2094
+ const selected$1 = "_selected_1kj0x_73";
2095
+ const highlighted = "_highlighted_1kj0x_77";
2095
2096
  const defaultStyles$5 = {
2096
2097
  searchContainer,
2097
2098
  input,
@@ -2099,6 +2100,7 @@ const defaultStyles$5 = {
2099
2100
  clearButton,
2100
2101
  suggestions,
2101
2102
  suggestion,
2103
+ disabled,
2102
2104
  selected: selected$1,
2103
2105
  highlighted
2104
2106
  };
@@ -2118,18 +2120,34 @@ function SearchInput({
2118
2120
  const [selectedIndex, setSelectedIndex] = useState(-1);
2119
2121
  const [suggestions2, setSuggestions] = useState();
2120
2122
  const [showSuggestions, setShowSuggestions] = useState(true);
2121
- function onKeyDown(event) {
2123
+ async function updateSelectedIndex(diff) {
2124
+ setSelectedIndex((currentIndex) => {
2125
+ const newIndex = Math.max(Math.min(currentIndex + diff, suggestions2.length - 1), -1);
2126
+ if (newIndex >= 0 && suggestions2[newIndex].disabled) {
2127
+ return currentIndex;
2128
+ }
2129
+ return newIndex;
2130
+ });
2131
+ }
2132
+ async function onKeyDown(event) {
2122
2133
  if (event.key === "ArrowDown") {
2123
2134
  event.preventDefault();
2124
- setSelectedIndex((currentIndex) => Math.min(currentIndex + 1, suggestions2.length - 1));
2135
+ updateSelectedIndex(1);
2125
2136
  } else if (event.key === "ArrowUp") {
2126
2137
  event.preventDefault();
2127
- setSelectedIndex((currentIndex) => Math.max(currentIndex - 1, -1));
2138
+ updateSelectedIndex(-1);
2128
2139
  } else if (event.key === "Enter" && selectedIndex >= 0) {
2129
2140
  event.preventDefault();
2130
2141
  onSelectSuggestion(suggestions2[selectedIndex]);
2131
2142
  } else if (event.key === "Enter") {
2132
- onSubmit(inputRef.current.value);
2143
+ event.preventDefault();
2144
+ if (onSubmit) {
2145
+ const shouldBlur = await onSubmit(inputRef.current.value);
2146
+ if (shouldBlur) {
2147
+ inputRef.current.blur();
2148
+ }
2149
+ }
2150
+ } else if (event.key === "Escape") {
2133
2151
  inputRef.current.blur();
2134
2152
  }
2135
2153
  }
@@ -2207,18 +2225,19 @@ function SuggestionList({
2207
2225
  className: styles2.suggestions,
2208
2226
  "aria-label": "Search suggestions",
2209
2227
  children: suggestions2.map((d2, index) => {
2210
- return jsx("li", {
2228
+ const shouldHighlight = !d2.disabled;
2229
+ return jsxs("li", {
2211
2230
  "aria-label": d2.text,
2212
- className: [styles2.suggestion, index === selectedIndex && styles2.selected].join(" "),
2231
+ className: [styles2.suggestion, index === selectedIndex && styles2.selected, d2.disabled && styles2.disabled].join(" "),
2213
2232
  onMouseDown: (e) => e.preventDefault(),
2214
2233
  onMouseOver: () => onMouseOver(d2, index),
2215
2234
  onClick: () => {
2216
2235
  onSelect(d2);
2217
2236
  },
2218
- children: d2.text.split(new RegExp(`(${highlightText})`, "ig")).map((part, i) => i % 2 === 1 ? jsx("span", {
2237
+ children: [shouldHighlight && d2.text.split(new RegExp(`(${highlightText})`, "ig")).map((part, i) => i % 2 === 1 ? jsx("span", {
2219
2238
  className: styles2.highlighted,
2220
2239
  children: part
2221
- }, i) : part)
2240
+ }, i) : part), !shouldHighlight && d2.text]
2222
2241
  }, index);
2223
2242
  })
2224
2243
  });
@@ -7616,7 +7635,7 @@ function Ticker({
7616
7635
  const offsetWidth = useMemo(() => {
7617
7636
  return -pageIndex * (pageWidth || 0);
7618
7637
  }, [pageIndex, pageWidth]);
7619
- const windowSize = useWindowSize();
7638
+ useWindowSize();
7620
7639
  const tickerRef = useRef();
7621
7640
  const tickerItemsRef = useRef();
7622
7641
  const tickerScrollRef = useRef();
@@ -7632,10 +7651,9 @@ function Ticker({
7632
7651
  setNumberOfPages(numberOfPages2);
7633
7652
  }, []);
7634
7653
  useLayoutEffect(() => {
7635
- const tickerItemsContainer = tickerItemsRef.current;
7636
- const hideButtons2 = windowSize.width >= 480 ? tickerScrollRef.current.scrollWidth <= tickerItemsContainer.clientWidth : childArray.length < 3;
7654
+ const hideButtons2 = childArray.length < 4;
7637
7655
  setHideButtons(hideButtons2);
7638
- }, [windowSize, setHideButtons]);
7656
+ }, [childArray]);
7639
7657
  function toggleExpandedState() {
7640
7658
  setExpanded((expanded2) => {
7641
7659
  const newState = !expanded2;