@guardian/interactive-component-library 0.1.0-alpha.23 → 0.1.0-alpha.25

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.
@@ -152,6 +152,8 @@ const defaultStyles$t = {
152
152
  backgroundRect
153
153
  };
154
154
  function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinate = "y", moveBothLabels = true) {
155
+ const maxIterations = 10;
156
+ let totalOverlap = 0;
155
157
  for (let index2 = 1; index2 < labelPositions.length; index2++) {
156
158
  const previousElement = labelPositions[index2 - 1];
157
159
  const element = labelPositions[index2];
@@ -165,8 +167,12 @@ function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinat
165
167
  } else {
166
168
  previousElement[coordinate] -= overlap;
167
169
  }
168
- return labelPositions;
170
+ totalOverlap += overlap;
169
171
  }
172
+ if (totalOverlap > 0 && iteration < maxIterations) {
173
+ return preventOverlap(labelPositions, iteration + 1, labelSize, coordinate, moveBothLabels);
174
+ }
175
+ return labelPositions;
170
176
  }
171
177
  function uniqueBy(array, key) {
172
178
  return [...array.reduce((map, d2) => map.set(d2[key], d2), /* @__PURE__ */ new Map()).values()];
@@ -189,6 +195,10 @@ const LabelType = {
189
195
  hanging: "hanging",
190
196
  inline: "inline"
191
197
  };
198
+ const LabelOverlapConfig = {
199
+ labelSize: 20,
200
+ moveBothLabels: false
201
+ };
192
202
  function StackedBar({
193
203
  stack,
194
204
  width,
@@ -197,7 +207,8 @@ function StackedBar({
197
207
  labelType = LabelType.inline,
198
208
  showBackgroundRect = false,
199
209
  createSVG = true,
200
- styles: styles2
210
+ styles: styles2,
211
+ labelOverlapConfig = LabelOverlapConfig
201
212
  }) {
202
213
  const rectElements = useRef([]);
203
214
  const textElements = useRef([]);
@@ -258,7 +269,7 @@ function StackedBar({
258
269
  totalW += itemWidth;
259
270
  return labelConfig;
260
271
  });
261
- return preventOverlap(labels, 0, 20, "x", false);
272
+ return preventOverlap(labels, 0, labelOverlapConfig.labelSize, "x", labelOverlapConfig.moveBothLabels);
262
273
  }, [stack, height, width]);
263
274
  const backgroundRect2 = jsx("g", {
264
275
  children: jsx("rect", {
@@ -1133,8 +1144,8 @@ const SquareIcon = ({
1133
1144
  })
1134
1145
  });
1135
1146
  };
1136
- const button$4 = "_button_1fees_1";
1137
- const icon$2 = "_icon_1fees_6";
1147
+ const button$4 = "_button_1kqfn_1";
1148
+ const icon$2 = "_icon_1kqfn_6";
1138
1149
  const defaultStyles$i = {
1139
1150
  button: button$4,
1140
1151
  icon: icon$2
@@ -1169,8 +1180,8 @@ function ArrowButton({
1169
1180
  })
1170
1181
  });
1171
1182
  }
1172
- const button$3 = "_button_3521c_1";
1173
- const buttonInner$1 = "_buttonInner_3521c_6";
1183
+ const button$3 = "_button_s6ell_1";
1184
+ const buttonInner$1 = "_buttonInner_s6ell_6";
1174
1185
  const defaultStyles$h = {
1175
1186
  button: button$3,
1176
1187
  buttonInner: buttonInner$1
@@ -1192,10 +1203,10 @@ function Button({
1192
1203
  })
1193
1204
  });
1194
1205
  }
1195
- const button$2 = "_button_125im_1";
1196
- const buttonBorder = "_buttonBorder_125im_11";
1197
- const svg$3 = "_svg_125im_19";
1198
- const path$3 = "_path_125im_25";
1206
+ const button$2 = "_button_nr8bh_1";
1207
+ const buttonBorder = "_buttonBorder_nr8bh_11";
1208
+ const svg$3 = "_svg_nr8bh_19";
1209
+ const path$3 = "_path_nr8bh_25";
1199
1210
  const defaultStyles$g = {
1200
1211
  button: button$2,
1201
1212
  buttonBorder,
@@ -3091,6 +3102,18 @@ function Modal({
3091
3102
  onClickOutside(event);
3092
3103
  }
3093
3104
  }, [onClickOutside, visible]);
3105
+ useEffect(() => {
3106
+ if (visible) {
3107
+ window.addEventListener("scroll", onClick, {
3108
+ once: true
3109
+ });
3110
+ }
3111
+ return () => {
3112
+ if (visible) {
3113
+ window.removeEventListener("scroll", onClick);
3114
+ }
3115
+ };
3116
+ }, [onClick, visible]);
3094
3117
  return createPortal(jsx(d, {
3095
3118
  in: visible,
3096
3119
  duration: 300,
@@ -3139,14 +3162,18 @@ function Dropdown({
3139
3162
  title: title2,
3140
3163
  hint: hint2,
3141
3164
  options,
3142
- onSelect
3165
+ onSelect,
3166
+ collapseOnSelect = false,
3167
+ expandByDefault = true
3143
3168
  }) {
3144
- const [expanded, setExpanded] = useState(true);
3169
+ const [expanded, setExpanded] = useState(expandByDefault);
3145
3170
  const [selectedIndex, setSelectedIndex] = useState(0);
3146
3171
  const onOptionClick = useCallback((option2, index2) => {
3147
3172
  setSelectedIndex(index2);
3148
3173
  if (onSelect)
3149
3174
  onSelect(option2, index2);
3175
+ if (collapseOnSelect)
3176
+ setExpanded(false);
3150
3177
  }, [onSelect]);
3151
3178
  const iconForSelectedOption = useMemo(() => {
3152
3179
  const selectedOption = options[selectedIndex];
@@ -3214,15 +3241,15 @@ function Checkmark() {
3214
3241
  })
3215
3242
  });
3216
3243
  }
3217
- const coalitionsWrapper = "_coalitionsWrapper_1ahqy_9";
3218
- const coalitionsContainer = "_coalitionsContainer_1ahqy_14";
3219
- const coalition = "_coalition_1ahqy_9";
3220
- const title = "_title_1ahqy_27";
3221
- const description = "_description_1ahqy_28";
3222
- const thresholdText = "_thresholdText_1ahqy_43";
3223
- const thresholdTextBold = "_thresholdTextBold_1ahqy_54";
3224
- const thresholdDot = "_thresholdDot_1ahqy_61";
3225
- const thresholdLine = "_thresholdLine_1ahqy_61";
3244
+ const coalitionsWrapper = "_coalitionsWrapper_4egbd_9";
3245
+ const coalitionsContainer = "_coalitionsContainer_4egbd_14";
3246
+ const coalition = "_coalition_4egbd_9";
3247
+ const title = "_title_4egbd_27";
3248
+ const description = "_description_4egbd_28";
3249
+ const thresholdText = "_thresholdText_4egbd_43";
3250
+ const thresholdTextBold = "_thresholdTextBold_4egbd_54";
3251
+ const thresholdDot = "_thresholdDot_4egbd_61";
3252
+ const thresholdLine = "_thresholdLine_4egbd_62";
3226
3253
  const defaultStyles = {
3227
3254
  coalitionsWrapper,
3228
3255
  coalitionsContainer,
@@ -3244,7 +3271,8 @@ function CoalitionsTracker({
3244
3271
  abbreviationAccessor = "abbreviation",
3245
3272
  thresholdTextBold: thresholdTextBold2,
3246
3273
  thresholdText: thresholdText2,
3247
- styles: styles2
3274
+ styles: styles2,
3275
+ labelOverlapConfig = LabelOverlapConfig
3248
3276
  }) {
3249
3277
  const wrapperRef = useRef(null);
3250
3278
  const thresholdTextRef = useRef(null);
@@ -3298,6 +3326,8 @@ function CoalitionsTracker({
3298
3326
  },
3299
3327
  children: list.description
3300
3328
  }), jsx(StackedBar, {
3329
+ labelOverlapConfig,
3330
+ labelType: LabelType.hanging,
3301
3331
  stack: list.stack,
3302
3332
  width: list.width,
3303
3333
  height: barChartHeight,
@@ -3629,6 +3659,7 @@ export {
3629
3659
  GradientIcon,
3630
3660
  GridType,
3631
3661
  InfoButton,
3662
+ LabelOverlapConfig,
3632
3663
  LabelType,
3633
3664
  LegendItem,
3634
3665
  Map$1 as Map,