@carto/meridian-ds 1.5.1 → 2.0.0-alpha-external-link.7

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{Alert-BiOR9aar.cjs → Alert-C-rl1sPM.cjs} +97 -1
  3. package/dist/{Alert-CywtIMOj.js → Alert-DmbdMf46.js} +99 -3
  4. package/dist/{ArrowDown-8fLj23Ge.cjs → ArrowDown-DJ0vhbsw.cjs} +2 -2
  5. package/dist/{ArrowDown-CY_wMVJT.js → ArrowDown-d6bxUL0F.js} +1 -1
  6. package/dist/{MenuItem-CXnnE5lK.js → MenuItem-C8x-GasJ.js} +10 -6
  7. package/dist/{MenuItem-Br2jY2lt.cjs → MenuItem-CyIdh2wX.cjs} +10 -6
  8. package/dist/{OpenDiagonallyRight-CSm5GYYJ.js → OpenDiagonallyRight-CGdCEXlF.js} +1 -1
  9. package/dist/{OpenDiagonallyRight-CM1tojUq.cjs → OpenDiagonallyRight-CpL4ROwg.cjs} +4 -4
  10. package/dist/{SwatchSquare-benaO55C.cjs → SwatchSquare-B8PIY3Rd.cjs} +3 -3
  11. package/dist/{SwatchSquare-DhaaXt53.js → SwatchSquare-CaaLsjAC.js} +1 -1
  12. package/dist/{TablePaginationActions-KpTvhN4Y.js → TablePaginationActions-BWer8cmX.js} +15 -4
  13. package/dist/{TablePaginationActions-CFGXm44W.cjs → TablePaginationActions-MwqZJoRm.cjs} +14 -3
  14. package/dist/components/index.cjs +456 -57
  15. package/dist/components/index.js +460 -60
  16. package/dist/custom-icons/index.cjs +608 -486
  17. package/dist/custom-icons/index.js +561 -439
  18. package/dist/theme/index.cjs +14 -10
  19. package/dist/theme/index.js +15 -11
  20. package/dist/types/components/atoms/Button.d.ts +10 -0
  21. package/dist/types/components/atoms/Button.d.ts.map +1 -1
  22. package/dist/types/components/atoms/Link.d.ts +16 -0
  23. package/dist/types/components/atoms/Link.d.ts.map +1 -0
  24. package/dist/types/components/atoms/ScreenReaderOnly.d.ts +3 -0
  25. package/dist/types/components/atoms/ScreenReaderOnly.d.ts.map +1 -0
  26. package/dist/types/components/atoms/index.d.ts +3 -0
  27. package/dist/types/components/atoms/index.d.ts.map +1 -1
  28. package/dist/types/components/molecules/Autocomplete/Autocomplete.d.ts.map +1 -1
  29. package/dist/types/components/molecules/Autocomplete/AutocompleteList.d.ts +13 -0
  30. package/dist/types/components/molecules/Autocomplete/AutocompleteList.d.ts.map +1 -0
  31. package/dist/types/components/molecules/Autocomplete/CreatableAutocomplete.d.ts +1 -1
  32. package/dist/types/components/molecules/Autocomplete/CreatableAutocomplete.d.ts.map +1 -1
  33. package/dist/types/components/molecules/Autocomplete/MultipleAutocomplete.d.ts +1 -1
  34. package/dist/types/components/molecules/Autocomplete/MultipleAutocomplete.d.ts.map +1 -1
  35. package/dist/types/components/molecules/Autocomplete/index.d.ts +3 -0
  36. package/dist/types/components/molecules/Autocomplete/index.d.ts.map +1 -1
  37. package/dist/types/components/molecules/Autocomplete/types.d.ts +107 -7
  38. package/dist/types/components/molecules/Autocomplete/types.d.ts.map +1 -1
  39. package/dist/types/components/molecules/Autocomplete/useAutocomplete.d.ts +11 -0
  40. package/dist/types/components/molecules/Autocomplete/useAutocomplete.d.ts.map +1 -0
  41. package/dist/types/components/molecules/Autocomplete/useAutocompleteRenderOption.d.ts +2 -1
  42. package/dist/types/components/molecules/Autocomplete/useAutocompleteRenderOption.d.ts.map +1 -1
  43. package/dist/types/components/molecules/Autocomplete/useMultipleAutocomplete.d.ts +26 -1
  44. package/dist/types/components/molecules/Autocomplete/useMultipleAutocomplete.d.ts.map +1 -1
  45. package/dist/types/components/molecules/Autocomplete/utils.d.ts +135 -0
  46. package/dist/types/components/molecules/Autocomplete/utils.d.ts.map +1 -1
  47. package/dist/types/components/molecules/Menu/Menu.d.ts.map +1 -1
  48. package/dist/types/components/molecules/Menu/MenuItem.d.ts.map +1 -1
  49. package/dist/types/components/molecules/Menu/MenuItemFilter.d.ts.map +1 -1
  50. package/dist/types/components/molecules/Menu/MenuList.d.ts.map +1 -1
  51. package/dist/types/components/molecules/MultipleSelectField/MultipleSelectField.d.ts.map +1 -1
  52. package/dist/types/custom-icons/AiAgent.d.ts +4 -0
  53. package/dist/types/custom-icons/AiAgent.d.ts.map +1 -0
  54. package/dist/types/custom-icons/HideRightsidebar.d.ts +4 -0
  55. package/dist/types/custom-icons/HideRightsidebar.d.ts.map +1 -0
  56. package/dist/types/custom-icons/ShowRightsidebar.d.ts +4 -0
  57. package/dist/types/custom-icons/ShowRightsidebar.d.ts.map +1 -0
  58. package/dist/types/custom-icons/index.d.ts +3 -0
  59. package/dist/types/custom-icons/index.d.ts.map +1 -1
  60. package/dist/types/localization/en.d.ts +1 -0
  61. package/dist/types/localization/en.d.ts.map +1 -1
  62. package/dist/types/localization/es.d.ts +1 -0
  63. package/dist/types/localization/es.d.ts.map +1 -1
  64. package/dist/types/localization/id.d.ts +1 -0
  65. package/dist/types/localization/id.d.ts.map +1 -1
  66. package/dist/types/localization/index.d.ts +3 -0
  67. package/dist/types/localization/index.d.ts.map +1 -1
  68. package/dist/types/theme/sections/components/forms.d.ts.map +1 -1
  69. package/dist/types/theme/sections/components/navigation.d.ts.map +1 -1
  70. package/dist/types/theme/theme-constants.d.ts +4 -0
  71. package/dist/types/theme/theme-constants.d.ts.map +1 -1
  72. package/dist/types/widgets/comparative/ComparativeCategoryWidgetUI/ComparativeCategoryWidgetUI.d.ts.map +1 -1
  73. package/dist/widgets/index.cjs +6 -6
  74. package/dist/widgets/index.js +6 -6
  75. package/package.json +1 -1
  76. package/dist/types/components/molecules/Autocomplete/ListBoxWithFilter.d.ts +0 -17
  77. package/dist/types/components/molecules/Autocomplete/ListBoxWithFilter.d.ts.map +0 -1
