@nutui/nutui-react 2.0.0-alpha.2 → 2.0.0-alpha.4

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/esm/Badge.js +4 -66
  3. package/dist/esm/CalendarItem.js +2 -12
  4. package/dist/esm/Cascader.js +4 -2
  5. package/dist/esm/CircleProgress.js +20 -25
  6. package/dist/esm/Dialog.js +162 -171
  7. package/dist/esm/Input.js +87 -193
  8. package/dist/esm/Popup.js +2 -4
  9. package/dist/esm/Switch.js +16 -30
  10. package/dist/esm/TabPane.js +0 -2
  11. package/dist/esm/Tabbar.js +29 -33
  12. package/dist/esm/TabbarItem.js +5 -75
  13. package/dist/esm/Tabs.js +2 -2
  14. package/dist/esm/badge2.js +69 -0
  15. package/dist/esm/nutui-react.es.js +170 -170
  16. package/dist/esm/overlay2.js +12 -14
  17. package/dist/esm/raf.js +16 -0
  18. package/dist/esm/tabbaritem2.js +61 -0
  19. package/dist/esm/tabpane2.js +7 -9
  20. package/dist/esm/tabs2.js +101 -93
  21. package/dist/locales/base.js +1 -1
  22. package/dist/locales/en-US.js +1 -1
  23. package/dist/locales/id-ID.js +1 -1
  24. package/dist/locales/zh-CN.js +1 -1
  25. package/dist/locales/zh-TW.js +1 -1
  26. package/dist/locales/zh-UG.js +1 -1
  27. package/dist/nutui.react.mjs +18569 -19365
  28. package/dist/nutui.react.umd.js +18567 -19363
  29. package/dist/packages/badge/badge.scss +0 -1
  30. package/dist/packages/circleprogress/circleprogress.scss +0 -9
  31. package/dist/packages/dialog/dialog.scss +36 -65
  32. package/dist/packages/input/input.scss +13 -180
  33. package/dist/packages/overlay/overlay.scss +11 -4
  34. package/dist/packages/switch/switch.scss +13 -31
  35. package/dist/packages/tabbar/tabbar.scss +16 -23
  36. package/dist/packages/tabbaritem/tabbaritem.scss +9 -70
  37. package/dist/packages/tabs/tabs.scss +196 -225
  38. package/dist/style.css +1 -1
  39. package/dist/style.mjs +1 -1
  40. package/dist/styles/themes/default.scss +17 -17
  41. package/dist/styles/variables-jmapp.scss +24 -27
  42. package/dist/styles/variables.scss +34 -30
  43. package/dist/types/index.d.ts +366 -423
  44. 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 = ["value", "color", "tabStyle", "background", "direction", "type", "titleScroll", "ellipsis", "animatedTime", "titleGutter", "size", "leftAlign", "titleNode", "children", "onClick", "onChange", "className", "autoHeight"];
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
- var Title = /* @__PURE__ */ _createClass(
35
- // eslint-disable-next-line no-useless-constructor
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
- value: 0,
47
- color: "",
48
- background: "",
35
+ activeColor: "",
49
36
  direction: "horizontal",
50
- type: "line",
51
- titleScroll: false,
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 pxCheck = function pxCheck2(value) {
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), value = _defaultProps$props.value, color = _defaultProps$props.color, tabStyle = _defaultProps$props.tabStyle, background = _defaultProps$props.background, direction = _defaultProps$props.direction, type = _defaultProps$props.type, titleScroll = _defaultProps$props.titleScroll, ellipsis = _defaultProps$props.ellipsis, animatedTime = _defaultProps$props.animatedTime, titleGutter = _defaultProps$props.titleGutter, size = _defaultProps$props.size, leftAlign = _defaultProps$props.leftAlign, titleNode = _defaultProps$props.titleNode, 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);
65
- var _useState = useState({
66
- index: 0
67
- }), _useState2 = _slicedToArray(_useState, 2), currentItem = _useState2[0], setCurrentItem = _useState2[1];
68
- var titles = useRef([]);
69
- useEffect(function() {
70
- var currentIndex = 0;
71
- titles.current = [];
72
- React__default.Children.forEach(children, function(child, idx) {
73
- if (!React__default.isValidElement(child)) {
74
- return null;
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
- var title = new Title();
77
- var childProps = child === null || child === void 0 ? void 0 : child.props;
78
- if (childProps !== null && childProps !== void 0 && childProps.title || childProps !== null && childProps !== void 0 && childProps.paneKey) {
79
- title.title = childProps === null || childProps === void 0 ? void 0 : childProps.title;
80
- title.paneKey = (childProps === null || childProps === void 0 ? void 0 : childProps.paneKey) || idx;
81
- title.disabled = childProps === null || childProps === void 0 ? void 0 : childProps.disabled;
82
- title.index = idx;
83
- if (title.paneKey === value) {
84
- currentIndex = idx;
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
- setCurrentItem(titles.current[currentIndex]);
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: type === "smile" ? color : "",
100
- background: type === "line" ? color : ""
106
+ color: activeType === "smile" ? activeColor : "",
107
+ background: activeType === "line" ? activeColor : ""
101
108
  };
102
- var index = titles.current.findIndex(function(t) {
103
- return t.paneKey === value;
104
- });
105
- var contentStyle = {
106
- transform: direction === "horizontal" ? "translate3d(-".concat(index * 100, "%, 0, 0)") : "translate3d( 0,-".concat(index * 100, "%, 0)"),
107
- transitionDuration: "".concat(animatedTime, "ms")
108
- };
109
- var tabChange = function tabChange2(item, index2) {
110
- onClick && onClick(item);
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
- setCurrentItem(item);
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(_objectSpread({}, tabStyle), {}, {
122
- background
123
- })
124
- }, !!titleNode && typeof titleNode === "function" ? titleNode() : titles.current.map(function(item, index2) {
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
- return tabChange(item);
136
+ tabChange(item);
129
137
  },
130
- className: classNames({
131
- active: !item.disabled && String(item.paneKey) === String(value),
132
- disabled: item.disabled,
133
- "nut-tabs__titles-item-left-align": leftAlign
134
- }, "".concat(b(""), "__titles-item")),
135
- key: item.paneKey
136
- }, type === "line" && React__default.createElement("div", {
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
- }), type === "smile" && React__default.createElement("div", {
140
- className: "".concat(b(""), "__titles-item__smile"),
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: ellipsis && !titleScroll && direction === "horizontal"
147
- }, "".concat(b(""), "__titles-item__text"))
155
+ ellipsis: true
156
+ }, "".concat(classPrefix, "__titles-item__text"))
148
157
  }, item.title));
149
158
  })), React__default.createElement("div", {
150
- className: "".concat(b(""), "__content__wrap")
159
+ className: "".concat(classPrefix, "__content__wrap")
151
160
  }, React__default.createElement("div", {
152
- className: "".concat(b(""), "__content"),
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
- activeKey: value
168
+ active: value === child.props.value
161
169
  });
162
- if (String(value) !== String(((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.paneKey) || idx) && autoHeight) {
170
+ if (String(value) !== String(child.props.value || idx) && autoHeight) {
163
171
  childProps = _objectSpread(_objectSpread({}, childProps), {}, {
164
172
  autoHeightClassName: "inactive"
165
173
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.2 Wed Apr 26 2023 18:37:18 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */