assui 2.0.76 → 2.0.80

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.
@@ -60,6 +60,7 @@ import Badge from 'antd/es/badge';
60
60
  import Tabs from 'antd/es/tabs';
61
61
  import { useParams } from 'react-router-dom';
62
62
  import useUrlState from '@ahooksjs/use-url-state';
63
+ import useControllableValue from 'ahooks/es/useControllableValue';
63
64
  import toArray from 'rc-util/lib/Children/toArray';
64
65
  var TabPane = Tabs.TabPane;
65
66
  var defaultBadgeProps = {};
@@ -70,11 +71,10 @@ var KeepTab = function KeepTab(props) {
70
71
  var children = props.children,
71
72
  defaultActiveKey = props.defaultActiveKey,
72
73
  saveActiveKeyName = props.saveActiveKeyName,
73
- tabActiveKey = props.activeKey,
74
74
  onChange = props.onChange,
75
75
  _b = props.badgeProps,
76
76
  badgeProps = _b === void 0 ? defaultBadgeProps : _b,
77
- restProps = __rest(props, ["children", "defaultActiveKey", "saveActiveKeyName", "activeKey", "onChange", "badgeProps"]);
77
+ restProps = __rest(props, ["children", "defaultActiveKey", "saveActiveKeyName", "onChange", "badgeProps"]);
78
78
 
79
79
  var defaultUrlParams = useParams();
80
80
 
@@ -82,21 +82,32 @@ var KeepTab = function KeepTab(props) {
82
82
  urlParams = _c[0],
83
83
  setUrlParams = _c[1];
84
84
 
85
+ var _d = __read(useControllableValue(props, {
86
+ valuePropName: 'activeKey',
87
+ defaultValue: defaultUrlParams[saveActiveKeyName] || defaultActiveKey
88
+ }), 2),
89
+ tabActiveKey = _d[0],
90
+ setTabActiveKey = _d[1];
91
+
85
92
  var arrayChildren = toArray(children);
86
93
  React.useEffect(function () {
87
- var _a, _b;
94
+ var _a;
88
95
 
89
- if (tabActiveKey) {
96
+ if (!('activeKey' in props)) {
90
97
  var resultActiveTab = find(arrayChildren, {
91
- key: tabActiveKey
98
+ key: urlParams[saveActiveKeyName]
92
99
  });
93
100
 
94
101
  if (!resultActiveTab || resultActiveTab.props.disabled) {
95
102
  setUrlParams((_a = {}, _a[saveActiveKeyName] = arrayChildren[0].key, _a));
96
- onChange === null || onChange === void 0 ? void 0 : onChange(arrayChildren[0].key);
97
- } else {
98
- setUrlParams((_b = {}, _b[saveActiveKeyName] = tabActiveKey, _b));
103
+ setTabActiveKey(arrayChildren[0].key);
99
104
  }
105
+ } else {
106
+ setTimeout(function () {
107
+ var _a;
108
+
109
+ setUrlParams((_a = {}, _a[saveActiveKeyName] = tabActiveKey, _a));
110
+ }, 50);
100
111
  }
101
112
  }, [tabActiveKey]);
102
113
 
@@ -104,10 +115,7 @@ var KeepTab = function KeepTab(props) {
104
115
  var _a;
105
116
 
106
117
  setUrlParams((_a = {}, _a[saveActiveKeyName] = nextActiveKey, _a));
107
-
108
- if (onChange) {
109
- onChange(nextActiveKey);
110
- }
118
+ setTabActiveKey(nextActiveKey);
111
119
  };
112
120
 
113
121
  var resultChildren = arrayChildren.map(function (childItem) {
@@ -127,20 +135,12 @@ var KeepTab = function KeepTab(props) {
127
135
 
128
136
  return childItem;
129
137
  });
130
- var resultTabActiveKey = {};
131
-
132
- if (tabActiveKey) {
133
- resultTabActiveKey = {
134
- activeKey: tabActiveKey
135
- };
136
- }
137
-
138
138
  return /*#__PURE__*/React.createElement(Tabs, __assign({
139
139
  animated: false,
140
140
  onChange: handleTabChange,
141
141
  destroyInactiveTabPane: true,
142
- defaultActiveKey: urlParams[saveActiveKeyName]
143
- }, resultTabActiveKey, restProps), resultChildren);
142
+ activeKey: tabActiveKey
143
+ }, restProps), resultChildren);
144
144
  };
145
145
 
