@ringcentral/juno 2.1.0 → 2.1.1

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.
@@ -22,7 +22,7 @@ exports.findChildrenByKey = function (childrenProp, key) {
22
22
  var _MoreMenuTabs = react_1.forwardRef(function (props, ref) {
23
23
  var orientation = props.orientation, childrenProp = props.children, valueProp = props.value, onChange = props.onChange, _a = props.MoreButtonProps, MoreButtonProps = _a === void 0 ? {} : _a, rest = tslib_1.__rest(props, ["orientation", "children", "value", "onChange", "MoreButtonProps"]);
24
24
  var onGroupInfoChange = MoreButtonProps.onGroupInfoChange, MoreButtonPropsRest = tslib_1.__rest(MoreButtonProps, ["onGroupInfoChange"]);
25
- var prevChildren = foundation_1.usePrevious(function () { return childrenProp; });
25
+ var prevChildrenProp = foundation_1.usePrevious(function () { return childrenProp; });
26
26
  var isVertical = orientation === 'vertical';
27
27
  var oriStr = isVertical ? 'height' : 'width';
28
28
  var innerRef = react_1.useRef(null);
@@ -54,42 +54,39 @@ var _MoreMenuTabs = react_1.forwardRef(function (props, ref) {
54
54
  throttleTabsSizeChange(obj);
55
55
  }, { mode: 'none' });
56
56
  var tabsSize = tabsSizeRef.current;
57
- // init all children elm
58
- if (tabRefsMapRef.current === undefined) {
59
- var getRefsMapAndSetDefaultTabChildren = function () {
60
- var tabRefs = new Map();
61
- var tabsTabDefaultChild = [];
62
- react_1.default.Children.forEach(childrenProp, function (child, index) {
63
- var _a = child.props, ref = _a.ref, value = _a.value;
64
- var innerRef = react_1.createRef();
65
- var tabRef = ref ? foundation_1.useForkRef(innerRef, ref) : innerRef;
66
- var childrenValue = value || index;
67
- var children = react_1.default.cloneElement(child, {
68
- ref: tabRef,
69
- value: childrenValue,
70
- });
71
- var keyString = typeof child.key === 'string' ? child.key : '';
72
- tabRefs.set(utils_1.getKey(keyString, index), {
73
- ref: tabRef,
74
- size: null,
75
- index: index,
76
- value: childrenValue,
77
- });
78
- tabsTabDefaultChild.push(children);
57
+ // initial tabRefsMapRef and tabsTabChildRef
58
+ if (tabRefsMapRef.current === undefined ||
59
+ prevChildrenProp !== childrenProp) {
60
+ var tabRefs_1 = new Map();
61
+ var tabsTabDefaultChild_1 = [];
62
+ react_1.default.Children.forEach(childrenProp, function (child, index) {
63
+ var _a = child.props, ref = _a.ref, value = _a.value;
64
+ var innerRef = react_1.createRef();
65
+ var tabRef = ref ? foundation_1.useForkRef(innerRef, ref) : innerRef;
66
+ var childrenValue = value || index;
67
+ var children = react_1.default.cloneElement(child, {
68
+ ref: tabRef,
69
+ value: childrenValue,
79
70
  });
80
- return {
81
- tabRefs: tabRefs,
82
- tabsTabDefaultChild: tabsTabDefaultChild,
83
- };
84
- };
85
- var _d = getRefsMapAndSetDefaultTabChildren(), tabRefs = _d.tabRefs, tabsTabDefaultChild = _d.tabsTabDefaultChild;
86
- tabRefsMapRef.current = tabRefs;
87
- tabsTabChildRef.current = tabsTabDefaultChild;
71
+ var keyString = typeof child.key === 'string' ? child.key : '';
72
+ tabRefs_1.set(utils_1.getKey(keyString, index), {
73
+ ref: tabRef,
74
+ size: null,
75
+ index: index,
76
+ value: childrenValue,
77
+ });
78
+ tabsTabDefaultChild_1.push(children);
79
+ });
80
+ tabRefsMapRef.current = tabRefs_1;
81
+ tabsTabChildRef.current = tabsTabDefaultChild_1;
88
82
  }
89
- // get all size when first render
83
+ // get real render size when render
90
84
  react_1.useEffect(function () {
85
+ if (childrenProp === prevChildrenProp) {
86
+ return;
87
+ }
91
88
  var tabRefsMap = tabRefsMapRef.current;
92
- if ((tabRefsMap === null || tabRefsMap === void 0 ? void 0 : tabRefsMap.size) !== undefined) {
89
+ if (tabRefsMap && tabRefsMap.size !== 0) {
93
90
  var allTabsSize_1 = tslib_1.__assign({}, utils_1.DEFAULT_SIZE);
94
91
  tabRefsMap.forEach(function (value, key) {
95
92
  var _a = utils_1.getDomBoundingClientSize(value.ref.current), width = _a.width, height = _a.height;
@@ -110,8 +107,7 @@ var _MoreMenuTabs = react_1.forwardRef(function (props, ref) {
110
107
  var size = utils_1.getDomBoundingClientSize(moreElm);
111
108
  moreTabSizeRef.current = size;
112
109
  }
113
- // eslint-disable-next-line react-hooks/exhaustive-deps
114
- }, []);
110
+ }, [childrenProp, prevChildrenProp]);
115
111
  react_1.useEffect(function () {
116
112
  var _a;
117
113
  var currSelectTabItem;
@@ -190,11 +186,11 @@ var _MoreMenuTabs = react_1.forwardRef(function (props, ref) {
190
186
  }
191
187
  };
192
188
  if (tabsSize.width !== 0 && tabsSize.height !== 0) {
193
- // computed: 1.resize 2. valueProp 3.moreMenuClick
189
+ // computed: 1.resize 2. valueProp 3.moreMenuClick 4.children change
194
190
  // not computed: visible tab change
195
191
  if (((_a = groupingRef.current) === null || _a === void 0 ? void 0 : _a.tabs.includes((currSelectTabItem === null || currSelectTabItem === void 0 ? void 0 : currSelectTabItem[0]) || '')) &&
196
192
  !hasResizeRef.current &&
197
- prevChildren === childrenProp) {
193
+ prevChildrenProp === childrenProp) {
198
194
  return;
199
195
  }
200
196
  computeTabChild(tabsSize);
@@ -202,10 +198,10 @@ var _MoreMenuTabs = react_1.forwardRef(function (props, ref) {
202
198
  }
203
199
  }, [
204
200
  childrenProp,
201
+ prevChildrenProp,
205
202
  isVertical,
206
203
  onGroupInfoChange,
207
204
  oriStr,
208
- prevChildren,
209
205
  tabsSize,
210
206
  valueProp,
211
207
  ]);
@@ -12,9 +12,11 @@ var _RcTabs = react_1.forwardRef(function (inProps, ref) {
12
12
  var classesProp = props.classes, childrenProp = props.children, variantProp = props.variant, size = props.size, MoreButtonProps = props.MoreButtonProps, rest = tslib_1.__rest(props, ["classes", "children", "variant", "size", "MoreButtonProps"]);
13
13
  var isMore = variantProp === 'moreMenu';
14
14
  var classes = react_1.useMemo(function () { return foundation_1.combineProps(utils_1.RcTabsClasses, classesProp); }, [classesProp]);
15
- var children = react_1.default.Children.map(childrenProp, function (child) {
16
- return react_1.default.cloneElement(child, { size: size });
17
- });
15
+ var children = react_1.useMemo(function () {
16
+ return react_1.default.Children.map(childrenProp, function (child) {
17
+ return react_1.default.cloneElement(child, { size: size });
18
+ });
19
+ }, [childrenProp, size]);
18
20
  if (isMore) {
19
21
  return (react_1.default.createElement(MoreMenuTabs_1.MoreMenuTabs, tslib_1.__assign({}, rest, { ref: ref, classes: classes, size: size, MoreButtonProps: MoreButtonProps }), children));
20
22
  }
@@ -20,7 +20,7 @@ export var findChildrenByKey = function (childrenProp, key) {
20
20
  var _MoreMenuTabs = forwardRef(function (props, ref) {
21
21
  var orientation = props.orientation, childrenProp = props.children, valueProp = props.value, onChange = props.onChange, _a = props.MoreButtonProps, MoreButtonProps = _a === void 0 ? {} : _a, rest = __rest(props, ["orientation", "children", "value", "onChange", "MoreButtonProps"]);
22
22
  var onGroupInfoChange = MoreButtonProps.onGroupInfoChange, MoreButtonPropsRest = __rest(MoreButtonProps, ["onGroupInfoChange"]);
23
- var prevChildren = usePrevious(function () { return childrenProp; });
23
+ var prevChildrenProp = usePrevious(function () { return childrenProp; });
24
24
  var isVertical = orientation === 'vertical';
25
25
  var oriStr = isVertical ? 'height' : 'width';
26
26
  var innerRef = useRef(null);
@@ -52,42 +52,39 @@ var _MoreMenuTabs = forwardRef(function (props, ref) {
52
52
  throttleTabsSizeChange(obj);
53
53
  }, { mode: 'none' });
54
54
  var tabsSize = tabsSizeRef.current;
55
- // init all children elm
56
- if (tabRefsMapRef.current === undefined) {
57
- var getRefsMapAndSetDefaultTabChildren = function () {
58
- var tabRefs = new Map();
59
- var tabsTabDefaultChild = [];
60
- React.Children.forEach(childrenProp, function (child, index) {
61
- var _a = child.props, ref = _a.ref, value = _a.value;
62
- var innerRef = createRef();
63
- var tabRef = ref ? useForkRef(innerRef, ref) : innerRef;
64
- var childrenValue = value || index;
65
- var children = React.cloneElement(child, {
66
- ref: tabRef,
67
- value: childrenValue,
68
- });
69
- var keyString = typeof child.key === 'string' ? child.key : '';
70
- tabRefs.set(getKey(keyString, index), {
71
- ref: tabRef,
72
- size: null,
73
- index: index,
74
- value: childrenValue,
75
- });
76
- tabsTabDefaultChild.push(children);
55
+ // initial tabRefsMapRef and tabsTabChildRef
56
+ if (tabRefsMapRef.current === undefined ||
57
+ prevChildrenProp !== childrenProp) {
58
+ var tabRefs_1 = new Map();
59
+ var tabsTabDefaultChild_1 = [];
60
+ React.Children.forEach(childrenProp, function (child, index) {
61
+ var _a = child.props, ref = _a.ref, value = _a.value;
62
+ var innerRef = createRef();
63
+ var tabRef = ref ? useForkRef(innerRef, ref) : innerRef;
64
+ var childrenValue = value || index;
65
+ var children = React.cloneElement(child, {
66
+ ref: tabRef,
67
+ value: childrenValue,
77
68
  });
78
- return {
79
- tabRefs: tabRefs,
80
- tabsTabDefaultChild: tabsTabDefaultChild,
81
- };
82
- };
83
- var _d = getRefsMapAndSetDefaultTabChildren(), tabRefs = _d.tabRefs, tabsTabDefaultChild = _d.tabsTabDefaultChild;
84
- tabRefsMapRef.current = tabRefs;
85
- tabsTabChildRef.current = tabsTabDefaultChild;
69
+ var keyString = typeof child.key === 'string' ? child.key : '';
70
+ tabRefs_1.set(getKey(keyString, index), {
71
+ ref: tabRef,
72
+ size: null,
73
+ index: index,
74
+ value: childrenValue,
75
+ });
76
+ tabsTabDefaultChild_1.push(children);
77
+ });
78
+ tabRefsMapRef.current = tabRefs_1;
79
+ tabsTabChildRef.current = tabsTabDefaultChild_1;
86
80
  }
87
- // get all size when first render
81
+ // get real render size when render
88
82
  useEffect(function () {
83
+ if (childrenProp === prevChildrenProp) {
84
+ return;
85
+ }
89
86
  var tabRefsMap = tabRefsMapRef.current;
90
- if ((tabRefsMap === null || tabRefsMap === void 0 ? void 0 : tabRefsMap.size) !== undefined) {
87
+ if (tabRefsMap && tabRefsMap.size !== 0) {
91
88
  var allTabsSize_1 = __assign({}, DEFAULT_SIZE);
92
89
  tabRefsMap.forEach(function (value, key) {
93
90
  var _a = getDomBoundingClientSize(value.ref.current), width = _a.width, height = _a.height;
@@ -108,8 +105,7 @@ var _MoreMenuTabs = forwardRef(function (props, ref) {
108
105
  var size = getDomBoundingClientSize(moreElm);
109
106
  moreTabSizeRef.current = size;
110
107
  }
111
- // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, []);
108
+ }, [childrenProp, prevChildrenProp]);
113
109
  useEffect(function () {
114
110
  var _a;
115
111
  var currSelectTabItem;
@@ -188,11 +184,11 @@ var _MoreMenuTabs = forwardRef(function (props, ref) {
188
184
  }
189
185
  };
190
186
  if (tabsSize.width !== 0 && tabsSize.height !== 0) {
191
- // computed: 1.resize 2. valueProp 3.moreMenuClick
187
+ // computed: 1.resize 2. valueProp 3.moreMenuClick 4.children change
192
188
  // not computed: visible tab change
193
189
  if (((_a = groupingRef.current) === null || _a === void 0 ? void 0 : _a.tabs.includes((currSelectTabItem === null || currSelectTabItem === void 0 ? void 0 : currSelectTabItem[0]) || '')) &&
194
190
  !hasResizeRef.current &&
195
- prevChildren === childrenProp) {
191
+ prevChildrenProp === childrenProp) {
196
192
  return;
197
193
  }
198
194
  computeTabChild(tabsSize);
@@ -200,10 +196,10 @@ var _MoreMenuTabs = forwardRef(function (props, ref) {
200
196
  }
201
197
  }, [
202
198
  childrenProp,
199
+ prevChildrenProp,
203
200
  isVertical,
204
201
  onGroupInfoChange,
205
202
  oriStr,
206
- prevChildren,
207
203
  tabsSize,
208
204
  valueProp,
209
205
  ]);
@@ -10,9 +10,11 @@ var _RcTabs = forwardRef(function (inProps, ref) {
10
10
  var classesProp = props.classes, childrenProp = props.children, variantProp = props.variant, size = props.size, MoreButtonProps = props.MoreButtonProps, rest = __rest(props, ["classes", "children", "variant", "size", "MoreButtonProps"]);
11
11
  var isMore = variantProp === 'moreMenu';
12
12
  var classes = useMemo(function () { return combineProps(RcTabsClasses, classesProp); }, [classesProp]);
13
- var children = React.Children.map(childrenProp, function (child) {
14
- return React.cloneElement(child, { size: size });
15
- });
13
+ var children = useMemo(function () {
14
+ return React.Children.map(childrenProp, function (child) {
15
+ return React.cloneElement(child, { size: size });
16
+ });
17
+ }, [childrenProp, size]);
16
18
  if (isMore) {
17
19
  return (React.createElement(MoreMenuTabs, __assign({}, rest, { ref: ref, classes: classes, size: size, MoreButtonProps: MoreButtonProps }), children));
18
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ringcentral/juno",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "author": "RingCentral",
5
5
  "license": "MIT",
6
6
  "bugs": {