@instructure/ui-text-area 11.6.0 → 11.6.1-snapshot-129
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 +40 -291
- package/es/TextArea/{index.js → v1/index.js} +2 -2
- package/es/TextArea/v2/index.js +350 -0
- package/es/TextArea/v2/props.js +26 -0
- package/es/TextArea/v2/styles.js +129 -0
- package/es/TextArea/v2/theme.js +76 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/TextArea/{index.js → v1/index.js} +4 -4
- package/lib/TextArea/v2/index.js +361 -0
- package/lib/TextArea/v2/props.js +31 -0
- package/lib/TextArea/v2/styles.js +135 -0
- package/lib/TextArea/v2/theme.js +82 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +43 -21
- package/src/TextArea/{index.tsx → v1/index.tsx} +2 -2
- package/src/TextArea/{props.ts → v1/props.ts} +1 -1
- package/src/TextArea/{styles.ts → v1/styles.ts} +4 -3
- package/src/TextArea/v2/README.md +136 -0
- package/src/TextArea/v2/index.tsx +434 -0
- package/src/TextArea/v2/props.ts +160 -0
- package/src/TextArea/v2/styles.ts +156 -0
- package/src/TextArea/v2/theme.ts +87 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TextArea/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/TextArea/v1/index.d.ts.map +1 -0
- package/types/TextArea/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/TextArea/v1/props.d.ts.map +1 -0
- package/types/TextArea/v1/styles.d.ts.map +1 -0
- package/types/TextArea/v1/theme.d.ts.map +1 -0
- package/types/TextArea/v2/index.d.ts +84 -0
- package/types/TextArea/v2/index.d.ts.map +1 -0
- package/types/TextArea/v2/props.d.ts +92 -0
- package/types/TextArea/v2/props.d.ts.map +1 -0
- package/types/TextArea/v2/styles.d.ts +21 -0
- package/types/TextArea/v2/styles.d.ts.map +1 -0
- package/types/TextArea/v2/theme.d.ts +10 -0
- package/types/TextArea/v2/theme.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/TextArea/index.d.ts.map +0 -1
- package/types/TextArea/props.d.ts.map +0 -1
- package/types/TextArea/styles.d.ts.map +0 -1
- package/types/TextArea/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/TextArea/{props.js → v1/props.js} +0 -0
- /package/es/TextArea/{styles.js → v1/styles.js} +0 -0
- /package/es/TextArea/{theme.js → v1/theme.js} +0 -0
- /package/lib/TextArea/{props.js → v1/props.js} +0 -0
- /package/lib/TextArea/{styles.js → v1/styles.js} +0 -0
- /package/lib/TextArea/{theme.js → v1/theme.js} +0 -0
- /package/src/TextArea/{README.md → v1/README.md} +0 -0
- /package/src/TextArea/{theme.ts → v1/theme.ts} +0 -0
- /package/types/TextArea/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/TextArea/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.TextArea = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _latest = require("@instructure/ui-form-field/latest");
|
|
11
|
+
var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
|
|
12
|
+
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
13
|
+
var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
|
|
14
|
+
var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
|
|
15
|
+
var _debounce = require("@instructure/debounce");
|
|
16
|
+
var _emotion = require("@instructure/emotion");
|
|
17
|
+
var _generateId = require("@instructure/ui-utils/lib/generateId.js");
|
|
18
|
+
var _px = require("@instructure/ui-utils/lib/px.js");
|
|
19
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
20
|
+
var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
|
|
21
|
+
var _DeterministicIdContext = require("@instructure/ui-react-utils/lib/DeterministicIdContext/DeterministicIdContext.js");
|
|
22
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
23
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
24
|
+
const _excluded = ["size", "autoGrow", "resize", "inline", "messages", "disabled", "readOnly", "layout", "required", "placeholder", "value", "defaultValue", "width", "height", "maxHeight", "textareaRef", "margin", "label", "onChange", "id", "themeOverride"];
|
|
25
|
+
/*
|
|
26
|
+
* The MIT License (MIT)
|
|
27
|
+
*
|
|
28
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
29
|
+
*
|
|
30
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
31
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
32
|
+
* in the Software without restriction, including without limitation the rights
|
|
33
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
34
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
35
|
+
* furnished to do so, subject to the following conditions:
|
|
36
|
+
*
|
|
37
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
38
|
+
* copies or substantial portions of the Software.
|
|
39
|
+
*
|
|
40
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
41
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
42
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
43
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
44
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
45
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
46
|
+
* SOFTWARE.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
---
|
|
50
|
+
category: components
|
|
51
|
+
---
|
|
52
|
+
**/
|
|
53
|
+
const TextArea = exports.TextArea = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
54
|
+
const _props$size = props.size,
|
|
55
|
+
size = _props$size === void 0 ? 'medium' : _props$size,
|
|
56
|
+
_props$autoGrow = props.autoGrow,
|
|
57
|
+
autoGrow = _props$autoGrow === void 0 ? true : _props$autoGrow,
|
|
58
|
+
_props$resize = props.resize,
|
|
59
|
+
resize = _props$resize === void 0 ? 'none' : _props$resize,
|
|
60
|
+
_props$inline = props.inline,
|
|
61
|
+
inline = _props$inline === void 0 ? false : _props$inline,
|
|
62
|
+
_props$messages = props.messages,
|
|
63
|
+
messages = _props$messages === void 0 ? [] : _props$messages,
|
|
64
|
+
_props$disabled = props.disabled,
|
|
65
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
66
|
+
_props$readOnly = props.readOnly,
|
|
67
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
68
|
+
_props$layout = props.layout,
|
|
69
|
+
layout = _props$layout === void 0 ? 'stacked' : _props$layout,
|
|
70
|
+
_props$required = props.required,
|
|
71
|
+
required = _props$required === void 0 ? false : _props$required,
|
|
72
|
+
placeholder = props.placeholder,
|
|
73
|
+
value = props.value,
|
|
74
|
+
defaultValue = props.defaultValue,
|
|
75
|
+
width = props.width,
|
|
76
|
+
height = props.height,
|
|
77
|
+
maxHeight = props.maxHeight,
|
|
78
|
+
textareaRef = props.textareaRef,
|
|
79
|
+
margin = props.margin,
|
|
80
|
+
label = props.label,
|
|
81
|
+
onChange = props.onChange,
|
|
82
|
+
propId = props.id,
|
|
83
|
+
themeOverride = props.themeOverride,
|
|
84
|
+
rest = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
85
|
+
|
|
86
|
+
// Use deterministic ID
|
|
87
|
+
const instanceCounterMap = (0, _react.useContext)(_DeterministicIdContext.DeterministicIdContext);
|
|
88
|
+
const defaultId = (0, _react.useMemo)(() => (0, _generateId.generateId)('TextArea', instanceCounterMap), [instanceCounterMap]);
|
|
89
|
+
const id = propId || defaultId;
|
|
90
|
+
|
|
91
|
+
// Use refs for mutable values
|
|
92
|
+
const _listener = (0, _react.useRef)();
|
|
93
|
+
const _request = (0, _react.useRef)();
|
|
94
|
+
const _textareaResizeListener = (0, _react.useRef)();
|
|
95
|
+
const _debounced = (0, _react.useRef)();
|
|
96
|
+
const _textarea = (0, _react.useRef)(null);
|
|
97
|
+
const _container = (0, _react.useRef)(null);
|
|
98
|
+
const _height = (0, _react.useRef)();
|
|
99
|
+
const _manuallyResized = (0, _react.useRef)(false);
|
|
100
|
+
const formFieldRef = (0, _react.useRef)(null);
|
|
101
|
+
|
|
102
|
+
// Compute invalid state
|
|
103
|
+
const _useMemo = (0, _react.useMemo)(() => {
|
|
104
|
+
const isInvalid = messages && messages.findIndex(message => message.type === 'error' || message.type === 'newError') >= 0;
|
|
105
|
+
const isSuccess = messages && messages.findIndex(message => message.type === 'success') >= 0;
|
|
106
|
+
return {
|
|
107
|
+
isInvalid,
|
|
108
|
+
isSuccess
|
|
109
|
+
};
|
|
110
|
+
}, [messages]),
|
|
111
|
+
isInvalid = _useMemo.isInvalid,
|
|
112
|
+
isSuccess = _useMemo.isSuccess;
|
|
113
|
+
|
|
114
|
+
// Use styles
|
|
115
|
+
const styles = (0, _emotion.useStyle)({
|
|
116
|
+
generateStyle: _styles.default,
|
|
117
|
+
themeOverride,
|
|
118
|
+
params: {
|
|
119
|
+
size,
|
|
120
|
+
disabled,
|
|
121
|
+
readOnly,
|
|
122
|
+
success: isSuccess,
|
|
123
|
+
invalid: isInvalid
|
|
124
|
+
},
|
|
125
|
+
componentId: 'TextArea',
|
|
126
|
+
displayName: 'TextArea'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Mock ResizeObserver for SSR
|
|
130
|
+
(0, _react.useEffect)(() => {
|
|
131
|
+
if (typeof window === 'undefined') {
|
|
132
|
+
global.ResizeObserver = class ResizeObserver {
|
|
133
|
+
observe() {
|
|
134
|
+
// do nothing
|
|
135
|
+
}
|
|
136
|
+
unobserve() {
|
|
137
|
+
// do nothing
|
|
138
|
+
}
|
|
139
|
+
disconnect() {
|
|
140
|
+
// do nothing
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}, []);
|
|
145
|
+
|
|
146
|
+
// Grow function
|
|
147
|
+
const grow = (0, _react.useCallback)(() => {
|
|
148
|
+
if (!_textarea.current || _manuallyResized.current) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const offset = _textarea.current.offsetHeight - _textarea.current.clientHeight;
|
|
152
|
+
let heightValue = '';
|
|
153
|
+
|
|
154
|
+
// Notes:
|
|
155
|
+
// 1. height has to be reset to `auto` every time this method runs, or scrollHeight will not reset
|
|
156
|
+
// 2. `_textarea.current.scrollHeight` will not reset if assigned to a variable; it needs to be written out each time
|
|
157
|
+
_textarea.current.style.height = 'auto';
|
|
158
|
+
_textarea.current.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
159
|
+
heightValue = _textarea.current.scrollHeight + offset + 'px';
|
|
160
|
+
const maxHeightPx = maxHeight ? (0, _px.px)(maxHeight, _container.current) : void 0;
|
|
161
|
+
if (maxHeight && maxHeightPx !== void 0 && _textarea.current.scrollHeight > maxHeightPx) {
|
|
162
|
+
_textarea.current.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
163
|
+
} else if (height) {
|
|
164
|
+
if (_textarea.current.value === '') {
|
|
165
|
+
heightValue = height;
|
|
166
|
+
} else if ((0, _px.px)(height, _container.current) > _textarea.current.scrollHeight) {
|
|
167
|
+
_textarea.current.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds height in pixels
|
|
168
|
+
heightValue = height;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// preserve container height to prevent scroll jumping on long textareas,
|
|
173
|
+
// but make sure container doesn't exceed maxHeight prop
|
|
174
|
+
const heightExceedsMax = maxHeightPx !== void 0 && (0, _px.px)(heightValue) > maxHeightPx;
|
|
175
|
+
if (!heightExceedsMax && _container.current) {
|
|
176
|
+
_container.current.style.minHeight = heightValue;
|
|
177
|
+
}
|
|
178
|
+
_height.current = heightValue;
|
|
179
|
+
_textarea.current.style.height = heightValue;
|
|
180
|
+
}, [height, maxHeight]);
|
|
181
|
+
|
|
182
|
+
// Textarea resize handler
|
|
183
|
+
const _textareaResize = (0, _react.useCallback)(() => {
|
|
184
|
+
if (!_textarea.current) return;
|
|
185
|
+
const textareaHeight = _textarea.current.style.height;
|
|
186
|
+
if (textareaHeight !== '' && textareaHeight !== _height.current) {
|
|
187
|
+
_manuallyResized.current = true;
|
|
188
|
+
_textarea.current.style.overflowY = 'auto';
|
|
189
|
+
|
|
190
|
+
// update container minHeight to ensure focus ring always wraps input
|
|
191
|
+
if (_container.current) {
|
|
192
|
+
_container.current.style.minHeight = textareaHeight;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, []);
|
|
196
|
+
|
|
197
|
+
// AutoGrow effect
|
|
198
|
+
(0, _react.useEffect)(() => {
|
|
199
|
+
if (autoGrow) {
|
|
200
|
+
if (!_debounced.current) {
|
|
201
|
+
_debounced.current = (0, _debounce.debounce)(grow, 200, {
|
|
202
|
+
leading: false,
|
|
203
|
+
trailing: true
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (!_listener.current) {
|
|
207
|
+
_listener.current = (0, _addEventListener.addEventListener)(window, 'resize', _debounced.current);
|
|
208
|
+
}
|
|
209
|
+
if (_textarea.current && !_textareaResizeListener.current) {
|
|
210
|
+
const _getBoundingClientRec = (0, _getBoundingClientRect.getBoundingClientRect)(_textarea.current),
|
|
211
|
+
origHeight = _getBoundingClientRec.height;
|
|
212
|
+
_textareaResizeListener.current = new ResizeObserver(entries => {
|
|
213
|
+
for (const entry of entries) {
|
|
214
|
+
const entryHeight = entry.contentRect.height;
|
|
215
|
+
if (origHeight !== entryHeight) {
|
|
216
|
+
_textareaResize();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
_textareaResizeListener.current.observe(_textarea.current);
|
|
221
|
+
}
|
|
222
|
+
_request.current = (0, _requestAnimationFrame.requestAnimationFrame)(grow);
|
|
223
|
+
}
|
|
224
|
+
}, [autoGrow, grow, _textareaResize]);
|
|
225
|
+
|
|
226
|
+
// Cleanup effect
|
|
227
|
+
(0, _react.useEffect)(() => {
|
|
228
|
+
return () => {
|
|
229
|
+
if (_listener.current) {
|
|
230
|
+
_listener.current.remove();
|
|
231
|
+
}
|
|
232
|
+
if (_textareaResizeListener.current) {
|
|
233
|
+
_textareaResizeListener.current.disconnect();
|
|
234
|
+
}
|
|
235
|
+
if (_request.current) {
|
|
236
|
+
_request.current.cancel();
|
|
237
|
+
}
|
|
238
|
+
if (_debounced.current) {
|
|
239
|
+
_debounced.current.cancel();
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}, []);
|
|
243
|
+
|
|
244
|
+
// Handle change
|
|
245
|
+
const handleChange = (0, _react.useCallback)(event => {
|
|
246
|
+
if (disabled || readOnly) {
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (typeof value === 'undefined') {
|
|
251
|
+
// if uncontrolled
|
|
252
|
+
if (autoGrow) {
|
|
253
|
+
if (!_debounced.current) {
|
|
254
|
+
_debounced.current = (0, _debounce.debounce)(grow, 200, {
|
|
255
|
+
leading: false,
|
|
256
|
+
trailing: true
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (!_listener.current) {
|
|
260
|
+
_listener.current = (0, _addEventListener.addEventListener)(window, 'resize', _debounced.current);
|
|
261
|
+
}
|
|
262
|
+
if (_textarea.current && !_textareaResizeListener.current) {
|
|
263
|
+
const _getBoundingClientRec2 = (0, _getBoundingClientRect.getBoundingClientRect)(_textarea.current),
|
|
264
|
+
origHeight = _getBoundingClientRec2.height;
|
|
265
|
+
_textareaResizeListener.current = new ResizeObserver(entries => {
|
|
266
|
+
for (const entry of entries) {
|
|
267
|
+
const entryHeight = entry.contentRect.height;
|
|
268
|
+
if (origHeight !== entryHeight) {
|
|
269
|
+
_textareaResize();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
_textareaResizeListener.current.observe(_textarea.current);
|
|
274
|
+
}
|
|
275
|
+
_request.current = (0, _requestAnimationFrame.requestAnimationFrame)(grow);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (typeof onChange === 'function') {
|
|
279
|
+
onChange(event);
|
|
280
|
+
}
|
|
281
|
+
}, [disabled, readOnly, value, onChange, autoGrow, grow, _textareaResize]);
|
|
282
|
+
|
|
283
|
+
// Expose API through ref using useImperativeHandle
|
|
284
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
285
|
+
focus: () => {
|
|
286
|
+
var _textarea$current;
|
|
287
|
+
(_textarea$current = _textarea.current) === null || _textarea$current === void 0 ? void 0 : _textarea$current.focus();
|
|
288
|
+
},
|
|
289
|
+
get value() {
|
|
290
|
+
var _textarea$current2;
|
|
291
|
+
return ((_textarea$current2 = _textarea.current) === null || _textarea$current2 === void 0 ? void 0 : _textarea$current2.value) || '';
|
|
292
|
+
},
|
|
293
|
+
get minHeight() {
|
|
294
|
+
var _textarea$current3;
|
|
295
|
+
return ((_textarea$current3 = _textarea.current) === null || _textarea$current3 === void 0 ? void 0 : _textarea$current3.style.minHeight) || '';
|
|
296
|
+
},
|
|
297
|
+
get focused() {
|
|
298
|
+
return (0, _isActiveElement.isActiveElement)(_textarea.current);
|
|
299
|
+
},
|
|
300
|
+
get invalid() {
|
|
301
|
+
return messages && messages.findIndex(message => message.type === 'error' || message.type === 'newError') >= 0;
|
|
302
|
+
},
|
|
303
|
+
get id() {
|
|
304
|
+
return id;
|
|
305
|
+
}
|
|
306
|
+
}), [id, messages]);
|
|
307
|
+
const style = {
|
|
308
|
+
width,
|
|
309
|
+
resize,
|
|
310
|
+
height: !autoGrow ? height : void 0,
|
|
311
|
+
maxHeight
|
|
312
|
+
};
|
|
313
|
+
const textarea = (0, _jsxRuntime.jsx)("textarea", {
|
|
314
|
+
...(0, _passthroughProps.passthroughProps)(rest),
|
|
315
|
+
value: value,
|
|
316
|
+
defaultValue: defaultValue,
|
|
317
|
+
placeholder: placeholder,
|
|
318
|
+
ref: textarea => {
|
|
319
|
+
_textarea.current = textarea;
|
|
320
|
+
if (typeof textareaRef === 'function') {
|
|
321
|
+
textareaRef(textarea);
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
style: style,
|
|
325
|
+
id: id,
|
|
326
|
+
required: required,
|
|
327
|
+
"aria-required": required,
|
|
328
|
+
"aria-invalid": isInvalid ? 'true' : void 0,
|
|
329
|
+
disabled: disabled,
|
|
330
|
+
readOnly: readOnly,
|
|
331
|
+
css: styles === null || styles === void 0 ? void 0 : styles.textArea,
|
|
332
|
+
onChange: handleChange
|
|
333
|
+
});
|
|
334
|
+
return (0, _jsxRuntime.jsx)(_latest.FormField, {
|
|
335
|
+
...(0, _pickProps.pickProps)(props, _latest.FormField.allowedProps),
|
|
336
|
+
label: label,
|
|
337
|
+
vAlign: "top",
|
|
338
|
+
id: id,
|
|
339
|
+
elementRef: el => {
|
|
340
|
+
formFieldRef.current = el;
|
|
341
|
+
},
|
|
342
|
+
margin: margin,
|
|
343
|
+
isRequired: required,
|
|
344
|
+
disabled: disabled,
|
|
345
|
+
readOnly: readOnly,
|
|
346
|
+
"data-cid": "TextArea",
|
|
347
|
+
children: (0, _jsxRuntime.jsx)("div", {
|
|
348
|
+
css: styles === null || styles === void 0 ? void 0 : styles.textAreaLayout,
|
|
349
|
+
style: {
|
|
350
|
+
width,
|
|
351
|
+
maxHeight
|
|
352
|
+
},
|
|
353
|
+
ref: node => {
|
|
354
|
+
_container.current = node;
|
|
355
|
+
},
|
|
356
|
+
children: textarea
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
TextArea.displayName = 'TextArea';
|
|
361
|
+
var _default = exports.default = TextArea;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['label', 'id', 'size', 'layout', 'autoGrow', 'resize', 'width', 'height', 'maxHeight', 'messages', 'inline', 'placeholder', 'disabled', 'readOnly', 'required', 'textareaRef', 'defaultValue', 'value', 'onChange', 'margin'];
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _emotion = require("@instructure/emotion");
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ---
|
|
34
|
+
* private: true
|
|
35
|
+
* ---
|
|
36
|
+
* Generates the style object from the theme and provided additional information
|
|
37
|
+
* @param {Object} componentTheme The theme variable object.
|
|
38
|
+
* @param {Object} params Additional parameters to customize the style.
|
|
39
|
+
* @return {Object} The final style object, which will be used in the component
|
|
40
|
+
*/
|
|
41
|
+
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
42
|
+
const disabled = params.disabled,
|
|
43
|
+
size = params.size,
|
|
44
|
+
success = params.success,
|
|
45
|
+
invalid = params.invalid,
|
|
46
|
+
readOnly = params.readOnly;
|
|
47
|
+
const fontSizeVariants = {
|
|
48
|
+
small: {
|
|
49
|
+
fontSize: componentTheme.fontSizeSm
|
|
50
|
+
},
|
|
51
|
+
medium: {
|
|
52
|
+
fontSize: componentTheme.fontSizeMd
|
|
53
|
+
},
|
|
54
|
+
large: {
|
|
55
|
+
fontSize: componentTheme.fontSizeLg
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const focusColor = disabled || readOnly ? 'info' : invalid ? 'danger' : success ? 'success' : 'info';
|
|
59
|
+
return {
|
|
60
|
+
textArea: {
|
|
61
|
+
label: 'textArea',
|
|
62
|
+
all: 'initial',
|
|
63
|
+
WebkitFontSmoothing: 'antialiased',
|
|
64
|
+
MozOsxFontSmoothing: 'grayscale',
|
|
65
|
+
appearance: 'none',
|
|
66
|
+
height: 'auto',
|
|
67
|
+
margin: 0,
|
|
68
|
+
width: '100%',
|
|
69
|
+
display: 'block',
|
|
70
|
+
boxSizing: 'border-box',
|
|
71
|
+
padding: componentTheme.padding,
|
|
72
|
+
fontFamily: componentTheme.fontFamily,
|
|
73
|
+
fontWeight: componentTheme.fontWeight,
|
|
74
|
+
borderWidth: componentTheme.borderWidth,
|
|
75
|
+
borderStyle: 'solid',
|
|
76
|
+
borderColor: componentTheme.borderColor,
|
|
77
|
+
borderRadius: componentTheme.borderRadius,
|
|
78
|
+
color: componentTheme.textColor,
|
|
79
|
+
background: componentTheme.backgroundColor,
|
|
80
|
+
whiteSpace: 'pre-wrap',
|
|
81
|
+
wordWrap: 'break-word',
|
|
82
|
+
textAlign: 'start',
|
|
83
|
+
...(!disabled && !readOnly && {
|
|
84
|
+
'&:hover': {
|
|
85
|
+
background: componentTheme.backgroundHoverColor,
|
|
86
|
+
borderColor: componentTheme.borderHoverColor,
|
|
87
|
+
'&::placeholder': {
|
|
88
|
+
color: componentTheme.placeholderHoverColor
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
...(readOnly && {
|
|
93
|
+
color: componentTheme.textReadonlyColor,
|
|
94
|
+
background: componentTheme.backgroundReadonlyColor,
|
|
95
|
+
borderColor: componentTheme.borderReadonlyColor
|
|
96
|
+
}),
|
|
97
|
+
...(disabled && {
|
|
98
|
+
color: componentTheme.textDisabledColor,
|
|
99
|
+
background: componentTheme.backgroundDisabledColor,
|
|
100
|
+
borderColor: componentTheme.borderDisabledColor,
|
|
101
|
+
cursor: 'not-allowed',
|
|
102
|
+
pointerEvents: 'none',
|
|
103
|
+
opacity: 0.5
|
|
104
|
+
}),
|
|
105
|
+
...(!disabled && !readOnly && success && {
|
|
106
|
+
borderColor: componentTheme.successBorderColor
|
|
107
|
+
}),
|
|
108
|
+
...fontSizeVariants[size],
|
|
109
|
+
...(0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
|
|
110
|
+
focusColor
|
|
111
|
+
}),
|
|
112
|
+
...(!disabled && !readOnly && {
|
|
113
|
+
'&[aria-invalid], &[aria-invalid]:focus': {
|
|
114
|
+
borderColor: componentTheme.errorBorderColor
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
'&::placeholder': {
|
|
118
|
+
color: componentTheme.placeholderColor
|
|
119
|
+
},
|
|
120
|
+
'&::-webkit-resizer': {
|
|
121
|
+
backgroundImage: `url("data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" viewBox="0 0 9 9" fill="none"><path d="M8.35352 0.353516L0.353516 8.35352M8.35352 4.35352L4.35352 8.35352" stroke="#8D959F"/></svg>')}")`,
|
|
122
|
+
backgroundColor: 'transparent',
|
|
123
|
+
backgroundPosition: 'bottom 2px right 2px',
|
|
124
|
+
// Position away from edges
|
|
125
|
+
backgroundRepeat: 'no-repeat',
|
|
126
|
+
backgroundSize: '10px 10px'
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
textAreaLayout: {
|
|
130
|
+
label: 'textArea__layout',
|
|
131
|
+
position: 'relative'
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
var _default = exports.default = generateStyle;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generates the theme object for the component from the theme and provided additional information
|
|
33
|
+
* @param {Object} theme The actual theme object.
|
|
34
|
+
* @return {Object} The final theme object with the overrides and component variables
|
|
35
|
+
*/
|
|
36
|
+
const generateComponentTheme = theme => {
|
|
37
|
+
var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6, _colors$contrasts7, _colors$contrasts8, _colors$contrasts9, _colors$contrasts0, _colors$contrasts1;
|
|
38
|
+
const colors = theme.colors,
|
|
39
|
+
typography = theme.typography,
|
|
40
|
+
borders = theme.borders,
|
|
41
|
+
spacing = theme.spacing,
|
|
42
|
+
forms = theme.forms,
|
|
43
|
+
themeName = theme.key;
|
|
44
|
+
const themeSpecificStyle = {
|
|
45
|
+
canvas: {
|
|
46
|
+
color: theme['ic-brand-font-color-dark'],
|
|
47
|
+
focusOutlineColor: theme['ic-brand-primary']
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const componentVariables = {
|
|
51
|
+
fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
|
|
52
|
+
fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
|
|
53
|
+
color: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.grey125125,
|
|
54
|
+
background: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.white1010,
|
|
55
|
+
requiredInvalidColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.red5782,
|
|
56
|
+
borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
|
|
57
|
+
borderStyle: borders === null || borders === void 0 ? void 0 : borders.style,
|
|
58
|
+
borderTopColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.grey3045,
|
|
59
|
+
borderRightColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.grey3045,
|
|
60
|
+
borderBottomColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.grey3045,
|
|
61
|
+
borderLeftColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts7 = colors.contrasts) === null || _colors$contrasts7 === void 0 ? void 0 : _colors$contrasts7.grey3045,
|
|
62
|
+
borderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium,
|
|
63
|
+
padding: spacing === null || spacing === void 0 ? void 0 : spacing.small,
|
|
64
|
+
focusOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts8 = colors.contrasts) === null || _colors$contrasts8 === void 0 ? void 0 : _colors$contrasts8.blue4570,
|
|
65
|
+
focusOutlineWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
|
|
66
|
+
focusOutlineStyle: borders === null || borders === void 0 ? void 0 : borders.style,
|
|
67
|
+
errorBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts9 = colors.contrasts) === null || _colors$contrasts9 === void 0 ? void 0 : _colors$contrasts9.red4570,
|
|
68
|
+
errorOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts0 = colors.contrasts) === null || _colors$contrasts0 === void 0 ? void 0 : _colors$contrasts0.red4570,
|
|
69
|
+
placeholderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts1 = colors.contrasts) === null || _colors$contrasts1 === void 0 ? void 0 : _colors$contrasts1.grey4570,
|
|
70
|
+
smallFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeSmall,
|
|
71
|
+
smallHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightSmall,
|
|
72
|
+
mediumFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
|
|
73
|
+
mediumHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightMedium,
|
|
74
|
+
largeFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeLarge,
|
|
75
|
+
largeHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightLarge
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
...componentVariables,
|
|
79
|
+
...themeSpecificStyle[themeName]
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var _default = exports.default = generateComponentTheme;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "TextArea", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _v.TextArea;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _v = require("../TextArea/v1");
|
package/lib/exports/b.js
ADDED