@nutui/nutui-react 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (117) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/dist/esm/Address.js +1 -1
  3. package/dist/esm/Animate.js +6 -7
  4. package/dist/esm/Audio.js +12 -8
  5. package/dist/esm/Avatar.js +30 -25
  6. package/dist/esm/AvatarGroup.js +10 -15
  7. package/dist/esm/Badge.js +4 -73
  8. package/dist/esm/CalendarItem.js +2 -12
  9. package/dist/esm/Cascader.js +67 -69
  10. package/dist/esm/Checkbox.js +1 -2
  11. package/dist/esm/CheckboxGroup.js +18 -20
  12. package/dist/esm/CircleProgress.js +20 -25
  13. package/dist/esm/DatePicker.js +10 -10
  14. package/dist/esm/Dialog.js +162 -171
  15. package/dist/esm/Divider.js +4 -3
  16. package/dist/esm/Drag.js +7 -9
  17. package/dist/esm/Elevator.js +39 -41
  18. package/dist/esm/Ellipsis.js +13 -12
  19. package/dist/esm/Empty.js +18 -26
  20. package/dist/esm/Image.js +5 -10
  21. package/dist/esm/ImagePreview.js +67 -58
  22. package/dist/esm/Indicator.js +4 -4
  23. package/dist/esm/Input.js +87 -193
  24. package/dist/esm/Menu.js +75 -73
  25. package/dist/esm/MenuItem.js +29 -27
  26. package/dist/esm/NavBar.js +17 -48
  27. package/dist/esm/NoticeBar.js +50 -87
  28. package/dist/esm/Notify.js +35 -46
  29. package/dist/esm/NumberKeyboard.js +137 -195
  30. package/dist/esm/Picker.js +175 -160
  31. package/dist/esm/Popup.js +2 -4
  32. package/dist/esm/Price.js +22 -23
  33. package/dist/esm/Progress.js +74 -67
  34. package/dist/esm/PullToRefresh.js +8 -8
  35. package/dist/esm/Radio.js +2 -0
  36. package/dist/esm/RadioGroup.js +31 -51
  37. package/dist/esm/Range/style/index.js +1 -1
  38. package/dist/esm/Range.js +119 -174
  39. package/dist/esm/Skeleton.js +1 -1
  40. package/dist/esm/Step.js +23 -28
  41. package/dist/esm/Steps/style/index.js +1 -1
  42. package/dist/esm/Steps.js +10 -11
  43. package/dist/esm/Swipe.js +4 -10
  44. package/dist/esm/Swiper.js +86 -91
  45. package/dist/esm/SwiperItem.js +1 -1
  46. package/dist/esm/Switch.js +16 -30
  47. package/dist/esm/TabPane.js +39 -5
  48. package/dist/esm/Tabbar/style/index.js +1 -1
  49. package/dist/esm/Tabbar.js +29 -33
  50. package/dist/esm/TabbarItem.js +5 -75
  51. package/dist/esm/Table.js +20 -34
  52. package/dist/esm/Tabs.js +2 -2
  53. package/dist/esm/TextArea.js +53 -81
  54. package/dist/esm/Uploader.js +2 -3
  55. package/dist/esm/badge2.js +69 -0
  56. package/dist/esm/cellgroup2.js +5 -4
  57. package/dist/esm/checkbox2.js +34 -47
  58. package/dist/esm/nutui-react.es.js +170 -170
  59. package/dist/esm/overlay2.js +12 -14
  60. package/dist/esm/radio2.js +52 -54
  61. package/dist/esm/raf.js +16 -0
  62. package/dist/esm/tabbaritem2.js +61 -0
  63. package/dist/esm/tabs2.js +126 -95
  64. package/dist/locales/base.js +1 -1
  65. package/dist/locales/en-US.js +1 -1
  66. package/dist/locales/id-ID.js +1 -1
  67. package/dist/locales/zh-CN.js +1 -1
  68. package/dist/locales/zh-TW.js +1 -1
  69. package/dist/locales/zh-UG.js +1 -1
  70. package/dist/nutui.react.mjs +21778 -22695
  71. package/dist/nutui.react.umd.js +21776 -22693
  72. package/dist/packages/badge/badge.scss +8 -18
  73. package/dist/packages/cascader/cascader.scss +0 -26
  74. package/dist/packages/cellgroup/cellgroup.scss +20 -16
  75. package/dist/packages/checkbox/checkbox.scss +8 -11
  76. package/dist/packages/circleprogress/circleprogress.scss +0 -9
  77. package/dist/packages/dialog/dialog.scss +36 -65
  78. package/dist/packages/elevator/elevator.scss +2 -28
  79. package/dist/packages/empty/empty.scss +0 -9
  80. package/dist/packages/imagepreview/imagepreview.scss +52 -16
  81. package/dist/packages/input/input.scss +13 -180
  82. package/dist/packages/menu/menu.scss +44 -55
  83. package/dist/packages/menuitem/menuitem.scss +16 -26
  84. package/dist/packages/navbar/navbar.scss +16 -115
  85. package/dist/packages/noticebar/noticebar.scss +18 -19
  86. package/dist/packages/notify/notify.scss +1 -1
  87. package/dist/packages/numberkeyboard/numberkeyboard.scss +29 -77
  88. package/dist/packages/overlay/overlay.scss +11 -4
  89. package/dist/packages/picker/picker.scss +66 -137
  90. package/dist/packages/price/price.scss +8 -0
  91. package/dist/packages/progress/progress.scss +19 -58
  92. package/dist/packages/pulltorefresh/pulltorefresh.scss +0 -8
  93. package/dist/packages/radio/radio.scss +13 -32
  94. package/dist/packages/radiogroup/radiogroup.scss +17 -51
  95. package/dist/packages/range/range.scss +24 -49
  96. package/dist/packages/step/step.scss +9 -62
  97. package/dist/packages/steps/steps.scss +2 -0
  98. package/dist/packages/swiper/swiper.scss +3 -18
  99. package/dist/packages/switch/switch.scss +13 -31
  100. package/dist/packages/tabbar/tabbar.scss +16 -22
  101. package/dist/packages/tabbaritem/tabbaritem.scss +9 -70
  102. package/dist/packages/table/table.scss +0 -56
  103. package/dist/packages/tabs/tabs.scss +196 -225
  104. package/dist/packages/textarea/textarea.scss +5 -12
  105. package/dist/style.css +1 -1
  106. package/dist/style.mjs +1 -1
  107. package/dist/styles/themes/default.scss +17 -18
  108. package/dist/styles/variables-jmapp.scss +120 -240
  109. package/dist/styles/variables.scss +139 -252
  110. package/dist/types/index.d.ts +541 -680
  111. package/package.json +2 -2
  112. package/dist/esm/Icon.js +0 -83
  113. package/dist/esm/tabpane2.js +0 -44
  114. package/dist/packages/icon/icon.scss +0 -0
  115. /package/dist/esm/{AvatarContext.js → context.js} +0 -0
  116. /package/dist/esm/{UserContext2.js → context2.js} +0 -0
  117. /package/dist/esm/{UserContext3.js → context3.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
- var _excluded = ["className", "disabled", "checked", "shape", "textPosition", "value", "icon", "checkedIcon", "iconSize", "onChange"];
4
+ var _excluded = ["children", "className", "style", "checked", "defaultChecked", "shape", "value", "icon", "activeIcon", "onChange"], _excluded2 = ["labelPosition", "disabled"];
5
5
  function ownKeys(object, enumerableOnly) {
6
6
  var keys = Object.keys(object);
7
7
  if (Object.getOwnPropertySymbols) {
@@ -23,106 +23,104 @@ function _objectSpread(target) {
23
23
  }
24
24
  return target;
25
25
  }
26
- import React__default, { useState, useContext, useEffect } from "react";
26
+ import React__default, { useContext } from "react";
27
27
  import { CheckChecked, CheckNormal } from "@nutui/icons-react";
28
+ import classNames from "classnames";
28
29
  import RadioGroup from "./RadioGroup.js";
29
30
  import { C as ComponentDefaults } from "./typings.js";
30
- var radioContext = {
31
- onChange: function onChange(val) {
32
- }
33
- };
34
- var RadioContext = React__default.createContext(radioContext);
31
+ import { u as usePropsValue } from "./use-props-value.js";
32
+ var RadioContext = React__default.createContext(null);
35
33
  var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
36
- className: "",
37
- style: {},
38
34
  disabled: false,
39
- checked: false,
40
35
  shape: "round",
41
36
  value: "",
42
- textPosition: "right",
43
- icon: "check-normal",
44
- checkedIcon: "check-checked",
45
- iconSize: 18,
46
- onChange: function onChange2(e) {
37
+ labelPosition: "right",
38
+ icon: null,
39
+ activeIcon: null,
40
+ onChange: function onChange(checked) {
47
41
  }
48
42
  });
49
43
  var Radio = function Radio2(props) {
50
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children;
51
- var className = props.className, disabled = props.disabled, checked = props.checked, shape = props.shape, textPosition = props.textPosition, value = props.value, icon = props.icon, checkedIcon = props.checkedIcon, iconSize = props.iconSize, onChange3 = props.onChange, rest = _objectWithoutProperties(props, _excluded);
52
- var componentName = "nut-radio";
53
- var _useState = useState(checked), _useState2 = _slicedToArray(_useState, 2), checkedStatement = _useState2[0], setCheckedStatement = _useState2[1];
54
- var _useState3 = useState(value), _useState4 = _slicedToArray(_useState3, 2), valueStatement = _useState4[0], setValueStatement = _useState4[1];
55
- var _useState5 = useState(disabled), _useState6 = _slicedToArray(_useState5, 2), disabledStatement = _useState6[0], setDisabledStatement = _useState6[1];
44
+ var classPrefix = "nut-radio";
45
+ var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children, className = _defaultProps$props.className, style = _defaultProps$props.style, checked = _defaultProps$props.checked, defaultChecked = _defaultProps$props.defaultChecked, shape = _defaultProps$props.shape, value = _defaultProps$props.value, icon = _defaultProps$props.icon, activeIcon = _defaultProps$props.activeIcon, onChange2 = _defaultProps$props.onChange, others = _objectWithoutProperties(_defaultProps$props, _excluded);
46
+ var labelPosition = others.labelPosition, disabled = others.disabled, rest = _objectWithoutProperties(others, _excluded2);
47
+ var _usePropsValue = usePropsValue({
48
+ value: checked,
49
+ defaultValue: defaultChecked,
50
+ finalValue: false,
51
+ onChange: onChange2
52
+ }), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), checkedStatement = _usePropsValue2[0], setCheckedStatement = _usePropsValue2[1];
56
53
  var context = useContext(RadioContext);
57
- useEffect(function() {
58
- setDisabledStatement(disabled);
59
- setValueStatement(value);
60
- setCheckedStatement(checked);
61
- }, [disabled, value, checked]);
54
+ if (context) {
55
+ checkedStatement = context.value === value;
56
+ if (context.labelPosition !== void 0) {
57
+ labelPosition = context.labelPosition;
58
+ }
59
+ if (context.disabled !== void 0) {
60
+ disabled = context.disabled;
61
+ }
62
+ setCheckedStatement = function setCheckedStatement2(value2) {
63
+ if (value2) {
64
+ context.check(props.value === void 0 ? "" : props.value);
65
+ } else {
66
+ context.uncheck();
67
+ }
68
+ };
69
+ }
62
70
  var renderLabel = function renderLabel2() {
63
71
  return React__default.createElement("div", {
64
- className: "".concat(componentName, "__label ").concat(disabledStatement ? "".concat(componentName, "__label--disabled") : "")
72
+ className: classNames("".concat(classPrefix, "__label"), _defineProperty({}, "".concat(classPrefix, "__label--disabled"), disabled))
65
73
  }, children);
66
74
  };
67
75
  var renderButton = function renderButton2() {
76
+ var _classNames2;
68
77
  return React__default.createElement("div", {
69
- className: "".concat(componentName, "__button ").concat(!disabledStatement && checkedStatement && "".concat(componentName, "__button--active"), " ").concat(disabledStatement ? "".concat(componentName, "__button--disabled") : "")
78
+ className: classNames("".concat(classPrefix, "__button"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(classPrefix, "__button--active"), checkedStatement), _defineProperty(_classNames2, "".concat(classPrefix, "__button--disabled"), disabled), _classNames2))
70
79
  }, children);
71
80
  };
