@ringcentral/juno 2.13.1 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/components/Downshift/Downshift.d.ts +47 -3
  2. package/components/Downshift/Downshift.js +50 -13
  3. package/components/Downshift/SuggestionList/SuggestionList.d.ts +19 -1
  4. package/components/Downshift/SuggestionList/SuggestionList.js +44 -29
  5. package/components/Downshift/styles/StyledPopper.d.ts +12 -7
  6. package/components/Downshift/styles/StyledPopper.js +6 -6
  7. package/components/Downshift/utils/useDownshift.d.ts +1 -0
  8. package/components/Downshift/utils/useDownshift.js +3 -0
  9. package/components/Forms/Select/Select.js +2 -2
  10. package/components/List/ListItem/ListItem.d.ts +3 -1
  11. package/components/List/ListItem/ListItem.js +3 -2
  12. package/components/List/ListItem/styles/ListItemStyle.d.ts +5 -0
  13. package/components/List/ListItem/styles/ListItemStyle.js +17 -5
  14. package/components/List/ListItem/utils/ListItemUtils.d.ts +2 -0
  15. package/components/List/ListItem/utils/ListItemUtils.js +5 -4
  16. package/components/Menu/MenuItem/MenuItem.d.ts +7 -6
  17. package/components/Menu/MenuItem/MenuItem.js +14 -4
  18. package/components/Menu/MenuItem/styles/MenuItemStyle.js +6 -3
  19. package/components/Menu/MenuItem/utils/MenuItemUtils.d.ts +4 -1
  20. package/components/Menu/MenuItem/utils/MenuItemUtils.js +4 -1
  21. package/components/Menu/MenuOption/styles/StyledMenuOption.d.ts +1 -1
  22. package/components/Menu/SubMenu/SubMenu.d.ts +1 -1
  23. package/components/Menu/SubMenu/utils/SubMenuUtils.d.ts +1 -1
  24. package/components/TablePagination/styles/TablePaginationStyle.d.ts +4 -4
  25. package/es6/components/Downshift/Downshift.js +51 -14
  26. package/es6/components/Downshift/SuggestionList/SuggestionList.js +44 -29
  27. package/es6/components/Downshift/styles/StyledPopper.js +6 -6
  28. package/es6/components/Downshift/utils/useDownshift.js +3 -0
  29. package/es6/components/Forms/Select/Select.js +2 -2
  30. package/es6/components/List/ListItem/ListItem.js +3 -2
  31. package/es6/components/List/ListItem/styles/ListItemStyle.js +19 -7
  32. package/es6/components/List/ListItem/utils/ListItemUtils.js +4 -3
  33. package/es6/components/Menu/MenuItem/MenuItem.js +16 -6
  34. package/es6/components/Menu/MenuItem/styles/MenuItemStyle.js +10 -7
  35. package/es6/components/Menu/MenuItem/utils/MenuItemUtils.js +4 -1
  36. package/package.json +1 -1
