assui 2.0.77 → 2.0.78

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,6 +82,13 @@ 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
94
  var _a, _b;
@@ -93,7 +100,7 @@ var KeepTab = function KeepTab(props) {
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);
103
+ setTabActiveKey(arrayChildren[0].key);
97
104
  }
98
105
  } else {
99
106
  setUrlParams((_b = {}, _b[saveActiveKeyName] = tabActiveKey, _b));
@@ -104,10 +111,7 @@ var KeepTab = function KeepTab(props) {
104
111
  var _a;
105
112
 
106
113
  setUrlParams((_a = {}, _a[saveActiveKeyName] = nextActiveKey, _a));
107
-
108
- if (onChange) {
109
- onChange(nextActiveKey);
110
- }
114
+ setTabActiveKey(nextActiveKey);
111
115
  };
112
116
 
113
117
  var resultChildren = arrayChildren.map(function (childItem) {
@@ -127,20 +131,12 @@ var KeepTab = function KeepTab(props) {
127
131
 
128
132
  return childItem;
129
133
  });
130
- var resultTabActiveKey = {};
131
-
132
- if (tabActiveKey) {
133
- resultTabActiveKey = {
134
- activeKey: tabActiveKey
135
- };
136
- }
137
-
138
134
  return /*#__PURE__*/React.createElement(Tabs, __assign({
139
135
  animated: false,
140
136
  onChange: handleTabChange,
141
137
  destroyInactiveTabPane: true,
142
- defaultActiveKey: urlParams[saveActiveKeyName]
143
- }, resultTabActiveKey, restProps), resultChildren);
138
+ activeKey: tabActiveKey
139
+ }, restProps), resultChildren);
144
140
  };
145
141
 
146
142
  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,6 +136,13 @@ 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
148
  var _a, _b;
@@ -146,7 +154,7 @@ var KeepTab = function KeepTab(props) {
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);
157
+ setTabActiveKey(arrayChildren[0].key);
150
158
  }
151
159
  } else {
152
160
  setUrlParams((_b = {}, _b[saveActiveKeyName] = tabActiveKey, _b));
@@ -157,10 +165,7 @@ var KeepTab = function KeepTab(props) {
157
165
  var _a;
158
166
 
159
167
  setUrlParams((_a = {}, _a[saveActiveKeyName] = nextActiveKey, _a));
160
-
161
- if (onChange) {
162
- onChange(nextActiveKey);
163
- }
168
+ setTabActiveKey(nextActiveKey);
164
169
  };
165
170
 
166
171
  var resultChildren = arrayChildren.map(function (childItem) {
@@ -180,20 +185,12 @@ var KeepTab = function KeepTab(props) {
180
185
 
181
186
  return childItem;
182
187
  });
183
- var resultTabActiveKey = {};
184
-
185
- if (tabActiveKey) {
186
- resultTabActiveKey = {
187
- activeKey: tabActiveKey
188
- };
189
- }
190
-
191
188
  return React.createElement(tabs_1["default"], __assign({
192
189
  animated: false,
193
190
  onChange: handleTabChange,
194
191
  destroyInactiveTabPane: true,
195
- defaultActiveKey: urlParams[saveActiveKeyName]
196
- }, resultTabActiveKey, restProps), resultChildren);
192
+ activeKey: tabActiveKey
193
+ }, restProps), resultChildren);
197
194
  };
198
195
 
199
196
  KeepTab.defaultProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assui",
3
- "version": "2.0.77",
3
+ "version": "2.0.78",
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": "9636a87471d75ecd5b903061c2ce5022d684833f"
72
+ "gitHead": "b2c664a6401c4e18e4d5ce6ddf01f565f8e85777"
73
73
  }