yootd 0.2.22 → 0.2.23
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/dist/tabs/index.js +43 -27
- package/package.json +1 -1
package/dist/tabs/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4
|
-
var _excluded = ["size", "capsule", "className", "items", "onChange", "activeKey", "destroyInactiveTabPane", "isTabMargin"];
|
4
|
+
var _excluded = ["size", "capsule", "className", "items", "onChange", "activeKey", "defaultActiveKey", "destroyInactiveTabPane", "isTabMargin"];
|
5
5
|
import { Tabs as AntTabs, Radio } from 'antd';
|
6
6
|
import React, { useEffect, useState } from 'react';
|
7
7
|
import { useBem } from "../hooks/useBem";
|
@@ -14,16 +14,18 @@ export var TabsComponent = function TabsComponent(_ref) {
|
|
14
14
|
items = _ref.items,
|
15
15
|
_onChange = _ref.onChange,
|
16
16
|
activeKey = _ref.activeKey,
|
17
|
+
defaultActiveKey = _ref.defaultActiveKey,
|
17
18
|
_ref$destroyInactiveT = _ref.destroyInactiveTabPane,
|
18
19
|
destroyInactiveTabPane = _ref$destroyInactiveT === void 0 ? false : _ref$destroyInactiveT,
|
19
20
|
_ref$isTabMargin = _ref.isTabMargin,
|
20
21
|
isTabMargin = _ref$isTabMargin === void 0 ? true : _ref$isTabMargin,
|
21
22
|
rest = _objectWithoutProperties(_ref, _excluded);
|
22
23
|
var mb = useBem('tabs');
|
23
|
-
|
24
|
+
// const [key, setKey] = useState<string>();
|
25
|
+
var _useState = useState(activeKey !== null && activeKey !== void 0 ? activeKey : defaultActiveKey),
|
24
26
|
_useState2 = _slicedToArray(_useState, 2),
|
25
|
-
|
26
|
-
|
27
|
+
capsuleKey = _useState2[0],
|
28
|
+
setCapsuleKey = _useState2[1];
|
27
29
|
var _useState3 = useState(new Set()),
|
28
30
|
_useState4 = _slicedToArray(_useState3, 2),
|
29
31
|
renderKey = _useState4[0],
|
@@ -40,22 +42,28 @@ export var TabsComponent = function TabsComponent(_ref) {
|
|
40
42
|
// 默认为小尺寸
|
41
43
|
_className = "".concat(mb.b('large'));
|
42
44
|
}
|
45
|
+
console.log("capsuleKey", capsuleKey);
|
46
|
+
|
43
47
|
// 给key设置默认值
|
44
48
|
useEffect(function () {
|
45
|
-
if (
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
if (capsuleKey != null) {
|
50
|
+
setRenderKey(function (prev) {
|
51
|
+
var newSet = new Set(prev);
|
52
|
+
newSet.add(capsuleKey);
|
53
|
+
return newSet;
|
49
54
|
});
|
50
55
|
} else {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
var _items$0$
|
55
|
-
|
56
|
+
setRenderKey(function (prev) {
|
57
|
+
var _items$;
|
58
|
+
var newSet = new Set(prev);
|
59
|
+
var firstKey = items === null || items === void 0 || (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.key;
|
60
|
+
if (firstKey != null) {
|
61
|
+
newSet.add(firstKey);
|
62
|
+
}
|
63
|
+
return newSet;
|
56
64
|
});
|
57
65
|
}
|
58
|
-
}, [
|
66
|
+
}, [capsuleKey, items]);
|
59
67
|
return /*#__PURE__*/React.createElement("div", {
|
60
68
|
className: "".concat(mb)
|
61
69
|
}, capsule ? /*#__PURE__*/React.createElement("div", {
|
@@ -65,22 +73,30 @@ export var TabsComponent = function TabsComponent(_ref) {
|
|
65
73
|
style: {
|
66
74
|
paddingBottom: isTabMargin ? 16 : 0
|
67
75
|
}
|
68
|
-
}, /*#__PURE__*/React.createElement(Radio.Group, {
|
69
|
-
value:
|
76
|
+
}, /*#__PURE__*/React.createElement(Radio.Group, _extends({}, activeKey != null ? {
|
77
|
+
value: activeKey
|
78
|
+
} : {}, defaultActiveKey != null ? {
|
79
|
+
defaultValue: defaultActiveKey
|
80
|
+
} : {}, {
|
70
81
|
onChange: function onChange(e) {
|
71
|
-
setKey(e.target.value);
|
72
82
|
setRenderKey(function (pre) {
|
73
83
|
return pre.add(e.target.value);
|
74
84
|
});
|
85
|
+
if (activeKey == null) {
|
86
|
+
setCapsuleKey(e.target.value);
|
87
|
+
}
|
75
88
|
_onChange === null || _onChange === void 0 || _onChange(e.target.value);
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
89
|
+
},
|
90
|
+
block: true,
|
91
|
+
optionType: "button",
|
92
|
+
options: items === null || items === void 0 ? void 0 : items.map(function (item) {
|
93
|
+
return {
|
94
|
+
value: item.key,
|
95
|
+
label: item.label
|
96
|
+
};
|
97
|
+
})
|
82
98
|
}))), destroyInactiveTabPane ? /*#__PURE__*/React.createElement("div", null, items === null || items === void 0 || (_items$find = items.find(function (item) {
|
83
|
-
return item.key ===
|
99
|
+
return item.key === capsuleKey;
|
84
100
|
})) === null || _items$find === void 0 ? void 0 : _items$find.children) : /*#__PURE__*/React.createElement("div", {
|
85
101
|
className: "".concat(mb.b('capsule').e('value'))
|
86
102
|
}, items === null || items === void 0 || (_items$filter = items.filter(function (item) {
|
@@ -89,17 +105,17 @@ export var TabsComponent = function TabsComponent(_ref) {
|
|
89
105
|
return /*#__PURE__*/React.createElement("div", {
|
90
106
|
key: item.key,
|
91
107
|
style: {
|
92
|
-
display:
|
108
|
+
display: capsuleKey === item.key ? 'block' : 'none'
|
93
109
|
}
|
94
110
|
}, item.children);
|
95
111
|
}))) : /*#__PURE__*/React.createElement(AntTabs, _extends({
|
96
|
-
activeKey:
|
112
|
+
activeKey: activeKey,
|
113
|
+
defaultActiveKey: defaultActiveKey,
|
97
114
|
size: size,
|
98
115
|
items: items,
|
99
116
|
className: "".concat(className !== null && className !== void 0 ? className : '', " ").concat(_className, " ").concat(isTabMargin ? '' : mb.b('istabmargin'), " "),
|
100
117
|
destroyInactiveTabPane: destroyInactiveTabPane,
|
101
118
|
onChange: function onChange(e) {
|
102
|
-
setKey(e);
|
103
119
|
_onChange === null || _onChange === void 0 || _onChange(e);
|
104
120
|
}
|
105
121
|
}, rest)));
|