@@ -1,15 +1,17 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { forwardRef, useState, useRef, useEffect, useMemo, Fragment as Fragment$1, useImperativeHandle, useCallback } from "react";
3
- import { styled, Box, Button as Button$1, CircularProgress, Popper, Grow, Paper, ClickAwayListener, MenuList as MenuList$1, MenuItem, ButtonGroup as ButtonGroup$1, TextField, InputAdornment, IconButton, Tooltip, Select, FormControl, InputLabel, FormHelperText, ToggleButtonGroup as ToggleButtonGroup$1, Menu as Menu$2, Link, Checkbox, ListItemText, Autocomplete as Autocomplete$1, Divider, ListItemIcon, createFilterOptions, Accordion, AccordionSummary, AccordionDetails, Avatar as Avatar$1, Snackbar as Snackbar$1, Portal, Fade, Slide, alpha, useTheme, Toolbar, AppBar as AppBar$1, Dialog as Dialog$1, DialogTitle as DialogTitle$1, Chip, DialogContent as DialogContent$1, DialogActions as DialogActions$1 } from "@mui/material";
4
- import { T as Typography, c as ICON_SIZE_SMALL, u as useImperativeIntl, N as NOTIFICATION_DURATION_IN_MS, A as APPBAR_SIZE } from "../TablePaginationActions-KpTvhN4Y.js";
5
- import { a } from "../TablePaginationActions-KpTvhN4Y.js";
6
- import { A as ArrowDown } from "../ArrowDown-CY_wMVJT.js";
7
- import { A as ArrowUp, O as OpenDiagonallyRight, C as CloseDiagonallyRight } from "../OpenDiagonallyRight-CSm5GYYJ.js";
2
+ import React, { forwardRef, useState, useRef, useEffect, useMemo, createElement, Fragment as Fragment$1, useCallback, useImperativeHandle } from "react";
8
3
  import { useIntl } from "react-intl";
9
- import { VisibilityOffOutlined, VisibilityOutlined, Cancel, AddCircleOutlineOutlined, ContentCopyOutlined, CloseOutlined, MenuOutlined, HelpOutline, TodayOutlined, MoreVertOutlined, ErrorOutline, Check } from "@mui/icons-material";
10
- import { I as IconButton$1, A as Alert$1 } from "../Alert-CywtIMOj.js";
4
+ import { styled, Box, Button as Button$1, CircularProgress, Popper, Grow, Paper, ClickAwayListener, MenuList as MenuList$1, MenuItem, ButtonGroup as ButtonGroup$1, TextField, InputAdornment, IconButton, Tooltip, Select, FormControl, InputLabel, FormHelperText, ToggleButtonGroup as ToggleButtonGroup$1, Menu as Menu$2, Link, Checkbox, ListItemText, Autocomplete as Autocomplete$1, Divider, ListItemIcon, createFilterOptions, Accordion, AccordionSummary, AccordionDetails, Avatar as Avatar$1, Snackbar as Snackbar$1, Portal, Fade, Slide, alpha, useTheme, Toolbar, AppBar as AppBar$1, Dialog as Dialog$1, DialogTitle as DialogTitle$1, Chip, DialogContent as DialogContent$1, DialogActions as DialogActions$1 } from "@mui/material";
5
+ import { OpenInNewOutlined, VisibilityOffOutlined, VisibilityOutlined, Cancel, AddCircleOutlineOutlined, ContentCopyOutlined, CloseOutlined, MenuOutlined, HelpOutline, TodayOutlined, MoreVertOutlined, ErrorOutline, Check } from "@mui/icons-material";
6
+ import { u as useImperativeIntl, T as Typography, c as ICON_SIZE_SMALL, f as MENU_ITEM_SIZE_EXTENDED, e as MENU_ITEM_SIZE_DENSE, d as MENU_LIST_MAX_SIZE, M as MENU_ITEM_SIZE_DEFAULT, N as NOTIFICATION_DURATION_IN_MS, A as APPBAR_SIZE } from "../TablePaginationActions-BWer8cmX.js";
7
+ import { a } from "../TablePaginationActions-BWer8cmX.js";
8
+ import { S as ScreenReaderOnly, I as IconButton$1, A as Alert$1 } from "../Alert-DmbdMf46.js";
9
+ import { L } from "../Alert-DmbdMf46.js";
10
+ import { A as ArrowDown } from "../ArrowDown-d6bxUL0F.js";
11
+ import { A as ArrowUp, O as OpenDiagonallyRight, C as CloseDiagonallyRight } from "../OpenDiagonallyRight-CGdCEXlF.js";
11
12
  import "cartocolor";
