@carto/meridian-ds 1.5.0 → 1.5.1-alpha-virtual-autocomplete.10
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 +442 -55
- package/dist/components/index.js +444 -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 +135 -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,130 @@ 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({
|
|
1192
|
+
options,
|
|
1193
|
+
groupBy,
|
|
1194
|
+
extended
|
|
1195
|
+
}) {
|
|
1196
|
+
const grouped = options.reduce(
|
|
1197
|
+
(acc, option) => {
|
|
1198
|
+
const group = groupBy(option);
|
|
1199
|
+
if (!acc[group]) {
|
|
1200
|
+
acc[group] = [];
|
|
1201
|
+
}
|
|
1202
|
+
acc[group].push(option);
|
|
1203
|
+
return acc;
|
|
1204
|
+
},
|
|
1205
|
+
{}
|
|
1206
|
+
);
|
|
1207
|
+
const result = [];
|
|
1208
|
+
Object.keys(grouped).forEach((title) => {
|
|
1209
|
+
result.push({ [AUTOCOMPLETE_GROUP_HEADER_PROPERTY]: true, title, extended });
|
|
1210
|
+
const groupOptions = grouped[title];
|
|
1211
|
+
if (groupOptions) {
|
|
1212
|
+
result.push(...groupOptions);
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
return result;
|
|
1216
|
+
}
|
|
1217
|
+
function warnDeprecatedGroupBy(componentName) {
|
|
1218
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1219
|
+
console.error(
|
|
1220
|
+
`${componentName}: The \`groupBy\` prop is deprecated and breaks virtualization. Use \`createAutocompleteGroupByList\` instead:
|
|
1221
|
+
|
|
1222
|
+
\`\`\`
|
|
1223
|
+
import { createAutocompleteGroupByList, ${componentName} } from "@carto/meridian-ds/components"
|
|
1224
|
+
|
|
1225
|
+
const groupedOptions = createAutocompleteGroupByList({
|
|
1226
|
+
options,
|
|
1227
|
+
groupBy: (option) => option.category
|
|
1228
|
+
})
|
|
1229
|
+
|
|
1230
|
+
<${componentName} options={groupedOptions} />
|
|
1231
|
+
\`\`\`
|
|
1232
|
+
`
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1098
1236
|
function _Autocomplete({
|
|
1099
1237
|
disabled,
|
|
1100
1238
|
loading,
|
|
1101
1239
|
...props
|
|
1102
1240
|
}, ref) {
|
|
1241
|
+
if (props.groupBy) {
|
|
1242
|
+
warnDeprecatedGroupBy("Autocomplete");
|
|
1243
|
+
}
|
|
1103
1244
|
return /* @__PURE__ */ jsx(
|
|
1104
1245
|
Autocomplete$1,
|
|
1105
1246
|
{
|
|
@@ -1116,15 +1257,24 @@ function _Autocomplete({
|
|
|
1116
1257
|
);
|
|
1117
1258
|
}
|
|
1118
1259
|
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
1260
|
function useAutocompleteRenderOption() {
|
|
1127
1261
|
const renderOption = (props, option, state, getOptionLabel, customIcon) => {
|
|
1262
|
+
const { key, ...otherProps } = props;
|
|
1263
|
+
if (isAutocompleteListGroupHeader(option)) {
|
|
1264
|
+
return /* @__PURE__ */ createElement(
|
|
1265
|
+
MenuItem$1,
|
|
1266
|
+
{
|
|
1267
|
+
...otherProps,
|
|
1268
|
+
subtitle: true,
|
|
1269
|
+
extended: option.extended,
|
|
1270
|
+
key,
|
|
1271
|
+
"aria-disabled": true,
|
|
1272
|
+
"aria-selected": false
|
|
1273
|
+
},
|
|
1274
|
+
option.title
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
const regularOption = option;
|
|
1128
1278
|
const {
|
|
1129
1279
|
title,
|
|
1130
1280
|
inputValue,
|
|
@@ -1141,9 +1291,8 @@ function useAutocompleteRenderOption() {
|
|
|
1141
1291
|
alternativeTitle,
|
|
1142
1292
|
secondaryText,
|
|
1143
1293
|
multiple
|
|
1144
|
-
} =
|
|
1145
|
-
const
|
|
1146
|
-
const isPrimitiveOptionType = typeof option === "string" || typeof option === "number";
|
|
1294
|
+
} = regularOption;
|
|
1295
|
+
const isPrimitiveOptionType = typeof regularOption === "string" || typeof regularOption === "number";
|
|
1147
1296
|
const getOptionLabelText = (getOptionLabel2, option2, alternativeTitle2, title2) => {
|
|
1148
1297
|
if (alternativeTitle2) return alternativeTitle2;
|
|
1149
1298
|
if (title2) return title2;
|
|
@@ -1177,7 +1326,7 @@ function useAutocompleteRenderOption() {
|
|
|
1177
1326
|
/* @__PURE__ */ jsxs(ListItemText, { children: [
|
|
1178
1327
|
getOptionLabelText(
|
|
1179
1328
|
getOptionLabel ?? getDefaultOptionLabel,
|
|
1180
|
-
|
|
1329
|
+
regularOption,
|
|
1181
1330
|
alternativeTitle,
|
|
1182
1331
|
title
|
|
1183
1332
|
),
|
|
@@ -1264,8 +1413,16 @@ function useMultipleAutocomplete({
|
|
|
1264
1413
|
options,
|
|
1265
1414
|
value,
|
|
1266
1415
|
onChange,
|
|
1267
|
-
getOptionLabel
|
|
1416
|
+
getOptionLabel,
|
|
1417
|
+
size,
|
|
1418
|
+
counterFormatter,
|
|
1419
|
+
counterText,
|
|
1420
|
+
allSelectedText
|
|
1268
1421
|
}) {
|
|
1422
|
+
const intl = useIntl();
|
|
1423
|
+
const intlConfig = useImperativeIntl(intl);
|
|
1424
|
+
const defaultCounterText = counterText || intlConfig.formatMessage({ id: "c4r.form.selected" });
|
|
1425
|
+
const defaultAllSelectedText = allSelectedText || intlConfig.formatMessage({ id: "c4r.form.allSelected" });
|
|
1269
1426
|
const [multipleValue, setMultipleValue] = useState(
|
|
1270
1427
|
Array.isArray(value) ? value : value ? [value] : []
|
|
1271
1428
|
);
|
|
@@ -1274,10 +1431,13 @@ function useMultipleAutocomplete({
|
|
|
1274
1431
|
const newValue = Array.isArray(value) ? value : value ? [value] : [];
|
|
1275
1432
|
setMultipleValue(newValue);
|
|
1276
1433
|
}, [value]);
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1434
|
+
const selectableOptions = options.filter(
|
|
1435
|
+
(option) => !isAutocompleteListGroupHeader(option)
|
|
1436
|
+
);
|
|
1437
|
+
const allSelected = multipleValue.length === selectableOptions.length;
|
|
1438
|
+
const someSelected = multipleValue.length > 0 && multipleValue.length < selectableOptions.length;
|
|
1279
1439
|
const handleSelectAll = (event) => {
|
|
1280
|
-
const newValue = allSelected ? [] : [...
|
|
1440
|
+
const newValue = allSelected ? [] : [...selectableOptions];
|
|
1281
1441
|
setMultipleValue(newValue);
|
|
1282
1442
|
onChange == null ? void 0 : onChange(
|
|
1283
1443
|
event,
|
|
@@ -1299,31 +1459,173 @@ function useMultipleAutocomplete({
|
|
|
1299
1459
|
getOptionLabel
|
|
1300
1460
|
);
|
|
1301
1461
|
};
|
|
1462
|
+
const getCounterRenderTags = useCallback(() => {
|
|
1463
|
+
const formatter = counterFormatter || createCounterFormatter({
|
|
1464
|
+
counterText: defaultCounterText,
|
|
1465
|
+
allText: defaultAllSelectedText
|
|
1466
|
+
});
|
|
1467
|
+
return createCounterRenderTags({
|
|
1468
|
+
formatCounter: formatter,
|
|
1469
|
+
options,
|
|
1470
|
+
size,
|
|
1471
|
+
getOptionLabel: getOptionLabel ? (option) => getOptionLabel(option) : void 0
|
|
1472
|
+
});
|
|
1473
|
+
}, [
|
|
1474
|
+
options,
|
|
1475
|
+
counterFormatter,
|
|
1476
|
+
defaultCounterText,
|
|
1477
|
+
defaultAllSelectedText,
|
|
1478
|
+
size,
|
|
1479
|
+
getOptionLabel
|
|
1480
|
+
]);
|
|
1302
1481
|
return {
|
|
1303
1482
|
multipleValue,
|
|
1304
1483
|
allSelected,
|
|
1305
1484
|
someSelected,
|
|
1306
1485
|
handleSelectAll,
|
|
1307
1486
|
handleChange,
|
|
1308
|
-
multipleRenderOption
|
|
1487
|
+
multipleRenderOption,
|
|
1488
|
+
getCounterRenderTags
|
|
1309
1489
|
};
|
|
1310
1490
|
}
|
|
1311
|
-
|
|
1491
|
+
const List = styled("ul")(
|
|
1492
|
+
({ theme, hasFilters }) => ({
|
|
1493
|
+
...!hasFilters && {
|
|
1494
|
+
paddingTop: `${theme.spacing(1)} !important`
|
|
1495
|
+
}
|
|
1496
|
+
})
|
|
1497
|
+
);
|
|
1498
|
+
const ItemWrapper = styled("div")(({ style, theme, isSubtitle, isExtended, isMultiple }) => {
|
|
1499
|
+
const getSubtitleStyles = () => {
|
|
1500
|
+
const baseStyles = {
|
|
1501
|
+
height: MENU_ITEM_SIZE_DENSE,
|
|
1502
|
+
minHeight: MENU_ITEM_SIZE_DENSE,
|
|
1503
|
+
marginTop: `${theme.spacing(1)} !important`,
|
|
1504
|
+
alignItems: "flex-end",
|
|
1505
|
+
...theme.typography.caption,
|
|
1506
|
+
fontWeight: 500
|
|
1507
|
+
};
|
|
1508
|
+
if (isExtended) {
|
|
1509
|
+
baseStyles.alignItems = "center";
|
|
1510
|
+
if (isMultiple) {
|
|
1511
|
+
baseStyles.marginLeft = theme.spacing(0.5);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return baseStyles;
|
|
1515
|
+
};
|
|
1516
|
+
return {
|
|
1517
|
+
pointerEvents: "none",
|
|
1518
|
+
// To avoid the extra div to receive the click event
|
|
1519
|
+
"& .MuiMenuItem-root": {
|
|
1520
|
+
pointerEvents: "auto",
|
|
1521
|
+
// Allow pointer events for the menu item
|
|
1522
|
+
marginTop: 0,
|
|
1523
|
+
"&:first-of-type": {
|
|
1524
|
+
marginTop: "0 !important"
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
...isSubtitle && {
|
|
1528
|
+
"& .MuiAutocomplete-option.MuiMenuItem-root": getSubtitleStyles(),
|
|
1529
|
+
// First item has no divider
|
|
1530
|
+
"&:not(:first-of-type)": {
|
|
1531
|
+
"&::before": {
|
|
1532
|
+
content: '""',
|
|
1533
|
+
position: "absolute",
|
|
1534
|
+
zIndex: 1,
|
|
1535
|
+
top: theme.spacing(0.5),
|
|
1536
|
+
left: 0,
|
|
1537
|
+
right: 0,
|
|
1538
|
+
height: "1px",
|
|
1539
|
+
backgroundColor: theme.palette.divider
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
},
|
|
1543
|
+
...!isSubtitle && {
|
|
1544
|
+
"& .MuiAutocomplete-option": {
|
|
1545
|
+
minHeight: `${style == null ? void 0 : style.height}px !important`
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
});
|
|
1550
|
+
function _AutocompleteList({
|
|
1312
1551
|
children,
|
|
1313
1552
|
showFilters,
|
|
1314
1553
|
allSelected,
|
|
1315
1554
|
someSelected,
|
|
1316
1555
|
handleSelectAll = () => void 0,
|
|
1317
1556
|
multiple,
|
|
1557
|
+
extended,
|
|
1558
|
+
itemHeight,
|
|
1559
|
+
maxListHeight = MENU_LIST_MAX_SIZE,
|
|
1318
1560
|
...otherProps
|
|
1319
1561
|
}, ref) {
|
|
1562
|
+
const childrenArray = useMemo(() => {
|
|
1563
|
+
return React.Children.toArray(children).map((child) => {
|
|
1564
|
+
if (!React.isValidElement(child)) {
|
|
1565
|
+
return {
|
|
1566
|
+
child,
|
|
1567
|
+
isSubtitle: false,
|
|
1568
|
+
isExtended: false,
|
|
1569
|
+
isMultiple: !!multiple
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
const props = child.props;
|
|
1573
|
+
return {
|
|
1574
|
+
child,
|
|
1575
|
+
isSubtitle: props.subtitle === true,
|
|
1576
|
+
isExtended: props.extended === true,
|
|
1577
|
+
isMultiple: !!multiple
|
|
1578
|
+
};
|
|
1579
|
+
});
|
|
1580
|
+
}, [children, multiple]);
|
|
1581
|
+
const defaultItemHeight = itemHeight ?? (extended ? MENU_ITEM_SIZE_EXTENDED : MENU_ITEM_SIZE_DEFAULT);
|
|
1582
|
+
const listboxHeight = useMemo(() => {
|
|
1583
|
+
const filterHeight = showFilters && multiple ? MENU_ITEM_SIZE_EXTENDED : 0;
|
|
1584
|
+
const availableHeight = maxListHeight - filterHeight;
|
|
1585
|
+
const calculatedHeight = Math.min(
|
|
1586
|
+
childrenArray.length * defaultItemHeight,
|
|
1587
|
+
availableHeight
|
|
1588
|
+
);
|
|
1589
|
+
return Math.max(calculatedHeight, defaultItemHeight);
|
|
1590
|
+
}, [
|
|
1591
|
+
showFilters,
|
|
1592
|
+
multiple,
|
|
1593
|
+
maxListHeight,
|
|
1594
|
+
childrenArray.length,
|
|
1595
|
+
defaultItemHeight
|
|
1596
|
+
]);
|
|
1597
|
+
const renderItem = ({
|
|
1598
|
+
index,
|
|
1599
|
+
style
|
|
1600
|
+
}) => {
|
|
1601
|
+
const item = childrenArray[index];
|
|
1602
|
+
if (!item) return null;
|
|
1603
|
+
const { child, isSubtitle, isExtended, isMultiple } = item;
|
|
1604
|
+
return /* @__PURE__ */ jsx(
|
|
1605
|
+
ItemWrapper,
|
|
1606
|
+
{
|
|
1607
|
+
style,
|
|
1608
|
+
isSubtitle,
|
|
1609
|
+
isExtended,
|
|
1610
|
+
isMultiple,
|
|
1611
|
+
"data-name": "virtual-menu-item",
|
|
1612
|
+
children: child
|
|
1613
|
+
}
|
|
1614
|
+
);
|
|
1615
|
+
};
|
|
1320
1616
|
return /* @__PURE__ */ jsxs(
|
|
1321
|
-
|
|
1617
|
+
List,
|
|
1322
1618
|
{
|
|
1323
1619
|
ref,
|
|
1324
1620
|
...otherProps,
|
|
1325
1621
|
role: "listbox",
|
|
1622
|
+
"data-list-height": listboxHeight,
|
|
1623
|
+
"data-item-height": defaultItemHeight,
|
|
1326
1624
|
"aria-multiselectable": multiple,
|
|
1625
|
+
hasFilters: showFilters,
|
|
1626
|
+
style: {
|
|
1627
|
+
maxHeight: maxListHeight + defaultItemHeight
|
|
1628
|
+
},
|
|
1327
1629
|
children: [
|
|
1328
1630
|
showFilters && multiple && /* @__PURE__ */ jsx(
|
|
1329
1631
|
MenuItemFilter,
|
|
@@ -1333,12 +1635,21 @@ function _ListboxWithFilter({
|
|
|
1333
1635
|
selectAll: handleSelectAll
|
|
1334
1636
|
}
|
|
1335
1637
|
),
|
|
1336
|
-
|
|
1638
|
+
/* @__PURE__ */ jsx(
|
|
1639
|
+
FixedSizeList,
|
|
1640
|
+
{
|
|
1641
|
+
height: listboxHeight,
|
|
1642
|
+
width: "100%",
|
|
1643
|
+
itemCount: childrenArray.length,
|
|
1644
|
+
itemSize: defaultItemHeight,
|
|
1645
|
+
children: renderItem
|
|
1646
|
+
}
|
|
1647
|
+
)
|
|
1337
1648
|
]
|
|
1338
1649
|
}
|
|
1339
1650
|
);
|
|
1340
1651
|
}
|
|
1341
|
-
const
|
|
1652
|
+
const AutocompleteList = forwardRef(_AutocompleteList);
|
|
1342
1653
|
function _CreatableAutocomplete({
|
|
1343
1654
|
newItemLabel,
|
|
1344
1655
|
newItemIcon,
|
|
@@ -1348,23 +1659,41 @@ function _CreatableAutocomplete({
|
|
|
1348
1659
|
disabled,
|
|
1349
1660
|
loading,
|
|
1350
1661
|
showFilters,
|
|
1662
|
+
showCounter = false,
|
|
1663
|
+
counterFormatter,
|
|
1664
|
+
counterText,
|
|
1665
|
+
allSelectedText,
|
|
1351
1666
|
options = [],
|
|
1352
1667
|
value,
|
|
1353
1668
|
onChange,
|
|
1354
1669
|
getLimitTagsText,
|
|
1670
|
+
renderTags,
|
|
1671
|
+
itemHeight,
|
|
1672
|
+
maxListHeight,
|
|
1673
|
+
extended,
|
|
1674
|
+
groupBy,
|
|
1355
1675
|
...props
|
|
1356
1676
|
}, ref) {
|
|
1677
|
+
if (groupBy) {
|
|
1678
|
+
warnDeprecatedGroupBy("CreatableAutocomplete");
|
|
1679
|
+
}
|
|
1357
1680
|
const { freeSolo = true, ...otherProps } = props;
|
|
1358
1681
|
const {
|
|
1359
1682
|
multipleValue,
|
|
1360
1683
|
allSelected,
|
|
1361
1684
|
someSelected,
|
|
1362
1685
|
handleSelectAll,
|
|
1363
|
-
handleChange
|
|
1686
|
+
handleChange,
|
|
1687
|
+
getCounterRenderTags
|
|
1364
1688
|
} = useMultipleAutocomplete({
|
|
1365
1689
|
options,
|
|
1366
1690
|
value,
|
|
1367
|
-
onChange
|
|
1691
|
+
onChange,
|
|
1692
|
+
getOptionLabel,
|
|
1693
|
+
size: props.size,
|
|
1694
|
+
counterFormatter,
|
|
1695
|
+
counterText,
|
|
1696
|
+
allSelectedText
|
|
1368
1697
|
});
|
|
1369
1698
|
const {
|
|
1370
1699
|
creatableFilterOptions,
|
|
@@ -1376,6 +1705,17 @@ function _CreatableAutocomplete({
|
|
|
1376
1705
|
newItemIcon,
|
|
1377
1706
|
multiple
|
|
1378
1707
|
});
|
|
1708
|
+
const listboxProps = {
|
|
1709
|
+
showFilters,
|
|
1710
|
+
allSelected,
|
|
1711
|
+
someSelected,
|
|
1712
|
+
handleSelectAll,
|
|
1713
|
+
multiple,
|
|
1714
|
+
itemHeight,
|
|
1715
|
+
maxListHeight,
|
|
1716
|
+
extended
|
|
1717
|
+
};
|
|
1718
|
+
const finalRenderTags = showCounter && multiple && !renderTags ? getCounterRenderTags() : renderTags;
|
|
1379
1719
|
return /* @__PURE__ */ jsx(
|
|
1380
1720
|
Autocomplete$1,
|
|
1381
1721
|
{
|
|
@@ -1387,18 +1727,13 @@ function _CreatableAutocomplete({
|
|
|
1387
1727
|
filterOptions: creatableFilterOptions,
|
|
1388
1728
|
getOptionLabel: creatableOptionLabel,
|
|
1389
1729
|
renderOption: creatableRenderOption,
|
|
1730
|
+
renderTags: finalRenderTags,
|
|
1390
1731
|
freeSolo,
|
|
1391
1732
|
forcePopupIcon: true,
|
|
1392
1733
|
multiple,
|
|
1393
1734
|
disableCloseOnSelect: disableCloseOnSelect ?? multiple,
|
|
1394
|
-
ListboxComponent:
|
|
1395
|
-
ListboxProps:
|
|
1396
|
-
showFilters,
|
|
1397
|
-
allSelected,
|
|
1398
|
-
someSelected,
|
|
1399
|
-
handleSelectAll,
|
|
1400
|
-
multiple
|
|
1401
|
-
},
|
|
1735
|
+
ListboxComponent: AutocompleteList,
|
|
1736
|
+
ListboxProps: listboxProps,
|
|
1402
1737
|
getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
|
|
1403
1738
|
disabled: disabled || loading,
|
|
1404
1739
|
popupIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: 18, color: "inherit" }) : /* @__PURE__ */ jsx(ArrowDown, {}),
|
|
@@ -1413,26 +1748,54 @@ function _MultipleAutocomplete({
|
|
|
1413
1748
|
disabled,
|
|
1414
1749
|
loading,
|
|
1415
1750
|
showFilters,
|
|
1751
|
+
showCounter = false,
|
|
1752
|
+
counterFormatter,
|
|
1753
|
+
counterText,
|
|
1754
|
+
allSelectedText,
|
|
1416
1755
|
options,
|
|
1417
1756
|
value,
|
|
1418
1757
|
onChange,
|
|
1419
1758
|
getOptionLabel,
|
|
1420
1759
|
getLimitTagsText,
|
|
1760
|
+
renderTags,
|
|
1761
|
+
itemHeight,
|
|
1762
|
+
maxListHeight,
|
|
1763
|
+
extended,
|
|
1764
|
+
groupBy,
|
|
1421
1765
|
...props
|
|
1422
1766
|
}, ref) {
|
|
1767
|
+
if (groupBy) {
|
|
1768
|
+
warnDeprecatedGroupBy("MultipleAutocomplete");
|
|
1769
|
+
}
|
|
1423
1770
|
const {
|
|
1424
1771
|
multipleValue,
|
|
1425
1772
|
allSelected,
|
|
1426
1773
|
someSelected,
|
|
1427
1774
|
handleSelectAll,
|
|
1428
1775
|
handleChange,
|
|
1429
|
-
multipleRenderOption
|
|
1776
|
+
multipleRenderOption,
|
|
1777
|
+
getCounterRenderTags
|
|
1430
1778
|
} = useMultipleAutocomplete({
|
|
1431
1779
|
options,
|
|
1432
1780
|
value,
|
|
1433
1781
|
onChange,
|
|
1434
|
-
getOptionLabel
|
|
1782
|
+
getOptionLabel,
|
|
1783
|
+
size: props.size,
|
|
1784
|
+
counterFormatter,
|
|
1785
|
+
counterText,
|
|
1786
|
+
allSelectedText
|
|
1435
1787
|
});
|
|
1788
|
+
const listboxProps = {
|
|
1789
|
+
showFilters,
|
|
1790
|
+
allSelected,
|
|
1791
|
+
someSelected,
|
|
1792
|
+
handleSelectAll,
|
|
1793
|
+
multiple: true,
|
|
1794
|
+
itemHeight,
|
|
1795
|
+
maxListHeight,
|
|
1796
|
+
extended
|
|
1797
|
+
};
|
|
1798
|
+
const finalRenderTags = showCounter && !renderTags ? getCounterRenderTags() : renderTags;
|
|
1436
1799
|
return /* @__PURE__ */ jsx(
|
|
1437
1800
|
Autocomplete$1,
|
|
1438
1801
|
{
|
|
@@ -1443,14 +1806,9 @@ function _MultipleAutocomplete({
|
|
|
1443
1806
|
onChange: handleChange,
|
|
1444
1807
|
getOptionLabel,
|
|
1445
1808
|
renderOption: renderOption ?? multipleRenderOption,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
allSelected,
|
|
1450
|
-
someSelected,
|
|
1451
|
-
handleSelectAll,
|
|
1452
|
-
multiple: true
|
|
1453
|
-
},
|
|
1809
|
+
renderTags: finalRenderTags,
|
|
1810
|
+
ListboxComponent: AutocompleteList,
|
|
1811
|
+
ListboxProps: listboxProps,
|
|
1454
1812
|
multiple: true,
|
|
1455
1813
|
getLimitTagsText: getLimitTagsText ?? getDefaultLimitTagsText,
|
|
1456
1814
|
disableCloseOnSelect,
|
|
@@ -1461,6 +1819,30 @@ function _MultipleAutocomplete({
|
|
|
1461
1819
|
);
|
|
1462
1820
|
}
|
|
1463
1821
|
const MultipleAutocomplete = forwardRef(_MultipleAutocomplete);
|
|
1822
|
+
function useAutocomplete({
|
|
1823
|
+
getOptionLabel = getDefaultOptionLabel
|
|
1824
|
+
}) {
|
|
1825
|
+
const { renderOption: autocompleteRenderOption } = useAutocompleteRenderOption();
|
|
1826
|
+
const internalGetOptionLabel = (option) => {
|
|
1827
|
+
if (isAutocompleteListGroupHeader(option)) {
|
|
1828
|
+
return option.title;
|
|
1829
|
+
}
|
|
1830
|
+
return getOptionLabel(option);
|
|
1831
|
+
};
|
|
1832
|
+
const singleRenderOption = (props, option, state) => {
|
|
1833
|
+
const optionWithMultiple = createOptionWithMultiple(option, false);
|
|
1834
|
+
return autocompleteRenderOption(
|
|
1835
|
+
props,
|
|
1836
|
+
optionWithMultiple,
|
|
1837
|
+
state,
|
|
1838
|
+
internalGetOptionLabel
|
|
1839
|
+
);
|
|
1840
|
+
};
|
|
1841
|
+
return {
|
|
1842
|
+
singleRenderOption,
|
|
1843
|
+
getOptionLabel: internalGetOptionLabel
|
|
1844
|
+
};
|
|
1845
|
+
}
|
|
1464
1846
|
const _CopiableComponent = ({
|
|
1465
1847
|
children,
|
|
1466
1848
|
disabled,
|
|
@@ -4681,10 +5063,12 @@ function CodeAreaDialog({
|
|
|
4681
5063
|
);
|
|
4682
5064
|
}
|
|
4683
5065
|
export {
|
|
5066
|
+
AUTOCOMPLETE_GROUP_HEADER_PROPERTY,
|
|
4684
5067
|
AccordionGroup,
|
|
4685
5068
|
Alert$1 as Alert,
|
|
4686
5069
|
AppBar,
|
|
4687
5070
|
Autocomplete,
|
|
5071
|
+
AutocompleteList,
|
|
4688
5072
|
Avatar,
|
|
4689
5073
|
Button,
|
|
4690
5074
|
CodeAreaDialog,
|
|
@@ -4732,6 +5116,9 @@ export {
|
|
|
4732
5116
|
UploadField,
|
|
4733
5117
|
UploadFieldBase,
|
|
4734
5118
|
copyString,
|
|
5119
|
+
createAutocompleteGroupByList,
|
|
4735
5120
|
dialogDimensionsBySize,
|
|
5121
|
+
isAutocompleteListGroupHeader,
|
|
5122
|
+
useAutocomplete,
|
|
4736
5123
|
useCopyValue
|
|
4737
5124
|
};
|