@instructure/ui-text-input 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.
Files changed (62) hide show
  1. package/CHANGELOG.md +47 -305
  2. package/es/TextInput/{index.js → v1/index.js} +2 -2
  3. package/es/TextInput/v2/index.js +308 -0
  4. package/es/TextInput/v2/props.js +26 -0
  5. package/es/TextInput/v2/styles.js +234 -0
  6. package/es/TextInput/v2/theme.js +73 -0
  7. package/es/{index.js → exports/a.js} +1 -1
  8. package/{src/index.ts → es/exports/b.js} +1 -2
  9. package/lib/TextInput/{index.js → v1/index.js} +3 -3
  10. package/lib/TextInput/v2/index.js +319 -0
  11. package/lib/TextInput/v2/props.js +31 -0
  12. package/lib/TextInput/v2/styles.js +239 -0
  13. package/lib/TextInput/v2/theme.js +79 -0
  14. package/lib/{index.js → exports/a.js} +2 -2
  15. package/lib/exports/b.js +12 -0
  16. package/package.json +45 -24
  17. package/src/TextInput/{index.tsx → v1/index.tsx} +2 -2
  18. package/src/TextInput/{props.ts → v1/props.ts} +1 -1
  19. package/src/TextInput/v2/README.md +334 -0
  20. package/src/TextInput/v2/index.tsx +406 -0
  21. package/src/TextInput/v2/props.ts +244 -0
  22. package/src/TextInput/v2/styles.ts +245 -0
  23. package/src/TextInput/v2/theme.ts +84 -0
  24. package/src/exports/a.ts +25 -0
  25. package/src/exports/b.ts +25 -0
  26. package/tsconfig.build.json +0 -3
  27. package/tsconfig.build.tsbuildinfo +1 -1
  28. package/types/TextInput/{index.d.ts → v1/index.d.ts} +1 -1
  29. package/types/TextInput/v1/index.d.ts.map +1 -0
  30. package/types/TextInput/{props.d.ts → v1/props.d.ts} +1 -1
  31. package/types/TextInput/v1/props.d.ts.map +1 -0
  32. package/types/TextInput/v1/styles.d.ts.map +1 -0
  33. package/types/TextInput/v1/theme.d.ts.map +1 -0
  34. package/types/TextInput/v2/index.d.ts +79 -0
  35. package/types/TextInput/v2/index.d.ts.map +1 -0
  36. package/types/TextInput/v2/props.d.ts +138 -0
  37. package/types/TextInput/v2/props.d.ts.map +1 -0
  38. package/types/TextInput/v2/styles.d.ts +16 -0
  39. package/types/TextInput/v2/styles.d.ts.map +1 -0
  40. package/types/TextInput/v2/theme.d.ts +10 -0
  41. package/types/TextInput/v2/theme.d.ts.map +1 -0
  42. package/types/exports/a.d.ts +3 -0
  43. package/types/exports/a.d.ts.map +1 -0
  44. package/types/exports/b.d.ts +3 -0
  45. package/types/exports/b.d.ts.map +1 -0
  46. package/types/TextInput/index.d.ts.map +0 -1
  47. package/types/TextInput/props.d.ts.map +0 -1
  48. package/types/TextInput/styles.d.ts.map +0 -1
  49. package/types/TextInput/theme.d.ts.map +0 -1
  50. package/types/index.d.ts +0 -3
  51. package/types/index.d.ts.map +0 -1
  52. /package/es/TextInput/{props.js → v1/props.js} +0 -0
  53. /package/es/TextInput/{styles.js → v1/styles.js} +0 -0
  54. /package/es/TextInput/{theme.js → v1/theme.js} +0 -0
  55. /package/lib/TextInput/{props.js → v1/props.js} +0 -0
  56. /package/lib/TextInput/{styles.js → v1/styles.js} +0 -0
  57. /package/lib/TextInput/{theme.js → v1/theme.js} +0 -0
  58. /package/src/TextInput/{README.md → v1/README.md} +0 -0
  59. /package/src/TextInput/{styles.ts → v1/styles.ts} +0 -0
  60. /package/src/TextInput/{theme.ts → v1/theme.ts} +0 -0
  61. /package/types/TextInput/{styles.d.ts → v1/styles.d.ts} +0 -0
  62. /package/types/TextInput/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -14,7 +14,7 @@ var _withDeterministicId = require("@instructure/ui-react-utils/lib/Deterministi
14
14
  var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
15
15
  var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
16
16
  var _getCSSStyleDeclaration = require("@instructure/ui-dom-utils/lib/getCSSStyleDeclaration.js");
17
- var _FormField = require("@instructure/ui-form-field/lib/FormField");
17
+ var _v11_ = require("@instructure/ui-form-field/v11_6");
18
18
  var _emotion = require("@instructure/emotion");
19
19
  var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
20
20
  var _styles = _interopRequireDefault(require("./styles"));
@@ -52,7 +52,7 @@ category: components
52
52
  tags: form, field
53
53
  ---
54
54
  **/
55
- let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_TextInput = class TextInput extends _react.Component {
55
+ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_TextInput = class TextInput extends _react.Component {
56
56
  constructor(props) {
57
57
  super(props);
58
58
  this.ref = null;
@@ -277,7 +277,7 @@ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDetermi
277
277
  children: [' ', "*"]
278
278
  })]
279
279
  }) : rawLabel;