72
81
  var color = function color2() {
73
- if (disabledStatement) {
74
- return "nut-radio__icon--disable";
75
- }
76
- if (checkedStatement) {
77
- return "nut-radio__icon";
78
- }
79
- return "nut-radio__icon--unchecked";
82
+ var _ref;
83
+ return _ref = {}, _defineProperty(_ref, "".concat(classPrefix, "__icon--disable"), disabled), _defineProperty(_ref, "".concat(classPrefix, "__icon"), checkedStatement), _defineProperty(_ref, "".concat(classPrefix, "__icon--unchecked"), !checkedStatement), _ref;
80
84
  };
81
85
  var renderIcon = function renderIcon2() {
82
- var icon2 = props.icon, iconSize2 = props.iconSize, checkedIcon2 = props.checkedIcon;
83
- if (!disabledStatement && checkedStatement) {
84
- return React__default.isValidElement(checkedIcon2) ? React__default.cloneElement(checkedIcon2, _objectSpread(_objectSpread({}, checkedIcon2.props), {}, {
85
- className: color()
86
+ var icon2 = props.icon, activeIcon2 = props.activeIcon;
87
+ if (checkedStatement) {
88
+ return React__default.isValidElement(activeIcon2) ? React__default.cloneElement(activeIcon2, _objectSpread(_objectSpread({}, activeIcon2.props), {}, {
89
+ className: classNames(color())
86
90
  })) : React__default.createElement(CheckChecked, {
87
- width: iconSize2,
88
- height: iconSize2,
89
- className: color()
91
+ className: classNames(color())
90
92
  });
91
93
  }
92
94
  return React__default.isValidElement(icon2) ? React__default.cloneElement(icon2, _objectSpread(_objectSpread({}, icon2.props), {}, {
93
- size: iconSize2,
94
- className: color()
95
+ className: classNames(color())
95
96
  })) : React__default.createElement(CheckNormal, {
96
- width: iconSize2,
97
- height: iconSize2,
98
- className: color()
97
+ className: classNames(color())
99
98
  });
100
99
  };
101
- var reverseState = textPosition === "left";
100
+ var reverse = labelPosition === "left";
102
101
  var renderRadioItem = function renderRadioItem2() {
103
102
  if (shape === "button") {
104
103
  return renderButton();
105
104
  }
106
- if (reverseState) {
105
+ if (reverse) {
107
106
  return React__default.createElement(React__default.Fragment, null, renderLabel(), renderIcon());
108
107
  }
109
108
  return React__default.createElement(React__default.Fragment, null, renderIcon(), renderLabel());
110
109
  };
111
110
  var handleClick = function handleClick2(e) {
112
- if (disabledStatement || checkedStatement)
111
+ if (disabled || checkedStatement)
113
112
  return;
114
113
  setCheckedStatement(!checkedStatement);
115
- onChange3 && onChange3(e);
116
- context && context.onChange(valueStatement);
117
114
  };
118
115
  return React__default.createElement("div", _objectSpread({
119
- className: "nut-radio ".concat(className, " ").concat(reverseState ? "".concat(componentName, "--reverse") : ""),
116
+ className: "".concat(classPrefix, " ").concat(className, " ").concat(reverse ? "".concat(classPrefix, "--reverse") : ""),
117
+ style,
120
118
  onClick: handleClick
121
119
  }, rest), renderRadioItem());
122
120
  };
123
121
  Radio.defaultProps = defaultProps;
124
122
  Radio.displayName = "NutRadio";
125
- Radio.RadioGroup = RadioGroup;
123
+ Radio.Group = RadioGroup;
126
124
  export {
127
125
  Radio as R,
128
126
  RadioContext as a
@@ -0,0 +1,16 @@
1
+ var _window = window;
2
+ function requestAniFrame() {
3
+ if (typeof _window !== "undefined") {
4
+ return _window.requestAnimationFrame || _window.webkitRequestAnimationFrame || function(callback) {
5
+ _window.setTimeout(callback, 1e3 / 60);
6
+ };
7
+ } else {
8
+ return function(callback) {
9
+ setTimeout(callback, 1e3 / 60);
10
+ };
11
+ }
12
+ }
13
+ var requestAniFrame$1 = requestAniFrame();
14
+ export {
15
+ requestAniFrame$1 as r
16
+ };
@@ -0,0 +1,61 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ var _excluded = ["className", "style", "title", "icon", "active", "activeColor", "inactiveColor", "index", "handleClick"];
4
+ function ownKeys(object, enumerableOnly) {
5
+ var keys = Object.keys(object);
6
+ if (Object.getOwnPropertySymbols) {
7
+ var symbols = Object.getOwnPropertySymbols(object);
8
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
9
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
10
+ })), keys.push.apply(keys, symbols);
11
+ }
12
+ return keys;
13
+ }
14
+ function _objectSpread(target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
18
+ _defineProperty(target, key, source[key]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
20
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
+ });
22
+ }
23
+ return target;
24
+ }
25
+ import React__default from "react";
26
+ import classNames from "classnames";
27
+ import { C as ComponentDefaults } from "./typings.js";
28
+ import { B as Badge } from "./badge2.js";
29
+ var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
30
+ title: "",
31
+ icon: null,
32
+ active: false,
33
+ index: 0,
34
+ handleClick: function handleClick(idx) {
35
+ }
36
+ });
37
+ var TabbarItem = function TabbarItem2(props) {
38
+ var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, style = _defaultProps$props.style, title = _defaultProps$props.title, icon = _defaultProps$props.icon, active = _defaultProps$props.active, activeColor = _defaultProps$props.activeColor, inactiveColor = _defaultProps$props.inactiveColor, index = _defaultProps$props.index, handleClick2 = _defaultProps$props.handleClick, rest = _objectWithoutProperties(_defaultProps$props, _excluded);
39
+ var classPrefix = "nut-tabbar-item";
40
+ var tabbarItemClass = classNames(className, classPrefix, _defineProperty({}, "".concat(classPrefix, "-active"), active));
41
+ var boxPrefix = "".concat(classPrefix, "__icon-box");
42
+ var titleClass = classNames(boxPrefix, "".concat(boxPrefix, "-nav"), _defineProperty({}, "".concat(boxPrefix, "-large"), !icon));
43
+ return React__default.createElement("div", {
44
+ className: tabbarItemClass,
45
+ style: _objectSpread({
46
+ color: active ? activeColor : inactiveColor
47
+ }, style),
48
+ onClick: function onClick() {
49
+ return handleClick2(index);
50
+ }
51
+ }, icon ? React__default.createElement(React__default.Fragment, null, React__default.createElement(Badge, _objectSpread({}, rest), React__default.createElement("div", {
52
+ className: boxPrefix
53
+ }, icon)), React__default.createElement("div", {
54
+ className: titleClass
55
+ }, title)) : React__default.createElement(Badge, _objectSpread({}, rest), React__default.createElement("div", {
56
+ className: titleClass
57
+ }, title)));
58
+ };
59
+ export {
60
+ TabbarItem as T
61
+ };
package/dist/esm/tabs2.js CHANGED
@@ -1,9 +1,7 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
2
  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"];
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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,171 @@ 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";
33
+ function useForceUpdate() {
34
+ var _React__default$useSt = React__default.useState(), _React__default$useSt2 = _slicedToArray(_React__default$useSt, 2), updateState = _React__default$useSt2[1];
35
+ return React__default.useCallback(function() {
36
+ return updateState({});
37
+ }, []);
38
+ }
44
39
  var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
45
40
  tabStyle: {},
46
- value: 0,
47
- color: "",
48
- background: "",
41
+ activeColor: "",
49
42
  direction: "horizontal",
50
- type: "line",
51
- titleScroll: false,
52
- ellipsis: true,
53
- animatedTime: 300,
54
- titleGutter: 0,
55
- size: "normal",
56
- leftAlign: false,
43
+ activeType: "line",
44
+ duration: 300,
57
45
  autoHeight: false
58
46
  });
59
- var pxCheck = function pxCheck2(value) {
60
- return Number.isNaN(Number(value)) ? String(value) : "".concat(value, "px");
61
- };
47
+ var classPrefix = "nut-tabs";
62
48
  var Tabs = function Tabs2(props) {
63
49
  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;
50
+ 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);
51
+ var _usePropsValue = usePropsValue({
52
+ value: props.value,
53
+ defaultValue: props.defaultValue,
54
+ finalValue: 0,
55
+ onChange
56
+ }), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), value = _usePropsValue2[0], setValue = _usePropsValue2[1];
57
+ var _useState = useState({}), _useState2 = _slicedToArray(_useState, 2), contentStyle = _useState2[0], setContentStyle = _useState2[1];
58
+ var titleItemsRef = useRef([]);
59
+ var navRef = useRef(null);
60
+ var scrollDirection = function scrollDirection2(nav, to, duration2, direction2) {
61
+ var count = 0;
62
+ var from = direction2 === "horizontal" ? nav.scrollLeft : nav.scrollTop;
63
+ var frames = duration2 === 0 ? 1 : Math.round(duration2 * 1e3 / 16);
64
+ function animate() {
65
+ if (direction2 === "horizontal") {
66
+ nav.scrollLeft += (to - from) / frames;
67
+ } else {
68
+ nav.scrollTop += (to - from) / frames;
75
69
  }
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;
70
+ if (++count < frames) {
71
+ requestAniFrame(animate);
72
+ }
73
+ }
74
+ animate();
75
+ };
76
+ var scrollIntoView = function scrollIntoView2(index, immediate) {
77
+ var nav = navRef.current;
78
+ var titleItem = titleItemsRef.current;
79
+ if (!nav || !titleItem || !titleItem[index]) {
80
+ return;
81
+ }
82
+ var title2 = titleItem[index];
83
+ var to = 0;
84
+ if (props.direction === "vertical") {
85
+ var runTop = title2.offsetTop - nav.offsetTop + 10;
86
+ to = runTop - (nav.offsetHeight - title2.offsetHeight) / 2;
87
+ } else {
88
+ to = title2.offsetLeft - (nav.offsetWidth - title2.offsetWidth) / 2;
89
+ }
90
+ scrollDirection(nav, to, immediate ? 0 : 0.3, props.direction);
91
+ };
92
+ var getTitles = function getTitles2() {
93
+ var titles2 = [];
94
+ React__default.Children.forEach(children, function(child, idx) {
95
+ if (React__default.isValidElement(child)) {
96
+ var props2 = child === null || child === void 0 ? void 0 : child.props;
97
+ if (props2 !== null && props2 !== void 0 && props2.title || props2 !== null && props2 !== void 0 && props2.value) {
98
+ titles2.push({
99
+ title: props2.title,
100
+ value: props2.value || idx,
101
+ disabled: props2.disabled
102
+ });
85
103
  }
86
104
  }
87
- titles.current.push(title);
88
105
  });
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)
106
+ return titles2;
97
107
  };
108
+ var titles = useRef(getTitles());
109
+ var forceUpdate = useForceUpdate();
110
+ useEffect(function() {
111
+ titles.current = getTitles();
112
+ var current = "";
113
+ titles.current.forEach(function(title2) {
114
+ if (title2.value == value) {
115
+ current = value;
116
+ }
117
+ });
118
+ if (current !== "" && current !== value) {
119
+ setValue(current);
120
+ } else {
121
+ forceUpdate();
122
+ }
123
+ }, [children]);
124
+ var classes = classNames(classPrefix, "".concat(classPrefix, "--").concat(direction), className);
125
+ 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
126
  var tabsActiveStyle = {
99
- color: type === "smile" ? color : "",
100
- background: type === "line" ? color : ""
127
+ color: activeType === "smile" ? activeColor : "",
128
+ background: activeType === "line" ? activeColor : ""
101
129
  };
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);
130
+ useEffect(function() {
131
+ var index = titles.current.findIndex(function(t) {
132
+ return t.value == value;
133
+ });
134
+ setContentStyle({
135
+ transform: direction === "horizontal" ? "translate3d(-".concat(index * 100, "%, 0, 0)") : "translate3d( 0,-".concat(index * 100, "%, 0)"),
136
+ transitionDuration: "".concat(duration, "ms")
137
+ });
138
+ setTimeout(function() {
139
+ scrollIntoView(index);
140
+ });
141
+ }, [value]);
142
+ var tabChange = function tabChange2(item) {
143
+ onClick && onClick(item.value);
111
144
  if (item.disabled) {
112
145
  return;
113
146
  }
114
- setCurrentItem(item);
115
- onChange && onChange(item);
147
+ setValue(item.value);
116
148
  };
