@nutui/nutui-react 2.0.0-alpha.5 → 2.0.0-alpha.7

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/esm/Table.js CHANGED
@@ -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 = ["children", "className", "style", "columns", "data", "bordered", "summary", "striped", "noData", "onSorter", "sorterIcon", "showHeader"];
4
+ var _excluded = ["children", "className", "style", "columns", "data", "bordered", "summary", "striped", "noData", "sorterIcon", "showHeader", "onSort"];
5
5
  function ownKeys(object, enumerableOnly) {
6
6
  var keys = Object.keys(object);
7
7
  if (Object.getOwnPropertySymbols) {
@@ -26,37 +26,34 @@ function _objectSpread(target) {
26
26
  import React__default, { useState, useEffect } from "react";
27
27
  import classNames from "classnames";
28
28
  import { DownArrow } from "@nutui/icons-react";
29
- import { c as cn } from "./bem.js";
30
29
  import { useConfig } from "./ConfigProvider.js";
31
30
  import { C as ComponentDefaults } from "./typings.js";
32
- import "@bem-react/classname";
33
31
  var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
34
- className: "",
35
- style: {},
36
32
  columns: [],
37
33
  data: [],
38
34
  bordered: true,
39
35
  striped: false,
40
- noData: "无数据",
36
+ noData: "",
41
37
  sorterIcon: null,
42
38
  showHeader: true
43
39
  });
44
40
  var Table = function Table2(props) {
45
41
  var _useConfig = useConfig(), locale = _useConfig.locale;
46
42
  defaultProps.noData = locale.noData;
47
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children, className = _defaultProps$props.className, style = _defaultProps$props.style, columns = _defaultProps$props.columns, data = _defaultProps$props.data, bordered = _defaultProps$props.bordered, summary = _defaultProps$props.summary, striped = _defaultProps$props.striped, noData = _defaultProps$props.noData, onSorter = _defaultProps$props.onSorter, sorterIcon = _defaultProps$props.sorterIcon, showHeader = _defaultProps$props.showHeader, rest = _objectWithoutProperties(_defaultProps$props, _excluded);
43
+ var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children, className = _defaultProps$props.className, style = _defaultProps$props.style, columns = _defaultProps$props.columns, data = _defaultProps$props.data, bordered = _defaultProps$props.bordered, summary = _defaultProps$props.summary, striped = _defaultProps$props.striped, noData = _defaultProps$props.noData, sorterIcon = _defaultProps$props.sorterIcon, showHeader = _defaultProps$props.showHeader, onSort = _defaultProps$props.onSort, rest = _objectWithoutProperties(_defaultProps$props, _excluded);
48
44
  var _useState = useState(data), _useState2 = _slicedToArray(_useState, 2), curData = _useState2[0], setCurData = _useState2[1];
49
45
  useEffect(function() {
50
46
  if (data && String(data) !== String(curData)) {
51
47
  setCurData(data);
52
48
  }
53
49
  }, [data]);
54
- var b = cn("table");
55
- var classes = classNames({});
56
- var cls = classNames(b(), classes, className);
50
+ var classPrefix = "nut-table";
51
+ var headerClassPrefix = "".concat(classPrefix, "__main__head__tr");
52
+ var bodyClassPrefix = "".concat(classPrefix, "__main__body__tr");
53
+ var cls = classNames(classPrefix, className);
57
54
  var handleSorterClick = function handleSorterClick2(item) {
58
55
  if (item.sorter) {
59
- onSorter && onSorter(item, curData);
56
+ onSort && onSort(item, curData);
60
57
  if (typeof item.sorter === "function") {
61
58
  setCurData(curData.sort(item.sorter));
62
59
  } else {
@@ -65,9 +62,8 @@ var Table = function Table2(props) {
65
62
  }
66
63
  };
67
64
  var cellClasses = function cellClasses2(item) {
68
- return _defineProperty({
69
- "nut-table__main__head__tr--border": props.bordered
70
- }, "nut-table__main__head__tr--align".concat(item.align ? item.align : ""), true);
65
+ var _ref;
66
+ return _ref = {}, _defineProperty(_ref, "".concat(headerClassPrefix, "--border"), props.bordered), _defineProperty(_ref, "".concat(headerClassPrefix, "--align").concat(item.align ? item.align : ""), true), _ref;
71
67
  };
72
68
  var getColumnItem = function getColumnItem2(value) {
73
69
  return columns.filter(function(item) {
@@ -77,7 +73,7 @@ var Table = function Table2(props) {
77
73
  var renderHeadCells = function renderHeadCells2() {
78
74
  return columns.map(function(item, index) {
79
75
  return React__default.createElement("span", {
80
- className: classNames("nut-table__main__head__tr__th", cellClasses(item)),
76
+ className: classNames("".concat(headerClassPrefix, "__th"), cellClasses(item)),
81
77
  key: item.key,
82
78
  onClick: function onClick() {
83
79
  return handleSorterClick(item);
@@ -97,7 +93,7 @@ var Table = function Table2(props) {
97
93
  return sortDataItem().map(function(_ref2, index) {
98
94
  var _ref3 = _slicedToArray(_ref2, 2), value = _ref3[0], render = _ref3[1];
99
95
  return React__default.createElement("span", {
100
- className: classNames("nut-table__main__body__tr__td", cellClasses(getColumnItem(value))),
96
+ className: classNames("".concat(bodyClassPrefix, "__td"), cellClasses(getColumnItem(value))),
101
97
  key: value
102
98
  }, typeof item[value] === "function" || typeof render === "function" ? React__default.createElement("div", null, render ? render(item) : item[value](item)) : item[value]);
103
99
  });
@@ -105,7 +101,7 @@ var Table = function Table2(props) {
105
101
  var renderBoyTrs = function renderBoyTrs2() {
106
102
  return curData.map(function(item, index) {
107
103
  return React__default.createElement("div", {
108
- className: "nut-table__main__body__tr",
104
+ className: bodyClassPrefix,
109
105
  key: index
110
106
  }, renderBodyTds(item));
111
107
  });
@@ -114,26 +110,16 @@ var Table = function Table2(props) {
114
110
  className: cls,
115
111
  style
116
112
  }, rest), React__default.createElement("div", {
117
- className: classNames("nut-table__main", {
118
- "nut-table__main--striped": striped
119
- })
113
+ className: classNames("".concat(classPrefix, "__main"), _defineProperty({}, "".concat(classPrefix, "__main--striped"), striped))
120
114
  }, showHeader && React__default.createElement("div", {
121
- className: "nut-table__main__head"
115
+ className: "".concat(classPrefix, "__main__head")
122
116
  }, React__default.createElement("div", {
123
- className: "nut-table__main__head__tr"
117
+ className: headerClassPrefix
124
118
  }, renderHeadCells())), React__default.createElement("div", {
125
- className: "nut-table__main__body"
126
- }, renderBoyTrs())), summary && React__default.createElement("div", {
127
- className: "nut-table__summary"
128
- }, React__default.createElement("span", {
129
- className: "nut-table__summary__text"
130
- }, summary)), curData.length === 0 && React__default.createElement("div", {
131
- className: "nut-table__nodata"
132
- }, React__default.createElement("div", {
133
- className: "nut-table__nodata"
134
- }, React__default.createElement("div", {
135
- className: "nut-table__nodata__text"
136
- }, noData))));
119
+ className: "".concat(classPrefix, "__main__body")
120
+ }, renderBoyTrs())), (summary || curData.length === 0) && React__default.createElement("div", {
121
+ className: "".concat(classPrefix, "__summary")
122
+ }, summary || noData));
137
123
  };
138
124
  Table.defaultProps = defaultProps;
139
125
  Table.displayName = "NutTable";
@@ -1,7 +1,7 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ var _excluded = ["className", "value", "defaultValue", "showCount", "maxLength", "rows", "placeholder", "readOnly", "disabled", "autoSize", "style", "onChange", "onBlur", "onFocus"];
5
5
  function ownKeys(object, enumerableOnly) {
6
6
  var keys = Object.keys(object);
7
7
  if (Object.getOwnPropertySymbols) {
@@ -23,131 +23,103 @@ function _objectSpread(target) {
23
23
  }
24
24
  return target;
25
25
  }
26
- import React__default, { useState, useRef, useEffect } from "react";
26
+ import React__default, { useRef, useEffect } from "react";
27
+ import classNames from "classnames";
27
28
  import { useConfig } from "./ConfigProvider.js";
28
- import { c as cn } from "./bem.js";
29
- import "@bem-react/classname";
30
- var defaultProps = {
29
+ import { C as ComponentDefaults } from "./typings.js";
30
+ import { u as usePropsValue } from "./use-props-value.js";
31
+ var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
31
32
  defaultValue: "",
32
- textAlign: "left",
33
- limitshow: false,
34
- maxlength: "",
35
- rows: "",
33
+ showCount: false,
34
+ rows: 2,
35
+ maxLength: 140,
36
36
  placeholder: "",
37
- readonly: false,
37
+ readOnly: false,
38
38
  disabled: false,
39
- autosize: false
40
- };
39
+ autoSize: false
40
+ });
41
41
  var TextArea = function TextArea2(props) {
42
42
  var _useConfig = useConfig(), locale = _useConfig.locale;
43
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, defaultValue = _defaultProps$props.defaultValue, textAlign = _defaultProps$props.textAlign, limitshow = _defaultProps$props.limitshow, maxlength = _defaultProps$props.maxlength, rows = _defaultProps$props.rows, placeholder = _defaultProps$props.placeholder, readonly = _defaultProps$props.readonly, disabled = _defaultProps$props.disabled, autosize = _defaultProps$props.autosize, style = _defaultProps$props.style, onChange = _defaultProps$props.onChange, onBlur = _defaultProps$props.onBlur, onFocus = _defaultProps$props.onFocus;
44
- var textareaBem = cn("textarea");
45
- var _useState = useState(""), _useState2 = _slicedToArray(_useState, 2), inputValue = _useState2[0], SetInputValue = _useState2[1];
43
+ var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, value = _defaultProps$props.value, defaultValue = _defaultProps$props.defaultValue, showCount = _defaultProps$props.showCount, maxLength = _defaultProps$props.maxLength, rows = _defaultProps$props.rows, placeholder = _defaultProps$props.placeholder, readOnly = _defaultProps$props.readOnly, disabled = _defaultProps$props.disabled, autoSize = _defaultProps$props.autoSize, style = _defaultProps$props.style, onChange = _defaultProps$props.onChange, onBlur = _defaultProps$props.onBlur, onFocus = _defaultProps$props.onFocus, rest = _objectWithoutProperties(_defaultProps$props, _excluded);
44
+ var classPrefix = "nut-textarea";
46
45
  var textareaRef = useRef(null);
47
- var compositingRef = useRef(false);
48
- useEffect(function() {
49
- var initValue = defaultValue;
50
- if (initValue && maxlength && _toConsumableArray(initValue).length > Number(maxlength)) {
51
- initValue = initValue.substring(0, Number(maxlength));
52
- }
53
- SetInputValue(initValue);
54
- if (autosize) {
55
- setTimeout(function() {
56
- setContentHeight();
57
- });
46
+ var compositionRef = useRef(false);
47
+ var format = function format2(value2) {
48
+ if (maxLength !== void 0 && value2.length > maxLength) {
49
+ return value2.substring(0, maxLength);
58
50
  }
59
- }, [defaultValue, autosize]);
51
+ return value2;
52
+ };
53
+ var _usePropsValue = usePropsValue({
54
+ value,
55
+ defaultValue,
56
+ finalValue: format(defaultValue),
57
+ onChange
58
+ }), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), inputValue = _usePropsValue2[0], setInputValue = _usePropsValue2[1];
60
59
  useEffect(function() {
61
- if (inputValue) {
62
- if (autosize) {
63
- setContentHeight();
64
- }
60
+ if (autoSize) {
61
+ setContentHeight();
65
62
  }
66
- }, [inputValue]);
63
+ }, [autoSize, defaultValue, inputValue]);
67
64
  var setContentHeight = function setContentHeight2() {
68
65
  var textarea = textareaRef.current;
69
66
  if (textarea) {
70
67
  textarea.style.height = "auto";
71
68
  var height = textarea === null || textarea === void 0 ? void 0 : textarea.scrollHeight;
72
- if (_typeof(autosize) === "object") {
73
- var maxHeight = autosize.maxHeight, minHeight = autosize.minHeight;
74
- if (maxHeight !== void 0) {
75
- height = Math.min(height, maxHeight);
76
- }
77
- if (minHeight !== void 0) {
78
- height = Math.max(height, minHeight);
79
- }
80
- }
81
69
  if (height) {
82
70
  textarea.style.height = "".concat(height, "px");
83
71
  }
84
72
  }
85
73
  };
86
- var textChange = function textChange2(event) {
74
+ var handleChange = function handleChange2(event) {
87
75
  var text = event.target;
88
- if (maxlength && _toConsumableArray(text.value).length > Number(maxlength) && !compositingRef.current) {
89
- text.value = text.value.substring(0, Number(maxlength));
90
- }
91
- SetInputValue(text.value);
92
- onChange && onChange(text.value, event);
76
+ var value2 = compositionRef.current ? text.value : format(text.value);
77
+ setInputValue(value2);
93
78
  };
94
- var textFocus = function textFocus2(event) {
79
+ var handleFocus = function handleFocus2(event) {
95
80
  if (disabled)
96
81
  return;
97
- if (readonly)
82
+ if (readOnly)
98
83
  return;
99
84
  onFocus && onFocus(event);
100
85
  };
101
- var textBlur = function textBlur2(event) {
86
+ var handleBlur = function handleBlur2(event) {
102
87
  if (disabled)
103
88
  return;
104
- if (readonly)
89
+ if (readOnly)
105
90
  return;
106
- var text = event.target;
107
- onChange && onChange(text.value, event);
108
91
  onBlur && onBlur(event);
109
92
  };
110
- var startComposing = function startComposing2() {
111
- compositingRef.current = true;
112
- };
113
- var endComposing = function endComposing2() {
114
- compositingRef.current = false;
115
- };
116
93
  return React__default.createElement("div", {
117
- className: "".concat(textareaBem(), " ").concat(disabled ? textareaBem("disabled") : "", " ").concat(className || "")
118
- }, React__default.createElement("textarea", {
94
+ className: classNames(classPrefix, className, _defineProperty({}, "".concat(classPrefix, "__disabled"), disabled))
95
+ }, React__default.createElement("textarea", _objectSpread({
119
96
  ref: textareaRef,
120
- className: textareaBem("textarea"),
121
- style: _objectSpread({
122
- textAlign
123
- }, style),
97
+ className: "".concat(classPrefix, "__textarea"),
98
+ style,
124
99
  disabled,
125
- readOnly: readonly,
100
+ readOnly,
126
101
  value: inputValue,
127
- // onInput={(e: any) => {
128
- // textChange(e)
129
- // }}
130
102
  onChange: function onChange2(e) {
131
- textChange(e);
103
+ return handleChange(e);
132
104
  },
133
105
  onBlur: function onBlur2(e) {
134
- textBlur(e);
106
+ return handleBlur(e);
135
107
  },
136
108
  onFocus: function onFocus2(e) {
137
- textFocus(e);
109
+ return handleFocus(e);
138
110
  },
139
- onCompositionEnd: function onCompositionEnd(e) {
140
- return endComposing();
111
+ onCompositionEnd: function onCompositionEnd() {
112
+ compositionRef.current = false;
141
113
  },
142
- onCompositionStart: function onCompositionStart(e) {
143
- return startComposing();
114
+ onCompositionStart: function onCompositionStart() {
115
+ compositionRef.current = true;
144
116
  },
145
117
  rows,
146
- maxLength: maxlength < 0 ? 0 : maxlength,
118
+ maxLength: maxLength === -1 ? void 0 : maxLength,
147
119
  placeholder: placeholder || locale.placeholder
148
- }), limitshow ? React__default.createElement("div", {
149
- className: textareaBem("limit")
150
- }, _toConsumableArray(inputValue).length, "/", maxlength < 0 ? 0 : maxlength) : null);
120
+ }, rest)), showCount && React__default.createElement("div", {
121
+ className: "".concat(classPrefix, "__limit")
122
+ }, inputValue.length, "/", maxLength < 0 ? 0 : maxLength));
151
123
  };
152
124
  TextArea.defaultProps = defaultProps;
153
125
  TextArea.displayName = "NutTextArea";
package/dist/esm/tabs2.js CHANGED
@@ -100,6 +100,18 @@ var Tabs = function Tabs2(props) {
100
100
  return titles2;
101
101
  };
102
102
  var titles = useRef(getTitles());
103
+ useEffect(function() {
104
+ titles.current = getTitles();
105
+ var current = "";
106
+ titles.current.forEach(function(title2) {
107
+ if (title2.value === value) {
108
+ current = value;
109
+ }
110
+ });
111
+ if (current !== "") {
112
+ setValue(current);
113
+ }
114
+ }, [children]);
103
115
  var classes = classNames(classPrefix, "".concat(classPrefix, "--").concat(direction), className);
104
116
  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));
105
117
  var tabsActiveStyle = {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 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.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 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.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 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.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 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.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 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.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */