@nutui/nutui-react 2.0.0-alpha.2 → 2.0.0-alpha.3
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/CHANGELOG.md +12 -0
- package/dist/esm/CalendarItem.js +2 -12
- package/dist/esm/Cascader.js +4 -2
- package/dist/esm/Dialog.js +162 -171
- package/dist/esm/Popup.js +2 -4
- package/dist/esm/Switch.js +16 -30
- package/dist/esm/TabPane.js +0 -2
- package/dist/esm/Tabs.js +2 -2
- package/dist/esm/nutui-react.es.js +170 -170
- package/dist/esm/overlay2.js +12 -14
- package/dist/esm/raf.js +16 -0
- package/dist/esm/tabpane2.js +7 -9
- package/dist/esm/tabs2.js +101 -93
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.mjs +18533 -19122
- package/dist/nutui.react.umd.js +18531 -19120
- package/dist/packages/dialog/dialog.scss +36 -65
- package/dist/packages/overlay/overlay.scss +11 -4
- package/dist/packages/switch/switch.scss +13 -31
- package/dist/packages/tabs/tabs.scss +196 -225
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/styles/themes/default.scss +17 -17
- package/dist/styles/variables-jmapp.scss +12 -11
- package/dist/styles/variables.scss +22 -14
- package/dist/types/index.d.ts +337 -360
- package/package.json +2 -2
package/dist/esm/tabs2.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
|
-
var _excluded = ["
|
|
4
|
+
var _excluded = ["activeColor", "tabStyle", "direction", "activeType", "duration", "align", "title", "children", "onClick", "onChange", "className", "autoHeight"];
|
|
7
5
|
function ownKeys(object, enumerableOnly) {
|
|
8
6
|
var keys = Object.keys(object);
|
|
9
7
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -28,138 +26,148 @@ function _objectSpread(target) {
|
|
|
28
26
|
import React__default, { useState, useRef, useEffect } from "react";
|
|
29
27
|
import classNames from "classnames";
|
|
30
28
|
import { JoySmile } from "@nutui/icons-react";
|
|
31
|
-
import { c as cn } from "./bem.js";
|
|
32
29
|
import { C as ComponentDefaults } from "./typings.js";
|
|
33
30
|
import TabPane from "./TabPane.js";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function Title2() {
|
|
37
|
-
_classCallCheck(this, Title2);
|
|
38
|
-
_defineProperty(this, "title", "");
|
|
39
|
-
_defineProperty(this, "paneKey", "");
|
|
40
|
-
_defineProperty(this, "disabled", false);
|
|
41
|
-
_defineProperty(this, "index", 0);
|
|
42
|
-
}
|
|
43
|
-
);
|
|
31
|
+
import { r as requestAniFrame } from "./raf.js";
|
|
32
|
+
import { u as usePropsValue } from "./use-props-value.js";
|
|
44
33
|
var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
|
|
45
34
|
tabStyle: {},
|
|
46
|
-
|
|
47
|
-
color: "",
|
|
48
|
-
background: "",
|
|
35
|
+
activeColor: "",
|
|
49
36
|
direction: "horizontal",
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
ellipsis: true,
|
|
53
|
-
animatedTime: 300,
|
|
54
|
-
titleGutter: 0,
|
|
55
|
-
size: "normal",
|
|
56
|
-
leftAlign: false,
|
|
37
|
+
activeType: "line",
|
|
38
|
+
duration: 300,
|
|
57
39
|
autoHeight: false
|
|
58
40
|
});
|
|
59
|
-
var
|
|
60
|
-
return Number.isNaN(Number(value)) ? String(value) : "".concat(value, "px");
|
|
61
|
-
};
|
|
41
|
+
var classPrefix = "nut-tabs";
|
|
62
42
|
var Tabs = function Tabs2(props) {
|
|
63
43
|
var _classNames;
|
|
64
|
-
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), activeColor = _defaultProps$props.activeColor, tabStyle = _defaultProps$props.tabStyle, direction = _defaultProps$props.direction, activeType = _defaultProps$props.activeType, duration = _defaultProps$props.duration, align = _defaultProps$props.align, title = _defaultProps$props.title, children = _defaultProps$props.children, onClick = _defaultProps$props.onClick, onChange = _defaultProps$props.onChange, className = _defaultProps$props.className, autoHeight = _defaultProps$props.autoHeight, rest = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
45
|
+
var _usePropsValue = usePropsValue({
|
|
46
|
+
value: props.value,
|
|
47
|
+
defaultValue: props.defaultValue,
|
|
48
|
+
finalValue: 0,
|
|
49
|
+
onChange
|
|
50
|
+
}), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), value = _usePropsValue2[0], setValue = _usePropsValue2[1];
|
|
51
|
+
var _useState = useState({}), _useState2 = _slicedToArray(_useState, 2), contentStyle = _useState2[0], setContentStyle = _useState2[1];
|
|
52
|
+
var titleItemsRef = useRef([]);
|
|
53
|
+
var navRef = useRef(null);
|
|
54
|
+
var scrollDirection = function scrollDirection2(nav, to, duration2, direction2) {
|
|
55
|
+
var count = 0;
|
|
56
|
+
var from = direction2 === "horizontal" ? nav.scrollLeft : nav.scrollTop;
|
|
57
|
+
var frames = duration2 === 0 ? 1 : Math.round(duration2 * 1e3 / 16);
|
|
58
|
+
function animate() {
|
|
59
|
+
if (direction2 === "horizontal") {
|
|
60
|
+
nav.scrollLeft += (to - from) / frames;
|
|
61
|
+
} else {
|
|
62
|
+
nav.scrollTop += (to - from) / frames;
|
|
63
|
+
}
|
|
64
|
+
if (++count < frames) {
|
|
65
|
+
requestAniFrame(animate);
|
|
75
66
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
}
|
|
68
|
+
animate();
|
|
69
|
+
};
|
|
70
|
+
var scrollIntoView = function scrollIntoView2(index, immediate) {
|
|
71
|
+
var nav = navRef.current;
|
|
72
|
+
var titleItem = titleItemsRef.current;
|
|
73
|
+
if (!nav || !titleItem || !titleItem[index]) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
var title2 = titleItem[index];
|
|
77
|
+
var to = 0;
|
|
78
|
+
if (props.direction === "vertical") {
|
|
79
|
+
var runTop = title2.offsetTop - nav.offsetTop + 10;
|
|
80
|
+
to = runTop - (nav.offsetHeight - title2.offsetHeight) / 2;
|
|
81
|
+
} else {
|
|
82
|
+
to = title2.offsetLeft - (nav.offsetWidth - title2.offsetWidth) / 2;
|
|
83
|
+
}
|
|
84
|
+
scrollDirection(nav, to, immediate ? 0 : 0.3, props.direction);
|
|
85
|
+
};
|
|
86
|
+
var getTitles = function getTitles2() {
|
|
87
|
+
var titles2 = [];
|
|
88
|
+
React__default.Children.forEach(children, function(child, idx) {
|
|
89
|
+
if (React__default.isValidElement(child)) {
|
|
90
|
+
var props2 = child === null || child === void 0 ? void 0 : child.props;
|
|
91
|
+
if (props2 !== null && props2 !== void 0 && props2.title || props2 !== null && props2 !== void 0 && props2.value) {
|
|
92
|
+
titles2.push({
|
|
93
|
+
title: props2.title,
|
|
94
|
+
value: props2.value || idx,
|
|
95
|
+
disabled: props2.disabled
|
|
96
|
+
});
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
|
-
titles.current.push(title);
|
|
88
99
|
});
|
|
89
|
-
|
|
90
|
-
}, [children]);
|
|
91
|
-
var b = cn("tabs");
|
|
92
|
-
var classes = classNames(direction, b(""), className);
|
|
93
|
-
var classesTitle = classNames((_classNames = {}, _defineProperty(_classNames, type, type), _defineProperty(_classNames, "scrollable", titleScroll), _defineProperty(_classNames, size, size), _classNames), "".concat(b(""), "__titles"));
|
|
94
|
-
var titleStyle = {
|
|
95
|
-
marginLeft: pxCheck(titleGutter),
|
|
96
|
-
marginRight: pxCheck(titleGutter)
|
|
100
|
+
return titles2;
|
|
97
101
|
};
|
|
102
|
+
var titles = useRef(getTitles());
|
|
103
|
+
var classes = classNames(classPrefix, "".concat(classPrefix, "--").concat(direction), className);
|
|
104
|
+
var classesTitle = classNames("".concat(classPrefix, "__titles"), (_classNames = {}, _defineProperty(_classNames, "".concat(classPrefix, "__titles--").concat(activeType), activeType), _defineProperty(_classNames, "".concat(classPrefix, "__titles--scrollable"), true), _defineProperty(_classNames, "".concat(classPrefix, "__titles--").concat(align), align), _classNames));
|
|
98
105
|
var tabsActiveStyle = {
|
|
99
|
-
color:
|
|
100
|
-
background:
|
|
106
|
+
color: activeType === "smile" ? activeColor : "",
|
|
107
|
+
background: activeType === "line" ? activeColor : ""
|
|
101
108
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
useEffect(function() {
|
|
110
|
+
var index = titles.current.findIndex(function(t) {
|
|
111
|
+
return t.value === value;
|
|
112
|
+
});
|
|
113
|
+
setContentStyle({
|
|
114
|
+
transform: direction === "horizontal" ? "translate3d(-".concat(index * 100, "%, 0, 0)") : "translate3d( 0,-".concat(index * 100, "%, 0)"),
|
|
115
|
+
transitionDuration: "".concat(duration, "ms")
|
|
116
|
+
});
|
|
117
|
+
scrollIntoView(index);
|
|
118
|
+
}, [value]);
|
|
119
|
+
var tabChange = function tabChange2(item, index) {
|
|
120
|
+
onClick && onClick(item.value);
|
|
111
121
|
if (item.disabled) {
|
|
112
122
|
return;
|
|
113
123
|
}
|
|
114
|
-
|
|
115
|
-
onChange && onChange(item);
|
|
124
|
+
setValue(item.value);
|
|
116
125
|
};
|
|
117
126
|
return React__default.createElement("div", _objectSpread({
|
|
118
127
|
className: classes
|
|
119
128
|
}, rest), React__default.createElement("div", {
|
|
120
129
|
className: classesTitle,
|
|
121
|
-
style: _objectSpread(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
style: _objectSpread({}, tabStyle),
|
|
131
|
+
ref: navRef
|
|
132
|
+
}, !!title && typeof title === "function" ? title() : titles.current.map(function(item, index) {
|
|
133
|
+
var _classNames2;
|
|
125
134
|
return React__default.createElement("div", {
|
|
126
|
-
style: titleStyle,
|
|
127
135
|
onClick: function onClick2(e) {
|
|
128
|
-
|
|
136
|
+
tabChange(item);
|
|
129
137
|
},
|
|
130
|
-
className: classNames({
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
className: "".concat(b(""), "__titles-item__line"),
|
|
138
|
+
className: classNames("".concat(classPrefix, "__titles-item"), (_classNames2 = {}, _defineProperty(_classNames2, "nut-tabs__titles-item--active", !item.disabled && String(item.value) === String(value)), _defineProperty(_classNames2, "nut-tabs__titles-item--disabled", item.disabled), _defineProperty(_classNames2, "nut-tabs__titles-item--".concat(align), align), _classNames2)),
|
|
139
|
+
ref: function ref(_ref) {
|
|
140
|
+
return titleItemsRef.current.push(_ref);
|
|
141
|
+
},
|
|
142
|
+
key: item.value
|
|
143
|
+
}, activeType === "line" && React__default.createElement("div", {
|
|
144
|
+
className: "".concat(classPrefix, "__titles-item__line"),
|
|
138
145
|
style: tabsActiveStyle
|
|
139
|
-
}),
|
|
140
|
-
className: "".concat(
|
|
146
|
+
}), activeType === "smile" && React__default.createElement("div", {
|
|
147
|
+
className: "".concat(classPrefix, "__titles-item__smile"),
|
|
141
148
|
style: tabsActiveStyle
|
|
142
149
|
}, React__default.createElement(JoySmile, {
|
|
143
|
-
color
|
|
150
|
+
color: activeColor,
|
|
151
|
+
width: 40,
|
|
152
|
+
height: 20
|
|
144
153
|
})), React__default.createElement("div", {
|
|
145
154
|
className: classNames({
|
|
146
|
-
ellipsis:
|
|
147
|
-
}, "".concat(
|
|
155
|
+
ellipsis: true
|
|
156
|
+
}, "".concat(classPrefix, "__titles-item__text"))
|
|
148
157
|
}, item.title));
|
|
149
158
|
})), React__default.createElement("div", {
|
|
150
|
-
className: "".concat(
|
|
159
|
+
className: "".concat(classPrefix, "__content__wrap")
|
|
151
160
|
}, React__default.createElement("div", {
|
|
152
|
-
className: "".concat(
|
|
161
|
+
className: "".concat(classPrefix, "__content"),
|
|
153
162
|
style: contentStyle
|
|
154
163
|
}, React__default.Children.map(children, function(child, idx) {
|
|
155
|
-
var _child$props;
|
|
156
164
|
if (!React__default.isValidElement(child)) {
|
|
157
165
|
return null;
|
|
158
166
|
}
|
|
159
167
|
var childProps = _objectSpread(_objectSpread({}, child.props), {}, {
|
|
160
|
-
|
|
168
|
+
active: value === child.props.value
|
|
161
169
|
});
|
|
162
|
-
if (String(value) !== String(
|
|
170
|
+
if (String(value) !== String(child.props.value || idx) && autoHeight) {
|
|
163
171
|
childProps = _objectSpread(_objectSpread({}, childProps), {}, {
|
|
164
172
|
autoHeightClassName: "inactive"
|
|
165
173
|
});
|
package/dist/locales/base.js
CHANGED
package/dist/locales/en-US.js
CHANGED
package/dist/locales/id-ID.js
CHANGED
package/dist/locales/zh-CN.js
CHANGED
package/dist/locales/zh-TW.js
CHANGED
package/dist/locales/zh-UG.js
CHANGED