@titaui/pc 1.11.27-beta.3 → 1.11.27-beta.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.
@@ -4,7 +4,7 @@
4
4
  min-height: 36px;
5
5
  background: #ffffff;
6
6
  cursor: text;
7
- border-radius: 4px;
7
+ border-radius: 8px;
8
8
  display: flex;
9
9
  align-items: center;
10
10
  padding: 7px 0;
@@ -118,3 +118,25 @@
118
118
  line-height: 18px;
119
119
  padding-left: 12px;
120
120
  }
121
+
122
+ .commonTextAreaWrapperTopShadow::before {
123
+ content: '';
124
+ border-radius: 8px;
125
+ height: 30px;
126
+ background: linear-gradient(180deg, #ffffff 0%, rgba(255, 255, 255, 0) 100%);
127
+ position: absolute;
128
+ top: 0;
129
+ width: 100%;
130
+ z-index: 2;
131
+ }
132
+
133
+ .commonTextAreaWrapperBottomShadow::after {
134
+ content: '';
135
+ border-radius: 8px;
136
+ height: 30px;
137
+ background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #ffffff 100%);
138
+ position: absolute;
139
+ bottom: 0;
140
+ width: 100%;
141
+ z-index: 2;
142
+ }
@@ -9,9 +9,13 @@ exports["default"] = void 0;
9
9
 
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
 
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+
12
14
  require("./index.css");
13
15
 
14
- var _excluded = ["disabled", "onFocus", "onBlur", "inputRef", "onChange", "autoHeight", "style", "className", "value", "placeholder", "maxLine", "maxLength", "initValue", "onErrorChange", "validator", "onKeyDown"];
16
+ var _excluded = ["disabled", "onFocus", "onBlur", "inputRef", "onChange", "className", "value", "placeholder", "maxLine", "maxLength", "initValue", "onErrorChange", "validator", "onKeyDown"];
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
19
 
16
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
21
 
@@ -19,12 +23,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
19
23
 
20
24
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
25
 
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
28
26
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
29
27
 
30
28
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -47,13 +45,11 @@ var Textarea = function Textarea(p) {
47
45
  _onBlur = p.onBlur,
48
46
  inputRef = p.inputRef,
49
47
  _onChange = p.onChange,
50
- _p$autoHeight = p.autoHeight,
51
- autoHeight = _p$autoHeight === void 0 ? true : _p$autoHeight,
52
- style = p.style,
53
48
  className = p.className,
54
49
  value = p.value,
55
50
  placeholder = p.placeholder,
56
- maxLine = p.maxLine,
51
+ _p$maxLine = p.maxLine,
52
+ maxLine = _p$maxLine === void 0 ? 4 : _p$maxLine,
57
53
  maxLength = p.maxLength,
58
54
  initValue = p.initValue,
59
55
  onErrorChange = p.onErrorChange,
@@ -68,65 +64,54 @@ var Textarea = function Textarea(p) {
68
64
  active = _useState2[0],
69
65
  setActive = _useState2[1];
70
66
 
71
- var _useState3 = (0, _react.useState)(),
67
+ var _useState3 = (0, _react.useState)(initValue || ""),
72
68
  _useState4 = _slicedToArray(_useState3, 2),
73
- height = _useState4[0],
74
- setHeight = _useState4[1];
75
-
76
- var _useState5 = (0, _react.useState)(initValue || ""),
77
- _useState6 = _slicedToArray(_useState5, 2),
78
- selfValue = _useState6[0],
79
- setSelfValue = _useState6[1];
69
+ selfValue = _useState4[0],
70
+ setSelfValue = _useState4[1];
80
71
 
81
- var hiddenRef = (0, _react.useRef)();
82
72
  var selfInputRef = (0, _react.useRef)();
83
73
  var realInputRef = inputRef || selfInputRef;
84
74
  var isControlled = ("value" in p);
85
75
  var realValue = isControlled ? value : selfValue;
86
76
 
87
- var _useState7 = (0, _react.useState)(false),
77
+ var _useState5 = (0, _react.useState)(false),
78
+ _useState6 = _slicedToArray(_useState5, 2),
79
+ error = _useState6[0],
80
+ setError = _useState6[1];
81
+
82
+ var _useState7 = (0, _react.useState)(""),
88
83
  _useState8 = _slicedToArray(_useState7, 2),
89
- error = _useState8[0],
90
- setError = _useState8[1];
84
+ errorText = _useState8[0],
85
+ setErrorText = _useState8[1];
86
+
87
+ var wrapperRef = (0, _react.useRef)();
91
88
 
92
- var _useState9 = (0, _react.useState)(""),
89
+ var _useState9 = (0, _react.useState)(false),
93
90
  _useState10 = _slicedToArray(_useState9, 2),
94
- errorText = _useState10[0],
95
- setErrorText = _useState10[1];
91
+ validateEnable = _useState10[0],
92
+ setvalidateEnable = _useState10[1];
96
93
 
97
- var _useState11 = (0, _react.useState)("auto"),
94
+ var _useState11 = (0, _react.useState)(false),
98
95
  _useState12 = _slicedToArray(_useState11, 2),
99
- maxHeight = _useState12[0],
100
- setMaxheight = _useState12[1];
101
-
102
- var wrapperRef = (0, _react.useRef)();
96
+ isTrue = _useState12[0],
97
+ setIsTrue = _useState12[1];
103
98
 
104
- var _useState13 = (0, _react.useState)(false),
99
+ var _useState13 = (0, _react.useState)(1),
105
100
  _useState14 = _slicedToArray(_useState13, 2),
106
- validateEnable = _useState14[0],
107
- setvalidateEnable = _useState14[1];
101
+ textAreaRows = _useState14[0],
102
+ setTextAreaRows = _useState14[1];
108
103
 
109
104
  var _useState15 = (0, _react.useState)(false),
110
105
  _useState16 = _slicedToArray(_useState15, 2),
111
- isTrue = _useState16[0],
112
- setIsTrue = _useState16[1];
113
-
114
- (0, _react.useEffect)(function () {
115
- if (autoHeight && hiddenRef.current && realInputRef.current) {
116
- // 自适应高度
117
- hiddenRef.current.value = "".concat(realValue || "");
118
- hiddenRef.current.style.width = window.getComputedStyle(realInputRef.current).width;
119
- var _height = hiddenRef.current.scrollHeight;
106
+ showTopShadow = _useState16[0],
107
+ setShowTopShadow = _useState16[1];
120
108
 
121
- if (maxLine && maxLine > 0) {
122
- var lineHeight = Number(window.getComputedStyle(realInputRef.current).lineHeight.replace("px", "")); // setMaxheight(maxLine * lineHeight + "px");
123
-
124
- setMaxheight("".concat(maxLine * lineHeight, "px"));
125
- }
126
-
127
- setHeight(_height);
128
- }
109
+ var _useState17 = (0, _react.useState)(false),
110
+ _useState18 = _slicedToArray(_useState17, 2),
111
+ showBottomShadow = _useState18[0],
112
+ setShowBottomShadow = _useState18[1];
129
113
 
114
+ (0, _react.useEffect)(function () {
130
115
  if (!validateEnable) return;
131
116
  var hasError = false;
132
117
  var eText = "";
@@ -158,7 +143,40 @@ var Textarea = function Textarea(p) {
158
143
 
159
144
  setError(hasError);
160
145
  }
161
- }, [realValue]); // 鼠标移入
146
+ }, [realValue]);
147
+
148
+ var handleShadowVisible = function handleShadowVisible() {
149
+ setTimeout(function () {
150
+ if (realInputRef.current) {
151
+ if (Math.abs(realInputRef.current.scrollHeight - realInputRef.current.offsetHeight) <= 3) {
152
+ setShowTopShadow(false);
153
+ setShowBottomShadow(false);
154
+ } else if (realInputRef.current.scrollTop > 0 && Math.abs(realInputRef.current.scrollHeight - realInputRef.current.scrollTop - realInputRef.current.offsetHeight) > 3) {
155
+ setShowTopShadow(true);
156
+ setShowBottomShadow(true);
157
+ } else if (realInputRef.current.scrollTop > 0) {
158
+ setShowTopShadow(true);
159
+ setShowBottomShadow(false);
160
+ } else {
161
+ setShowTopShadow(false);
162
+ setShowBottomShadow(true);
163
+ }
164
+ }
165
+ }, 0);
166
+ };
167
+
168
+ var resetTextareaHeight = function resetTextareaHeight() {
169
+ setTimeout(function () {
170
+ var rows = realInputRef.current && Math.ceil(realInputRef.current.scrollHeight / 22);
171
+
172
+ if (rows && rows <= maxLine) {
173
+ setTextAreaRows(rows);
174
+ } else {
175
+ setTextAreaRows(maxLine);
176
+ }
177
+ }, 0);
178
+ }; // 鼠标移入
179
+
162
180
 
163
181
  var changeMoveOver = function changeMoveOver() {
164
182
  setIsTrue(true);
@@ -173,7 +191,7 @@ var Textarea = function Textarea(p) {
173
191
  var areaFocus = active ? "area-focus" : areaNormal;
174
192
  var areaError = error ? "area-error" : areaFocus;
175
193
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
176
- className: "\n ".concat(prefixCls, "\n ").concat(areaError, " \n ").concat(disabled ? " disabled" : "", "\n "),
194
+ className: "\n ".concat(prefixCls, "\n ").concat(areaError, "\n ").concat(disabled ? " disabled" : "", "\n "),
177
195
  onFocus: function onFocus() {},
178
196
  onBlur: function onBlur() {},
179
197
  onMouseOver: changeMoveOver,
@@ -185,24 +203,18 @@ var Textarea = function Textarea(p) {
185
203
  (_realInputRef$current = realInputRef.current) === null || _realInputRef$current === void 0 ? void 0 : _realInputRef$current.focus();
186
204
  }
187
205
  }, /*#__PURE__*/_react["default"].createElement("div", {
188
- className: "inner scrollbar-size-sm",
189
- style: autoHeight ? {
190
- maxHeight: maxHeight
191
- } : {
192
- height: "100%"
193
- }
206
+ className: (0, _classnames["default"])("inner scrollbar-size-sm", {
207
+ commonTextAreaWrapperTopShadow: showTopShadow,
208
+ commonTextAreaWrapperBottomShadow: showBottomShadow
209
+ })
194
210
  }, /*#__PURE__*/_react["default"].createElement("textarea", _extends({
195
211
  className: "".concat(className, " scrollbar-size-sm"),
196
212
  disabled: disabled,
197
213
  ref: realInputRef,
198
- style: _objectSpread(_objectSpread({}, style || {}), autoHeight ? {
199
- height: height
200
- } : {
201
- height: "100%"
202
- }),
203
214
  value: realValue,
204
- rows: 1,
215
+ rows: textAreaRows,
205
216
  placeholder: placeholder,
217
+ onScroll: handleShadowVisible,
206
218
  onChange: function onChange(e) {
207
219
  if (!isControlled) {
208
220
  setSelfValue(e.target.value);
@@ -212,6 +224,7 @@ var Textarea = function Textarea(p) {
212
224
  _onChange(e);
213
225
  }
214
226
 
227
+ resetTextareaHeight();
215
228
  setvalidateEnable(true);
216
229
  },
217
230
  onFocus: function onFocus(e) {
@@ -237,18 +250,7 @@ var Textarea = function Textarea(p) {
237
250
  _onBlur(e);
238
251
  }
239
252
  }
240
- }, others)), /*#__PURE__*/_react["default"].createElement("textarea", {
241
- className: className,
242
- ref: hiddenRef,
243
- placeholder: placeholder,
244
- value: realValue,
245
- rows: 1,
246
- style: _objectSpread(_objectSpread({}, style || {}), {
247
- height: "0!important",
248
- visibility: "hidden",
249
- position: "absolute"
250
- })
251
- }))), error && /*#__PURE__*/_react["default"].createElement("div", {
253
+ }, others)))), error && /*#__PURE__*/_react["default"].createElement("div", {
252
254
  className: "err-color"
253
255
  }, errorText));
254
256
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titaui/pc",
3
- "version": "1.11.27-beta.3",
3
+ "version": "1.11.27-beta.4",
4
4
  "nameCN": "",
5
5
  "description": "",
6
6
  "main": "lib/index.js",