@@ -19,7 +19,7 @@ var List = forwardRef(function (props, ref) {
19
19
  var SuggestionList = forwardRef(function (inProps, ref) {
20
20
  var _a;
21
21
  var props = useThemeProps({ props: inProps, name: 'RcSuggestionList' });
22
- var highlightedIndex = props.highlightedIndex, options = props.options, getItemProps = props.getItemProps, getMenuProps = props.getMenuProps, renderOption = props.renderOption, inputValue = props.inputValue, groupVariant = props.groupVariant, groupExpanded = props.groupExpanded, renderGroup = props.renderGroup, optionsGroupList = props.optionsGroupList, getOptionDisabled = props.getOptionDisabled, MenuItem = props.MenuItem, changeHighlightedIndexReason = props.changeHighlightedIndexReason, isKeepHighlightedIndex = props.isKeepHighlightedIndex, componentsProp = props.components, onUpdatePopper = props.onUpdatePopper, getOptionLabel = props.getOptionLabel, padding = props.padding, _b = props.maxContainerHeight, maxContainerHeight = _b === void 0 ? '100%' : _b, classNameProp = props.className, classesProp = props.classes, _c = props.position, position = _c === void 0 ? 'absolute' : _c, rest = __rest(props, ["highlightedIndex", "options", "getItemProps", "getMenuProps", "renderOption", "inputValue", "groupVariant", "groupExpanded", "renderGroup", "optionsGroupList", "getOptionDisabled", "MenuItem", "changeHighlightedIndexReason", "isKeepHighlightedIndex", "components", "onUpdatePopper", "getOptionLabel", "padding", "maxContainerHeight", "className", "classes", "position"]);
22
+ var highlightedIndex = props.highlightedIndex, options = props.options, getItemProps = props.getItemProps, _b = props.virtualize, virtualize = _b === void 0 ? true : _b, getMenuProps = props.getMenuProps, renderOption = props.renderOption, selectedOptions = props.value, inputValue = props.inputValue, groupVariant = props.groupVariant, groupExpanded = props.groupExpanded, renderGroup = props.renderGroup, optionsGroupList = props.optionsGroupList, getOptionDisabled = props.getOptionDisabled, MenuItem = props.MenuItem, changeHighlightedIndexReason = props.changeHighlightedIndexReason, isKeepHighlightedIndex = props.isKeepHighlightedIndex, componentsProp = props.components, onUpdatePopper = props.onUpdatePopper, getOptionLabel = props.getOptionLabel, padding = props.padding, _c = props.maxContainerHeight, maxContainerHeight = _c === void 0 ? '100%' : _c, classNameProp = props.className, classesProp = props.classes, _d = props.position, position = _d === void 0 ? 'absolute' : _d, selectedIndex = props.selectedIndex, rest = __rest(props, ["highlightedIndex", "options", "getItemProps", "virtualize", "getMenuProps", "renderOption", "value", "inputValue", "groupVariant", "groupExpanded", "renderGroup", "optionsGroupList", "getOptionDisabled", "MenuItem", "changeHighlightedIndexReason", "isKeepHighlightedIndex", "components", "onUpdatePopper", "getOptionLabel", "padding", "maxContainerHeight", "className", "classes", "position", "selectedIndex"]);
23
23
  var vlRef = useRef(null);
24
24
  var forkVlRef = useForkRef(ref, vlRef);
25
25
  var isTitleMode = groupVariant === 'normal';
@@ -28,7 +28,7 @@ var SuggestionList = forwardRef(function (inProps, ref) {
28
28
  var itemCount = options.length;
29
29
  var classes = combineClasses(RcSuggestionListClasses, classesProp);
30
30
  var className = clsx(classNameProp, classes === null || classes === void 0 ? void 0 : classes.root);
31
- var _d = useDynamicHeight({
31
+ var _e = useDynamicHeight({
32
32
  itemCount: itemCount,
33
33
  maxContainerHeight: maxContainerHeight,
34
34
  onContainerHeightChange: function (changeHeight) {
@@ -38,25 +38,30 @@ var SuggestionList = forwardRef(function (inProps, ref) {
38
38
  onUpdatePopper === null || onUpdatePopper === void 0 ? void 0 : onUpdatePopper();
39
39
  }
40
40
  },
41
- }), totalListHeightChanged = _d.totalListHeightChanged, style = _d.style, containerHeighRef = _d.containerHeighRef;
41
+ }), totalListHeightChanged = _e.totalListHeightChanged, style = _e.style, containerHeighRef = _e.containerHeighRef;
42
42
  var sleep = useSleep().sleep;
43
43
  var scrollToIndexWithRetry = useRetry(function (location) { return __awaiter(void 0, void 0, void 0, function () {
44
- var toIndex, toElm;
45
- var _a, _b;
46
- return __generator(this, function (_c) {
47
- switch (_c.label) {
44
+ var toIndex, toElm_1, toElm;
45
+ var _a, _b, _c;
46
+ return __generator(this, function (_d) {
47
+ switch (_d.label) {
48
48
  case 0:
49
+ toIndex = location.index;
50
+ if (!virtualize) {
51
+ toElm_1 = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-item-index=\"" + toIndex + "\"]");
52
+ toElm_1 === null || toElm_1 === void 0 ? void 0 : toElm_1.scrollIntoView({ block: 'nearest', inline: 'nearest' });
53
+ return [2 /*return*/, true];
54
+ }
49
55
  if (location.index === 0 && padding !== undefined) {
50
56
  location = __assign(__assign({}, location), { offset: -(typeof padding === 'number'
51
57
  ? padding
52
58
  : menuListBoundaryPadding) });
53
59
  }
54
- (_a = vlRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex(location);
55
- toIndex = location.index;
60
+ (_b = vlRef.current) === null || _b === void 0 ? void 0 : _b.scrollToIndex(location);
56
61
  return [4 /*yield*/, sleep(0)];
57
62
  case 1:
58
- _c.sent();
59
- toElm = (_b = listRef.current) === null || _b === void 0 ? void 0 : _b.querySelector("[data-item-index=\"" + toIndex + "\"]");
63
+ _d.sent();
64
+ toElm = (_c = listRef.current) === null || _c === void 0 ? void 0 : _c.querySelector("[data-item-index=\"" + toIndex + "\"]");
60
65
  if (toElm) {
61
66
  return [2 /*return*/, true];
62
67
  }
@@ -67,10 +72,10 @@ var SuggestionList = forwardRef(function (inProps, ref) {
67
72
  retryTimes: 10,
68
73
  intervalTime: 20,
69
74
  }).retry;
70
- var _e = useHighlightScroll({
75
+ var _f = useHighlightScroll({
71
76
  containerHeighRef: containerHeighRef,
72
77
  scrollToIndex: scrollToIndexWithRetry,
73
- }), scrollerRef = _e.scrollerRef, scrollerRefFn = _e.scrollerRefFn, itemsRendered = _e.itemsRendered, scrollToHighlightedIndex = _e.scrollToHighlightedIndex;
78
+ }), scrollerRef = _f.scrollerRef, scrollerRefFn = _f.scrollerRefFn, itemsRendered = _f.itemsRendered, scrollToHighlightedIndex = _f.scrollToHighlightedIndex;
74
79
  // for safari, prevent popover
75
80
  var virtuosoViewPort = (_a = scrollerRef.current) === null || _a === void 0 ? void 0 : _a.firstElementChild;
76
81
  useLayoutEffect(function () {
@@ -80,7 +85,7 @@ var SuggestionList = forwardRef(function (inProps, ref) {
80
85
  }, [virtuosoViewPort, position]);
81
86
  var prevHighlightedIndex = usePrevious(function () { return highlightedIndex; }, true);
82
87
  useLayoutEffect(function () {
83
- if (vlRef.current &&
88
+ if ((!virtualize || vlRef.current) &&
84
89
  !isKeepHighlightedIndex &&
85
90
  // * only scroll when reason is 'keyboard'
86
91
  changeHighlightedIndexReason &&
@@ -118,8 +123,9 @@ var SuggestionList = forwardRef(function (inProps, ref) {
118
123
  index: index,
119
124
  className: isGroupTitle ? classes.groupTitle : undefined,
120
125
  });
121
- var selected = highlightedIndex === index;
122
- var resultProps = __assign(__assign(__assign({}, option), itemProps), { key: itemProps.id });
126
+ var highlighted = highlightedIndex === index;
127
+ var selected = selectedIndex === index;
128
+ var resultProps = __assign(__assign(__assign({ 'data-item-index': !virtualize ? index : undefined }, option), itemProps), { key: itemProps.id });
123
129
  var indexInOwnGroup = resultProps.indexInOwnGroup;
124
130
  delete resultProps.indexInOwnGroup;
125
131
  // * when item is not disabled, that should check outside is that disabled
@@ -129,6 +135,7 @@ var SuggestionList = forwardRef(function (inProps, ref) {
129
135
  var state = {
130
136
  inputValue: inputValue,
131
137
  selected: selected,
138
+ highlighted: highlighted,
132
139
  index: index,
133
140
  indexInOwnGroup: indexInOwnGroup,
134
141
  };
@@ -141,9 +148,11 @@ var SuggestionList = forwardRef(function (inProps, ref) {
141
148
  }
142
149
  // TODO: that MenuItem will be remove
143
150
  if (MenuItem) {
144
- return (React.createElement(MenuItem, __assign({}, resultProps, { itemId: option.id, "data-suggestion-item-id": option.id, isHighlighted: selected, isMember: option.isMember })));
151
+ return (React.createElement(MenuItem
152
+ // when not virtualize, use index as key
153
+ , __assign({}, resultProps, { itemId: option.id, "data-suggestion-item-id": option.id, isHighlighted: selected || highlighted, isMember: option.isMember })));
145
154
  }
146
- return (React.createElement(RcMenuItem, __assign({ component: "div", selected: selected }, omit(resultProps, [
155
+ return (React.createElement(RcMenuItem, __assign({ component: "div", selected: selected, focused: highlighted }, omit(resultProps, [
147
156
  'isSuggestion',
148
157
  'freeSolo',
149
158
  'label',
@@ -164,17 +173,23 @@ var SuggestionList = forwardRef(function (inProps, ref) {
164
173
  var components = useMemo(function () {
165
174
  return __assign({ List: List, Header: PaddingComponent, Footer: PaddingComponent }, componentsProp);
166
175
  }, [componentsProp, PaddingComponent]);
167
- return (React.createElement(SuggestionListContext.Provider, { value: listRef },
168
- React.createElement(Virtuoso, __assign({ ref: forkVlRef, totalCount: itemCount, data: itemData, className: className, components: components, itemContent: itemContent }, getMenuProps(), combineProps({
169
- scrollerRef: function (scrollElm) {
170
- scrollerRefFn(scrollElm);
171
- modifyVlScrollerStyle(scrollElm, position);
172
- },
173
- itemsRendered: itemsRendered,
174
- totalListHeightChanged: totalListHeightChanged,
175
- style: style,
176
- isScrolling: handleScrolling,
177
- }, rest)))));
176
+ return (React.createElement(SuggestionListContext.Provider, { value: listRef }, virtualize ? (React.createElement(Virtuoso, __assign({ ref: forkVlRef, totalCount: itemCount, data: itemData, className: className, components: components, itemContent: itemContent }, getMenuProps(), combineProps({
177
+ scrollerRef: function (scrollElm) {
178
+ scrollerRefFn(scrollElm);
179
+ modifyVlScrollerStyle(scrollElm, position);
180
+ },
181
+ itemsRendered: itemsRendered,
182
+ totalListHeightChanged: totalListHeightChanged,
183
+ style: style,
184
+ isScrolling: handleScrolling,
185
+ }, rest)))) : (React.createElement(List, { style: { maxHeight: style.height, overflow: 'auto' }, ref: function (scrollElm) {
186
+ scrollerRefFn(scrollElm);
187
+ } },
188
+ React.createElement(PaddingComponent, null),
189
+ options.map(function (x, i) {
190
+ return itemContent(i, x);
191
+ }),
192
+ React.createElement(PaddingComponent, null)))));
178
193
  });
179
194
  export var RcSuggestionList = styled(SuggestionList)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", ";\n"], ["\n ", ";\n"])), SuggestionListStyle);
180
195
  RcSuggestionList.displayName = 'RcSuggestionList';
@@ -4,13 +4,13 @@ import { css, palette2, radius, shadows, styled } from '../../../foundation';
4
4
  import { RcPopper } from '../../Popper';
5
5
  var radiusLg = radius('lg');
6
6
  var _StyledPopper = forwardRef(function (_a, ref) {
7
- var position = _a.position, rest = __rest(_a, ["position"]);
8
- return React.createElement(RcPopper, __assign({ ref: ref }, rest));
7
+ var position = _a.position, _b = _a.component, Component = _b === void 0 ? RcPopper : _b, rest = __rest(_a, ["position", "component"]);
8
+ return React.createElement(Component, __assign({ ref: ref }, rest));
9
9
  });
10
- export var StyledPopper = styled(_StyledPopper)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n box-shadow: ", ";\n background-color: ", ";\n overflow: hidden;\n\n ", "\n"], ["\n box-shadow: ", ";\n background-color: ", ";\n overflow: hidden;\n\n ",
11
- "\n"])), shadows('1'), palette2('neutral', 'elevation'), function (_a) {
10
+ export var StyledPopper = styled(_StyledPopper)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n > div {\n box-shadow: ", ";\n background-color: ", ";\n overflow: hidden;\n\n ", "\n }\n"], ["\n > div {\n box-shadow: ", ";\n background-color: ", ";\n overflow: hidden;\n\n ",
11
+ "\n }\n"])), shadows('1'), palette2('neutral', 'elevation'), function (_a) {
12
12
  var position = _a.position;
13
- return position === 'top'
14
- ? css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-top-right-radius: ", ";\n border-top-left-radius: ", ";\n "], ["\n border-top-right-radius: ", ";\n border-top-left-radius: ", ";\n "])), radiusLg, radiusLg) : css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-bottom-right-radius: ", ";\n border-bottom-left-radius: ", ";\n "], ["\n border-bottom-right-radius: ", ";\n border-bottom-left-radius: ", ";\n "])), radiusLg, radiusLg);
13
+ return position === 'top-start'
14
+ ? css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-top-right-radius: ", ";\n border-top-left-radius: ", ";\n "], ["\n border-top-right-radius: ", ";\n border-top-left-radius: ", ";\n "])), radiusLg, radiusLg) : css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-bottom-right-radius: ", ";\n border-bottom-left-radius: ", ";\n "], ["\n border-bottom-right-radius: ", ";\n border-bottom-left-radius: ", ";\n "])), radiusLg, radiusLg);
15
15
  });
16
16
  var templateObject_1, templateObject_2, templateObject_3;
@@ -9,6 +9,7 @@ var DEFAULT_HIGHLIGHTED_INDEX = -1;
9
9
  export var useDownshift = function (_a) {
10
10
  var multipleProp = _a.multiple, variant = _a.variant, labelProp = _a.label, inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ? DEFAULT_GET_OPTION_LABEL : _b, _c = _a.keyToTags, keyToTags = _c === void 0 ? DEFAULT_KEY_TO_CHIPS : _c, filterOptionsProp = _a.filterOptions, disabledItemsHighlightable = _a.disabledItemsHighlightable, options = _a.options, freeSolo = _a.freeSolo, onInputChangeProp = _a.onInputChange, maxFreeSolo = _a.maxFreeSolo, onMaxFreeSolo = _a.onMaxFreeSolo, openOnFocus = _a.openOnFocus, disableCloseOnSelect = _a.disableCloseOnSelect, initialIsOpen = _a.initialIsOpen, autoSelect = _a.autoSelect, inputContainerRef = _a.inputContainerRef, inputRef = _a.inputRef, wrapperRef = _a.wrapperRef, onKeyDownProp = _a.onKeyDown, onSelectChange = _a.onChange, _d = _a.value, selectedItemsProp = _d === void 0 ? [] : _d, disabled = _a.disabled, renderNoOptions = _a.renderNoOptions, onClear = _a.onClear, autoHighlight = _a.autoHighlight, getOptionDisabled = _a.getOptionDisabled, addNoOptionItem = _a.addNoOptionItem, groupBy = _a.groupBy, onGroupExpanded = _a.onGroupExpanded, groupVariant = _a.groupVariant, groupExpanded = _a.groupExpanded, groupDefaultExpanded = _a.groupDefaultExpanded, getExpandIconProps = _a.getExpandIconProps, required = _a.required, openProp = _a.open, onOpen = _a.onOpen, onClose = _a.onClose, focused = _a.focused;
11
11
  var isAutocomplete = variant === 'autocomplete';
12
+ var autoCompleteSelectedIndexRef = useRef(DEFAULT_HIGHLIGHTED_INDEX);
12
13
  var downshiftId = useId('downshift', true);
13
14
  var _e = __read(useControlled({
14
15
  controlled: focused,
@@ -235,6 +236,7 @@ export var useDownshift = function (_a) {
235
236
  var fIndex = optionItems.findIndex(function (x) { return getOptionLabel(x) === itemText_1; });
236
237
  if (fIndex > -1) {
237
238
  toIndex = fIndex;
239
+ autoCompleteSelectedIndexRef.current = fIndex;
238
240
  }
239
241
  }
240
242
  setHighlightedIndex(toIndex, { reason: 'auto' });
@@ -518,5 +520,6 @@ export var useDownshift = function (_a) {
518
520
  focused: focused !== null && focused !== void 0 ? focused : (tagFocused || inputFocused ? true : undefined),
519
521
  id: downshiftId,
520
522
  inputChanged: isInputValueChangedRef.current,
523
+ autoCompleteSelectedIndex: autoCompleteSelectedIndexRef.current,
521
524
  };
522
525
  };
@@ -14,7 +14,7 @@ var _RcSelect = forwardRef(function (inProps, ref) {
14
14
  var props = useThemeProps({ props: inProps, name: 'RcSelect' });
15
15
  var children = props.children, onChange = props.onChange, defaultValue = props.defaultValue, SelectInputPropsProp = props.SelectInputProps, MenuProps = props.MenuProps, textVariant = props.textVariant, placeholder = props.placeholder, renderValue = props.renderValue, displayEmpty = props.displayEmpty, variant = props.variant, size = props.size, value = props.value, virtualize = props.virtualize,
16
16
  // * below is should pick into TextField props
17
- focused = props.focused, gutterBottom = props.gutterBottom, helperText = props.helperText, color = props.color, label = props.label, id = props.id, className = props.className, validate = props.validate, InputProps = props.InputProps, required = props.required, fullWidth = props.fullWidth, disabled = props.disabled, error = props.error, rest = __rest(props, ["children", "onChange", "defaultValue", "SelectInputProps", "MenuProps", "textVariant", "placeholder", "renderValue", "displayEmpty", "variant", "size", "value", "virtualize", "focused", "gutterBottom", "helperText", "color", "label", "id", "className", "validate", "InputProps", "required", "fullWidth", "disabled", "error"]);
17
+ focused = props.focused, gutterBottom = props.gutterBottom, helperText = props.helperText, color = props.color, label = props.label, id = props.id, className = props.className, title = props.title, validate = props.validate, InputProps = props.InputProps, required = props.required, fullWidth = props.fullWidth, disabled = props.disabled, error = props.error, rest = __rest(props, ["children", "onChange", "defaultValue", "SelectInputProps", "MenuProps", "textVariant", "placeholder", "renderValue", "displayEmpty", "variant", "size", "value", "virtualize", "focused", "gutterBottom", "helperText", "color", "label", "id", "className", "title", "validate", "InputProps", "required", "fullWidth", "disabled", "error"]);
18
18
  var hasDefaultValue = hasValue(defaultValue);
19
19
  var nonValue = (!hasValue(value) && !hasDefaultValue) ||
20
20
  // * if that can't displayEmpty, and that value === '', same as no value
@@ -68,7 +68,7 @@ var _RcSelect = forwardRef(function (inProps, ref) {
68
68
  }, [InputProps, placeholder, nonValue, applyClasses, variant]);
69
69
  var valueIsNumber = typeof value === 'number';
70
70
  var currValue = valueIsNumber ? value : value || '';
71
- return (React.createElement(RcSelectTextField, { ref: ref, id: id, className: className,
71
+ return (React.createElement(RcSelectTextField, { ref: ref, id: id, className: className, title: title,
72
72
  // for when that is select type that type will be select onChange, just any for ignore that
73
73
  onChange: onChange, color: color, select: true, focused: focused, gutterBottom: gutterBottom, helperText: helperText, label: label,
74
74
  // when that has defaultValue, and that value always to be undefined
@@ -23,14 +23,15 @@ var _RcListItem = forwardRef(function (inProps, ref) {
23
23
  },
24
24
  ]);
25
25
  }
26
- var classesProp = props.classes, color = props.color, TouchRipplePropsProp = props.TouchRippleProps, children = props.children, className = props.className, singleLine = props.singleLine, button = props.button, size = props.size, canHover = props.canHover, isInline = props.isInline, baseColor = props.baseColor, title = props.title, highlighted = props.highlighted, maxWidth = props.maxWidth, rest = __rest(props, ["classes", "color", "TouchRippleProps", "children", "className", "singleLine", "button", "size", "canHover", "isInline", "baseColor", "title", "highlighted", "maxWidth"]);
26
+ var classesProp = props.classes, color = props.color, TouchRipplePropsProp = props.TouchRippleProps, children = props.children, className = props.className, singleLine = props.singleLine, button = props.button, size = props.size, canHover = props.canHover, isInline = props.isInline, baseColor = props.baseColor, title = props.title, highlighted = props.highlighted, maxWidth = props.maxWidth, focused = props.focused, rest = __rest(props, ["classes", "color", "TouchRippleProps", "children", "className", "singleLine", "button", "size", "canHover", "isInline", "baseColor", "title", "highlighted", "maxWidth", "focused"]);
27
27
  var classes = useMemo(function () { return combineClasses(RcListItemClasses, classesProp); }, [classesProp]);
28
28
  var ListItemClassName = useMemo(function () {
29
29
  var _a;
30
30
  return clsx(className, (_a = {},
31
31
  _a[RcListItemMultilineClassName] = !singleLine,
32
+ _a[classes.focusVisible] = focused,
32
33
  _a));
33
- }, [className, singleLine]);
34
+ }, [className, singleLine, classes, focused]);
34
35
  // * when not button can't have TouchRippleProps
35
36
  var additionProps = useMemo(function () {
36
37
  return button
@@ -1,14 +1,26 @@
1
- import { __makeTemplateObject } from "tslib";
2
- import { css, getParsePaletteColor, nonTouchHoverMedia, palette2, px, setAlpha, setOpacity, spacing, typography, } from '../../../../foundation';
1
+ import { __assign, __makeTemplateObject } from "tslib";
2
+ import { css, focusVisible, getParsePaletteColor, nonTouchHoverMedia, palette2, px, setAlpha, setOpacity, spacing, typography, } from '../../../../foundation';
3
3
  import { RcFormControlLabel } from '../../../Forms/FormControlLabel';
4
4
  import { RcSwitch } from '../../../Forms/Switch';
5
5
  import { colorMap, RcListItemClasses, RcListItemRippleClasses, RcListItemTopAndBottomPaddings, } from '../utils';
6
6
  export var ListItemFormControlStyle = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", " {\n margin-right: 0;\n\n > ", " {\n /** The DOM structure of Switch is special,\n should remove this after fix Switch as common control */\n margin-left: ", ";\n margin-right: ", ";\n }\n }\n"], ["\n ", " {\n margin-right: 0;\n\n > ", " {\n /** The DOM structure of Switch is special,\n should remove this after fix Switch as common control */\n margin-left: ", ";\n margin-right: ", ";\n }\n }\n"])), RcFormControlLabel, RcSwitch, spacing(1), spacing(1));
7
- export var ListItemStyle = function (_a) {
8
- var maxWidth = _a.maxWidth, isInline = _a.isInline, size = _a.size, onClick = _a.onClick, color = _a.color, canHover = _a.canHover, _b = _a.baseColor, baseColorProp = _b === void 0 ? 'black' : _b, highlighted = _a.highlighted;
7
+ export var sharedListItemStyle = function (_a) {
8
+ var highlighted = _a.highlighted, color = _a.color, canHover = _a.canHover, _b = _a.baseColor, baseColorProp = _b === void 0 ? 'black' : _b, mainClasses = _a.mainClasses, rippleClasses = _a.rippleClasses;
9
9
  var baseColor = getParsePaletteColor(color !== null && color !== void 0 ? color : colorMap[baseColorProp]);
10
+ return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", ";\n color: ", ";\n\n ", ";\n\n ", ",\n &.", " {\n background-color: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n .", " {\n color: ", ";\n }\n\n ", ";\n "], ["\n ", ";\n color: ", ";\n\n ",
11
+ ";\n\n "
12
+ // that for menuItem, because in current version of menuItem that not support focused classes
13
+ // TODO: that can be remove after upgrade to V5
14
+ ,
15
+ ",\n &.", " {\n background-color: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n .", " {\n color: ", ";\n }\n\n ", ";\n "])), typography('body1'), palette2('neutral', 'f06'), highlighted && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: ", ";\n "], ["\n background-color: ", ";\n "])), setAlpha(baseColor, 0.05)),
16
+ // that for menuItem, because in current version of menuItem that not support focused classes
17
+ // TODO: that can be remove after upgrade to V5
18
+ focusVisible, mainClasses.focusVisible, setOpacity(baseColor, '16'), nonTouchHoverMedia, canHover ? setOpacity(baseColor, '08') : 'unset', mainClasses.selected, setOpacity(baseColor, '12'), rippleClasses.rippleVisible, baseColor, ListItemFormControlStyle);
19
+ };
20
+ export var ListItemStyle = function (props) {
21
+ var maxWidth = props.maxWidth, isInline = props.isInline, size = props.size, onClick = props.onClick;
10
22
  var defaultPadding = RcListItemTopAndBottomPaddings[size];
11
- return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", ";\n width: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n display: ", ";\n color: ", ";\n cursor: ", ";\n\n ", ";\n\n &.", " {\n background-color: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n .", " {\n color: ", ";\n }\n\n &.", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n }\n\n ", ";\n "], ["\n ", ";\n width: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n display: ", ";\n color: ", ";\n cursor: ", ";\n\n ",
12
- ";\n\n &.", " {\n background-color: ", ";\n }\n\n ", " {\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n .", " {\n color: ", ";\n }\n\n &.", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n }\n\n ", ";\n "])), typography('body1'), maxWidth ? px(maxWidth) : '100%', defaultPadding, defaultPadding, isInline ? 'inline-flex' : 'flex', palette2('neutral', 'f06'), onClick ? 'pointer' : 'default', highlighted && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: ", ";\n "], ["\n background-color: ", ";\n "])), setAlpha(baseColor, 0.05)), RcListItemClasses.focusVisible, setOpacity(baseColor, '16'), nonTouchHoverMedia, canHover ? setOpacity(baseColor, '08') : 'unset', RcListItemClasses.selected, setOpacity(baseColor, '12'), RcListItemRippleClasses.rippleVisible, baseColor, RcListItemClasses.gutters, spacing(4), spacing(4), RcListItemClasses.dense, spacing(1), spacing(1), ListItemFormControlStyle);
23
+ return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n display: ", ";\n cursor: ", ";\n\n ", ";\n\n &.", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n }\n "], ["\n width: ", ";\n padding-top: ", ";\n padding-bottom: ", ";\n display: ", ";\n cursor: ", ";\n\n ",
24
+ ";\n\n &.", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n }\n "])), maxWidth ? px(maxWidth) : '100%', defaultPadding, defaultPadding, isInline ? 'inline-flex' : 'flex', onClick ? 'pointer' : 'default', sharedListItemStyle(__assign(__assign({}, props), { mainClasses: RcListItemClasses, rippleClasses: RcListItemRippleClasses })), RcListItemClasses.gutters, spacing(4), spacing(4), RcListItemClasses.dense, spacing(1), spacing(1));
13
25
  };
14
- var templateObject_1, templateObject_2, templateObject_3;
26
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
@@ -1,7 +1,8 @@
1
1
  import { RcClasses, spacing, } from '../../../../foundation';
2
- var RcListItemPrefix = 'RcListItem';
2
+ export var RcListItemPrefix = 'RcListItem';
3
+ export var RcListItemRipplePrefix = RcListItemPrefix + "TouchRipple";
3
4
  export var RcListItemMultilineClassName = RcListItemPrefix + "-multiline";
4
- export var RcListItemClasses = RcClasses(['focusVisible', 'gutters', 'dense', 'selected'], RcListItemPrefix);
5
+ export var RcListItemClasses = RcClasses(['gutters', 'dense', 'selected', 'focusVisible'], RcListItemPrefix);
5
6
  export var RcListItemTopAndBottomPaddings = {
6
7
  small: spacing(1),
7
8
  medium: spacing(1.25),
@@ -11,4 +12,4 @@ export var colorMap = {
11
12
  secondary: 'highlight.f02',
12
13
  black: 'action.grayLight',
13
14
  };
14
- export var RcListItemRippleClasses = RcClasses(['rippleVisible'], 'RcListItemTouchRipple');
15
+ export var RcListItemRippleClasses = RcClasses(['rippleVisible'], RcListItemRipplePrefix);
@@ -3,7 +3,7 @@ import React, { forwardRef, useContext, useImperativeHandle, useMemo, } from 're
3
3
  import clsx from 'clsx';
4
4
  import MuiMenuItem from '@material-ui/core/MenuItem';
5
5
  import { Check as checkSvg } from '@ringcentral/juno-icon';
6
- import { combineClasses, isRcElement, logInDev, omit, styled, useEventCallback, useId, useThemeProps, } from '../../../foundation';
6
+ import { combineClasses, isRcElement, logInDev, omit, styled, useEventCallback, useId, useThemeProps, combineProps, } from '../../../foundation';
7
7
  import { RcIcon } from '../../Icon';
8
8
  import { RcListItemSecondaryAction } from '../../List';
9
9
  import { RcListItemAvatar } from '../../List/ListItemAvatar';
@@ -13,11 +13,11 @@ import { RcMenuContext } from '../Menu/MenuContext';
13
13
  import { RcMenuListContext } from '../MenuList/MenuListContext';
14
14
  import { RcSubMenuContext } from '../SubMenu/SubMenuContext';
15
15
  import { MenuItemStyle, StyledCheckIcon } from './styles';
16
- import { RcMenuItemClasses } from './utils';
16
+ import { RcMenuItemClasses, RcMenuItemRippleClasses } from './utils';
17
17
  var _RcMenuItem = forwardRef(function (inProps, ref) {
18
18
  var _a;
19
19
  var props = useThemeProps({ props: inProps, name: 'RcMenuItem' });
20
- var classesProp = props.classes, children = props.children, className = props.className, onMouseEnter = props.onMouseEnter, onClick = props.onClick, onFocus = props.onFocus, size = props.size, type = props.type, checked = props.checked, icon = props.icon, symbol = props.symbol, avatar = props.avatar, secondaryAction = props.secondaryAction, idRef = props.idRef, isSubMenuItem = props.isSubMenuItem, title = props.title, rest = __rest(props, ["classes", "children", "className", "onMouseEnter", "onClick", "onFocus", "size", "type", "checked", "icon", "symbol", "avatar", "secondaryAction", "idRef", "isSubMenuItem", "title"]);
20
+ var classesProp = props.classes, children = props.children, color = props.color, button = props.button, className = props.className, onMouseEnter = props.onMouseEnter, onClick = props.onClick, onFocus = props.onFocus, highlighted = props.highlighted, size = props.size, type = props.type, checked = props.checked, icon = props.icon, symbol = props.symbol, avatar = props.avatar, secondaryAction = props.secondaryAction, idRef = props.idRef, isSubMenuItem = props.isSubMenuItem, TouchRipplePropsProp = props.TouchRippleProps, title = props.title, focused = props.focused, rest = __rest(props, ["classes", "children", "color", "button", "className", "onMouseEnter", "onClick", "onFocus", "highlighted", "size", "type", "checked", "icon", "symbol", "avatar", "secondaryAction", "idRef", "isSubMenuItem", "TouchRippleProps", "title", "focused"]);
21
21
  var isCheckedType = type === 'checked';
22
22
  var menuItemId = useId('menu-item', true);
23
23
  var menuContext = useContext(RcMenuContext);
@@ -34,7 +34,7 @@ var _RcMenuItem = forwardRef(function (inProps, ref) {
34
34
  }
35
35
  });
36
36
  var classes = useMemo(function () { return combineClasses(RcMenuItemClasses, classesProp); }, [classesProp]);
37
- var toClasses = useMemo(function () { return omit(classes, ['checked', 'unchecked']); }, [classes]);
37
+ var toClasses = useMemo(function () { return omit(classes, ['checked', 'unchecked', 'focusVisible']); }, [classes]);
38
38
  var itemAvatar = useMemo(function () {
39
39
  if (React.isValidElement(avatar)) {
40
40
  return isRcElement(avatar, ['RcListItemAvatar']) ? (avatar) : (React.createElement(RcListItemAvatar, null, avatar));
@@ -68,6 +68,14 @@ var _RcMenuItem = forwardRef(function (inProps, ref) {
68
68
  }
69
69
  return secondaryAction ? (isRcElement(secondaryAction, ['RcListItemSecondaryAction']) ? (secondaryAction) : (React.createElement(RcListItemSecondaryAction, null, secondaryAction))) : null;
70
70
  }, [checked, isCheckedType, secondaryAction]);
71
+ // * when not button can't have TouchRippleProps
72
+ var additionProps = useMemo(function () {
73
+ return button
74
+ ? {
75
+ TouchRippleProps: combineProps({ classes: RcMenuItemRippleClasses }, TouchRipplePropsProp),
76
+ }
77
+ : {};
78
+ }, [TouchRipplePropsProp, button]);
71
79
  var handleMouseEnter = useEventCallback(function (e) {
72
80
  onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(e);
73
81
  setFocusedMenuItemId();
@@ -87,10 +95,11 @@ var _RcMenuItem = forwardRef(function (inProps, ref) {
87
95
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
88
96
  });
89
97
  useImperativeHandle(idRef, function () { return menuItemId; }, [menuItemId]);
90
- return (React.createElement(MuiMenuItem, __assign({ "aria-checked": isCheckedType && checked ? true : undefined }, rest, { ref: ref, title: typeof title === 'string' ? title : undefined, classes: toClasses, className: clsx(className, (_a = {},
98
+ return (React.createElement(MuiMenuItem, __assign({ "aria-checked": isCheckedType && checked ? true : undefined }, additionProps, rest, { ref: ref, title: typeof title === 'string' ? title : undefined, classes: toClasses, className: clsx(className, (_a = {},
91
99
  _a[classes.checked] = isCheckedType && checked,
92
100
  _a[classes.unchecked] = isCheckedType && !checked,
93
- _a)), onMouseEnter: handleMouseEnter, onClick: handleClick, onFocus: handleFocus, "data-menuitem-id": menuItemId }),
101
+ _a[classes.focusVisible] = focused,
102
+ _a)), onMouseEnter: handleMouseEnter, onClick: handleClick, onFocus: handleFocus, "data-menuitem-id": menuItemId, button: button }),
94
103
  itemAvatar,
95
104
  itemIcon,
96
105
  children,
@@ -99,6 +108,7 @@ var _RcMenuItem = forwardRef(function (inProps, ref) {
99
108
  var RcMenuItem = styled(withTooltip(_RcMenuItem))(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", ";\n"], ["\n ", ";\n"])), MenuItemStyle);
100
109
  RcMenuItem.defaultProps = {
101
110
  size: 'medium',
111
+ button: true,
102
112
  };
103
113
  RcMenuItem.displayName = 'RcMenuItem';
104
114
  export { RcMenuItem };
@@ -1,13 +1,16 @@
1
- import { __makeTemplateObject } from "tslib";
2
- import { css, palette2, spacing, styled, typography, } from '../../../../foundation';
1
+ import { __assign, __makeTemplateObject } from "tslib";
2
+ import { css, spacing, styled } from '../../../../foundation';
3
3
  import { RcIcon } from '../../../Icon';
4
- import { ListItemFormControlStyle } from '../../../List/ListItem/styles';
5
- import { RcMenuItemClasses, RcMenuItemLeftAndRightPaddings, RcMenuItemTopAndBottomPaddings, } from '../utils';
4
+ import { sharedListItemStyle } from '../../../List/ListItem/styles';
5
+ import { RcMenuItemClasses, RcMenuItemLeftAndRightPaddings, RcMenuItemRippleClasses, RcMenuItemTopAndBottomPaddings, } from '../utils';
6
6
  export var StyledCheckIcon = styled(RcIcon)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 22px;\n"], ["\n height: 22px;\n"])));
7
- export var MenuItemStyle = function (_a) {
8
- var size = _a.size;
7
+ export var MenuItemStyle = function (props) {
8
+ var size = props.size, _a = props.color, color = _a === void 0 ? 'action.grayLight' : _a;
9
9
  var topAndBottomPadding = RcMenuItemTopAndBottomPaddings[size];
10
10
  var leftAndRightPadding = RcMenuItemLeftAndRightPaddings[size];
11
- return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n outline: none;\n box-sizing: border-box;\n ", ";\n color: ", ";\n height: auto;\n min-height: 32px;\n min-width: 112px;\n padding-top: ", ";\n padding-bottom: ", ";\n\n .", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n min-height: auto;\n line-height: 22px;\n font-weight: 700;\n }\n\n ", ";\n "], ["\n outline: none;\n box-sizing: border-box;\n ", ";\n color: ", ";\n height: auto;\n min-height: 32px;\n min-width: 112px;\n padding-top: ", ";\n padding-bottom: ", ";\n\n .", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n min-height: auto;\n line-height: 22px;\n font-weight: 700;\n }\n\n ", ";\n "])), typography('body1'), palette2('neutral', 'f06'), topAndBottomPadding, topAndBottomPadding, RcMenuItemClasses.gutters, leftAndRightPadding, leftAndRightPadding, RcMenuItemClasses.dense, spacing(1), spacing(1), ListItemFormControlStyle);
11
+ return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n outline: none;\n box-sizing: border-box;\n height: auto;\n min-height: 32px;\n min-width: 112px;\n padding-top: ", ";\n padding-bottom: ", ";\n\n ", ";\n\n .", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n min-height: auto;\n line-height: 22px;\n font-weight: 700;\n }\n "], ["\n outline: none;\n box-sizing: border-box;\n height: auto;\n min-height: 32px;\n min-width: 112px;\n padding-top: ", ";\n padding-bottom: ", ";\n\n ",
12
+ ";\n\n .", " {\n padding-left: ", ";\n padding-right: ", ";\n }\n\n &.", " {\n padding-top: ", ";\n padding-bottom: ", ";\n min-height: auto;\n line-height: 22px;\n font-weight: 700;\n }\n "])), topAndBottomPadding, topAndBottomPadding, sharedListItemStyle(__assign(__assign({}, props), { color: color,
13
+ // in menuItem always be can hover
14
+ canHover: true, mainClasses: RcMenuItemClasses, rippleClasses: RcMenuItemRippleClasses })), RcMenuItemClasses.gutters, leftAndRightPadding, leftAndRightPadding, RcMenuItemClasses.dense, spacing(1), spacing(1));
12
15
  };
13
16
  var templateObject_1, templateObject_2;
@@ -1,5 +1,7 @@
1
1
  import { RcClasses, spacing } from '../../../../foundation';
2
- export var RcMenuItemClasses = RcClasses(['checked', 'unchecked', 'gutters', 'dense'], 'RcMenuItem');
2
+ export var RcMenuItemPrefix = 'RcMenuItem';
3
+ export var RcMenuItemRipplePrefix = RcMenuItemPrefix + "TouchRipple";
4
+ export var RcMenuItemClasses = RcClasses(['checked', 'unchecked', 'gutters', 'dense', 'selected', 'focusVisible'], RcMenuItemPrefix);
3
5
  export var RcMenuItemTopAndBottomPaddings = {
4
6
  medium: spacing(1),
5
7
  large: spacing(2),
@@ -8,3 +10,4 @@ export var RcMenuItemLeftAndRightPaddings = {
8
10
  medium: spacing(4),
9
11
  large: spacing(5),
10
12
  };
13
+ export var RcMenuItemRippleClasses = RcClasses(['rippleVisible'], RcMenuItemRipplePrefix);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ringcentral/juno",
3
- "version": "2.13.1",
3
+ "version": "2.16.0",
4
4
  "author": "RingCentral",
5
5
  "license": "MIT",
6
6
  "main": "./index.js",