12
- import { M as MenuItem$1 } from "../MenuItem-CXnnE5lK.js";
13
+ import { M as MenuItem$1 } from "../MenuItem-C8x-GasJ.js";
14
+ import { FixedSizeList } from "react-window";
13
15
  import { DatePicker as DatePicker$1 } from "@mui/x-date-pickers/DatePicker";
14
16
  import { PickersDay as PickersDay$1 } from "@mui/x-date-pickers";
15
17
  import { TimePicker as TimePicker$1 } from "@mui/x-date-pickers/TimePicker";
@@ -60,10 +62,15 @@ function _Button({
60
62
  startIcon,
61
63
  endIcon,
62
64
  loadingPosition,
65
+ external,
66
+ showExternalIcon = true,
63
67
  ...otherProps
64
68
  }, ref) {
69
+ const intl = useIntl();
70
+ const intlConfig = useImperativeIntl(intl);
65
71
  const defaultIconLoader = /* @__PURE__ */ jsx(CircularProgress, { size: 18, color: "inherit" });
66
72
  const isDefaultLoading = loading && loadingPosition === void 0;
73
+ const isExternalLink = otherProps.href && external;
67
74
  const renderContent = () => {
68
75
  if (isDefaultLoading) {
69
76
  return /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
@@ -71,6 +78,14 @@ function _Button({
71
78
  /* @__PURE__ */ jsx(HiddenText, { children })
72
79
  ] });
73
80
  }
81
+ if (isExternalLink) {
82
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
83
+ children,
84
+ /* @__PURE__ */ jsx(ScreenReaderOnly, { id: "external-hint", children: `(${intlConfig.formatMessage({
85
+ id: "c4r.button.opensInNewTab"
86
+ })})` })
87
+ ] });
88
+ }
74
89
  return children;
75
90
  };
76
91
  const getIconForPosition = (position) => {
@@ -83,7 +98,11 @@ function _Button({
83
98
  }
84
99
  return void 0;
85
100
  }
86
- return position === "start" ? startIcon : endIcon;
101
+ if (position === "start") {
102
+ return startIcon;
103
+ } else {
104
+ return endIcon || (isExternalLink && showExternalIcon ? /* @__PURE__ */ jsx(OpenInNewOutlined, {}) : void 0);
105
+ }
87
106
  };