146
146
  KeepTab.defaultProps = {
@@ -112,6 +112,8 @@ var react_router_dom_1 = require("react-router-dom");
112
112
 
113
113
  var use_url_state_1 = __importDefault(require("@ahooksjs/use-url-state"));
114
114
 
115
+ var useControllableValue_1 = __importDefault(require("ahooks/es/useControllableValue"));
116
+
115
117
  var toArray_1 = __importDefault(require("rc-util/lib/Children/toArray"));
116
118
 
117
119
  var TabPane = tabs_1["default"].TabPane;
@@ -123,11 +125,10 @@ var KeepTab = function KeepTab(props) {
123
125
  var children = props.children,
124
126
  defaultActiveKey = props.defaultActiveKey,
125
127
  saveActiveKeyName = props.saveActiveKeyName,
126
- tabActiveKey = props.activeKey,
127
128
  onChange = props.onChange,
128
129
  _b = props.badgeProps,
129
130
  badgeProps = _b === void 0 ? defaultBadgeProps : _b,
130
- restProps = __rest(props, ["children", "defaultActiveKey", "saveActiveKeyName", "activeKey", "onChange", "badgeProps"]);
131
+ restProps = __rest(props, ["children", "defaultActiveKey", "saveActiveKeyName", "onChange", "badgeProps"]);
131
132
 
132
133
  var defaultUrlParams = react_router_dom_1.useParams();
133
134
 
@@ -135,21 +136,32 @@ var KeepTab = function KeepTab(props) {
135
136
  urlParams = _c[0],
136
137
  setUrlParams = _c[1];
137
138
 
139
+ var _d = __read(useControllableValue_1["default"](props, {
140
+ valuePropName: 'activeKey',
141
+ defaultValue: defaultUrlParams[saveActiveKeyName] || defaultActiveKey
142
+ }), 2),
143
+ tabActiveKey = _d[0],
144
+ setTabActiveKey = _d[1];
145
+
138
146
  var arrayChildren = toArray_1["default"](children);
139
147
  React.useEffect(function () {
140
- var _a, _b;
148
+ var _a;
141
149
 
142
- if (tabActiveKey) {
150
+ if (!('activeKey' in props)) {
143
151
  var resultActiveTab = lodash_1.find(arrayChildren, {
144
- key: tabActiveKey
152
+ key: urlParams[saveActiveKeyName]
145
153
  });
146
154
 
147
155
  if (!resultActiveTab || resultActiveTab.props.disabled) {
148
156
  setUrlParams((_a = {}, _a[saveActiveKeyName] = arrayChildren[0].key, _a));
149
- onChange === null || onChange === void 0 ? void 0 : onChange(arrayChildren[0].key);
150
- } else {
151
- setUrlParams((_b = {}, _b[saveActiveKeyName] = tabActiveKey, _b));
157
+ setTabActiveKey(arrayChildren[0].key);
152
158
  }
159
+ } else {
160
+ setTimeout(function () {
161
+ var _a;
162
+
163
+ setUrlParams((_a = {}, _a[saveActiveKeyName] = tabActiveKey, _a));
164
+ }, 50);
153
165
  }
154
166
  }, [tabActiveKey]);
155
167
 
@@ -157,10 +169,7 @@ var KeepTab = function KeepTab(props) {
157
169
  var _a;
158
170
 
159
171
  setUrlParams((_a = {}, _a[saveActiveKeyName] = nextActiveKey, _a));
160
-
161
- if (onChange) {
162
- onChange(nextActiveKey);
163
- }
172
+ setTabActiveKey(nextActiveKey);
164
173
  };
165
174
 
166
175
  var resultChildren = arrayChildren.map(function (childItem) {
@@ -180,20 +189,12 @@ var KeepTab = function KeepTab(props) {
180
189
 
181
190
  return childItem;
182
191
  });
183
- var resultTabActiveKey = {};
184
-
185
- if (tabActiveKey) {
186
- resultTabActiveKey = {
187
- activeKey: tabActiveKey
188
- };
189
- }
190
-
191
192
  return React.createElement(tabs_1["default"], __assign({
192
193
  animated: false,
193
194
  onChange: handleTabChange,
194
195
  destroyInactiveTabPane: true,
195
- defaultActiveKey: urlParams[saveActiveKeyName]
196
- }, resultTabActiveKey, restProps), resultChildren);
196
+ activeKey: tabActiveKey
197
+ }, restProps), resultChildren);
197
198
  };
198
199
 
199
200
  KeepTab.defaultProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assui",
3
- "version": "2.0.76",
3
+ "version": "2.0.80",
4
4
  "description": "react ui library",
5
5
  "author": "jason <usochen@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -69,5 +69,5 @@
69
69
  "node": ">=10.0.0"
70
70
  },
71
71
  "license": "MIT",
72
- "gitHead": "6e4862aa641f382f96afc1d00af96c68d23f424d"
72
+ "gitHead": "05f837927f2f7f2f045757c1da82ff1e2b9e4956"
73
73
  }