@carto/meridian-ds 1.5.0 → 1.5.1-alpha-virtual-autocomplete.9
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.
- package/CHANGELOG.md +6 -0
- package/dist/{Alert-BiOR9aar.cjs → Alert-BzEgeyQJ.cjs} +1 -1
- package/dist/{Alert-CywtIMOj.js → Alert-CnaTtNJd.js} +1 -1
- package/dist/{MenuItem-CXnnE5lK.js → MenuItem-C1DvWMry.js} +10 -6
- package/dist/{MenuItem-Br2jY2lt.cjs → MenuItem-C4bG5WHw.cjs} +10 -6
- package/dist/{TablePaginationActions-KpTvhN4Y.js → TablePaginationActions-Cz5Hbi6N.js} +9 -1
- package/dist/{TablePaginationActions-CFGXm44W.cjs → TablePaginationActions-mbbjzV6Y.cjs} +8 -0
- package/dist/components/index.cjs +435 -55
- package/dist/components/index.js +437 -57
- package/dist/theme/index.cjs +13 -9
- package/dist/theme/index.js +14 -10
- package/dist/types/components/atoms/SplitButton.d.ts +9 -5
- package/dist/types/components/atoms/SplitButton.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/AutocompleteList.d.ts +13 -0
- package/dist/types/components/molecules/Autocomplete/AutocompleteList.d.ts.map +1 -0
- package/dist/types/components/molecules/Autocomplete/CreatableAutocomplete.d.ts +1 -1
- package/dist/types/components/molecules/Autocomplete/CreatableAutocomplete.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/MultipleAutocomplete.d.ts +1 -1
- package/dist/types/components/molecules/Autocomplete/MultipleAutocomplete.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/index.d.ts +3 -0
- package/dist/types/components/molecules/Autocomplete/index.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/types.d.ts +107 -7
- package/dist/types/components/molecules/Autocomplete/types.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/useAutocomplete.d.ts +11 -0
- package/dist/types/components/molecules/Autocomplete/useAutocomplete.d.ts.map +1 -0
- package/dist/types/components/molecules/Autocomplete/useAutocompleteRenderOption.d.ts +2 -1
- package/dist/types/components/molecules/Autocomplete/useAutocompleteRenderOption.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/useMultipleAutocomplete.d.ts +26 -1
- package/dist/types/components/molecules/Autocomplete/useMultipleAutocomplete.d.ts.map +1 -1
- package/dist/types/components/molecules/Autocomplete/utils.d.ts +107 -0
- package/dist/types/components/molecules/Autocomplete/utils.d.ts.map +1 -1
- package/dist/types/components/molecules/Menu/Menu.d.ts.map +1 -1
- package/dist/types/components/molecules/Menu/MenuItem.d.ts.map +1 -1
- package/dist/types/components/molecules/Menu/MenuItemFilter.d.ts.map +1 -1
- package/dist/types/components/molecules/Menu/MenuList.d.ts.map +1 -1
- package/dist/types/components/molecules/MultipleSelectField/MultipleSelectField.d.ts.map +1 -1
- package/dist/types/theme/sections/components/forms.d.ts.map +1 -1
- package/dist/types/theme/sections/components/navigation.d.ts.map +1 -1
- package/dist/types/theme/theme-constants.d.ts +4 -0
- package/dist/types/theme/theme-constants.d.ts.map +1 -1
- package/dist/widgets/index.cjs +2 -2
- package/dist/widgets/index.js +2 -2
- package/package.json +1 -1
- package/dist/types/components/molecules/Autocomplete/ListBoxWithFilter.d.ts +0 -17
- package/dist/types/components/molecules/Autocomplete/ListBoxWithFilter.d.ts.map +0 -1
package/dist/components/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useState, useRef, useEffect, useMemo, Fragment as Fragment$1,
|
|
2
|
+
import React, { forwardRef, useState, useRef, useEffect, useMemo, createElement, Fragment as Fragment$1, useCallback, useImperativeHandle } from "react";
|
|
3
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-
|
|
5
|
-
import { a } from "../TablePaginationActions-
|
|
4
|
+
import { T as Typography, c as ICON_SIZE_SMALL, u as useImperativeIntl, 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-Cz5Hbi6N.js";
|
|
5
|
+
import { a } from "../TablePaginationActions-Cz5Hbi6N.js";
|
|
6
6
|
import { A as ArrowDown } from "../ArrowDown-CY_wMVJT.js";
|
|
7
7
|
import { A as ArrowUp, O as OpenDiagonallyRight, C as CloseDiagonallyRight } from "../OpenDiagonallyRight-CSm5GYYJ.js";
|
|
8
8
|
import { useIntl } from "react-intl";
|
|
9
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-
|
|
10
|
+
import { I as IconButton$1, A as Alert$1 } from "../Alert-CnaTtNJd.js";
|
|
11
11
|
import "cartocolor";
|
|
12
|
-
import { M as MenuItem$1 } from "../MenuItem-
|
|
12
|
+
import { M as MenuItem$1 } from "../MenuItem-C1DvWMry.js";
|
|
13
|
+
import { FixedSizeList } from "react-window";
|
|
13
14
|
import { DatePicker as DatePicker$1 } from "@mui/x-date-pickers/DatePicker";
|
|
14
15
|
import { PickersDay as PickersDay$1 } from "@mui/x-date-pickers";
|
|
15
16
|
import { TimePicker as TimePicker$1 } from "@mui/x-date-pickers/TimePicker";
|
|
@@ -107,6 +108,9 @@ const ButtonGroup = styled(ButtonGroup$1)(({ theme, size }) => ({
|
|
|
107
108
|
}));
|
|
108
109
|
function SplitButton({
|
|
109
110
|
options,
|
|
111
|
+
disabled,
|
|
112
|
+
loading,
|
|
113
|
+
loadingPosition,
|
|
110
114
|
onClick,
|
|
111
115
|
variant,
|
|
112
116
|
size,
|
|
@@ -145,8 +149,17 @@ function SplitButton({
|
|
|
145
149
|
color,
|
|
146
150
|
...otherProps,
|
|
147
151
|
children: [
|
|
148
|
-
/* @__PURE__ */ jsx(
|
|
149
|
-
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
Button,
|
|
154
|
+
{
|
|
155
|
+
disabled,
|
|
156
|
+
loading,
|
|
157
|
+
loadingPosition,
|
|
158
|
+
onClick: handleClick,
|
|
159
|
+
children: (_a = options[selectedIndex]) == null ? void 0 : _a.label
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ jsx(Button, { disabled: loading || disabled, onClick: handleToggle, children: open ? /* @__PURE__ */ jsx(ArrowUp, {}) : /* @__PURE__ */ jsx(ArrowDown, {}) })
|
|
150
163
|
]
|
|
151
164
|
}
|
|
152
165
|
),
|
|
@@ -466,10 +479,10 @@ function ToggleButtonGroup({
|
|
|
466
479
|
}
|
|
467
480
|
const StyledMenu = styled(Menu$2, {
|
|
468
481
|
shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
|
|
469
|
-
})(({
|
|
482
|
+
})(({ extended, width, height }) => ({
|
|
470
483
|
...extended && {
|
|
471
484
|
".MuiMenuItem-root": {
|
|
472
|
-
minHeight:
|
|
485
|
+
minHeight: MENU_ITEM_SIZE_EXTENDED
|
|
473
486
|
}
|
|
474
487
|
},
|
|
475
488
|
...width && {
|
|
@@ -509,10 +522,10 @@ function _Menu({ extended, width, height, MenuListProps, ...otherProps }, ref) {
|
|
|
509
522
|
const Menu$1 = forwardRef(_Menu);
|
|
510
523
|
const StyledMenuList = styled(MenuList$1, {
|
|
511
524
|
shouldForwardProp: (prop) => !["extended", "width", "height"].includes(prop)
|
|
512
|
-
})(({
|
|
525
|
+
})(({ extended, width, height }) => ({
|
|
513
526
|
...extended && {
|
|
514
527
|
".MuiMenuItem-root": {
|
|
515
|
-
minHeight:
|
|
528
|
+
minHeight: MENU_ITEM_SIZE_EXTENDED
|
|
516
529
|
}
|
|
517
530
|
},
|
|
518
531
|
"&.MuiList-root": {
|
|
@@ -543,7 +556,8 @@ function _MenuList({ extended, width, height, ...otherProps }, ref) {
|
|
|
543
556
|
}
|
|
544
557
|
const MenuList = forwardRef(_MenuList);
|
|
545
558
|
const StyledMenuItem$1 = styled(MenuItem$1)(() => ({
|
|
546
|
-
marginTop: "0 !important"
|
|
559
|
+
marginTop: "0 !important",
|
|
560
|
+
marginBottom: "0 !important"
|
|
547
561
|
}));
|
|
548
562
|
const LinkFilter = styled(Link)(
|
|
549
563
|
({ disabled, theme }) => ({
|
|
@@ -783,12 +797,20 @@ function _MultipleSelectField({
|
|
|
783
797
|
},
|
|
784
798
|
children: [
|
|
785
799
|
showFilters && /* @__PURE__ */ jsx(
|
|
786
|
-
|
|
800
|
+
Box,
|
|
787
801
|
{
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
802
|
+
sx: {
|
|
803
|
+
mb: 1
|
|
804
|
+
},
|
|
805
|
+
children: /* @__PURE__ */ jsx(
|
|
806
|
+
MenuItemFilter,
|
|
807
|
+
{
|
|
808
|
+
areAllSelected,
|
|
809
|
+
areAnySelected,
|
|
810
|
+
selectAll,
|
|
811
|
+
selectAllDisabled
|
|
812
|
+
}
|
|
813
|
+
)
|
|
792
814
|
}
|
|
793
815
|
),
|
|
794
816
|
options == null ? void 0 : options.map((option) => {
|
|
@@ -1095,11 +1117,123 @@ function UploadField({
|
|
|
1095
1117
|
)
|
|
1096
1118
|
] });
|
|
1097
1119
|
}
|
|
1120
|
+
const AUTOCOMPLETE_GROUP_HEADER_PROPERTY = "__isGroupHeader";
|
|
1121
|
+
function isAutocompleteListGroupHeader(option) {
|
|
1122
|
+
return typeof option === "object" && option !== null && AUTOCOMPLETE_GROUP_HEADER_PROPERTY in option;
|
|
1123
|
+
}
|
|
1124
|
+
const getDefaultOptionLabel = (option) => {
|
|
1125
|
+
return option && typeof option === "object" ? option.title ?? String(option) : String(option);
|
|
1126
|
+
};
|
|
1127
|
+
const createOptionWithMultiple = (option, multiple) => {
|
|
1128
|
+
return typeof option !== "object" || option === null ? { value: option, multiple } : { ...option, multiple };
|
|
1129
|
+
};
|
|
1130
|
+
const getDefaultLimitTagsText = (more) => /* @__PURE__ */ jsxs("span", { "data-testid": "more-options-tag", children: [
|
|
1131
|
+
"+",
|
|
1132
|
+
more
|
|
1133
|
+
] });
|
|
1134
|
+
function createCounterRenderTags({
|
|
1135
|
+
formatCounter,
|
|
1136
|
+
options = [],
|
|
1137
|
+
size = "small",
|
|
1138
|
+
getOptionLabel = getDefaultOptionLabel
|
|
1139
|
+
}) {
|
|
1140
|
+
const CounterRenderTags = (value) => {
|
|
1141
|
+
if (value.length === 0) {
|
|
1142
|
+
return null;
|
|
1143
|
+
}
|
|
1144
|
+
const selectedCount = value.length;
|
|
1145
|
+
const selectableOptions = options.filter(
|
|
1146
|
+
(option) => !isAutocompleteListGroupHeader(option)
|
|
1147
|
+
);
|
|
1148
|
+
const totalCount = selectableOptions.length;
|
|
1149
|
+
const text = formatCounter({
|
|
1150
|
+
selectedCount,
|
|
1151
|
+
totalCount,
|
|
1152
|
+
selectedItems: value,
|
|
1153
|
+
allItems: selectableOptions,
|
|
1154
|
+
getOptionLabel
|
|
1155
|
+
});
|
|
1156
|
+
return /* @__PURE__ */ jsx(
|
|
1157
|
+
Typography,
|
|
1158
|
+
{
|
|
1159
|
+
variant: size === "small" ? "body2" : "body1",
|
|
1160
|
+
component: "span",
|
|
1161
|
+
"data-testid": "counter-tag",
|
|
1162
|
+
sx: {
|
|
1163
|
+
ml: 1
|
|
1164
|
+
},
|
|
1165
|
+
children: text
|
|
1166
|
+
}
|
|
1167
|
+
);
|
|
1168
|
+
};
|
|
1169
|
+
return CounterRenderTags;
|
|
1170
|
+
}
|
|
1171
|
+
function createCounterFormatter({
|
|
1172
|
+
counterText,
|
|
1173
|
+
allText,
|
|
1174
|
+
showSingleItemText = true
|
|
1175
|
+
}) {
|
|
1176
|
+
return ({
|
|
1177
|
+
selectedCount,
|
|
1178
|
+
totalCount,
|
|
1179
|
+
selectedItems,
|
|
1180
|
+
getOptionLabel
|
|
1181
|
+
}) => {
|
|
1182
|
+
if (selectedCount === totalCount && totalCount > 0) {
|
|
1183
|
+
return allText;
|
|
1184
|
+
} else if (selectedCount === 1 && showSingleItemText) {
|
|
1185
|
+
return getOptionLabel(selectedItems[0]);
|
|
1186
|
+
} else {
|
|
1187
|
+
return `${selectedCount} ${counterText}`;
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
function createAutocompleteGroupByList(options, groupBy, extended) {
|
|
1192
|
+
const grouped = options.reduce(
|
|
1193
|
+
(acc, option) => {
|
|
1194
|
+
const group = groupBy(option);
|
|
1195
|
+
if (!acc[group]) {
|
|
1196
|
+
acc[group] = [];
|
|
1197
|
+
}
|
|
1198
|
+
acc[group].push(option);
|
|
1199
|
+
return acc;
|
|
1200
|
+
},
|
|
1201
|
+
{}
|
|
1202
|
+
);
|
|
1203
|
+
const result = [];
|
|
1204
|
+
Object.keys(grouped).forEach((title) => {
|
|
1205
|
+
result.push({ [AUTOCOMPLETE_GROUP_HEADER_PROPERTY]: true, title, extended });
|
|
1206
|
+
const groupOptions = grouped[title];
|
|
1207
|
+
if (groupOptions) {
|
|
1208
|
+
result.push(...groupOptions);
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
return result;
|
|
1212
|
+
}
|
|
1213
|
+
function warnDeprecatedGroupBy(componentName) {
|
|
1214
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1215
|
+
console.error(
|
|
1216
|
+
`${componentName}: The \`groupBy\` prop is deprecated and breaks virtualization. Use \`createAutocompleteGroupByList\` instead:
|
|
1217
|
+
|
|
1218
|
+
\`\`\`
|
|
1219
|
+
import { createAutocompleteGroupByList, ${componentName} } from "@carto/meridian-ds/components"
|
|
1220
|
+
|
|
1221
|
+
const groupedOptions = createAutocompleteGroupByList(options, (option) => option.category)
|
|
1222
|
+
|
|
1223
|
+
<${componentName} options={groupedOptions} />
|
|
1224
|
+
\`\`\`
|
|
1225
|
+
`
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1098
1229
|
function _Autocomplete({
|
|
1099
1230
|
disabled,
|
|
1100
1231
|
loading,
|
|
1101
1232
|
...props
|
|
1102
1233
|
}, ref) {
|
|
1234
|
+
if (props.groupBy) {
|
|
1235
|
+
warnDeprecatedGroupBy("Autocomplete");
|
|
1236
|
+
}
|
|
1103
1237
|
return /* @__PURE__ */ jsx(
|
|
1104
1238
|
Autocomplete$1,
|
|
1105
1239
|
{
|
|
@@ -1116,15 +1250,24 @@ function _Autocomplete({
|
|
|
1116
1250
|
);
|
|
1117
1251
|
}
|
|
1118
1252
|
const Autocomplete = forwardRef(_Autocomplete);
|
|
1119
|
-
const getDefaultOptionLabel = (option) => {
|
|
1120
|
-
return option && typeof option === "object" ? option.title ?? String(option) : String(option);
|
|
1121
|
-
};
|
|
1122
|
-
const createOptionWithMultiple = (option, multiple) => {
|
|
1123
|
-
return typeof option !== "object" || option === null ? { value: option, multiple } : { ...option, multiple };
|
|
1124
|
-
};
|
|
1125
|
-
const getDefaultLimitTagsText = (more) => /* @__PURE__ */ jsx("span", { "data-testid": "more-options-tag", children: `+${more}` });
|
|
1126
1253
|
function useAutocompleteRenderOption() {
|
|
1127
1254
|
const renderOption = (props, option, state, getOptionLabel, customIcon) => {
|
|
1255
|
+
const { key, ...otherProps } = props;
|
|
1256
|
+
if (isAutocompleteListGroupHeader(option)) {
|
|
1257
|
+
return /* @__PURE__ */ createElement(
|
|
1258
|
+
MenuItem$1,
|
|
1259
|
+
{
|
|
1260
|
+
...otherProps,
|
|
1261
|
+
subtitle: true,
|
|
1262
|
+
extended: option.extended,
|
|
1263
|
+
key,
|
|
1264
|
+
"aria-disabled": true,
|
|
1265
|
+
"aria-selected": false
|
|
1266
|
+
},
|
|
1267
|
+
option.title
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
const regularOption = option;
|
|
1128
1271
|
const {
|
|
1129
1272
|
title,
|
|
1130
1273
|
inputValue,
|
|
@@ -1141,9 +1284,8 @@ function useAutocompleteRenderOption() {
|
|
|
1141
1284
|
alternativeTitle,
|
|
1142
1285
|
secondaryText,
|
|
1143
1286
|
multiple
|
|
1144
|
-
} =
|
|
1145
|
-
const
|
|
1146
|
-
const isPrimitiveOptionType = typeof option === "string" || typeof option === "number";
|
|
1287
|
+
} = regularOption;
|
|
1288
|
+
const isPrimitiveOptionType = typeof regularOption === "string" || typeof regularOption === "number";
|
|
1147
1289
|
const getOptionLabelText = (getOptionLabel2, option2, alternativeTitle2, title2) => {
|
|
1148
1290
|
if (alternativeTitle2) return alternativeTitle2;
|
|
1149
1291
|
if (title2) return title2;
|
|
@@ -1177,7 +1319,7 @@ function useAutocompleteRenderOption() {
|
|
|
1177
1319
|
/* @__PURE__ */ jsxs(ListItemText, { children: [
|
|
1178
1320
|
getOptionLabelText(
|
|
1179
1321
|
getOptionLabel ?? getDefaultOptionLabel,
|
|
1180
|
-
|
|
1322
|
+
regularOption,
|
|
1181
1323
|
alternativeTitle,
|
|
1182
1324
|
title
|
|
1183
1325
|
),
|
|
@@ -1264,8 +1406,16 @@ function useMultipleAutocomplete({
|
|
|
1264
1406
|
options,
|
|
1265
1407
|
value,
|
|
1266
1408
|
onChange,
|
|
1267
|
-
getOptionLabel
|
|
1409
|
+
getOptionLabel,
|
|
1410
|
+
size,
|
|
1411
|
+
counterFormatter,
|
|
1412
|
+
counterText,
|
|
1413
|
+
allSelectedText
|
|
1268
1414
|
}) {
|
|
1415
|
+
const intl = useIntl();
|
|
1416
|
+
const intlConfig = useImperativeIntl(intl);
|
|
1417
|
+
const defaultCounterText = counterText || intlConfig.formatMessage({ id: "c4r.form.selected" });
|
|
1418
|
+
const defaultAllSelectedText = allSelectedText || intlConfig.formatMessage({ id: "c4r.form.allSelected" });
|
|
1269
1419
|
const [multipleValue, setMultipleValue] = useState(
|
|
1270
1420
|
Array.isArray(value) ? value : value ? [value] : []
|
|
1271
1421
|
);
|
|
@@ -1274,10 +1424,13 @@ function useMultipleAutocomplete({
|
|
|
1274
1424
|
const newValue = Array.isArray(value) ? value : value ? [value] : [];
|
|
1275
1425
|
setMultipleValue(newValue);
|
|
1276
1426
|
}, [value]);
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1427
|
+
const selectableOptions = options.filter(
|
|
1428
|
+
(option) => !isAutocompleteListGroupHeader(option)
|
|
1429
|
+
);
|
|
1430
|
+
const allSelected = multipleValue.length === selectableOptions.length;
|
|
1431
|
+
const someSelected = multipleValue.length > 0 && multipleValue.length < selectableOptions.length;
|
|
1279
1432
|
const handleSelectAll = (event) => {
|
|
1280
|
-
const newValue = allSelected ? [] : [...
|
|
1433
|
+
const newValue = allSelected ? [] : [...selectableOptions];
|
|
1281
1434
|
setMultipleValue(newValue);
|
|
1282
1435
|
onChange == null ? void 0 : onChange(
|
|
1283
1436
|
event,
|
|
@@ -1299,31 +1452,173 @@ function useMultipleAutocomplete({
|
|
|
1299
1452
|
getOptionLabel
|
|
1300
1453
|
);
|
|
1301
1454
|
};
|
|
1455
|
+
const getCounterRenderTags = useCallback(() => {
|
|
1456
|
+
const formatter = counterFormatter || createCounterFormatter({
|
|
1457
|
+
counterText: defaultCounterText,
|
|
1458
|
+
allText: defaultAllSelectedText
|
|
1459
|
+
});
|
|
1460
|
+
return createCounterRenderTags({
|
|
1461
|
+
formatCounter: formatter,
|
|
1462
|
+
options,
|
|
1463
|
+
size,
|
|
1464
|
+
getOptionLabel: getOptionLabel ? (option) => getOptionLabel(option) : void 0
|
|
1465
|
+
});
|
|
1466
|
+
}, [
|
|
1467
|
+
options,
|
|
1468
|
+
counterFormatter,
|
|
1469
|
+
defaultCounterText,
|
|
1470
|
+
defaultAllSelectedText,
|
|
1471
|
+
size,
|
|
1472
|
+
getOptionLabel
|
|
1473
|
+
]);
|
|
1302
1474
|
return {
|
|
1303
1475
|
multipleValue,
|
|
1304
1476
|
allSelected,
|
|
1305
1477
|
someSelected,
|
|
1306
1478
|
handleSelectAll,
|
|
1307
1479
|
handleChange,
|
|
1308
|
-
multipleRenderOption
|
|
1480
|
+
multipleRenderOption,
|
|
1481
|
+
getCounterRenderTags
|
|
1309
1482
|
};
|
|
1310
1483
|
}
|
|
1311
|
-
|
|
1484
|
+
const List = styled("ul")(
|
|
1485
|
+
({ theme, hasFilters }) => ({
|
|
1486
|
+
...!hasFilters && {
|
|
1487
|
+
paddingTop: `${theme.spacing(1)} !important`
|
|
1488
|
+
}
|
|
1489
|
+
})
|
|
1490
|
+
);
|
|
1491
|
+
const ItemWrapper = styled("div")(({ style, theme, isSubtitle, isExtended, isMultiple }) => {
|
|
1492
|
+
const getSubtitleStyles = () => {
|
|
1493
|
+
const baseStyles = {
|
|
1494
|
+
height: MENU_ITEM_SIZE_DENSE,
|
|
1495
|
+
minHeight: MENU_ITEM_SIZE_DENSE,
|
|
1496
|
+
marginTop: `${theme.spacing(1)} !important`,
|
|
1497
|
+
alignItems: "flex-end",
|
|
1498
|
+
...theme.typography.caption,
|
|
1499
|
+
fontWeight: 500
|
|
1500
|
+
};
|
|
1501
|
+
if (isExtended) {
|
|
1502
|
+
baseStyles.alignItems = "center";
|
|
1503
|
+
if (isMultiple) {
|
|
1504
|
+
baseStyles.marginLeft = theme.spacing(0.5);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return baseStyles;
|
|
1508
|
+
};
|
|
1509
|
+
return {
|
|
1510
|
+
pointerEvents: "none",
|
|
1511
|
+
// To avoid the extra div to receive the click event
|
|
1512
|
+
"& .MuiMenuItem-root": {
|
|
1513
|
+
pointerEvents: "auto",
|
|
1514
|
+
// Allow pointer events for the menu item
|
|
1515
|
+
marginTop: 0,
|
|
1516
|
+
"&:first-of-type": {
|
|
1517
|
+
marginTop: "0 !important"
|
|
1518
|
+
}
|
|
1519
|
+
},
|
|
1520
|
+
...isSubtitle && {
|
|
1521
|
+
"& .MuiAutocomplete-option.MuiMenuItem-root": getSubtitleStyles(),
|
|
1522
|
+
// First item has no divider
|
|
1523
|
+
"&:not(:first-of-type)": {
|
|
1524
|
+
"&::before": {
|
|
1525
|
+
content: '""',
|
|
1526
|
+
position: "absolute",
|
|
1527
|
+
zIndex: 1,
|
|
1528
|
+
top: theme.spacing(0.5),
|
|
1529
|
+
left: 0,
|
|
1530
|
+
right: 0,
|
|
1531
|
+
height: "1px",
|
|
1532
|
+
backgroundColor: theme.palette.divider
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
},
|
|
1536
|
+
...!isSubtitle && {
|
|
1537
|
+
"& .MuiAutocomplete-option": {
|
|
1538
|
+
minHeight: `${style == null ? void 0 : style.height}px !important`
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
});
|
|
1543
|
+
function _AutocompleteList({
|
|
1312
1544
|
children,
|
|
1313
1545
|
showFilters,
|
|
1314
1546
|
allSelected,
|
|
1315
1547
|
someSelected,
|
|
1316
1548
|
handleSelectAll = () => void 0,
|
|
1317
1549
|
multiple,
|
|
1550
|
+
extended,
|
|
1551
|
+
itemHeight,
|
|
1552
|
+
maxListHeight = MENU_LIST_MAX_SIZE,
|
|
1318
1553
|
...otherProps
|
|
1319
1554
|
}, ref) {
|
|
1555
|
+
const childrenArray = useMemo(() => {
|
|
1556
|
+
return React.Children.toArray(children).map((child) => {
|
|
1557
|
+
if (!React.isValidElement(child)) {
|
|
1558
|
+
return {
|
|
1559
|
+
child,
|
|
1560
|
+
isSubtitle: false,
|
|
1561
|
+
isExtended: false,
|
|
1562
|
+
isMultiple: !!multiple
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
const props = child.props;
|
|
1566
|
+
return {
|
|
1567
|
+
child,
|
|
1568
|
+
isSubtitle: props.subtitle === true,
|
|
1569
|
+
isExtended: props.extended === true,
|
|
1570
|
+
isMultiple: !!multiple
|
|
1571
|
+
};
|
|
1572
|
+
});
|
|
1573
|
+
}, [children, multiple]);
|
|
1574
|
+
const defaultItemHeight = itemHeight ?? (extended ? MENU_ITEM_SIZE_EXTENDED : MENU_ITEM_SIZE_DEFAULT);
|
|
1575
|
+
const listboxHeight = useMemo(() => {
|
|
1576
|
+
const filterHeight = showFilters && multiple ? MENU_ITEM_SIZE_EXTENDED : 0;
|
|
1577
|
+
const availableHeight = maxListHeight - filterHeight;
|
|
1578
|
+
const calculatedHeight = Math.min(
|
|
1579
|
+
childrenArray.length * defaultItemHeight,
|
|
1580
|
+
availableHeight
|
|
1581
|
+
);
|
|
1582
|
+
return Math.max(calculatedHeight, defaultItemHeight);
|
|
1583
|
+
}, [
|
|
1584
|
+
showFilters,
|
|
1585
|
+
multiple,
|
|
1586
|
+
maxListHeight,
|
|
1587
|
+
childrenArray.length,
|
|
1588
|
+
defaultItemHeight
|
|
1589
|
+
]);
|
|
1590
|
+
const renderItem = ({
|
|
1591
|
+
index,
|
|
1592
|
+
style
|
|
1593
|
+
}) => {
|
|
1594
|
+
const item = childrenArray[index];
|
|
1595
|
+
if (!item) return null;
|
|
1596
|
+
const { child, isSubtitle, isExtended, isMultiple } = item;
|
|
1597
|
+
return /* @__PURE__ */ jsx(
|
|
1598
|
+
ItemWrapper,
|
|
1599
|
+
{
|
|
1600
|
+
style,
|
|
1601
|
+
isSubtitle,
|
|
1602
|
+
isExtended,
|
|
1603
|
+
isMultiple,
|
|
1604
|
+
"data-name": "virtual-menu-item",
|
|
1605
|
+
children: child
|
|
1606
|
+
}
|
|
1607
|
+
);
|
|
1608
|
+
};
|
|
1320
1609
|
return /* @__PURE__ */ jsxs(
|
|
1321
|
-
|
|
1610
|
+
List,
|
|
1322
1611
|
{
|
|
1323
1612
|
ref,
|
|
1324
1613
|
...otherProps,
|
|
1325
1614
|
role: "listbox",
|
|
1615
|
+
"data-list-height": listboxHeight,
|
|
1616
|
+
"data-item-height": defaultItemHeight,
|
|
1326
1617
|
"aria-multiselectable": multiple,
|
|
1618
|
+
hasFilters: showFilters,
|
|
1619
|
+
style: {
|
|
1620
|
+
maxHeight: maxListHeight + defaultItemHeight
|
|
1621
|
+
},
|
|
1327
1622
|
children: [
|
|
1328
1623
|
showFilters && multiple && /* @__PURE__ */ jsx(
|
|
1329
1624
|
MenuItemFilter,
|
|
@@ -1333,12 +1628,21 @@ function _ListboxWithFilter({
|
|
|
1333
1628
|
selectAll: handleSelectAll
|
|
1334
1629
|
}
|
|
1335
1630
|
),
|
|
1336
|
-
|
|
1631
|
+
/* @__PURE__ */ jsx(
|
|
1632
|
+
FixedSizeList,
|
|
1633
|
+
{
|
|
1634
|
+
height: listboxHeight,
|
|
1635
|
+
width: "100%",
|
|
1636
|
+
itemCount: childrenArray.length,
|
|
1637
|
+
itemSize: defaultItemHeight,
|
|
1638
|
+
children: renderItem
|
|
1639
|
+
}
|
|
1640
|
+
)
|
|
1337
1641
|
]
|
|
1338
1642
|
}
|
|
1339
1643
|
);
|
|
1340
1644
|
}
|
|
1341
|
-
const
|
|
1645
|
+
const AutocompleteList = forwardRef(_AutocompleteList);
|
|
1342
1646
|
function _CreatableAutocomplete({
|
|
1343
1647
|
newItemLabel,
|
|
1344
1648
|
newItemIcon,
|
|
@@ -1348,23 +1652,41 @@ function _CreatableAutocomplete({
|
|
|
1348
1652
|
disabled,
|
|
1349
1653
|
loading,
|
|
1350
1654
|
showFilters,
|
|
1655
|
+
showCounter = false,
|
|
1656
|
+
counterFormatter,
|
|
1657
|
+
counterText,
|
|
1658
|
+
allSelectedText,
|
|
1351
1659
|
options = [],
|
|
1352
1660
|
value,
|
|
1353
1661
|
onChange,
|
|
1354
1662
|
getLimitTagsText,
|
|
1663
|
+
renderTags,
|
|
1664
|
+
itemHeight,
|
|
1665
|
+
maxListHeight,
|
|
1666
|
+
extended,
|
|
1667
|
+
groupBy,
|
|
1355
1668
|
...props
|
|
1356
1669
|
}, ref) {
|
|
1670
|
+
if (groupBy) {
|
|
1671
|
+
warnDeprecatedGroupBy("CreatableAutocomplete");
|
|
1672
|
+
}
|
|
1357
1673
|
const { freeSolo = true, ...otherProps } = props;
|
|
1358
1674
|
const {
|
|
1359
1675
|
multipleValue,
|
|
1360
1676
|
allSelected,
|
|
1361
1677
|
someSelected,
|
|
1362
1678
|
handleSelectAll,
|
|
1363
|
-
handleChange
|
|
1679
|
+
handleChange,
|
|
1680
|
+
getCounterRenderTags
|
|
1364
1681
|
} = useMultipleAutocomplete({
|
|
1365
1682
|
options,
|
|
1366
1683
|
value,
|
|
1367
|
-
onChange
|
|
1684
|
+
onChange,
|
|
1685
|
+
getOptionLabel,
|
|
1686
|
+
size: props.size,
|
|
1687
|
+
counterFormatter,
|
|
1688
|
+
counterText,
|
|
1689
|
+
allSelectedText
|
|
1368
1690
|
});
|
|
1369
1691
|
const {
|
|
1370
1692
|
creatableFilterOptions,
|
|
@@ -1376,6 +1698,17 @@ function _CreatableAutocomplete({
|
|
|
1376
1698
|
newItemIcon,
|
|
1377
1699
|
multiple
|
|
1378
1700
|
});
|
|
1701
|
+
const listboxProps = {
|
|
1702
|
+
showFilters,
|
|
1703
|
+
allSelected,
|
|
1704
|
+
someSelected,
|
|
1705
|
+
handleSelectAll,
|
|
1706
|
+
multiple,
|
|
1707
|
+
itemHeight,
|
|
1708
|
+
maxListHeight,
|
|
1709
|
+
extended
|
|
1710
|
+
};
|
|
1711
|
+
const finalRenderTags = showCounter && multiple && !renderTags ? getCounterRenderTags() : renderTags;
|
|
1379
1712
|
return /* @__PURE__ */ jsx(
|
|
1380
1713
|
Autocomplete$1,
|
|
1381
1714
|
{
|
|
@@ -1387,18 +1720,13 @@ function _CreatableAutocomplete({
|
|
|
1387
1720
|
filterOptions: creatableFilterOptions,
|
|
1388
1721
|
getOptionLabel: creatableOptionLabel,
|
|
1389
1722
|
renderOption: creatableRenderOption,
|
|
1723
|
+
renderTags: finalRenderTags,
|
|
1390
1724
|
freeSolo,
|
|
1391
1725
|
forcePopupIcon: true,
|
|
1392
1726
|
multiple,
|
|
1393
1727
|
disableCloseOnSelect: disableCloseOnSelect ?? multiple,
|
|
1394
|
-
ListboxComponent:
|
|
1395
|
-
ListboxProps:
|
|
1396
|
-
showFilters,
|
|
1397
|
-
allSelected,
|
|
1398
|
-
someSelected,
|
|
1399
|
-
handleSelectAll,
|
|
1400
|
-
multiple
|
|
1401
|
-
},
|
|
1728
|
+
ListboxComponent: AutocompleteList,
|
|
1729
|
+
ListboxProps: listboxProps,
|
|
1402
1730
|
getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
|
|
1403
1731
|
disabled: disabled || loading,
|
|
1404
1732
|
popupIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: 18, color: "inherit" }) : /* @__PURE__ */ jsx(ArrowDown, {}),
|
|
@@ -1413,26 +1741,54 @@ function _MultipleAutocomplete({
|
|
|
1413
1741
|
disabled,
|
|
1414
1742
|
loading,
|
|
1415
1743
|
showFilters,
|
|
1744
|
+
showCounter = false,
|
|
1745
|
+
counterFormatter,
|
|
1746
|
+
counterText,
|
|
1747
|
+
allSelectedText,
|
|
1416
1748
|
options,
|
|
1417
1749
|
value,
|
|
1418
1750
|
onChange,
|
|
1419
1751
|
getOptionLabel,
|
|
1420
1752
|
getLimitTagsText,
|
|
1753
|
+
renderTags,
|
|
1754
|
+
itemHeight,
|
|
1755
|
+
maxListHeight,
|
|
1756
|
+
extended,
|
|
1757
|
+
groupBy,
|
|
1421
1758
|
...props
|
|
1422
1759
|
}, ref) {
|
|
1760
|
+
if (groupBy) {
|
|
1761
|
+
warnDeprecatedGroupBy("MultipleAutocomplete");
|
|
1762
|
+
}
|
|
1423
1763
|
const {
|
|
1424
1764
|
multipleValue,
|
|
1425
1765
|
allSelected,
|
|
1426
1766
|
someSelected,
|
|
1427
1767
|
handleSelectAll,
|
|
1428
1768
|
handleChange,
|
|
1429
|
-
multipleRenderOption
|
|
1769
|
+
multipleRenderOption,
|
|
1770
|
+
getCounterRenderTags
|
|
1430
1771
|
} = useMultipleAutocomplete({
|
|
1431
1772
|
options,
|
|
1432
1773
|
value,
|
|
1433
1774
|
onChange,
|
|
1434
|
-
getOptionLabel
|
|
1775
|
+
getOptionLabel,
|
|
1776
|
+
size: props.size,
|
|
1777
|
+
counterFormatter,
|
|
1778
|
+
counterText,
|
|
1779
|
+
allSelectedText
|
|
1435
1780
|
});
|
|
1781
|
+
const listboxProps = {
|
|
1782
|
+
showFilters,
|
|
1783
|
+
allSelected,
|
|
1784
|
+
someSelected,
|
|
1785
|
+
handleSelectAll,
|
|
1786
|
+
multiple: true,
|
|
1787
|
+
itemHeight,
|
|
1788
|
+
maxListHeight,
|
|
1789
|
+
extended
|
|
1790
|
+
};
|
|
1791
|
+
const finalRenderTags = showCounter && !renderTags ? getCounterRenderTags() : renderTags;
|
|
1436
1792
|
return /* @__PURE__ */ jsx(
|
|
1437
1793
|
Autocomplete$1,
|
|
1438
1794
|
{
|
|
@@ -1443,14 +1799,9 @@ function _MultipleAutocomplete({
|
|
|
1443
1799
|
onChange: handleChange,
|
|
1444
1800
|
getOptionLabel,
|
|
1445
1801
|
renderOption: renderOption ?? multipleRenderOption,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
allSelected,
|
|
1450
|
-
someSelected,
|
|
1451
|
-
handleSelectAll,
|
|
1452
|
-
multiple: true
|
|
1453
|
-
},
|
|
1802
|
+
renderTags: finalRenderTags,
|
|
1803
|
+
ListboxComponent: AutocompleteList,
|
|
1804
|
+
ListboxProps: listboxProps,
|
|
1454
1805
|
multiple: true,
|
|
1455
1806
|
getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
|
|
1456
1807
|
disableCloseOnSelect,
|
|
@@ -1461,6 +1812,30 @@ function _MultipleAutocomplete({
|
|
|
1461
1812
|
);
|
|
1462
1813
|
}
|
|
1463
1814
|
const MultipleAutocomplete = forwardRef(_MultipleAutocomplete);
|
|
1815
|
+
function useAutocomplete({
|
|
1816
|
+
getOptionLabel = getDefaultOptionLabel
|
|
1817
|
+
}) {
|
|
1818
|
+
const { renderOption: autocompleteRenderOption } = useAutocompleteRenderOption();
|
|
1819
|
+
const internalGetOptionLabel = (option) => {
|
|
1820
|
+
if (isAutocompleteListGroupHeader(option)) {
|
|
1821
|
+
return option.title;
|
|
1822
|
+
}
|
|
1823
|
+
return getOptionLabel(option);
|
|
1824
|
+
};
|
|
1825
|
+
const singleRenderOption = (props, option, state) => {
|
|
1826
|
+
const optionWithMultiple = createOptionWithMultiple(option, false);
|
|
1827
|
+
return autocompleteRenderOption(
|
|
1828
|
+
props,
|
|
1829
|
+
optionWithMultiple,
|
|
1830
|
+
state,
|
|
1831
|
+
internalGetOptionLabel
|
|
1832
|
+
);
|
|
1833
|
+
};
|
|
1834
|
+
return {
|
|
1835
|
+
singleRenderOption,
|
|
1836
|
+
getOptionLabel: internalGetOptionLabel
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1464
1839
|
const _CopiableComponent = ({
|
|
1465
1840
|
children,
|
|
1466
1841
|
disabled,
|
|
@@ -4681,10 +5056,12 @@ function CodeAreaDialog({
|
|
|
4681
5056
|
);
|
|
4682
5057
|
}
|
|
4683
5058
|
export {
|
|
5059
|
+
AUTOCOMPLETE_GROUP_HEADER_PROPERTY,
|
|
4684
5060
|
AccordionGroup,
|
|
4685
5061
|
Alert$1 as Alert,
|
|
4686
5062
|
AppBar,
|
|
4687
5063
|
Autocomplete,
|
|
5064
|
+
AutocompleteList,
|
|
4688
5065
|
Avatar,
|
|
4689
5066
|
Button,
|
|
4690
5067
|
CodeAreaDialog,
|
|
@@ -4732,6 +5109,9 @@ export {
|
|
|
4732
5109
|
UploadField,
|
|
4733
5110
|
UploadFieldBase,
|
|
4734
5111
|
copyString,
|
|
5112
|
+
createAutocompleteGroupByList,
|
|
4735
5113
|
dialogDimensionsBySize,
|
|
5114
|
+
isAutocompleteListGroupHeader,
|
|
5115
|
+
useAutocomplete,
|
|
4736
5116
|
useCopyValue
|
|
4737
5117
|
};
|