88
107
  return /* @__PURE__ */ jsx(
89
108
  Button$1,
@@ -93,7 +112,12 @@ function _Button({
93
112
  endIcon: getIconForPosition("end"),
94
113
  ...otherProps,
95
114
  role: otherProps.href ? "link" : "button",
115
+ ...isExternalLink && {
116
+ target: "_blank",
117
+ rel: "noopener noreferrer"
118
+ },
96
119
  ref,
120
+ "aria-describedby": isExternalLink ? "external-hint" : void 0,
97
121
  children: /* @__PURE__ */ jsx(Typography, { variant: "inherit", color: "inherit", noWrap: true, component: "span", children: renderContent() })
98
122
  }
99
123
  );
@@ -478,10 +502,10 @@ function ToggleButtonGroup({
478
502
  }
479
503
  const StyledMenu = styled(Menu$2, {
480
504
  shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
481
- })(({ theme, extended, width, height }) => ({
505
+ })(({ extended, width, height }) => ({
482
506
  ...extended && {
483
507
  ".MuiMenuItem-root": {
484
- minHeight: theme.spacing(6)
508
+ minHeight: MENU_ITEM_SIZE_EXTENDED
485
509
  }
486
510
  },
487
511
  ...width && {
@@ -521,10 +545,10 @@ function _Menu({ extended, width, height, MenuListProps, ...otherProps }, ref) {
521
545
  const Menu$1 = forwardRef(_Menu);
522
546
  const StyledMenuList = styled(MenuList$1, {
523
547
  shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
524
- })(({ theme, extended, width, height }) => ({
548
+ })(({ extended, width, height }) => ({
525
549
  ...extended && {
526
550
  ".MuiMenuItem-root": {
527
- minHeight: theme.spacing(6)
551
+ minHeight: MENU_ITEM_SIZE_EXTENDED
528
552
  }
529
553
  },
530
554
  "&.MuiList-root": {
@@ -555,7 +579,8 @@ function _MenuList({ extended, width, height, ...otherProps }, ref) {
555
579
  }
556
580
  const MenuList = forwardRef(_MenuList);
557
581
  const StyledMenuItem$1 = styled(MenuItem$1)(() => ({
558
- marginTop: "0 !important"
582
+ marginTop: "0 !important",
583
+ marginBottom: "0 !important"
559
584
  }));
560
585
  const LinkFilter = styled(Link)(
561
586
  ({ disabled, theme }) => ({
@@ -795,12 +820,20 @@ function _MultipleSelectField({
795
820
  },
796
821
  children: [
797
822
  showFilters && /* @__PURE__ */ jsx(
798
- MenuItemFilter,
823
+ Box,
799
824
  {
800
- areAllSelected,
801
- areAnySelected,
802
- selectAll,
803
- selectAllDisabled
825
+ sx: {
826
+ mb: 1
827
+ },
828
+ children: /* @__PURE__ */ jsx(
829
+ MenuItemFilter,
830
+ {
831
+ areAllSelected,
832
+ areAnySelected,
833
+ selectAll,
834
+ selectAllDisabled
835
+ }
836
+ )
804
837
  }
805
838
  ),
806
839
  options == null ? void 0 : options.map((option) => {
@@ -1107,11 +1140,130 @@ function UploadField({
1107
1140
  )
1108
1141
  ] });
1109
1142
  }
1143
+ const AUTOCOMPLETE_GROUP_HEADER_PROPERTY = "__isGroupHeader";
1144
+ function isAutocompleteListGroupHeader(option) {
1145
+ return typeof option === "object" && option !== null && AUTOCOMPLETE_GROUP_HEADER_PROPERTY in option;
1146
+ }
1147
+ const getDefaultOptionLabel = (option) => {
1148
+ return option && typeof option === "object" ? option.title ?? String(option) : String(option);
1149
+ };
1150
+ const createOptionWithMultiple = (option, multiple) => {
1151
+ return typeof option !== "object" || option === null ? { value: option, multiple } : { ...option, multiple };
1152
+ };
1153
+ const getDefaultLimitTagsText = (more) => /* @__PURE__ */ jsxs("span", { "data-testid": "more-options-tag", children: [
1154
+ "+",
1155
+ more
1156
+ ] });
1157
+ function createCounterRenderTags({
1158
+ formatCounter,
1159
+ options = [],
1160
+ size = "small",
1161
+ getOptionLabel = getDefaultOptionLabel
1162
+ }) {
1163
+ const CounterRenderTags = (value) => {
1164
+ if (value.length === 0) {
1165
+ return null;
1166
+ }
1167
+ const selectedCount = value.length;
1168
+ const selectableOptions = options.filter(
1169
+ (option) => !isAutocompleteListGroupHeader(option)
1170
+ );
1171
+ const totalCount = selectableOptions.length;
1172
+ const text = formatCounter({
1173
+ selectedCount,
1174
+ totalCount,
1175
+ selectedItems: value,
1176
+ allItems: selectableOptions,
1177
+ getOptionLabel
1178
+ });
1179
+ return /* @__PURE__ */ jsx(
1180
+ Typography,
1181
+ {
1182
+ variant: size === "small" ? "body2" : "body1",
1183
+ component: "span",
1184
+ "data-testid": "counter-tag",
1185
+ sx: {
1186
+ ml: 1
1187
+ },
1188
+ children: text
1189
+ }
1190
+ );
1191
+ };
1192
+ return CounterRenderTags;
1193
+ }
1194
+ function createCounterFormatter({
1195
+ counterText,
1196
+ allText,
1197
+ showSingleItemText = true
1198
+ }) {
1199
+ return ({
1200
+ selectedCount,
1201
+ totalCount,
1202
+ selectedItems,
1203
+ getOptionLabel
1204
+ }) => {
1205
+ if (selectedCount === totalCount && totalCount > 0) {
1206
+ return allText;
1207
+ } else if (selectedCount === 1 && showSingleItemText) {
1208
+ return getOptionLabel(selectedItems[0]);
1209
+ } else {
1210
+ return `${selectedCount} ${counterText}`;
1211
+ }
1212
+ };
1213
+ }
1214
+ function createAutocompleteGroupByList({
1215
+ options,
1216
+ groupBy,
1217
+ extended
1218
+ }) {
1219
+ const grouped = options.reduce(
1220
+ (acc, option) => {
1221
+ const group = groupBy(option);
1222
+ if (!acc[group]) {
1223
+ acc[group] = [];
1224
+ }
1225
+ acc[group].push(option);
1226
+ return acc;
1227
+ },
1228
+ {}
1229
+ );
1230
+ const result = [];
1231
+ Object.keys(grouped).forEach((title) => {
1232
+ result.push({ [AUTOCOMPLETE_GROUP_HEADER_PROPERTY]: true, title, extended });
1233
+ const groupOptions = grouped[title];
1234
+ if (groupOptions) {
1235
+ result.push(...groupOptions);
1236
+ }
1237
+ });
1238
+ return result;
1239
+ }
1240
+ function warnDeprecatedGroupBy(componentName) {
1241
+ if (process.env.NODE_ENV !== "production") {
1242
+ console.error(
1243
+ `${componentName}: The \`groupBy\` prop is deprecated and breaks virtualization. Use \`createAutocompleteGroupByList\` instead:
1244
+
1245
+ \`\`\`
1246
+ import { createAutocompleteGroupByList, ${componentName} } from "@carto/meridian-ds/components"
1247
+
1248
+ const groupedOptions = createAutocompleteGroupByList({
1249
+ options,
1250
+ groupBy: (option) => option.category
1251
+ })
1252
+
1253
+ <${componentName} options={groupedOptions} />
1254
+ \`\`\`
1255
+ `
1256
+ );
1257
+ }
1258
+ }
1110
1259
  function _Autocomplete({
1111
1260
  disabled,
1112
1261
  loading,
1113
1262
  ...props
1114
1263
  }, ref) {
1264
+ if (props.groupBy) {
1265
+ warnDeprecatedGroupBy("Autocomplete");
1266
+ }
1115
1267
  return /* @__PURE__ */ jsx(
1116
1268
  Autocomplete$1,
1117
1269
  {
@@ -1128,15 +1280,24 @@ function _Autocomplete({
1128
1280
  );
1129
1281
  }
1130
1282
  const Autocomplete = forwardRef(_Autocomplete);
1131
- const getDefaultOptionLabel = (option) => {
1132
- return option && typeof option === "object" ? option.title ?? String(option) : String(option);
1133
- };
1134
- const createOptionWithMultiple = (option, multiple) => {
1135
- return typeof option !== "object" || option === null ? { value: option, multiple } : { ...option, multiple };
1136
- };
1137
- const getDefaultLimitTagsText = (more) => /* @__PURE__ */ jsx("span", { "data-testid": "more-options-tag", children: `+${more}` });
1138
1283
  function useAutocompleteRenderOption() {
1139
1284
  const renderOption = (props, option, state, getOptionLabel, customIcon) => {
1285
+ const { key, ...otherProps } = props;
1286
+ if (isAutocompleteListGroupHeader(option)) {
1287
+ return /* @__PURE__ */ createElement(
1288
+ MenuItem$1,
1289
+ {
1290
+ ...otherProps,
1291
+ subtitle: true,
1292
+ extended: option.extended,
1293
+ key,
1294
+ "aria-disabled": true,
1295
+ "aria-selected": false
1296
+ },
1297
+ option.title
1298
+ );
1299
+ }
1300
+ const regularOption = option;
1140
1301
  const {
1141
1302
  title,
1142
1303
  inputValue,
@@ -1153,9 +1314,8 @@ function useAutocompleteRenderOption() {
1153
1314
  alternativeTitle,
1154
1315
  secondaryText,
1155
1316
  multiple
1156
- } = option;
1157
- const { key, ...otherProps } = props;
1158
- const isPrimitiveOptionType = typeof option === "string" || typeof option === "number";
1317
+ } = regularOption;
1318
+ const isPrimitiveOptionType = typeof regularOption === "string" || typeof regularOption === "number";
1159
1319
  const getOptionLabelText = (getOptionLabel2, option2, alternativeTitle2, title2) => {
1160
1320
  if (alternativeTitle2) return alternativeTitle2;
1161
1321
  if (title2) return title2;
@@ -1189,7 +1349,7 @@ function useAutocompleteRenderOption() {
1189
1349
  /* @__PURE__ */ jsxs(ListItemText, { children: [
1190
1350
  getOptionLabelText(
1191
1351
  getOptionLabel ?? getDefaultOptionLabel,
1192
- option,
1352
+ regularOption,
1193
1353
  alternativeTitle,
1194
1354
  title
1195
1355
  ),
@@ -1276,8 +1436,16 @@ function useMultipleAutocomplete({
1276
1436
  options,
1277
1437
  value,
1278
1438
  onChange,
1279
- getOptionLabel
1439
+ getOptionLabel,
1440
+ size,
1441
+ counterFormatter,
1442
+ counterText,
1443
+ allSelectedText
1280
1444
  }) {
1445
+ const intl = useIntl();
1446
+ const intlConfig = useImperativeIntl(intl);
1447
+ const defaultCounterText = counterText || intlConfig.formatMessage({ id: "c4r.form.selected" });
1448
+ const defaultAllSelectedText = allSelectedText || intlConfig.formatMessage({ id: "c4r.form.allSelected" });
1281
1449
  const [multipleValue, setMultipleValue] = useState(
1282
1450
  Array.isArray(value) ? value : value ? [value] : []
1283
1451
  );
@@ -1286,10 +1454,13 @@ function useMultipleAutocomplete({
1286
1454
  const newValue = Array.isArray(value) ? value : value ? [value] : [];
1287
1455
  setMultipleValue(newValue);
1288
1456
  }, [value]);
1289
- const allSelected = multipleValue.length === options.length;
1290
- const someSelected = multipleValue.length > 0 && multipleValue.length < options.length;
1457
+ const selectableOptions = options.filter(
1458
+ (option) => !isAutocompleteListGroupHeader(option)
1459
+ );
1460
+ const allSelected = multipleValue.length === selectableOptions.length;
1461
+ const someSelected = multipleValue.length > 0 && multipleValue.length < selectableOptions.length;
1291
1462
  const handleSelectAll = (event) => {
1292
- const newValue = allSelected ? [] : [...options];
1463
+ const newValue = allSelected ? [] : [...selectableOptions];
1293
1464
  setMultipleValue(newValue);
1294
1465
  onChange == null ? void 0 : onChange(
1295
1466
  event,
@@ -1311,31 +1482,173 @@ function useMultipleAutocomplete({
1311
1482
  getOptionLabel
1312
1483
  );
1313
1484
  };
1485
+ const getCounterRenderTags = useCallback(() => {
1486
+ const formatter = counterFormatter || createCounterFormatter({
1487
+ counterText: defaultCounterText,
1488
+ allText: defaultAllSelectedText
1489
+ });
1490
+ return createCounterRenderTags({
1491
+ formatCounter: formatter,
1492
+ options,
1493
+ size,
1494
+ getOptionLabel: getOptionLabel ? (option) => getOptionLabel(option) : void 0
1495
+ });
1496
+ }, [
1497
+ options,
1498
+ counterFormatter,
1499
+ defaultCounterText,
1500
+ defaultAllSelectedText,
1501
+ size,
1502
+ getOptionLabel
1503
+ ]);
1314
1504
  return {
1315
1505
  multipleValue,
1316
1506
  allSelected,
1317
1507
  someSelected,
1318
1508
  handleSelectAll,
1319
1509
  handleChange,
1320
- multipleRenderOption
1510
+ multipleRenderOption,
1511
+ getCounterRenderTags
1321
1512
  };
1322
1513
  }
1323
- function _ListboxWithFilter({
1514
+ const List = styled("ul")(
1515
+ ({ theme, hasFilters }) => ({
1516
+ ...!hasFilters && {
1517
+ paddingTop: `${theme.spacing(1)} !important`
1518
+ }
1519
+ })
1520
+ );
1521
+ const ItemWrapper = styled("div")(({ style, theme, isSubtitle, isExtended, isMultiple }) => {
1522
+ const getSubtitleStyles = () => {
1523
+ const baseStyles = {
1524
+ height: MENU_ITEM_SIZE_DENSE,
1525
+ minHeight: MENU_ITEM_SIZE_DENSE,
1526
+ marginTop: `${theme.spacing(1)} !important`,
1527
+ alignItems: "flex-end",
1528
+ ...theme.typography.caption,
1529
+ fontWeight: 500
1530
+ };
1531
+ if (isExtended) {
1532
+ baseStyles.alignItems = "center";
1533
+ if (isMultiple) {
1534
+ baseStyles.marginLeft = theme.spacing(0.5);
1535
+ }
1536
+ }
1537
+ return baseStyles;
1538
+ };
1539
+ return {
1540
+ pointerEvents: "none",
1541
+ // To avoid the extra div to receive the click event
1542
+ "& .MuiMenuItem-root": {
1543
+ pointerEvents: "auto",
1544
+ // Allow pointer events for the menu item
1545
+ marginTop: 0,
1546
+ "&:first-of-type": {
1547
+ marginTop: "0 !important"
1548
+ }
1549
+ },
1550
+ ...isSubtitle && {
1551
+ "& .MuiAutocomplete-option.MuiMenuItem-root": getSubtitleStyles(),
1552
+ // First item has no divider
1553
+ "&:not(:first-of-type)": {
1554
+ "&::before": {
1555
+ content: '""',
1556
+ position: "absolute",
1557
+ zIndex: 1,
1558
+ top: theme.spacing(0.5),
1559
+ left: 0,
1560
+ right: 0,
1561
+ height: "1px",
1562
+ backgroundColor: theme.palette.divider
1563
+ }
1564
+ }
1565
+ },
1566
+ ...!isSubtitle && {
1567
+ "& .MuiAutocomplete-option": {
1568
+ minHeight: `${style == null ? void 0 : style.height}px !important`
1569
+ }
1570
+ }
1571
+ };
1572
+ });
1573
+ function _AutocompleteList({
1324
1574
  children,
1325
1575
  showFilters,
1326
1576
  allSelected,
1327
1577
  someSelected,
1328
1578
  handleSelectAll = () => void 0,
1329
1579
  multiple,
1580
+ extended,
1581
+ itemHeight,
1582
+ maxListHeight = MENU_LIST_MAX_SIZE,
1330
1583
  ...otherProps
1331
1584
  }, ref) {
1585
+ const childrenArray = useMemo(() => {
1586
+ return React.Children.toArray(children).map((child) => {
1587
+ if (!React.isValidElement(child)) {
1588
+ return {
1589
+ child,
1590
+ isSubtitle: false,
1591
+ isExtended: false,
1592
+ isMultiple: !!multiple
1593
+ };
1594
+ }
1595
+ const props = child.props;
1596
+ return {
1597
+ child,
1598
+ isSubtitle: props.subtitle === true,
1599
+ isExtended: props.extended === true,
1600
+ isMultiple: !!multiple
1601
+ };
1602
+ });
1603
+ }, [children, multiple]);
1604
+ const defaultItemHeight = itemHeight ?? (extended ? MENU_ITEM_SIZE_EXTENDED : MENU_ITEM_SIZE_DEFAULT);
1605
+ const listboxHeight = useMemo(() => {
1606
+ const filterHeight = showFilters && multiple ? MENU_ITEM_SIZE_EXTENDED : 0;
1607
+ const availableHeight = maxListHeight - filterHeight;
1608
+ const calculatedHeight = Math.min(
1609
+ childrenArray.length * defaultItemHeight,
1610
+ availableHeight
1611
+ );
1612
+ return Math.max(calculatedHeight, defaultItemHeight);
1613
+ }, [
1614
+ showFilters,
1615
+ multiple,
1616
+ maxListHeight,
1617
+ childrenArray.length,
1618
+ defaultItemHeight
1619
+ ]);
1620
+ const renderItem = ({
1621
+ index,
1622
+ style
1623
+ }) => {
1624
+ const item = childrenArray[index];
1625
+ if (!item) return null;
1626
+ const { child, isSubtitle, isExtended, isMultiple } = item;
1627
+ return /* @__PURE__ */ jsx(
1628
+ ItemWrapper,
1629
+ {
1630
+ style,
1631
+ isSubtitle,
1632
+ isExtended,
1633
+ isMultiple,
1634
+ "data-name": "virtual-menu-item",
1635
+ children: child
1636
+ }
1637
+ );
1638
+ };
1332
1639
  return /* @__PURE__ */ jsxs(
1333
- "ul",
1640
+ List,
1334
1641
  {
1335
1642
  ref,
1336
1643
  ...otherProps,
1337
1644
  role: "listbox",
1645
+ "data-list-height": listboxHeight,
1646
+ "data-item-height": defaultItemHeight,
1338
1647
  "aria-multiselectable": multiple,
1648
+ hasFilters: showFilters,
1649
+ style: {
1650
+ maxHeight: maxListHeight + defaultItemHeight
1651
+ },
1339
1652
  children: [
1340
1653
  showFilters && multiple && /* @__PURE__ */ jsx(
1341
1654
  MenuItemFilter,
@@ -1345,12 +1658,21 @@ function _ListboxWithFilter({
1345
1658
  selectAll: handleSelectAll
1346
1659
  }
1347
1660
  ),
1348
- children
1661
+ /* @__PURE__ */ jsx(
1662
+ FixedSizeList,
1663
+ {
1664
+ height: listboxHeight,
1665
+ width: "100%",
1666
+ itemCount: childrenArray.length,
1667
+ itemSize: defaultItemHeight,
1668
+ children: renderItem
1669
+ }
1670
+ )
1349
1671
  ]
1350
1672
  }
1351
1673
  );
1352
1674
  }
1353
- const ListboxWithFilter = forwardRef(_ListboxWithFilter);
1675
+ const AutocompleteList = forwardRef(_AutocompleteList);
1354
1676
  function _CreatableAutocomplete({
1355
1677
  newItemLabel,
1356
1678
  newItemIcon,
@@ -1360,23 +1682,41 @@ function _CreatableAutocomplete({
1360
1682
  disabled,
1361
1683
  loading,
1362
1684
  showFilters,
1685
+ showCounter = false,
1686
+ counterFormatter,
1687
+ counterText,
1688
+ allSelectedText,
1363
1689
  options = [],
1364
1690
  value,
1365
1691
  onChange,
1366
1692
  getLimitTagsText,
1693
+ renderTags,
1694
+ itemHeight,
1695
+ maxListHeight,
1696
+ extended,
1697
+ groupBy,
1367
1698
  ...props
1368
1699
  }, ref) {
1700
+ if (groupBy) {
1701
+ warnDeprecatedGroupBy("CreatableAutocomplete");
1702
+ }
1369
1703
  const { freeSolo = true, ...otherProps } = props;
1370
1704
  const {
1371
1705
  multipleValue,
1372
1706
  allSelected,
1373
1707
  someSelected,
1374
1708
  handleSelectAll,
1375
- handleChange
1709
+ handleChange,
1710
+ getCounterRenderTags
1376
1711
  } = useMultipleAutocomplete({
1377
1712
  options,
1378
1713
  value,
1379
- onChange
1714
+ onChange,
1715
+ getOptionLabel,
1716
+ size: props.size,
1717
+ counterFormatter,
1718
+ counterText,
1719
+ allSelectedText
1380
1720
  });
1381
1721
  const {
1382
1722
  creatableFilterOptions,
@@ -1388,6 +1728,17 @@ function _CreatableAutocomplete({
1388
1728
  newItemIcon,
1389
1729
  multiple
1390
1730
  });
1731
+ const listboxProps = {
1732
+ showFilters,
1733
+ allSelected,
1734
+ someSelected,
1735
+ handleSelectAll,
1736
+ multiple,
1737
+ itemHeight,
1738
+ maxListHeight,
1739
+ extended
1740
+ };
1741
+ const finalRenderTags = showCounter && multiple && !renderTags ? getCounterRenderTags() : renderTags;
1391
1742
  return /* @__PURE__ */ jsx(
1392
1743
  Autocomplete$1,
1393
1744
  {
@@ -1399,18 +1750,13 @@ function _CreatableAutocomplete({
1399
1750
  filterOptions: creatableFilterOptions,
1400
1751
  getOptionLabel: creatableOptionLabel,
1401
1752
  renderOption: creatableRenderOption,
1753
+ renderTags: finalRenderTags,
1402
1754
  freeSolo,
1403
1755
  forcePopupIcon: true,
1404
1756
  multiple,
1405
1757
  disableCloseOnSelect: disableCloseOnSelect ?? multiple,
1406
- ListboxComponent: ListboxWithFilter,
1407
- ListboxProps: {
1408
- showFilters,
1409
- allSelected,
1410
- someSelected,
1411
- handleSelectAll,
1412
- multiple
1413
- },
1758
+ ListboxComponent: AutocompleteList,
1759
+ ListboxProps: listboxProps,
1414
1760
  getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
1415
1761
  disabled: disabled || loading,
1416
1762
  popupIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: 18, color: "inherit" }) : /* @__PURE__ */ jsx(ArrowDown, {}),
@@ -1425,26 +1771,54 @@ function _MultipleAutocomplete({
1425
1771
  disabled,
1426
1772
  loading,
1427
1773
  showFilters,
1774
+ showCounter = false,
1775
+ counterFormatter,
1776
+ counterText,
1777
+ allSelectedText,
1428
1778
  options,
1429
1779
  value,
1430
1780
  onChange,
1431
1781
  getOptionLabel,
1432
1782
  getLimitTagsText,
1783
+ renderTags,
1784
+ itemHeight,
1785
+ maxListHeight,
1786
+ extended,
1787
+ groupBy,
1433
1788
  ...props
1434
1789
  }, ref) {
1790
+ if (groupBy) {
1791
+ warnDeprecatedGroupBy("MultipleAutocomplete");
1792
+ }
1435
1793
  const {
1436
1794
  multipleValue,
1437
1795
  allSelected,
1438
1796
  someSelected,
1439
1797
  handleSelectAll,
1440
1798
  handleChange,
1441
- multipleRenderOption
1799
+ multipleRenderOption,
1800
+ getCounterRenderTags
1442
1801
  } = useMultipleAutocomplete({
1443
1802
  options,
1444
1803
  value,
1445
1804
  onChange,
1446
- getOptionLabel
1805
+ getOptionLabel,
1806
+ size: props.size,
1807
+ counterFormatter,
1808
+ counterText,
1809
+ allSelectedText
1447
1810
  });
1811
+ const listboxProps = {
1812
+ showFilters,
1813
+ allSelected,
1814
+ someSelected,
1815
+ handleSelectAll,
1816
+ multiple: true,
1817
+ itemHeight,
1818
+ maxListHeight,
1819
+ extended
1820
+ };
1821
+ const finalRenderTags = showCounter && !renderTags ? getCounterRenderTags() : renderTags;
1448
1822
  return /* @__PURE__ */ jsx(
1449
1823
  Autocomplete$1,
1450
1824
  {
@@ -1455,14 +1829,9 @@ function _MultipleAutocomplete({
1455
1829
  onChange: handleChange,
1456
1830
  getOptionLabel,
1457
1831
  renderOption: renderOption ?? multipleRenderOption,
1458
- ListboxComponent: ListboxWithFilter,
1459
- ListboxProps: {
1460
- showFilters,
1461
- allSelected,
1462
- someSelected,
1463
- handleSelectAll,
1464
- multiple: true
1465
- },
1832
+ renderTags: finalRenderTags,
1833
+ ListboxComponent: AutocompleteList,
1834
+ ListboxProps: listboxProps,
1466
1835
  multiple: true,
1467
1836
  getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
1468
1837
  disableCloseOnSelect,
@@ -1473,6 +1842,30 @@ function _MultipleAutocomplete({
1473
1842
  );
1474
1843
  }
1475
1844
  const MultipleAutocomplete = forwardRef(_MultipleAutocomplete);
1845
+ function useAutocomplete({
1846
+ getOptionLabel = getDefaultOptionLabel
1847
+ }) {
1848
+ const { renderOption: autocompleteRenderOption } = useAutocompleteRenderOption();
1849
+ const internalGetOptionLabel = (option) => {
1850
+ if (isAutocompleteListGroupHeader(option)) {
1851
+ return option.title;
1852
+ }
1853
+ return getOptionLabel(option);
1854
+ };
1855
+ const singleRenderOption = (props, option, state) => {
1856
+ const optionWithMultiple = createOptionWithMultiple(option, false);
1857
+ return autocompleteRenderOption(
1858
+ props,
1859
+ optionWithMultiple,
1860
+ state,
1861
+ internalGetOptionLabel
1862
+ );
1863
+ };
1864
+ return {
1865
+ singleRenderOption,
1866
+ getOptionLabel: internalGetOptionLabel
1867
+ };
1868
+ }
1476
1869
  const _CopiableComponent = ({
1477
1870
  children,
1478
1871
  disabled,
@@ -4693,10 +5086,12 @@ function CodeAreaDialog({
4693
5086
  );
4694
5087
  }
4695
5088
  export {
5089
+ AUTOCOMPLETE_GROUP_HEADER_PROPERTY,
4696
5090
  AccordionGroup,
4697
5091
  Alert$1 as Alert,
4698
5092
  AppBar,
4699
5093
  Autocomplete,
5094
+ AutocompleteList,
4700
5095
  Avatar,
4701
5096
  Button,
4702
5097
  CodeAreaDialog,
@@ -4725,6 +5120,7 @@ export {
4725
5120
  DialogStepper,
4726
5121
  IconButton$1 as IconButton,
4727
5122
  LabelWithIndicator,
5123
+ L as Link,
4728
5124
  Menu$1 as Menu,
4729
5125
  MenuItem$1 as MenuItem,
4730
5126
  MenuItemFilter,
@@ -4732,6 +5128,7 @@ export {
4732
5128
  MultipleAutocomplete,
4733
5129
  MultipleSelectField,
4734
5130
  PasswordField,
5131
+ ScreenReaderOnly,
4735
5132
  SelectField,
4736
5133
  Snackbar,
4737
5134
  SplitButton,
@@ -4744,6 +5141,9 @@ export {
4744
5141
  UploadField,
4745
5142
  UploadFieldBase,
4746
5143
  copyString,
5144
+ createAutocompleteGroupByList,
4747
5145
  dialogDimensionsBySize,
5146
+ isAutocompleteListGroupHeader,
5147
+ useAutocomplete,
4748
5148
  useCopyValue
4749
5149
  };