280
- return (0, _jsxRuntime.jsx)(_FormField.FormField, {
280
+ return (0, _jsxRuntime.jsx)(_v11_.FormField, {
281
281
  id: this.id,
282
282
  label: label,
283
283
  messagesId: this._messagesId,
@@ -0,0 +1,319 @@
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.TextInput = void 0;
8
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
+ var _react = require("react");
10
+ var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
11
+ var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
12
+ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
13
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
14
+ var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
15
+ var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
16
+ var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
17
+ var _getCSSStyleDeclaration = require("@instructure/ui-dom-utils/lib/getCSSStyleDeclaration.js");
18
+ var _latest = require("@instructure/ui-form-field/latest");
19
+ var _emotion = require("@instructure/emotion");
20
+ var _styles = _interopRequireDefault(require("./styles"));
21
+ var _props = require("./props");
22
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
23
+ const _excluded = ["type", "size", "htmlSize", "display", "textAlign", "placeholder", "value", "defaultValue", "isRequired", "onFocus"];
24
+ var _dec, _dec2, _class, _TextInput;
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
+ tags: form, field, input
52
+ ---
53
+ **/
54
+ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_TextInput = class TextInput extends _react.Component {
55
+ constructor(props) {
56
+ super(props);
57
+ this.ref = null;
58
+ this._input = null;
59
+ this._afterElement = null;
60
+ this._defaultId = void 0;
61
+ this._messagesId = void 0;
62
+ this._focusListener = null;
63
+ this.handleRef = el => {
64
+ const elementRef = this.props.elementRef;
65
+ this.ref = el;
66
+ if (typeof elementRef === 'function') {
67
+ elementRef(el);
68
+ }
69
+ };
70
+ this.makeStyleProps = () => {
71
+ const afterElementHasWidth = this.state.afterElementHasWidth;
72
+ const beforeElement = this.props.renderBeforeInput ? (0, _callRenderProp.callRenderProp)(this.props.renderBeforeInput) : null;
73
+ const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
74
+ return {
75
+ interaction: this.interaction,
76
+ invalid: this.invalid,
77
+ success: success,
78
+ afterElementHasWidth: afterElementHasWidth,
79
+ beforeElementExists: !!beforeElement
80
+ };
81
+ };
82
+ this.handleInputRef = node => {
83
+ this._input = node;
84
+ if (typeof this.props.inputRef === 'function') {
85
+ this.props.inputRef(node);
86
+ }
87
+ };
88
+ this.handleChange = event => {
89
+ if (typeof this.props.onChange === 'function') {
90
+ this.props.onChange(event, event.target.value);
91
+ }
92
+ };
93
+ this.handleBlur = event => {
94
+ if (typeof this.props.onBlur === 'function') {
95
+ this.props.onBlur(event);
96
+ }
97
+ };
98
+ this.handleFocus = event => {
99
+ if (typeof this.props.onFocus === 'function') {
100
+ this.props.onFocus(event);
101
+ }
102
+ };
103
+ this.state = {
104
+ afterElementHasWidth: void 0
105
+ };
106
+ this._defaultId = props.deterministicId();
107
+ this._messagesId = props.deterministicId('TextInput-messages');
108
+ }
109
+ componentDidMount() {
110
+ var _this$props$makeStyle, _this$props;
111
+ if (this._input) {
112
+ this._focusListener = (0, _addEventListener.addEventListener)(this._input, 'focus', this.handleFocus);
113
+ this.setState({
114
+ afterElementHasWidth: this.getElementHasWidth(this._afterElement)
115
+ });
116
+ }
117
+ this.adjustAfterElementHeight();
118
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
119
+ }
120
+ componentWillUnmount() {
121
+ if (this._focusListener) {
122
+ this._focusListener.remove();
123
+ }
124
+ }
125
+ componentDidUpdate(prevProps) {
126
+ var _this$props$makeStyle2, _this$props2;
127
+ if (prevProps.renderAfterInput !== this.props.renderAfterInput) {
128
+ this.setState({
129
+ afterElementHasWidth: this.getElementHasWidth(this._afterElement)
130
+ });
131
+ }
132
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
133
+ }
134
+ renderInstUIIcon(elementToRender) {
135
+ var _type;
136
+ if (!elementToRender) {
137
+ return null;
138
+ }
139
+ const rendered = (0, _callRenderProp.callRenderProp)(elementToRender);
140
+ // Map sizes to Lucide icon semantic size tokens
141
+ const linkSizeToIconSize = {
142
+ small: 'sm',
143
+ medium: 'md',
144
+ large: 'lg'
145
+ };
146
+ const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
147
+ if (/*#__PURE__*/(0, _react.isValidElement)(elementToRender) && ((_type = elementToRender.type) === null || _type === void 0 ? void 0 : _type.name) === 'WrappedIcon') {
148
+ return (0, _safeCloneElement.safeCloneElement)(rendered, {
149
+ size: iconSize
150
+ });
151
+ }
152
+ return rendered;
153
+ }
154
+ adjustAfterElementHeight() {
155
+ var _this$_afterElement, _afterElementChild$fi;
156
+ const afterElementChild = (_this$_afterElement = this._afterElement) === null || _this$_afterElement === void 0 ? void 0 : _this$_afterElement.firstElementChild;
157
+
158
+ // Check if the child is a button, then get the button's first child (the content span)
159
+ const buttonContentSpan = (afterElementChild === null || afterElementChild === void 0 ? void 0 : afterElementChild.tagName) === 'BUTTON' ? afterElementChild.firstElementChild : null;
160
+
161
+ // This is a necessary workaround for DateInput2 because it uses a Popover, which has a nested Button as an afterElement
162
+ // Check if the child is a Popover's inner span containing a button, then get the button's first child (the content span)
163
+ const popoverContentSpan = (afterElementChild === null || afterElementChild === void 0 ? void 0 : afterElementChild.tagName) === 'SPAN' && ((_afterElementChild$fi = afterElementChild.firstElementChild) === null || _afterElementChild$fi === void 0 ? void 0 : _afterElementChild$fi.tagName) === 'BUTTON' ? afterElementChild.firstElementChild.firstElementChild : null;
164
+ const targetSpan = buttonContentSpan !== null && buttonContentSpan !== void 0 ? buttonContentSpan : popoverContentSpan;
165
+ if (targetSpan) {
166
+ // Set the height to 36px (the height of a medium TextInput) to avoid layout shift when the afterElement content changes
167
+ // this temporary workaround is necessary because otherwise the layout breaks, later on IconButton's default height will be adjusted to the TextInput size
168
+ // so this workaround will not be needed anymore
169
+ targetSpan.style.height = '36px';
170
+ }
171
+ }
172
+ focus() {
173
+ var _this$_input;
174
+ (_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
175
+ }
176
+ get interaction() {
177
+ return (0, _getInteraction.getInteraction)({
178
+ props: this.props
179
+ });
180
+ }
181
+ get hasMessages() {
182
+ return !!this.props.messages && this.props.messages.length > 0;
183
+ }
184
+ get invalid() {
185
+ return !!this.props.messages && this.props.messages.findIndex(message => {
186
+ return message.type === 'error' || message.type === 'newError';
187
+ }) >= 0;
188
+ }
189
+ get focused() {
190
+ return (0, _isActiveElement.isActiveElement)(this._input);
191
+ }
192
+ get value() {
193
+ var _this$_input2;
194
+ return (_this$_input2 = this._input) === null || _this$_input2 === void 0 ? void 0 : _this$_input2.value;
195
+ }
196
+ get id() {
197
+ return this.props.id || this._defaultId;
198
+ }
199
+ renderInput() {
200
+ var _this$props$styles;
201
+ const _this$props3 = this.props,
202
+ type = _this$props3.type,
203
+ size = _this$props3.size,
204
+ htmlSize = _this$props3.htmlSize,
205
+ display = _this$props3.display,
206
+ textAlign = _this$props3.textAlign,
207
+ placeholder = _this$props3.placeholder,
208
+ value = _this$props3.value,
209
+ defaultValue = _this$props3.defaultValue,
210
+ isRequired = _this$props3.isRequired,
211
+ onFocus = _this$props3.onFocus,
212
+ rest = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
213
+ const props = (0, _passthroughProps.passthroughProps)(rest);
214
+ const interaction = this.interaction;
215
+ let descriptionIds = '';
216
+ if (props['aria-describedby']) {
217
+ descriptionIds = `${props['aria-describedby']}`;
218
+ }
219
+ return (0, _jsxRuntime.jsx)("input", {
220
+ ...props,
221
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.textInput,
222
+ defaultValue: defaultValue,
223
+ value: value,
224
+ placeholder: interaction === 'enabled' ? placeholder : void 0,
225
+ ref: this.handleInputRef,
226
+ type: type,
227
+ id: this.id,
228
+ required: isRequired,
229
+ "aria-invalid": this.invalid ? 'true' : void 0,
230
+ disabled: interaction === 'disabled',
231
+ readOnly: interaction === 'readonly',
232
+ "aria-describedby": descriptionIds !== '' ? descriptionIds : void 0,
233
+ size: htmlSize,
234
+ onChange: this.handleChange,
235
+ onBlur: this.handleBlur
236
+ });
237
+ }
238
+ getElementHasWidth(element) {
239
+ if (!element) {
240
+ return void 0;
241
+ }
242
+ const computedStyle = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element);
243
+ if (!computedStyle) {
244
+ return void 0;
245
+ }
246
+ const width = computedStyle.width,
247
+ paddingInlineStart = computedStyle.paddingInlineStart,
248
+ paddingInlineEnd = computedStyle.paddingInlineEnd;
249
+ if (width === 'auto' || width === '') {
250
+ // This is a workaround for an edge-case, when the TextInput's parent
251
+ // is hidden on load, so the element is not visible either.
252
+ // In this case the computed width is going to be either 'auto' or '',
253
+ // so we assume it has width so that the padding won't be removed.
254
+ return true;
255
+ }
256
+ const elementWidth = parseFloat(width) - parseFloat(paddingInlineStart) - parseFloat(paddingInlineEnd);
257
+ return elementWidth > 0;
258
+ }
259
+ render() {
260
+ const _this$props4 = this.props,
261
+ width = _this$props4.width,
262
+ display = _this$props4.display,
263
+ renderLabel = _this$props4.renderLabel,
264
+ renderBeforeInput = _this$props4.renderBeforeInput,
265
+ renderAfterInput = _this$props4.renderAfterInput,
266
+ messages = _this$props4.messages,
267
+ inputContainerRef = _this$props4.inputContainerRef,
268
+ isRequired = _this$props4.isRequired,
269
+ styles = _this$props4.styles;
270
+ const beforeElement = this.renderInstUIIcon(renderBeforeInput);
271
+ const afterElement = this.renderInstUIIcon(renderAfterInput);
272
+ const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== void 0 || renderAfterInput !== void 0;
273
+ const label = (0, _callRenderProp.callRenderProp)(renderLabel);
274
+ return (0, _jsxRuntime.jsx)(_latest.FormField, {
275
+ id: this.id,
276
+ label: label,
277
+ messagesId: this._messagesId,
278
+ messages: messages,
279
+ inline: display === 'inline-block',
280
+ width: width,
281
+ inputContainerRef: inputContainerRef,
282
+ layout: this.props.layout,
283
+ elementRef: this.handleRef,
284
+ margin: this.props.margin,
285
+ isRequired: isRequired,
286
+ disabled: this.interaction === 'disabled',
287
+ readOnly: this.interaction === 'readonly',
288
+ "data-cid": "TextInput",
289
+ children: (0, _jsxRuntime.jsx)("span", {
290
+ css: styles === null || styles === void 0 ? void 0 : styles.facade,
291
+ children: renderBeforeOrAfter ? (0, _jsxRuntime.jsxs)("span", {
292
+ css: styles === null || styles === void 0 ? void 0 : styles.layout,
293
+ children: [beforeElement, (0, _jsxRuntime.jsxs)("span", {
294
+ css: styles === null || styles === void 0 ? void 0 : styles.inputLayout,
295
+ children: [this.renderInput(), afterElement && (0, _jsxRuntime.jsx)("span", {
296
+ css: styles === null || styles === void 0 ? void 0 : styles.afterElement,
297
+ ref: e => {
298
+ this._afterElement = e;
299
+ },
300
+ children: afterElement
301
+ })]
302
+ })]
303
+ }) : (/* If no prepended or appended content, don't render Flex layout */
304
+ this.renderInput())
305
+ })
306
+ });
307
+ }
308
+ }, _TextInput.displayName = "TextInput", _TextInput.componentId = 'TextInput', _TextInput.allowedProps = _props.allowedProps, _TextInput.defaultProps = {
309
+ type: 'text',
310
+ // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
311
+ interaction: void 0,
312
+ isRequired: false,
313
+ display: 'block',
314
+ shouldNotWrap: false,
315
+ size: 'medium',
316
+ textAlign: 'start',
317
+ messages: []
318
+ }, _TextInput)) || _class) || _class);
319
+ var _default = exports.default = TextInput;
@@ -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 = ['renderLabel', 'type', 'id', 'value', 'defaultValue', 'interaction', 'messages', 'size', 'textAlign', 'width', 'htmlSize', 'display', 'shouldNotWrap', 'placeholder', 'isRequired', 'elementRef', 'inputRef', 'inputContainerRef', 'renderBeforeInput', 'renderAfterInput', 'onChange', 'onBlur', 'onFocus', 'margin'];
@@ -0,0 +1,239 @@
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 componentTheme The theme variable object.
38
+ * @param props the props of the component, the style is applied to
39
+ * @param sharedTokens Shared token object that stores common values for the theme.
40
+ * @param state the state of the component, the style is applied to
41
+ * @return The final style object, which will be used in the component
42
+ */
43
+ const generateStyle = (componentTheme, props, sharedTokens, state) => {
44
+ const size = props.size,
45
+ textAlign = props.textAlign,
46
+ shouldNotWrap = props.shouldNotWrap;
47
+ const interaction = state.interaction,
48
+ success = state.success,
49
+ invalid = state.invalid,
50
+ afterElementHasWidth = state.afterElementHasWidth,
51
+ beforeElementExists = state.beforeElementExists;
52
+ const sizeVariants = {
53
+ small: {
54
+ fontSize: componentTheme.fontSizeSm,
55
+ height: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`,
56
+ lineHeight: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`
57
+ },
58
+ medium: {
59
+ fontSize: componentTheme.fontSizeMd,
60
+ height: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`,
61
+ lineHeight: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`
62
+ },
63
+ large: {
64
+ fontSize: componentTheme.fontSizeLg,
65
+ height: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`,
66
+ lineHeight: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`
67
+ }
68
+ };
69
+ const paddingHorizontalVariants = {
70
+ small: componentTheme.paddingHorizontalSm,
71
+ medium: componentTheme.paddingHorizontalMd,
72
+ large: componentTheme.paddingHorizontalLg
73
+ };
74
+ const inputInteractionStates = {
75
+ ...(interaction === 'enabled' && {
76
+ color: componentTheme.textColor,
77
+ '&::placeholder': {
78
+ color: componentTheme.placeholderColor
79
+ },
80
+ '&:hover::placeholder': {
81
+ color: componentTheme.placeholderHoverColor
82
+ }
83
+ // placeholder is not rendered in the `readOnly` and `disabled` state
84
+ }),
85
+ ...(interaction === 'readonly' && {
86
+ color: componentTheme.textReadonlyColor
87
+ }),
88
+ ...(interaction === 'disabled' && {
89
+ color: componentTheme.textDisabledColor
90
+ })
91
+ };
92
+ const inputStyle = {
93
+ all: 'initial',
94
+ width: '100%',
95
+ WebkitFontSmoothing: 'antialiased',
96
+ MozOsxFontSmoothing: 'grayscale',
97
+ appearance: 'none',
98
+ margin: 0,
99
+ display: 'block',
100
+ boxSizing: 'border-box',
101
+ outline: 'none',
102
+ fontFamily: componentTheme.fontFamily,
103
+ fontWeight: componentTheme.fontWeight,
104
+ // padding of the text in the input
105
+ padding: `0 ${componentTheme.gapContent} 0 ${componentTheme.gapContent}`,
106
+ background: 'transparent',
107
+ border: 'none',
108
+ verticalAlign: 'baseline',
109
+ '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
110
+ display: 'none !important'
111
+ },
112
+ '&:focus': {
113
+ boxShadow: 'initial'
114
+ },
115
+ ...sizeVariants[size],
116
+ textAlign: textAlign,
117
+ ...inputInteractionStates
118
+ };
119
+ const viewBase = {
120
+ boxSizing: 'border-box',
121
+ fontFamily: componentTheme.fontFamily,
122
+ maxWidth: '100%',
123
+ overflow: 'visible',
124
+ unicodeBidi: 'isolate'
125
+ };
126
+ const containerInteractionStates = {
127
+ ...(interaction === 'enabled' && {
128
+ backgroundColor: componentTheme.backgroundColor,
129
+ borderColor: componentTheme.borderColor,
130
+ ...(success && {
131
+ borderColor: componentTheme.successBorderColor
132
+ }),
133
+ ...(invalid && {
134
+ borderColor: componentTheme.errorBorderColor
135
+ }),
136
+ '&:hover': {
137
+ backgroundColor: componentTheme.backgroundHoverColor,
138
+ borderColor: componentTheme.borderHoverColor,
139
+ ...(success && {
140
+ borderColor: componentTheme.successBorderColor
141
+ }),
142
+ ...(invalid && {
143
+ borderColor: componentTheme.errorBorderColor
144
+ })
145
+ }
146
+ }),
147
+ ...(interaction === 'readonly' && {
148
+ backgroundColor: componentTheme.backgroundReadonlyColor,
149
+ borderColor: componentTheme.borderReadonlyColor
150
+ }),
151
+ ...(interaction === 'disabled' && {
152
+ cursor: 'not-allowed',
153
+ pointerEvents: 'none',
154
+ backgroundColor: componentTheme.backgroundDisabledColor,
155
+ borderColor: componentTheme.borderDisabledColor
156
+ })
157
+ };
158
+ const focusOutline = (0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
159
+ focusColor: invalid ? 'danger' : success ? 'success' : void 0,
160
+ // Only display the focus outline when the input is focused.
161
+ // This is to prevent double focus ring when e.g., a Button is rendered in
162
+ // `renderBeforeInput`
163
+ customCSSSelector: '&:has(input:focus)'
164
+ });
165
+ return {
166
+ textInput: {
167
+ label: 'textInput',
168
+ ...inputStyle,
169
+ '&:is(input)[type]': inputStyle,
170
+ '&:-webkit-any(input)[type]': inputStyle
171
+ },
172
+ facade: {
173
+ label: 'textInput__facade',
174
+ position: 'relative',
175
+ display: 'block',
176
+ boxSizing: 'border-box',
177
+ border: `${componentTheme.borderWidth} solid`,
178
+ borderRadius: componentTheme.borderRadius,
179
+ color: componentTheme.textColor,
180
+ ...containerInteractionStates,
181
+ ...focusOutline
182
+ },
183
+ layout: {
184
+ label: 'textInput__layout',
185
+ ...viewBase,
186
+ display: 'flex',
187
+ alignItems: 'center',
188
+ justifyContent: 'flex-start',
189
+ flexDirection: 'row',
190
+ ...(!shouldNotWrap && {
191
+ flexWrap: 'wrap'
192
+ }),
193
+ // left padding of the `renderBeforeInput` element
194
+ ...(beforeElementExists && {
195
+ paddingInlineStart: paddingHorizontalVariants[size]
196
+ })
197
+ },
198
+ inputLayout: {
199
+ label: 'textInput__inputLayout',
200
+ flexGrow: 1,
201
+ ...viewBase,
202
+ display: 'flex',
203
+ alignItems: 'center',
204
+ justifyContent: 'flex-start',
205
+ flexDirection: 'row'
206
+ },
207
+ afterElement: {
208
+ // the next couple lines (until the `label`) is needed so the IconButton looks OK inside the TextInput
209
+ // explanation: if the content inside is not a button or a popover (which could contain a button) it should have some padding on the right
210
+ // lineHeight is only needed if it is not popover or button
211
+ '& > :not(button):not([data-position^="Popover"])': {
212
+ marginRight: paddingHorizontalVariants[size]
213
+ // TODO check if it looks OK with the new buttons. With this it does not look OK with new icons
214
+ //...(sizeVariants[size!] && {
215
+ // lineHeight: sizeVariants[size!]?.lineHeight
216
+ //})
217
+ },
218
+ display: 'flex',
219
+ alignItems: 'center',
220
+ // Spread all sizeVariants except lineHeight (handled above)
221
+ ...(sizeVariants[size] ?
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ (({
224
+ lineHeight,
225
+ ...rest
226
+ }) => rest)(sizeVariants[size]) : {}),
227
+ label: 'textInput__afterElement',
228
+ ...viewBase,
229
+ borderRadius: componentTheme.borderRadius,
230
+ flexShrink: 0,
231
+ // we only override the padding once the width is calculated,
232
+ // it needs the padding on render
233
+ ...(afterElementHasWidth === false && {
234
+ paddingInlineEnd: 0
235
+ })
236
+ }
237
+ };
238
+ };
239
+ var _default = exports.default = generateStyle;