@ringcentral/juno 1.12.3-beta.5791-ea7a35ca → 1.12.4-beta.5841-601f173e
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/components/Buttons/Button/Button.d.ts +2 -2
- package/components/Buttons/Button/styles/StyledButton.js +4 -2
- package/components/Card/Card/Card.d.ts +2 -2
- package/components/Chip/Chip.d.ts +10 -3
- package/components/Chip/Chip.js +5 -3
- package/components/Chip/styles/ChipStyle.js +5 -4
- package/components/Chip/utils/ChipUtils.d.ts +1 -1
- package/components/Chip/utils/ChipUtils.js +1 -1
- package/components/Dialer/DialTextField/DialTextField.d.ts +1 -1
- package/components/Downshift/Downshift.d.ts +20 -9
- package/components/Downshift/Downshift.js +15 -5
- package/components/Downshift/SuggestionList/SuggestionList.d.ts +2 -2
- package/components/Downshift/SuggestionList/SuggestionList.js +12 -6
- package/components/Downshift/SuggestionList/utils/index.d.ts +1 -0
- package/components/Downshift/SuggestionList/utils/index.js +1 -0
- package/components/Downshift/SuggestionList/utils/useSuggestionList.d.ts +298 -0
- package/components/Downshift/SuggestionList/utils/useSuggestionList.js +239 -0
- package/components/Downshift/styles/StyledTextField.d.ts +1 -1
- package/components/Downshift/utils/DownshiftUtils.d.ts +12 -0
- package/components/Downshift/utils/DownshiftUtils.js +19 -1
- package/components/Downshift/utils/SelectItem.d.ts +19 -0
- package/components/Downshift/utils/useDownshift.d.ts +5 -2
- package/components/Downshift/utils/useDownshift.interface.d.ts +5 -0
- package/components/Downshift/utils/useDownshift.js +31 -13
- package/components/Downshift/utils/useDownshiftGroup.d.ts +7 -7
- package/components/Downshift/utils/useDownshiftGroup.js +45 -19
- package/components/Forms/Picker/TimePicker/NumberPicker.js +1 -3
- package/components/Forms/Picker/TimePicker/TimePicker.d.ts +13 -58
- package/components/Forms/Picker/TimePicker/TimePicker.js +15 -21
- package/components/Forms/Picker/TimePicker/index.d.ts +1 -0
- package/components/Forms/Picker/TimePicker/index.js +1 -0
- package/components/Forms/Picker/TimePicker/styles/StyledPickerPopperWrap.d.ts +8 -8
- package/components/Forms/Picker/TimePicker/utils/TimePickerHelper.d.ts +24 -0
- package/components/Forms/Picker/TimePicker/utils/TimePickerHelper.js +25 -1
- package/components/Forms/Picker/styles/StyledPickerTextField.d.ts +1 -1
- package/components/Forms/Select/PlainSelect/PlainSelect.d.ts +1 -1
- package/components/Forms/Select/PlainSelect/PlainSelect.js +5 -4
- package/components/Forms/Select/PlainSelect/styles/StyledSelect.js +4 -3
- package/components/Forms/Select/Select.d.ts +2 -2
- package/components/Forms/Select/Select.js +2 -2
- package/components/Forms/Select/styles/StyledSelect.js +22 -18
- package/components/Forms/TextField/TextField.d.ts +4 -2
- package/components/Forms/TextField/TextField.js +2 -2
- package/components/Forms/TextField/styles/OutlineTextFieldStyle.js +4 -2
- package/components/Forms/TextField/styles/TextFieldStyle.js +8 -4
- package/components/Forms/Textarea/Textarea.d.ts +1 -1
- package/components/Menu/SubMenu/SubMenu.js +1 -1
- package/components/Toast/Toast.d.ts +30 -0
- package/components/Toast/Toast.js +49 -0
- package/components/Toast/ToastContainer.d.ts +12 -0
- package/components/Toast/ToastContainer.js +17 -0
- package/components/Toast/index.d.ts +3 -0
- package/components/Toast/index.js +7 -0
- package/components/Toast/styles/ToastStyle.d.ts +4 -0
- package/components/Toast/styles/ToastStyle.js +12 -0
- package/components/Toast/styles/index.d.ts +1 -0
- package/components/Toast/styles/index.js +4 -0
- package/components/Toast/utils/ToastUtils.d.ts +1 -0
- package/components/Toast/utils/ToastUtils.js +3 -0
- package/components/Toast/utils/index.d.ts +1 -0
- package/components/Toast/utils/index.js +4 -0
- package/components/Virtuoso/utils/useHighlightScroll.d.ts +1 -1
- package/es6/components/Buttons/Button/styles/StyledButton.js +4 -2
- package/es6/components/Chip/Chip.js +6 -4
- package/es6/components/Chip/styles/ChipStyle.js +6 -5
- package/es6/components/Chip/utils/ChipUtils.js +1 -1
- package/es6/components/Downshift/Downshift.js +16 -7
- package/es6/components/Downshift/SuggestionList/SuggestionList.js +13 -7
- package/es6/components/Downshift/SuggestionList/utils/index.js +1 -0
- package/es6/components/Downshift/SuggestionList/utils/useSuggestionList.js +237 -0
- package/es6/components/Downshift/utils/DownshiftUtils.js +19 -1
- package/es6/components/Downshift/utils/useDownshift.js +31 -13
- package/es6/components/Downshift/utils/useDownshiftGroup.js +46 -20
- package/es6/components/Forms/Picker/TimePicker/NumberPicker.js +1 -3
- package/es6/components/Forms/Picker/TimePicker/TimePicker.js +15 -21
- package/es6/components/Forms/Picker/TimePicker/index.js +1 -0
- package/es6/components/Forms/Picker/TimePicker/utils/TimePickerHelper.js +25 -1
- package/es6/components/Forms/Select/PlainSelect/PlainSelect.js +5 -4
- package/es6/components/Forms/Select/PlainSelect/styles/StyledSelect.js +4 -3
- package/es6/components/Forms/Select/Select.js +2 -2
- package/es6/components/Forms/Select/styles/StyledSelect.js +24 -20
- package/es6/components/Forms/TextField/TextField.js +2 -2
- package/es6/components/Forms/TextField/styles/OutlineTextFieldStyle.js +5 -3
- package/es6/components/Forms/TextField/styles/TextFieldStyle.js +9 -5
- package/es6/components/Menu/SubMenu/SubMenu.js +1 -1
- package/es6/components/Toast/Toast.js +47 -0
- package/es6/components/Toast/ToastContainer.js +15 -0
- package/es6/components/Toast/index.js +3 -0
- package/es6/components/Toast/styles/ToastStyle.js +10 -0
- package/es6/components/Toast/styles/index.js +1 -0
- package/es6/components/Toast/utils/ToastUtils.js +1 -0
- package/es6/components/Toast/utils/index.js +1 -0
- package/es6/foundation/config.js +8 -5
- package/es6/foundation/contexts/PortalWindowContext.js +3 -1
- package/es6/foundation/hooks/useAnnouncer/useAnnouncer.js +7 -0
- package/es6/foundation/hooks/useKeyboardMoveFocus/useKeyboardMoveFocus.js +2 -1
- package/es6/foundation/theme/ThemeProvider.js +17 -4
- package/es6/foundation/theme/assets/zIndex.json +2 -1
- package/foundation/config.js +8 -5
- package/foundation/contexts/PortalWindowContext.js +3 -1
- package/foundation/hooks/useAnnouncer/useAnnouncer.d.ts +7 -0
- package/foundation/hooks/useAnnouncer/useAnnouncer.js +7 -0
- package/foundation/hooks/useKeyboardMoveFocus/useKeyboardMoveFocus.js +2 -1
- package/foundation/theme/ThemeProvider.d.ts +2 -0
- package/foundation/theme/ThemeProvider.js +15 -2
- package/foundation/theme/assets/zIndex.json +2 -1
- package/package.json +3 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
var foundation_1 = require("../../foundation");
|
|
6
|
+
var Portal_1 = require("../Portal");
|
|
7
|
+
var styles_1 = require("./styles");
|
|
8
|
+
var utils_1 = require("./utils");
|
|
9
|
+
var _RcToastContainer = react_1.forwardRef(function (props, ref) {
|
|
10
|
+
var _a = props.container, container = _a === void 0 ? document.body : _a, _b = props.id, id = _b === void 0 ? utils_1.RC_TOAST_CONTAINER_ID : _b, rest = tslib_1.__rest(props, ["container", "id"]);
|
|
11
|
+
return (react_1.default.createElement(Portal_1.RcPortal, { container: container },
|
|
12
|
+
react_1.default.createElement("div", tslib_1.__assign({}, rest, { id: id, ref: ref }))));
|
|
13
|
+
});
|
|
14
|
+
var RcToastContainer = foundation_1.styled(_RcToastContainer)(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), styles_1.ToastContainerStyle);
|
|
15
|
+
exports.RcToastContainer = RcToastContainer;
|
|
16
|
+
RcToastContainer.displayName = 'RcToastContainer';
|
|
17
|
+
var templateObject_1;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./Toast"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./ToastContainer"), exports);
|
|
6
|
+
var styles_1 = require("./styles");
|
|
7
|
+
exports.ToastContainerStyle = styles_1.ToastContainerStyle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var foundation_1 = require("../../../foundation");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
exports.ToastStyle = function () {
|
|
7
|
+
return foundation_1.css(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n &:last-of-type {\n margin-bottom: 0;\n }\n\n margin-bottom: ", ";\n\n ", "\n position: static;\n transform: none;\n "], ["\n &:last-of-type {\n margin-bottom: 0;\n }\n\n margin-bottom: ", ";\n\n ", /** clean snackbar style about anchorOrigin */ "\n position: static;\n transform: none;\n "])), foundation_1.spacing(3), '' /** clean snackbar style about anchorOrigin */);
|
|
8
|
+
};
|
|
9
|
+
exports.ToastContainerStyle = function () {
|
|
10
|
+
return foundation_1.css(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n #", " {\n padding-left: ", ";\n padding-right: ", ";\n\n position: fixed;\n top: ", ";\n left: 0;\n right: 0;\n\n z-index: ", ";\n box-sizing: border-box;\n pointer-events: none;\n }\n "], ["\n #", " {\n padding-left: ", ";\n padding-right: ", ";\n\n position: fixed;\n top: ", ";\n left: 0;\n right: 0;\n\n z-index: ", ";\n box-sizing: border-box;\n pointer-events: none;\n }\n "])), utils_1.RC_TOAST_CONTAINER_ID, foundation_1.spacing(4), foundation_1.spacing(4), foundation_1.spacing(22), foundation_1.zIndex('toast'));
|
|
11
|
+
};
|
|
12
|
+
var templateObject_1, templateObject_2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ToastStyle';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RC_TOAST_CONTAINER_ID = "RC_TOAST_CONTAINER";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ToastUtils';
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { IndexLocationWithAlign, ListItem } from 'react-virtuoso';
|
|
3
3
|
declare type UseHighlightScrollParams = {
|
|
4
4
|
/** function to call to scroll to target index */
|
|
5
|
-
scrollToIndex: (location:
|
|
5
|
+
scrollToIndex: (location: IndexLocationWithAlign) => void;
|
|
6
6
|
/** that scroll container height ref */
|
|
7
7
|
containerHeighRef: React.MutableRefObject<number>;
|
|
8
8
|
};
|
|
@@ -3,11 +3,13 @@ import { css, fakeBorder, focusVisible, getParsePaletteColor, nonTouchHoverMedia
|
|
|
3
3
|
import { RcButtonClasses, RcButtonColors, RcButtonHeights, RcButtonIconSpace, RcButtonMinWidths, RcButtonPadding, RcButtonTextColors, RcButtonTypographies, } from '../utils';
|
|
4
4
|
export var buttonColor = function (_a) {
|
|
5
5
|
var color = _a.color;
|
|
6
|
-
return RcButtonColors[color] ||
|
|
6
|
+
return (typeof color === 'string' && RcButtonColors[color]) ||
|
|
7
|
+
getParsePaletteColor(color);
|
|
7
8
|
};
|
|
8
9
|
export var plainButtonTextColor = function (_a) {
|
|
9
10
|
var color = _a.color;
|
|
10
|
-
return RcButtonTextColors[color] ||
|
|
11
|
+
return (typeof color === 'string' && RcButtonTextColors[color]) ||
|
|
12
|
+
getParsePaletteColor(color);
|
|
11
13
|
};
|
|
12
14
|
export var buttonTextColor = function (props) {
|
|
13
15
|
return paletteContrastText(buttonColor(props));
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { __assign, __makeTemplateObject, __rest } from "tslib";
|
|
2
2
|
import React, { forwardRef, useMemo, } from 'react';
|
|
3
3
|
import MuiChip from '@material-ui/core/Chip';
|
|
4
|
-
import { combineClasses, isRcElement, styled, useThemeProps, } from '../../foundation';
|
|
4
|
+
import { combineClasses, isRcElement, omit, styled, useThemeProps, } from '../../foundation';
|
|
5
5
|
import DeleteCircle from '../../icon/DeleteCircle';
|
|
6
6
|
import { RcIconButton } from '../Buttons/IconButton';
|
|
7
7
|
import { ChipStyle } from './styles';
|
|
8
8
|
import { RcChipClasses } from './utils';
|
|
9
|
+
import clsx from 'clsx';
|
|
9
10
|
var _RcChip = forwardRef(function (inProps, ref) {
|
|
10
11
|
var props = useThemeProps({ props: inProps, name: 'RcChip' });
|
|
11
|
-
var AvatarProp = props.Avatar, deleteTooltip = props.deleteTooltip, deleteAutomationId = props.deleteAutomationId, isError = props.isError, classesProp = props.classes, _a = props.avatar, avatarProp = _a === void 0 ? AvatarProp : _a, _b = props.error, error = _b === void 0 ? isError : _b, id = props.id, label = props.label, disabled = props.disabled, deleteIconProp = props.deleteIcon, deleteIconProps = props.deleteIconProps, tabIndex = props.tabIndex, rest = __rest(props, ["Avatar", "deleteTooltip", "deleteAutomationId", "isError", "classes", "avatar", "error", "id", "label", "disabled", "deleteIcon", "deleteIconProps", "tabIndex"]);
|
|
12
|
-
var
|
|
12
|
+
var AvatarProp = props.Avatar, deleteTooltip = props.deleteTooltip, deleteAutomationId = props.deleteAutomationId, isError = props.isError, classesProp = props.classes, _a = props.avatar, avatarProp = _a === void 0 ? AvatarProp : _a, _b = props.error, error = _b === void 0 ? isError : _b, id = props.id, label = props.label, disabled = props.disabled, deleteIconProp = props.deleteIcon, deleteIconProps = props.deleteIconProps, tabIndex = props.tabIndex, focused = props.focused, color = props.color, className = props.className, rest = __rest(props, ["Avatar", "deleteTooltip", "deleteAutomationId", "isError", "classes", "avatar", "error", "id", "label", "disabled", "deleteIcon", "deleteIconProps", "tabIndex", "focused", "color", "className"]);
|
|
13
|
+
var combinedClasses = useMemo(function () { return combineClasses(RcChipClasses, classesProp); }, [classesProp]);
|
|
14
|
+
var classes = useMemo(function () { return omit(combinedClasses, ['focused']); }, [combinedClasses]);
|
|
13
15
|
var deleteIcon = useMemo(function () {
|
|
14
16
|
return deleteIconProp ? (React.cloneElement(deleteIconProp, __assign({ tabIndex: -1 }, deleteIconProps))) : (React.createElement(RcIconButton, __assign({ tabIndex: -1, disabled: disabled, variant: "plain", size: "medium", title: deleteTooltip, color: error ? 'danger.f02' : undefined, "data-test-automation-id": deleteAutomationId, symbol: DeleteCircle }, deleteIconProps)));
|
|
15
17
|
}, [
|
|
@@ -35,7 +37,7 @@ var _RcChip = forwardRef(function (inProps, ref) {
|
|
|
35
37
|
}
|
|
36
38
|
return undefined;
|
|
37
39
|
}, [avatarProp]);
|
|
38
|
-
return (React.createElement(MuiChip, __assign({ ref: ref, id: id, tabIndex: disabled ? -1 : tabIndex, label: label, disabled: disabled, classes: classes, avatar: avatar, deleteIcon: deleteIcon, "data-test-automation-class": "selected-item", "data-test-automation-value": id ? id : label, "data-is-error": error }, rest)));
|
|
40
|
+
return (React.createElement(MuiChip, __assign({ ref: ref, id: id, tabIndex: disabled ? -1 : tabIndex, label: label, disabled: disabled, classes: classes, className: clsx(className, focused ? combinedClasses.focused : undefined), avatar: avatar, deleteIcon: deleteIcon, "data-test-automation-class": "selected-item", "data-test-automation-value": id ? id : label, "data-is-error": error }, rest)));
|
|
39
41
|
});
|
|
40
42
|
var RcChip = styled(_RcChip)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), ChipStyle);
|
|
41
43
|
RcChip.defaultProps = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __makeTemplateObject } from "tslib";
|
|
2
|
-
import { css, ellipsis, fakeBorder, focusVisible, focusVisibleColor, nonTouchHoverMedia, palette2, radius, setOpacity, spacing, typography, } from '../../../foundation';
|
|
2
|
+
import { css, ellipsis, fakeBorder, focusVisible, focusVisibleColor, getParsePaletteColor, nonTouchHoverMedia, palette2, radius, setOpacity, spacing, typography, } from '../../../foundation';
|
|
3
3
|
import { disabledColor, textColor } from '../../Forms/TextField/styles';
|
|
4
4
|
import { RcChipClasses } from '../utils';
|
|
5
5
|
var defaultBgColor = palette2('action', 'grayDark');
|
|
@@ -8,9 +8,10 @@ function fakePseudoRoundBorder(addOptions) {
|
|
|
8
8
|
return fakeBorder(__assign({ pseudo: true, radius: 'round' }, addOptions));
|
|
9
9
|
}
|
|
10
10
|
export var ChipStyle = function (props) {
|
|
11
|
-
var isError = props.isError, _a = props.error, error = _a === void 0 ? isError : _a;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
";\n
|
|
11
|
+
var isError = props.isError, _a = props.error, error = _a === void 0 ? isError : _a, colorProp = props.color;
|
|
12
|
+
var color = getParsePaletteColor(colorProp, focusVisibleColor);
|
|
13
|
+
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n height: 28px;\n box-sizing: border-box;\n padding: ", ";\n background-color: ", ";\n color: ", ";\n position: relative;\n border-radius: ", ";\n ", ";\n\n ", ";\n ", ";\n\n &.", ", ", " {\n ", ";\n\n background-color: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", ", &:focus {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n\n &.", " {\n color: ", ";\n opacity: 1;\n }\n\n ", ";\n\n .", " {\n color: ", ";\n margin-left: 0px;\n margin-right: -4px;\n\n span {\n width: auto;\n height: auto;\n }\n }\n "], ["\n height: 28px;\n box-sizing: border-box;\n padding: ", ";\n background-color: ", ";\n color: ", ";\n position: relative;\n border-radius: ", ";\n ", ";\n\n ", ";\n ", ";\n\n &.", ", ", " {\n ", ";\n\n background-color: ",
|
|
14
|
+
";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", ", &:focus {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n\n &.", " {\n color: ", ";\n opacity: 1;\n }\n\n ",
|
|
15
|
+
";\n\n .", " {\n color: ", ";\n margin-left: 0px;\n margin-right: -4px;\n\n span {\n width: auto;\n height: auto;\n }\n }\n "])), spacing(0.5), palette2('neutral', 'b03'), textColor, radius('round'), ellipsis, typography('body1'), fakePseudoRoundBorder(), RcChipClasses.focused, focusVisible, fakePseudoRoundBorder({ color: color }), setOpacity(error ? errorBgColor : defaultBgColor, '08'), nonTouchHoverMedia, setOpacity(defaultBgColor, '12'), RcChipClasses.focused, setOpacity(defaultBgColor, '16'), setOpacity(defaultBgColor, '24'), RcChipClasses.disabled, disabledColor, error && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n &:not(.", ") {\n color: ", ";\n ", ";\n\n background-color: ", ";\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &:focus {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n }\n "], ["\n &:not(.", ") {\n color: ", ";\n ", ";\n\n background-color: ", ";\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &:focus {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n }\n "])), RcChipClasses.disabled, palette2('danger', 'f02'), fakePseudoRoundBorder({ color: palette2('danger', 'f02') }), palette2('danger', 'b01'), nonTouchHoverMedia, setOpacity(errorBgColor, '08'), setOpacity(errorBgColor, '16'), setOpacity(errorBgColor, '24')), RcChipClasses.avatar, palette2('neutral', 'b01'));
|
|
15
16
|
};
|
|
16
17
|
var templateObject_1, templateObject_2;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign, __makeTemplateObject, __read, __rest } from "tslib";
|
|
2
2
|
import React, { forwardRef, memo, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
-
import { combineClasses, combineProps, omit, styled, useEventCallback, useForkRef, useThemeProps, withDeprecatedCheck, } from '../../foundation';
|
|
3
|
+
import { combineClasses, combineProps, getParsePaletteColor, omit, styled, useEventCallback, useForkRef, useTheme, useThemeProps, withDeprecatedCheck, } from '../../foundation';
|
|
4
4
|
import ArrowDown from '../../icon/ArrowDown';
|
|
5
5
|
import ArrowUp from '../../icon/ArrowUp';
|
|
6
6
|
import { RcChip } from '../Chip';
|
|
@@ -11,7 +11,8 @@ import { RcSuggestionList } from './SuggestionList';
|
|
|
11
11
|
import { DEFAULT_GET_OPTION_LABEL, DEFAULT_KEY_TO_CHIPS, DEFAULT_LIMIT_CHIPS, RcDownshiftDefaultFilterOptions, RcDownshiftInputClasses, useDownshift, useDownshiftError, } from './utils';
|
|
12
12
|
var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
13
13
|
var props = useThemeProps({ props: inProps, name: 'RcDownshift' });
|
|
14
|
-
var
|
|
14
|
+
var theme = useTheme();
|
|
15
|
+
var _a = props.itemToString, itemToString = _a === void 0 ? DEFAULT_GET_OPTION_LABEL : _a, _b = props.keyToChips, keyToChips = _b === void 0 ? DEFAULT_KEY_TO_CHIPS : _b, _c = props.limitOfFreeChips, limitOfFreeChips = _c === void 0 ? DEFAULT_LIMIT_CHIPS : _c, minRowHeight = props.minRowHeight, suggestionItems = props.suggestionItems, messageRef = props.messageRef, MenuItem = props.MenuItem, inputLabel = props.inputLabel, nameError = props.nameError, maxLength = props.maxLength, InputItem = props.InputItem, emailError = props.emailError, autoSwitchEmail = props.autoSwitchEmail, enableFreeChips = props.enableFreeChips, inputPlaceholder = props.inputPlaceholder, errorSelectedItems = props.errorSelectedItems, enableAutoTransform = props.enableAutoTransform, allowPlainHelperText = props.allowPlainHelperText, TextFieldProps = props.TextFieldProps, selectedItemsProp = props.selectedItems, automationId = props.automationId, screenReader = props.screenReader, onSelectChange = props.onSelectChange, variant = props.variant, groupExpanded = props.groupExpanded, groupDefaultExpanded = props.groupDefaultExpanded, _d = props.groupVariant, groupVariant = _d === void 0 ? 'normal' : _d, getExpandIconProps = props.getExpandIconProps, groupBy = props.groupBy, _e = props.value, valueProp = _e === void 0 ? selectedItemsProp : _e, _f = props.autoHighlight, autoHighlight = _f === void 0 ? true : _f, _g = props.fullWidth, fullWidth = _g === void 0 ? true : _g, _h = props.clearBtn, clearBtn = _h === void 0 ? false : _h, _j = props.toggleButton, toggleButton = _j === void 0 ? false : _j, _k = props.multiple, multiple = _k === void 0 ? false : _k, clearButtonProps = props.clearButtonProps, onClear = props.onClear, ToggleButtonProps = props.ToggleButtonProps, inputValueProp = props.inputValue, onKeyDownProp = props.onKeyDown, helperTextProp = props.helperText, options = props.options, openOnFocus = props.openOnFocus, _l = props.getOptionLabel, getOptionLabel = _l === void 0 ? itemToString : _l, renderInput = props.renderInput, _m = props.label, label = _m === void 0 ? inputLabel : _m, _o = props.inputRef, inputRefProp = _o === void 0 ? messageRef : _o, _p = props.error, error = _p === void 0 ? nameError : _p, _q = props.placeholder, placeholder = _q === void 0 ? inputPlaceholder : _q, _r = props.freeSolo, freeSolo = _r === void 0 ? enableFreeChips : _r, _s = props.keyToTags, keyToTags = _s === void 0 ? keyToChips : _s, _t = props.maxFreeSolo, maxFreeSolo = _t === void 0 ? limitOfFreeChips : _t, SuggestionListProps = props.SuggestionListProps, _u = props.autoSelect, autoSelect = _u === void 0 ? enableAutoTransform : _u, PopperProps = props.PopperProps, initialIsOpen = props.initialIsOpen, disabled = props.disabled, requiredProp = props.required, _v = props.defaultIsOpen, defaultIsOpen = _v === void 0 ? openOnFocus : _v, _w = props.disableCloseOnSelect, disableCloseOnSelect = _w === void 0 ? defaultIsOpen : _w, _x = props.onChange, onChangeProp = _x === void 0 ? onSelectChange : _x, onInputChangeProp = props.onInputChange, onMaxFreeSolo = props.onMaxFreeSolo, FormHelperTextPropsProp = props.FormHelperTextProps, action = props.action, filterOptions = props.filterOptions, renderOption = props.renderOption, renderTags = props.renderTags, getOptionDisabled = props.getOptionDisabled, renderGroup = props.renderGroup, onGroupExpanded = props.onGroupExpanded, renderNoOptions = props.renderNoOptions, InputPropsProp = props.InputProps, debug = props.debug, disabledItemsHighlightable = props.disabledItemsHighlightable, openProp = props.open, onOpen = props.onOpen, onClose = props.onClose, focused = props.focused, color = props.color, rest = __rest(props, ["itemToString", "keyToChips", "limitOfFreeChips", "minRowHeight", "suggestionItems", "messageRef", "MenuItem", "inputLabel", "nameError", "maxLength", "InputItem", "emailError", "autoSwitchEmail", "enableFreeChips", "inputPlaceholder", "errorSelectedItems", "enableAutoTransform", "allowPlainHelperText", "TextFieldProps", "selectedItems", "automationId", "screenReader", "onSelectChange", "variant", "groupExpanded", "groupDefaultExpanded", "groupVariant", "getExpandIconProps", "groupBy", "value", "autoHighlight", "fullWidth", "clearBtn", "toggleButton", "multiple", "clearButtonProps", "onClear", "ToggleButtonProps", "inputValue", "onKeyDown", "helperText", "options", "openOnFocus", "getOptionLabel", "renderInput", "label", "inputRef", "error", "placeholder", "freeSolo", "keyToTags", "maxFreeSolo", "SuggestionListProps", "autoSelect", "PopperProps", "initialIsOpen", "disabled", "required", "defaultIsOpen", "disableCloseOnSelect", "onChange", "onInputChange", "onMaxFreeSolo", "FormHelperTextProps", "action", "filterOptions", "renderOption", "renderTags", "getOptionDisabled", "renderGroup", "onGroupExpanded", "renderNoOptions", "InputProps", "debug", "disabledItemsHighlightable", "open", "onOpen", "onClose", "focused", "color"]);
|
|
15
16
|
var _y = __read(useState('bottom'), 2), position = _y[0], setPosition = _y[1];
|
|
16
17
|
var innerInputRef = useRef(null);
|
|
17
18
|
var textFieldRef = useRef(null);
|
|
@@ -23,6 +24,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
23
24
|
useDownshiftError({ isNew: isNew, MenuItem: MenuItem, InputItem: InputItem });
|
|
24
25
|
var required = requiredProp || (TextFieldProps === null || TextFieldProps === void 0 ? void 0 : TextFieldProps.required);
|
|
25
26
|
var _z = useDownshift({
|
|
27
|
+
focused: focused,
|
|
26
28
|
open: openProp,
|
|
27
29
|
variant: variant,
|
|
28
30
|
onOpen: onOpen,
|
|
@@ -34,6 +36,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
34
36
|
inputValue: inputValueProp,
|
|
35
37
|
getOptionDisabled: getOptionDisabled,
|
|
36
38
|
groupExpanded: groupVariant === 'normal' ? true : groupExpanded,
|
|
39
|
+
groupDefaultExpanded: groupDefaultExpanded,
|
|
37
40
|
getExpandIconProps: getExpandIconProps,
|
|
38
41
|
options: suggestionItems || options,
|
|
39
42
|
freeSolo: freeSolo,
|
|
@@ -59,7 +62,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
59
62
|
onKeyDown: onKeyDownProp,
|
|
60
63
|
disabledItemsHighlightable: disabledItemsHighlightable,
|
|
61
64
|
onGroupExpanded: onGroupExpanded,
|
|
62
|
-
}), focusInput = _z.focusInput, optionItems = _z.optionItems, optionsGroupList = _z.optionsGroupList, selectedItems = _z.selectedItems, highlightedIndex = _z.highlightedIndex, getToggleButtonProps = _z.getToggleButtonProps, getTagProps = _z.getTagProps, getTagListBoxProps = _z.getTagListBoxProps, getMenuProps = _z.getMenuProps, getPopperProps = _z.getPopperProps, getInputProps = _z.getInputProps, getInputAriaProps = _z.getInputAriaProps, getLabelProps = _z.getLabelProps, getItemProps = _z.getItemProps, isOpen = _z.isOpen, inputValue = _z.inputValue, isTagsFocus = _z.isTagsFocus, activeIndex = _z.activeIndex, setActiveIndex = _z.setActiveIndex, setHighlightedIndex = _z.setHighlightedIndex, onInputChange = _z.onInputChange, keepHighlightedIndex = _z.keepHighlightedIndex, changeHighlightedIndexReason = _z.changeHighlightedIndexReason, closeMenu = _z.closeMenu, openMenu = _z.openMenu, reset = _z.reset, getClearButtonProps = _z.getClearButtonProps, noOptionItem = _z.noOptionItem, getNoOptionsProps = _z.getNoOptionsProps, isKeepHighlightedIndex = _z.isKeepHighlightedIndex;
|
|
65
|
+
}), focusInput = _z.focusInput, optionItems = _z.optionItems, optionsGroupList = _z.optionsGroupList, selectedItems = _z.selectedItems, highlightedIndex = _z.highlightedIndex, getToggleButtonProps = _z.getToggleButtonProps, getTagProps = _z.getTagProps, getTagListBoxProps = _z.getTagListBoxProps, getMenuProps = _z.getMenuProps, getPopperProps = _z.getPopperProps, getInputProps = _z.getInputProps, getInputAriaProps = _z.getInputAriaProps, getLabelProps = _z.getLabelProps, getItemProps = _z.getItemProps, isOpen = _z.isOpen, inputValue = _z.inputValue, isTagsFocus = _z.isTagsFocus, activeIndex = _z.activeIndex, setActiveIndex = _z.setActiveIndex, setHighlightedIndex = _z.setHighlightedIndex, onInputChange = _z.onInputChange, keepHighlightedIndex = _z.keepHighlightedIndex, changeHighlightedIndexReason = _z.changeHighlightedIndexReason, closeMenu = _z.closeMenu, openMenu = _z.openMenu, reset = _z.reset, getClearButtonProps = _z.getClearButtonProps, noOptionItem = _z.noOptionItem, getNoOptionsProps = _z.getNoOptionsProps, isKeepHighlightedIndex = _z.isKeepHighlightedIndex, isFocused = _z.isFocused;
|
|
63
66
|
var open = Boolean((isOpen || noOptionItem) && textFieldRef.current);
|
|
64
67
|
var _0 = getInputProps(), onBlur = _0.onBlur, InputProps = __rest(_0, ["onBlur"]);
|
|
65
68
|
var helperText = isNew
|
|
@@ -85,6 +88,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
var toTextFieldRef = useForkRef(textFieldRef, ref);
|
|
91
|
+
var colorHex = useMemo(function () { return (color ? getParsePaletteColor(color)({ theme: theme }) : undefined); }, [color, theme]);
|
|
88
92
|
var startAdornment = (function () {
|
|
89
93
|
if (variant === 'autocomplete') {
|
|
90
94
|
return undefined;
|
|
@@ -99,7 +103,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
99
103
|
if (selectedItem.error) {
|
|
100
104
|
oneOfTagError = true;
|
|
101
105
|
}
|
|
102
|
-
return tagProps;
|
|
106
|
+
return __assign(__assign({}, tagProps), { color: colorHex });
|
|
103
107
|
};
|
|
104
108
|
return renderTags
|
|
105
109
|
? renderTags(selectedItems, getCustomizedTagProps)
|
|
@@ -120,9 +124,14 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
120
124
|
} })));
|
|
121
125
|
});
|
|
122
126
|
})();
|
|
127
|
+
var isDownshiftFocused = focused !== null && focused !== void 0 ? focused : (isTagsFocus || isFocused ? true : undefined);
|
|
123
128
|
var endAdornment = (toggleButton || clearBtn) && (React.createElement(EndAdornment, null,
|
|
124
129
|
clearBtn && (React.createElement(ClearIconButton, __assign({}, getClearButtonProps(clearButtonProps)))),
|
|
125
|
-
toggleButton && (React.createElement(ArrowDownButton, __assign({ variant: "plain", "aria-hidden": true, color:
|
|
130
|
+
toggleButton && (React.createElement(ArrowDownButton, __assign({ variant: "plain", "aria-hidden": true, color: isDownshiftFocused
|
|
131
|
+
? color || 'interactive.f01'
|
|
132
|
+
: error
|
|
133
|
+
? 'danger.f02'
|
|
134
|
+
: 'neutral.f04', size: "large", symbol: isOpen ? ArrowUp : ArrowDown }, getToggleButtonProps(ToggleButtonProps))))));
|
|
126
135
|
var _1 = (function () {
|
|
127
136
|
var _a = InputPropsProp || {}, classes = _a.classes, restInputPropsProp = __rest(_a, ["classes"]);
|
|
128
137
|
var toClasses = combineClasses(classes, RcDownshiftInputClasses);
|
|
@@ -154,7 +163,7 @@ var _RcDownshift = memo(forwardRef(function (inProps, ref) {
|
|
|
154
163
|
(_a = popperRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
|
155
164
|
});
|
|
156
165
|
return (React.createElement(React.Fragment, null,
|
|
157
|
-
React.createElement(StyledTextField, __assign({ renderInput: renderInput, hasTags: hasTags, ref: toTextFieldRef, inputRef: inputRef, "data-test-automation-id": automationId, fullWidth: fullWidth, placeholder: !hasTags ? placeholder : undefined, label: label, focused:
|
|
166
|
+
React.createElement(StyledTextField, __assign({ renderInput: renderInput, hasTags: hasTags, ref: toTextFieldRef, inputRef: inputRef, "data-test-automation-id": automationId, fullWidth: fullWidth, placeholder: !hasTags ? placeholder : undefined, label: label, focused: isDownshiftFocused, disabled: disabled, required: required, color: color,
|
|
158
167
|
// * if below one of tag is error, that main downshift default will be error
|
|
159
168
|
error: error !== null && error !== void 0 ? error : oneOfTagError, FormHelperTextProps: FormHelperTextProps, InputProps: TextFieldInputProps, helperText: helperText }, combineProps({
|
|
160
169
|
InputLabelProps: getLabelProps(),
|
|
@@ -286,5 +295,5 @@ var RcDownshift = styled(withDeprecatedCheck(_RcDownshift, [
|
|
|
286
295
|
RcDownshift.defaultProps = {};
|
|
287
296
|
RcDownshift.displayName = 'RcDownshift';
|
|
288
297
|
var ExportType = RcDownshift;
|
|
289
|
-
export { ExportType as RcDownshift, RcDownshiftDefaultFilterOptions };
|
|
298
|
+
export { ExportType as RcDownshift, RcDownshiftDefaultFilterOptions, RcDownshiftInput, };
|
|
290
299
|
var templateObject_1;
|
|
@@ -6,7 +6,7 @@ import ArrowDown2 from '../../../icon/ArrowDown2';
|
|
|
6
6
|
import { RcBox } from '../../Box';
|
|
7
7
|
import { RcIconButton } from '../../Buttons/IconButton';
|
|
8
8
|
import { RcMenuItem } from '../../Menu/MenuItem';
|
|
9
|
-
import { StyledMenuListPadding } from '../../VirtualizedMenu/styles';
|
|
9
|
+
import { menuListBoundaryPadding, StyledMenuListPadding, } from '../../VirtualizedMenu/styles';
|
|
10
10
|
import { useDynamicHeight, useHighlightScroll, Virtuoso, } from '../../Virtuoso';
|
|
11
11
|
import { SuggestionListStyle } from './styles';
|
|
12
12
|
import { RcSuggestionListClasses } from './utils';
|
|
@@ -45,8 +45,13 @@ var SuggestionList = forwardRef(function (inProps, ref) {
|
|
|
45
45
|
return __generator(this, function (_c) {
|
|
46
46
|
switch (_c.label) {
|
|
47
47
|
case 0:
|
|
48
|
+
if (location.index === 0 && padding !== undefined) {
|
|
49
|
+
location = __assign(__assign({}, location), { offset: -(typeof padding === 'number'
|
|
50
|
+
? padding
|
|
51
|
+
: menuListBoundaryPadding) });
|
|
52
|
+
}
|
|
48
53
|
(_a = vlRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex(location);
|
|
49
|
-
toIndex =
|
|
54
|
+
toIndex = location.index;
|
|
50
55
|
return [4 /*yield*/, sleep(0)];
|
|
51
56
|
case 1:
|
|
52
57
|
_c.sent();
|
|
@@ -139,12 +144,13 @@ var SuggestionList = forwardRef(function (inProps, ref) {
|
|
|
139
144
|
expandIconProps && (React.createElement(RcIconButton, __assign({}, expandIconProps, { symbol: ArrowDown2 })))));
|
|
140
145
|
};
|
|
141
146
|
var PaddingComponent = useMemo(function () {
|
|
142
|
-
|
|
147
|
+
var paddingValue = padding !== undefined && itemCount > 0
|
|
143
148
|
? typeof padding === 'number'
|
|
144
|
-
?
|
|
145
|
-
:
|
|
146
|
-
:
|
|
147
|
-
|
|
149
|
+
? padding
|
|
150
|
+
: menuListBoundaryPadding
|
|
151
|
+
: 0;
|
|
152
|
+
return function () { return React.createElement(StyledMenuListPadding, { height: paddingValue }); };
|
|
153
|
+
}, [itemCount, padding]);
|
|
148
154
|
var components = useMemo(function () {
|
|
149
155
|
return __assign({ List: List, Header: PaddingComponent, Footer: PaddingComponent }, componentsProp);
|
|
150
156
|
}, [componentsProp, PaddingComponent]);
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { __read, __rest } from "tslib";
|
|
2
|
+
import { useMemo, useRef } from 'react';
|
|
3
|
+
import uniqueId from 'lodash/uniqueId';
|
|
4
|
+
import { useControlled } from '@material-ui/core/utils';
|
|
5
|
+
import { combineProps, useForceUpdate, useKeyboardMoveFocus, useResultRef, } from '../../../../foundation';
|
|
6
|
+
import { DEFAULT_GET_OPTION_LABEL, isItemCanSelected, } from '../../utils';
|
|
7
|
+
import { useDownshiftGroup } from '../../utils/useDownshiftGroup';
|
|
8
|
+
var DEFAULT_HIGHLIGHTED_INDEX = -1;
|
|
9
|
+
var componentName = 'useSuggestionList';
|
|
10
|
+
/**
|
|
11
|
+
* provide suggestion list with search function and expandable group with virtualized list
|
|
12
|
+
*/
|
|
13
|
+
export var useSuggestionList = function (_a) {
|
|
14
|
+
var inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ? DEFAULT_GET_OPTION_LABEL : _b, filterOptions = _a.filterOptions, disabledItemsHighlightable = _a.disabledItemsHighlightable, options = _a.options, onInputChangeProp = _a.onInputChange, inputRef = _a.inputRef, onKeyDownProp = _a.onKeyDown, onSelect = _a.onSelect, onClear = _a.onClear, getOptionDisabled = _a.getOptionDisabled, groupBy = _a.groupBy, onGroupExpanded = _a.onGroupExpanded, groupVariant = _a.groupVariant, groupExpanded = _a.groupExpanded, groupDefaultExpanded = _a.groupDefaultExpanded, getExpandIconProps = _a.getExpandIconProps;
|
|
15
|
+
var _c = __read(useControlled({
|
|
16
|
+
controlled: inputValueProp,
|
|
17
|
+
default: '',
|
|
18
|
+
name: componentName,
|
|
19
|
+
}), 2), inputValue = _c[0], setInputValue = _c[1];
|
|
20
|
+
var updateInputValue = function (newValue) {
|
|
21
|
+
onInputChangeProp === null || onInputChangeProp === void 0 ? void 0 : onInputChangeProp(newValue);
|
|
22
|
+
setInputValue(newValue);
|
|
23
|
+
};
|
|
24
|
+
var focusInput = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
25
|
+
var suggestionListId = useResultRef(function () {
|
|
26
|
+
return uniqueId("suggestion-list-");
|
|
27
|
+
}).current;
|
|
28
|
+
// * use -2 for us know that is init state, for recalculate defaultHighlightedIndex
|
|
29
|
+
var highlightedIndexRef = useRef(DEFAULT_HIGHLIGHTED_INDEX);
|
|
30
|
+
var changeHighlightedIndexReason = useRef();
|
|
31
|
+
var forceUpdate = useForceUpdate();
|
|
32
|
+
var filteredResult = useMemo(function () {
|
|
33
|
+
var getFilteredItems = function (items) {
|
|
34
|
+
if (filterOptions) {
|
|
35
|
+
return filterOptions(items, {
|
|
36
|
+
inputValue: inputValue,
|
|
37
|
+
getOptionLabel: getOptionLabel,
|
|
38
|
+
selectedItems: [],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return items;
|
|
42
|
+
};
|
|
43
|
+
// * only when isOpen calculate the filtered result
|
|
44
|
+
var results = getFilteredItems(options);
|
|
45
|
+
return results;
|
|
46
|
+
}, [filterOptions, getOptionLabel, inputValue, options]);
|
|
47
|
+
var _d = useDownshiftGroup({
|
|
48
|
+
groupBy: groupBy,
|
|
49
|
+
options: options,
|
|
50
|
+
filteredResult: filteredResult,
|
|
51
|
+
getExpandIconProps: getExpandIconProps,
|
|
52
|
+
groupExpanded: groupExpanded,
|
|
53
|
+
groupDefaultExpanded: groupDefaultExpanded,
|
|
54
|
+
onGroupExpanded: onGroupExpanded,
|
|
55
|
+
groupVariant: groupVariant,
|
|
56
|
+
getOptionDisabled: getOptionDisabled,
|
|
57
|
+
id: suggestionListId,
|
|
58
|
+
}), groupedResult = _d.groupedResult, handleGroupExpandedChange = _d.handleGroupExpandedChange, optionsGroupList = _d.optionsGroupList;
|
|
59
|
+
var optionItems = groupBy ? groupedResult : filteredResult;
|
|
60
|
+
var setHighlightedIndex = function (index, _a) {
|
|
61
|
+
var _b = _a.reRender, reRender = _b === void 0 ? false : _b, reason = _a.reason;
|
|
62
|
+
changeHighlightedIndexReason.current = reason;
|
|
63
|
+
if (highlightedIndexRef.current !== index) {
|
|
64
|
+
highlightedIndexRef.current = index;
|
|
65
|
+
if (reRender)
|
|
66
|
+
forceUpdate();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var handleInputChange = function (newValue) {
|
|
70
|
+
if (inputValue !== newValue) {
|
|
71
|
+
setHighlightedIndex(DEFAULT_HIGHLIGHTED_INDEX, { reason: 'auto' });
|
|
72
|
+
updateInputValue(newValue);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
var getIsItemCanSelected = function (item) {
|
|
77
|
+
return ((!!item && item.freeSolo) ||
|
|
78
|
+
(isItemCanSelected(item) && !(getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(item))));
|
|
79
|
+
};
|
|
80
|
+
var selectItemFn = function (e, selectedItem) {
|
|
81
|
+
if (getIsItemCanSelected(selectedItem)) {
|
|
82
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(e, selectedItem);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
var resetState = function () {
|
|
88
|
+
if (inputRef.current && inputRef.current.value.length > 0) {
|
|
89
|
+
updateInputValue('');
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var reset = function (isFocus) {
|
|
93
|
+
resetState();
|
|
94
|
+
onInputChangeProp === null || onInputChangeProp === void 0 ? void 0 : onInputChangeProp('');
|
|
95
|
+
if (isFocus)
|
|
96
|
+
focusInput();
|
|
97
|
+
};
|
|
98
|
+
var onKeyFocusedIndexHandle = useKeyboardMoveFocus({
|
|
99
|
+
options: optionItems,
|
|
100
|
+
focusedIndexRef: highlightedIndexRef,
|
|
101
|
+
infinite: true,
|
|
102
|
+
onFocusedIndexChange: function (event, toIndex) {
|
|
103
|
+
setHighlightedIndex(toIndex, { reason: 'keyboard', reRender: true });
|
|
104
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
105
|
+
},
|
|
106
|
+
getOptionDisabled: disabledItemsHighlightable
|
|
107
|
+
? undefined
|
|
108
|
+
: function (child) {
|
|
109
|
+
return !getIsItemCanSelected(child);
|
|
110
|
+
},
|
|
111
|
+
}).onKeyFocusedIndexHandle;
|
|
112
|
+
var getItemProps = function (_a) {
|
|
113
|
+
var item = _a.item, index = _a.index, itemRest = __rest(_a, ["item", "index"]);
|
|
114
|
+
return combineProps({
|
|
115
|
+
id: suggestionListId + "-option-" + index,
|
|
116
|
+
role: 'option',
|
|
117
|
+
onClick: function (e) {
|
|
118
|
+
selectItemFn(e, item);
|
|
119
|
+
},
|
|
120
|
+
onMouseDown: function (e) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
},
|
|
124
|
+
onMouseOver: function () {
|
|
125
|
+
if (highlightedIndexRef.current !== index) {
|
|
126
|
+
setHighlightedIndex(index, { reason: 'mouse', reRender: true });
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
}, itemRest);
|
|
130
|
+
};
|
|
131
|
+
var getInputProps = function (props) {
|
|
132
|
+
return combineProps({
|
|
133
|
+
id: suggestionListId + "-input",
|
|
134
|
+
autoComplete: 'off',
|
|
135
|
+
onChange: function (e) {
|
|
136
|
+
var changeValue = e.target.value;
|
|
137
|
+
handleInputChange(changeValue);
|
|
138
|
+
},
|
|
139
|
+
onKeyDown: function (e) {
|
|
140
|
+
var _a;
|
|
141
|
+
onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(e, highlightedIndexRef.current);
|
|
142
|
+
var highlightedIndex = highlightedIndexRef.current;
|
|
143
|
+
switch (e.key) {
|
|
144
|
+
case 'F10':
|
|
145
|
+
if (e.shiftKey) {
|
|
146
|
+
var currOption = optionItems[highlightedIndex];
|
|
147
|
+
var currentGroup = currOption.group;
|
|
148
|
+
if (currentGroup && currentGroup.options.length > 1) {
|
|
149
|
+
handleGroupExpandedChange(currentGroup.group);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
case 'Enter':
|
|
154
|
+
if (e.which === 229)
|
|
155
|
+
return;
|
|
156
|
+
if (highlightedIndex !== DEFAULT_HIGHLIGHTED_INDEX) {
|
|
157
|
+
var currOption = optionItems[highlightedIndex];
|
|
158
|
+
var isGroupTitle = currOption === ((_a = currOption.group) === null || _a === void 0 ? void 0 : _a.options[0]);
|
|
159
|
+
if (isGroupTitle) {
|
|
160
|
+
var onClick = currOption.group.getExpandIconProps().onClick;
|
|
161
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
selectItemFn(e, currOption);
|
|
165
|
+
}
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
}
|
|
168
|
+
// always preventDefault for not inset all enter into textarea
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
break;
|
|
171
|
+
default:
|
|
172
|
+
onKeyFocusedIndexHandle(e);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
}, props);
|
|
177
|
+
};
|
|
178
|
+
var getInputAriaProps = function (props) {
|
|
179
|
+
return combineProps({
|
|
180
|
+
// * provide for when container click focus on input
|
|
181
|
+
onContainerClick: focusInput,
|
|
182
|
+
role: 'combobox',
|
|
183
|
+
'aria-autocomplete': 'list',
|
|
184
|
+
// TODO
|
|
185
|
+
'aria-expanded': true,
|
|
186
|
+
'aria-haspopup': true,
|
|
187
|
+
'aria-owns': suggestionListId + "-menu",
|
|
188
|
+
'aria-activedescendant': highlightedIndexRef.current > -1
|
|
189
|
+
? suggestionListId + "-option-" + highlightedIndexRef.current
|
|
190
|
+
: undefined,
|
|
191
|
+
}, props);
|
|
192
|
+
};
|
|
193
|
+
var getLabelProps = function (props) {
|
|
194
|
+
return combineProps({
|
|
195
|
+
htmlFor: suggestionListId + "-input",
|
|
196
|
+
id: suggestionListId + "-label",
|
|
197
|
+
}, props);
|
|
198
|
+
};
|
|
199
|
+
var getMenuProps = function (restMenuProps) {
|
|
200
|
+
return combineProps({
|
|
201
|
+
'aria-labelledby': suggestionListId + "-label",
|
|
202
|
+
id: suggestionListId + "-menu",
|
|
203
|
+
role: 'listbox',
|
|
204
|
+
}, restMenuProps);
|
|
205
|
+
};
|
|
206
|
+
var getClearButtonProps = function (props) {
|
|
207
|
+
return combineProps({
|
|
208
|
+
id: suggestionListId + "-clear-button",
|
|
209
|
+
onClick: function (e) {
|
|
210
|
+
onClear === null || onClear === void 0 ? void 0 : onClear(e);
|
|
211
|
+
reset(true);
|
|
212
|
+
},
|
|
213
|
+
}, props);
|
|
214
|
+
};
|
|
215
|
+
var resultObj = {
|
|
216
|
+
focusInput: focusInput,
|
|
217
|
+
getClearButtonProps: getClearButtonProps,
|
|
218
|
+
getLabelProps: getLabelProps,
|
|
219
|
+
getMenuProps: getMenuProps,
|
|
220
|
+
getInputProps: getInputProps,
|
|
221
|
+
getInputAriaProps: getInputAriaProps,
|
|
222
|
+
getItemProps: getItemProps,
|
|
223
|
+
highlightedIndex: highlightedIndexRef.current,
|
|
224
|
+
optionItems: optionItems,
|
|
225
|
+
inputValue: inputValue,
|
|
226
|
+
onInputChange: handleInputChange,
|
|
227
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
228
|
+
changeHighlightedIndexReason: changeHighlightedIndexReason.current,
|
|
229
|
+
reset: reset,
|
|
230
|
+
forceUpdate: forceUpdate,
|
|
231
|
+
optionsGroupList: optionsGroupList,
|
|
232
|
+
/** current suggestion list id */
|
|
233
|
+
id: suggestionListId,
|
|
234
|
+
};
|
|
235
|
+
changeHighlightedIndexReason.current = undefined;
|
|
236
|
+
return resultObj;
|
|
237
|
+
};
|
|
@@ -9,14 +9,32 @@ export var isItemCanSelected = function (item) {
|
|
|
9
9
|
export var DEFAULT_KEY_TO_CHIPS = [';', ',', '\\n'];
|
|
10
10
|
export var DEFAULT_LIMIT_CHIPS = 20;
|
|
11
11
|
export var DEFAULT_GET_OPTION_LABEL = function (item) {
|
|
12
|
-
return item.label || '';
|
|
12
|
+
return (item === null || item === void 0 ? void 0 : item.label) || '';
|
|
13
13
|
};
|
|
14
14
|
export var RcDownshiftDefaultRenderNoOptions = function (getNoOptionsProps) {
|
|
15
15
|
return (React.createElement(RcMenuItem, __assign({ component: "div" }, getNoOptionsProps()), "No Options"));
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* default downshift filter options method, use with `variant="tags"`
|
|
19
|
+
*
|
|
20
|
+
* - filter options by input value and selected items
|
|
21
|
+
*/
|
|
17
22
|
export var RcDownshiftDefaultFilterOptions = function (options, _a) {
|
|
18
23
|
var inputValue = _a.inputValue, getOptionLabel = _a.getOptionLabel, selectedItems = _a.selectedItems;
|
|
19
24
|
return options.filter(function (item) {
|
|
20
25
|
return selectedItems.indexOf(item) < 0 && (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(item).toLowerCase().startsWith((inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()) || ''));
|
|
21
26
|
});
|
|
22
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* default downshift filter options method, use with `variant="autocomplete"`
|
|
30
|
+
*
|
|
31
|
+
* - when open menu and not change value, that will return whole options
|
|
32
|
+
* - only filter options by input value when have input value changed
|
|
33
|
+
*/
|
|
34
|
+
export var RcAutocompleteDefaultFilterOptions = function (options, _a) {
|
|
35
|
+
var inputValue = _a.inputValue, getOptionLabel = _a.getOptionLabel, inputChanged = _a.inputChanged;
|
|
36
|
+
if (!inputChanged) {
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
return options.filter(function (item) { return getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(item).toLowerCase().startsWith((inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()) || ''); });
|
|
40
|
+
};
|