117
149
  return React__default.createElement("div", _objectSpread({
118
150
  className: classes
119
151
  }, rest), React__default.createElement("div", {
120
152
  className: classesTitle,
121
- style: _objectSpread(_objectSpread({}, tabStyle), {}, {
122
- background
123
- })
124
- }, !!titleNode && typeof titleNode === "function" ? titleNode() : titles.current.map(function(item, index2) {
153
+ style: _objectSpread({}, tabStyle),
154
+ ref: navRef
155
+ }, !!title && typeof title === "function" ? title() : titles.current.map(function(item) {
156
+ var _classNames2;
125
157
  return React__default.createElement("div", {
126
- style: titleStyle,
127
- onClick: function onClick2(e) {
128
- return tabChange(item);
158
+ onClick: function onClick2() {
159
+ tabChange(item);
129
160
  },
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"),
161
+ 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)),
162
+ ref: function ref(_ref) {
163
+ return titleItemsRef.current.push(_ref);
164
+ },
165
+ key: item.value
166
+ }, activeType === "line" && React__default.createElement("div", {
167
+ className: "".concat(classPrefix, "__titles-item__line"),
138
168
  style: tabsActiveStyle
139
- }), type === "smile" && React__default.createElement("div", {
140
- className: "".concat(b(""), "__titles-item__smile"),
169
+ }), activeType === "smile" && React__default.createElement("div", {
170
+ className: "".concat(classPrefix, "__titles-item__smile"),
141
171
  style: tabsActiveStyle
142
172
  }, React__default.createElement(JoySmile, {
143
- color
173
+ color: activeColor,
174
+ width: 40,
175
+ height: 20
144
176
  })), React__default.createElement("div", {
145
177
  className: classNames({
146
- ellipsis: ellipsis && !titleScroll && direction === "horizontal"
147
- }, "".concat(b(""), "__titles-item__text"))
178
+ ellipsis: true
179
+ }, "".concat(classPrefix, "__titles-item__text"))
148
180
  }, item.title));
149
181
  })), React__default.createElement("div", {
150
- className: "".concat(b(""), "__content__wrap")
182
+ className: "".concat(classPrefix, "__content__wrap")
151
183
  }, React__default.createElement("div", {
152
- className: "".concat(b(""), "__content"),
184
+ className: "".concat(classPrefix, "__content"),
153
185
  style: contentStyle
154
186
  }, React__default.Children.map(children, function(child, idx) {
155
- var _child$props;
156
187
  if (!React__default.isValidElement(child)) {
157
188
  return null;
158
189
  }
159
190
  var childProps = _objectSpread(_objectSpread({}, child.props), {}, {
160
- activeKey: value
191
+ active: value === child.props.value
161
192
  });
162
- if (String(value) !== String(((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.paneKey) || idx) && autoHeight) {
193
+ if (String(value) !== String(child.props.value || idx) && autoHeight) {
163
194
  childProps = _objectSpread(_objectSpread({}, childProps), {}, {
164
195
  autoHeightClassName: "inactive"
165
196
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 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.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 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.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 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.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 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.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 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.1 Fri Apr 21 2023 18:05:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.10 Fri May 19 2023 19:00:38 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */