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

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.
@@ -3132,18 +3132,19 @@ function Modal({
3132
3132
  })
3133
3133
  }), document.body);
3134
3134
  }
3135
- const container = "_container_iozsb_1";
3136
- const button$1 = "_button_iozsb_6";
3137
- const icon = "_icon_iozsb_22";
3138
- const title$1 = "_title_iozsb_27";
3139
- const popout = "_popout_iozsb_34";
3140
- const hint = "_hint_iozsb_51";
3141
- const option = "_option_iozsb_58";
3142
- const optionIcon = "_optionIcon_iozsb_79";
3143
- const optionTitle = "_optionTitle_iozsb_84";
3144
- const optionDescription = "_optionDescription_iozsb_92";
3145
- const checkmark = "_checkmark_iozsb_99";
3146
- const checkmarkPath = "_checkmarkPath_iozsb_105";
3135
+ const container = "_container_1enis_1";
3136
+ const button$1 = "_button_1enis_6";
3137
+ const icon = "_icon_1enis_22";
3138
+ const title$1 = "_title_1enis_27";
3139
+ const popout = "_popout_1enis_34";
3140
+ const hint = "_hint_1enis_51";
3141
+ const groupHeader = "_groupHeader_1enis_58";
3142
+ const option = "_option_1enis_65";
3143
+ const optionIcon = "_optionIcon_1enis_86";
3144
+ const optionTitle = "_optionTitle_1enis_91";
3145
+ const optionDescription = "_optionDescription_1enis_99";
3146
+ const checkmark = "_checkmark_1enis_106";
3147
+ const checkmarkPath = "_checkmarkPath_1enis_112";
3147
3148
  const styles$2 = {
3148
3149
  container,
3149
3150
  button: button$1,
@@ -3151,6 +3152,7 @@ const styles$2 = {
3151
3152
  title: title$1,
3152
3153
  popout,
3153
3154
  hint,
3155
+ groupHeader,
3154
3156
  option,
3155
3157
  optionIcon,
3156
3158
  optionTitle,
@@ -3175,10 +3177,29 @@ function Dropdown({
3175
3177
  if (collapseOnSelect)
3176
3178
  setExpanded(false);
3177
3179
  }, [onSelect]);
3180
+ const optionGroups = useMemo(() => {
3181
+ const containsOptionGroups = "options" in options[0];
3182
+ if (!containsOptionGroups) {
3183
+ return [{
3184
+ options
3185
+ }];
3186
+ }
3187
+ let optionIndex = 0;
3188
+ for (const group2 of options) {
3189
+ for (const option2 of group2.options) {
3190
+ option2.index = optionIndex;
3191
+ optionIndex++;
3192
+ }
3193
+ }
3194
+ return options;
3195
+ }, options);
3196
+ const flatOptions = useMemo(() => {
3197
+ return optionGroups.map((group2) => group2.options).flat();
3198
+ }, [optionGroups]);
3178
3199
  const iconForSelectedOption = useMemo(() => {
3179
- const selectedOption = options[selectedIndex];
3200
+ const selectedOption = flatOptions[selectedIndex];
3180
3201
  return selectedOption.icon;
3181
- }, [options, selectedIndex]);
3202
+ }, [flatOptions, selectedIndex]);
3182
3203
  return jsxs("div", {
3183
3204
  className: styles$2.container,
3184
3205
  children: [jsxs("button", {
@@ -3203,9 +3224,28 @@ function Dropdown({
3203
3224
  children: [hint2 && jsx("p", {
3204
3225
  className: styles$2.hint,
3205
3226
  children: hint2
3206
- }), options.map((option2, index2) => jsxs("button", {
3227
+ }), optionGroups.map((group2) => jsx(OptionGroup, {
3228
+ ...group2,
3229
+ selectedIndex,
3230
+ onOptionClick
3231
+ }))]
3232
+ })]
3233
+ });
3234
+ }
3235
+ function OptionGroup({
3236
+ title: title2,
3237
+ options,
3238
+ selectedIndex,
3239
+ onOptionClick
3240
+ }) {
3241
+ return jsxs(Fragment, {
3242
+ children: [title2 && jsx("p", {
3243
+ className: styles$2.groupHeader,
3244
+ children: title2
3245
+ }), options.map((option2) => {
3246
+ return jsxs("button", {
3207
3247
  className: styles$2.option,
3208
- onClick: () => onOptionClick(option2, index2),
3248
+ onClick: () => onOptionClick(option2, option2.index),
3209
3249
  children: [jsx("img", {
3210
3250
  src: option2.icon,
3211
3251
  className: styles$2.optionIcon
@@ -3218,11 +3258,11 @@ function Dropdown({
3218
3258
  className: styles$2.optionDescription,
3219
3259
  children: option2.description
3220
3260
  })]
3221
- }), index2 === selectedIndex && jsx("div", {
3261
+ }), option2.index === selectedIndex && jsx("div", {
3222
3262
  className: styles$2.checkmark,
3223
3263
  children: jsx(Checkmark, {})
3224
3264
  })]
3225
- }, option2.title))]
3265
+ }, option2.title);
3226
3266
  })]
3227
3267
  });
3228
3268
  }