@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
@@ -0,0 +1,308 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["type", "size", "htmlSize", "display", "textAlign", "placeholder", "value", "defaultValue", "isRequired", "onFocus"];
3
+ var _dec, _dec2, _class, _TextInput;
4
+ /*
5
+ * The MIT License (MIT)
6
+ *
7
+ * Copyright (c) 2015 - present Instructure, Inc.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ import { Component, isValidElement } from 'react';
29
+ import { callRenderProp, getInteraction, passthroughProps, withDeterministicId, safeCloneElement } from '@instructure/ui-react-utils';
30
+ import { isActiveElement, addEventListener, getCSSStyleDeclaration } from '@instructure/ui-dom-utils';
31
+ import { FormField } from '@instructure/ui-form-field/latest';
32
+ import { withStyle } from '@instructure/emotion';
33
+ import generateStyle from "./styles.js";
34
+ import { allowedProps } from "./props.js";
35
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
36
+ /**
37
+ ---
38
+ category: components
39
+ tags: form, field, input
40
+ ---
41
+ **/
42
+ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_TextInput = class TextInput extends Component {
43
+ constructor(props) {
44
+ super(props);
45
+ this.ref = null;
46
+ this._input = null;
47
+ this._afterElement = null;
48
+ this._defaultId = void 0;
49
+ this._messagesId = void 0;
50
+ this._focusListener = null;
51
+ this.handleRef = el => {
52
+ const elementRef = this.props.elementRef;
53
+ this.ref = el;
54
+ if (typeof elementRef === 'function') {
55
+ elementRef(el);
56
+ }
57
+ };
58
+ this.makeStyleProps = () => {
59
+ const afterElementHasWidth = this.state.afterElementHasWidth;
60
+ const beforeElement = this.props.renderBeforeInput ? callRenderProp(this.props.renderBeforeInput) : null;
61
+ const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
62
+ return {
63
+ interaction: this.interaction,
64
+ invalid: this.invalid,
65
+ success: success,
66
+ afterElementHasWidth: afterElementHasWidth,
67
+ beforeElementExists: !!beforeElement
68
+ };
69
+ };
70
+ this.handleInputRef = node => {
71
+ this._input = node;
72
+ if (typeof this.props.inputRef === 'function') {
73
+ this.props.inputRef(node);
74
+ }
75
+ };
76
+ this.handleChange = event => {
77
+ if (typeof this.props.onChange === 'function') {
78
+ this.props.onChange(event, event.target.value);
79
+ }
80
+ };
81
+ this.handleBlur = event => {
82
+ if (typeof this.props.onBlur === 'function') {
83
+ this.props.onBlur(event);
84
+ }
85
+ };
86
+ this.handleFocus = event => {
87
+ if (typeof this.props.onFocus === 'function') {
88
+ this.props.onFocus(event);
89
+ }
90
+ };
91
+ this.state = {
92
+ afterElementHasWidth: void 0
93
+ };
94
+ this._defaultId = props.deterministicId();
95
+ this._messagesId = props.deterministicId('TextInput-messages');
96
+ }
97
+ componentDidMount() {
98
+ var _this$props$makeStyle, _this$props;
99
+ if (this._input) {
100
+ this._focusListener = addEventListener(this._input, 'focus', this.handleFocus);
101
+ this.setState({
102
+ afterElementHasWidth: this.getElementHasWidth(this._afterElement)
103
+ });
104
+ }
105
+ this.adjustAfterElementHeight();
106
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
107
+ }
108
+ componentWillUnmount() {
109
+ if (this._focusListener) {
110
+ this._focusListener.remove();
111
+ }
112
+ }
113
+ componentDidUpdate(prevProps) {
114
+ var _this$props$makeStyle2, _this$props2;
115
+ if (prevProps.renderAfterInput !== this.props.renderAfterInput) {
116
+ this.setState({
117
+ afterElementHasWidth: this.getElementHasWidth(this._afterElement)
118
+ });
119
+ }
120
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
121
+ }
122
+ renderInstUIIcon(elementToRender) {
123
+ var _type;
124
+ if (!elementToRender) {
125
+ return null;
126
+ }
127
+ const rendered = callRenderProp(elementToRender);
128
+ // Map sizes to Lucide icon semantic size tokens
129
+ const linkSizeToIconSize = {
130
+ small: 'sm',
131
+ medium: 'md',
132
+ large: 'lg'
133
+ };
134
+ const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
135
+ if (/*#__PURE__*/isValidElement(elementToRender) && ((_type = elementToRender.type) === null || _type === void 0 ? void 0 : _type.name) === 'WrappedIcon') {
136
+ return safeCloneElement(rendered, {
137
+ size: iconSize
138
+ });
139
+ }
140
+ return rendered;
141
+ }
142
+ adjustAfterElementHeight() {
143
+ var _this$_afterElement, _afterElementChild$fi;
144
+ const afterElementChild = (_this$_afterElement = this._afterElement) === null || _this$_afterElement === void 0 ? void 0 : _this$_afterElement.firstElementChild;
145
+
146
+ // Check if the child is a button, then get the button's first child (the content span)
147
+ const buttonContentSpan = (afterElementChild === null || afterElementChild === void 0 ? void 0 : afterElementChild.tagName) === 'BUTTON' ? afterElementChild.firstElementChild : null;
148
+
149
+ // This is a necessary workaround for DateInput2 because it uses a Popover, which has a nested Button as an afterElement
150
+ // Check if the child is a Popover's inner span containing a button, then get the button's first child (the content span)
151
+ 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;
152
+ const targetSpan = buttonContentSpan !== null && buttonContentSpan !== void 0 ? buttonContentSpan : popoverContentSpan;
153
+ if (targetSpan) {
154
+ // Set the height to 36px (the height of a medium TextInput) to avoid layout shift when the afterElement content changes
155
+ // this temporary workaround is necessary because otherwise the layout breaks, later on IconButton's default height will be adjusted to the TextInput size
156
+ // so this workaround will not be needed anymore
157
+ targetSpan.style.height = '36px';
158
+ }
159
+ }
160
+ focus() {
161
+ var _this$_input;
162
+ (_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
163
+ }
164
+ get interaction() {
165
+ return getInteraction({
166
+ props: this.props
167
+ });
168
+ }
169
+ get hasMessages() {
170
+ return !!this.props.messages && this.props.messages.length > 0;
171
+ }
172
+ get invalid() {
173
+ return !!this.props.messages && this.props.messages.findIndex(message => {
174
+ return message.type === 'error' || message.type === 'newError';
175
+ }) >= 0;
176
+ }
177
+ get focused() {
178
+ return isActiveElement(this._input);
179
+ }
180
+ get value() {
181
+ var _this$_input2;
182
+ return (_this$_input2 = this._input) === null || _this$_input2 === void 0 ? void 0 : _this$_input2.value;
183
+ }
184
+ get id() {
185
+ return this.props.id || this._defaultId;
186
+ }
187
+ renderInput() {
188
+ var _this$props$styles;
189
+ const _this$props3 = this.props,
190
+ type = _this$props3.type,
191
+ size = _this$props3.size,
192
+ htmlSize = _this$props3.htmlSize,
193
+ display = _this$props3.display,
194
+ textAlign = _this$props3.textAlign,
195
+ placeholder = _this$props3.placeholder,
196
+ value = _this$props3.value,
197
+ defaultValue = _this$props3.defaultValue,
198
+ isRequired = _this$props3.isRequired,
199
+ onFocus = _this$props3.onFocus,
200
+ rest = _objectWithoutProperties(_this$props3, _excluded);
201
+ const props = passthroughProps(rest);
202
+ const interaction = this.interaction;
203
+ let descriptionIds = '';
204
+ if (props['aria-describedby']) {
205
+ descriptionIds = `${props['aria-describedby']}`;
206
+ }
207
+ return _jsx("input", {
208
+ ...props,
209
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.textInput,
210
+ defaultValue: defaultValue,
211
+ value: value,
212
+ placeholder: interaction === 'enabled' ? placeholder : void 0,
213
+ ref: this.handleInputRef,
214
+ type: type,
215
+ id: this.id,
216
+ required: isRequired,
217
+ "aria-invalid": this.invalid ? 'true' : void 0,
218
+ disabled: interaction === 'disabled',
219
+ readOnly: interaction === 'readonly',
220
+ "aria-describedby": descriptionIds !== '' ? descriptionIds : void 0,
221
+ size: htmlSize,
222
+ onChange: this.handleChange,
223
+ onBlur: this.handleBlur
224
+ });
225
+ }
226
+ getElementHasWidth(element) {
227
+ if (!element) {
228
+ return void 0;
229
+ }
230
+ const computedStyle = getCSSStyleDeclaration(element);
231
+ if (!computedStyle) {
232
+ return void 0;
233
+ }
234
+ const width = computedStyle.width,
235
+ paddingInlineStart = computedStyle.paddingInlineStart,
236
+ paddingInlineEnd = computedStyle.paddingInlineEnd;
237
+ if (width === 'auto' || width === '') {
238
+ // This is a workaround for an edge-case, when the TextInput's parent
239
+ // is hidden on load, so the element is not visible either.
240
+ // In this case the computed width is going to be either 'auto' or '',
241
+ // so we assume it has width so that the padding won't be removed.
242
+ return true;
243
+ }
244
+ const elementWidth = parseFloat(width) - parseFloat(paddingInlineStart) - parseFloat(paddingInlineEnd);
245
+ return elementWidth > 0;
246
+ }
247
+ render() {
248
+ const _this$props4 = this.props,
249
+ width = _this$props4.width,
250
+ display = _this$props4.display,
251
+ renderLabel = _this$props4.renderLabel,
252
+ renderBeforeInput = _this$props4.renderBeforeInput,
253
+ renderAfterInput = _this$props4.renderAfterInput,
254
+ messages = _this$props4.messages,
255
+ inputContainerRef = _this$props4.inputContainerRef,
256
+ isRequired = _this$props4.isRequired,
257
+ styles = _this$props4.styles;
258
+ const beforeElement = this.renderInstUIIcon(renderBeforeInput);
259
+ const afterElement = this.renderInstUIIcon(renderAfterInput);
260
+ const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== void 0 || renderAfterInput !== void 0;
261
+ const label = callRenderProp(renderLabel);
262
+ return _jsx(FormField, {
263
+ id: this.id,
264
+ label: label,
265
+ messagesId: this._messagesId,
266
+ messages: messages,
267
+ inline: display === 'inline-block',
268
+ width: width,
269
+ inputContainerRef: inputContainerRef,
270
+ layout: this.props.layout,
271
+ elementRef: this.handleRef,
272
+ margin: this.props.margin,
273
+ isRequired: isRequired,
274
+ disabled: this.interaction === 'disabled',
275
+ readOnly: this.interaction === 'readonly',
276
+ "data-cid": "TextInput",
277
+ children: _jsx("span", {
278
+ css: styles === null || styles === void 0 ? void 0 : styles.facade,
279
+ children: renderBeforeOrAfter ? _jsxs("span", {
280
+ css: styles === null || styles === void 0 ? void 0 : styles.layout,
281
+ children: [beforeElement, _jsxs("span", {
282
+ css: styles === null || styles === void 0 ? void 0 : styles.inputLayout,
283
+ children: [this.renderInput(), afterElement && _jsx("span", {
284
+ css: styles === null || styles === void 0 ? void 0 : styles.afterElement,
285
+ ref: e => {
286
+ this._afterElement = e;
287
+ },
288
+ children: afterElement
289
+ })]
290
+ })]
291
+ }) : (/* If no prepended or appended content, don't render Flex layout */
292
+ this.renderInput())
293
+ })
294
+ });
295
+ }
296
+ }, _TextInput.displayName = "TextInput", _TextInput.componentId = 'TextInput', _TextInput.allowedProps = allowedProps, _TextInput.defaultProps = {
297
+ type: 'text',
298
+ // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
299
+ interaction: void 0,
300
+ isRequired: false,
301
+ display: 'block',
302
+ shouldNotWrap: false,
303
+ size: 'medium',
304
+ textAlign: 'start',
305
+ messages: []
306
+ }, _TextInput)) || _class) || _class);
307
+ export default TextInput;
308
+ export { TextInput };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const 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'];
26
+ export { allowedProps };
@@ -0,0 +1,234 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { calcFocusOutlineStyles } from '@instructure/emotion';
26
+
27
+ /**
28
+ * ---
29
+ * private: true
30
+ * ---
31
+ * Generates the style object from the theme and provided additional information
32
+ * @param componentTheme The theme variable object.
33
+ * @param props the props of the component, the style is applied to
34
+ * @param sharedTokens Shared token object that stores common values for the theme.
35
+ * @param state the state of the component, the style is applied to
36
+ * @return The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (componentTheme, props, sharedTokens, state) => {
39
+ const size = props.size,
40
+ textAlign = props.textAlign,
41
+ shouldNotWrap = props.shouldNotWrap;
42
+ const interaction = state.interaction,
43
+ success = state.success,
44
+ invalid = state.invalid,
45
+ afterElementHasWidth = state.afterElementHasWidth,
46
+ beforeElementExists = state.beforeElementExists;
47
+ const sizeVariants = {
48
+ small: {
49
+ fontSize: componentTheme.fontSizeSm,
50
+ height: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`,
51
+ lineHeight: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`
52
+ },
53
+ medium: {
54
+ fontSize: componentTheme.fontSizeMd,
55
+ height: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`,
56
+ lineHeight: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`
57
+ },
58
+ large: {
59
+ fontSize: componentTheme.fontSizeLg,
60
+ height: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`,
61
+ lineHeight: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`
62
+ }
63
+ };
64
+ const paddingHorizontalVariants = {
65
+ small: componentTheme.paddingHorizontalSm,
66
+ medium: componentTheme.paddingHorizontalMd,
67
+ large: componentTheme.paddingHorizontalLg
68
+ };
69
+ const inputInteractionStates = {
70
+ ...(interaction === 'enabled' && {
71
+ color: componentTheme.textColor,
72
+ '&::placeholder': {
73
+ color: componentTheme.placeholderColor
74
+ },
75
+ '&:hover::placeholder': {
76
+ color: componentTheme.placeholderHoverColor
77
+ }
78
+ // placeholder is not rendered in the `readOnly` and `disabled` state
79
+ }),
80
+ ...(interaction === 'readonly' && {
81
+ color: componentTheme.textReadonlyColor
82
+ }),
83
+ ...(interaction === 'disabled' && {
84
+ color: componentTheme.textDisabledColor
85
+ })
86
+ };
87
+ const inputStyle = {
88
+ all: 'initial',
89
+ width: '100%',
90
+ WebkitFontSmoothing: 'antialiased',
91
+ MozOsxFontSmoothing: 'grayscale',
92
+ appearance: 'none',
93
+ margin: 0,
94
+ display: 'block',
95
+ boxSizing: 'border-box',
96
+ outline: 'none',
97
+ fontFamily: componentTheme.fontFamily,
98
+ fontWeight: componentTheme.fontWeight,
99
+ // padding of the text in the input
100
+ padding: `0 ${componentTheme.gapContent} 0 ${componentTheme.gapContent}`,
101
+ background: 'transparent',
102
+ border: 'none',
103
+ verticalAlign: 'baseline',
104
+ '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
105
+ display: 'none !important'
106
+ },
107
+ '&:focus': {
108
+ boxShadow: 'initial'
109
+ },
110
+ ...sizeVariants[size],
111
+ textAlign: textAlign,
112
+ ...inputInteractionStates
113
+ };
114
+ const viewBase = {
115
+ boxSizing: 'border-box',
116
+ fontFamily: componentTheme.fontFamily,
117
+ maxWidth: '100%',
118
+ overflow: 'visible',
119
+ unicodeBidi: 'isolate'
120
+ };
121
+ const containerInteractionStates = {
122
+ ...(interaction === 'enabled' && {
123
+ backgroundColor: componentTheme.backgroundColor,
124
+ borderColor: componentTheme.borderColor,
125
+ ...(success && {
126
+ borderColor: componentTheme.successBorderColor
127
+ }),
128
+ ...(invalid && {
129
+ borderColor: componentTheme.errorBorderColor
130
+ }),
131
+ '&:hover': {
132
+ backgroundColor: componentTheme.backgroundHoverColor,
133
+ borderColor: componentTheme.borderHoverColor,
134
+ ...(success && {
135
+ borderColor: componentTheme.successBorderColor
136
+ }),
137
+ ...(invalid && {
138
+ borderColor: componentTheme.errorBorderColor
139
+ })
140
+ }
141
+ }),
142
+ ...(interaction === 'readonly' && {
143
+ backgroundColor: componentTheme.backgroundReadonlyColor,
144
+ borderColor: componentTheme.borderReadonlyColor
145
+ }),
146
+ ...(interaction === 'disabled' && {
147
+ cursor: 'not-allowed',
148
+ pointerEvents: 'none',
149
+ backgroundColor: componentTheme.backgroundDisabledColor,
150
+ borderColor: componentTheme.borderDisabledColor
151
+ })
152
+ };
153
+ const focusOutline = calcFocusOutlineStyles(sharedTokens.focusOutline, {
154
+ focusColor: invalid ? 'danger' : success ? 'success' : void 0,
155
+ // Only display the focus outline when the input is focused.
156
+ // This is to prevent double focus ring when e.g., a Button is rendered in
157
+ // `renderBeforeInput`
158
+ customCSSSelector: '&:has(input:focus)'
159
+ });
160
+ return {
161
+ textInput: {
162
+ label: 'textInput',
163
+ ...inputStyle,
164
+ '&:is(input)[type]': inputStyle,
165
+ '&:-webkit-any(input)[type]': inputStyle
166
+ },
167
+ facade: {
168
+ label: 'textInput__facade',
169
+ position: 'relative',
170
+ display: 'block',
171
+ boxSizing: 'border-box',
172
+ border: `${componentTheme.borderWidth} solid`,
173
+ borderRadius: componentTheme.borderRadius,
174
+ color: componentTheme.textColor,
175
+ ...containerInteractionStates,
176
+ ...focusOutline
177
+ },
178
+ layout: {
179
+ label: 'textInput__layout',
180
+ ...viewBase,
181
+ display: 'flex',
182
+ alignItems: 'center',
183
+ justifyContent: 'flex-start',
184
+ flexDirection: 'row',
185
+ ...(!shouldNotWrap && {
186
+ flexWrap: 'wrap'
187
+ }),
188
+ // left padding of the `renderBeforeInput` element
189
+ ...(beforeElementExists && {
190
+ paddingInlineStart: paddingHorizontalVariants[size]
191
+ })
192
+ },
193
+ inputLayout: {
194
+ label: 'textInput__inputLayout',
195
+ flexGrow: 1,
196
+ ...viewBase,
197
+ display: 'flex',
198
+ alignItems: 'center',
199
+ justifyContent: 'flex-start',
200
+ flexDirection: 'row'
201
+ },
202
+ afterElement: {
203
+ // the next couple lines (until the `label`) is needed so the IconButton looks OK inside the TextInput
204
+ // 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
205
+ // lineHeight is only needed if it is not popover or button
206
+ '& > :not(button):not([data-position^="Popover"])': {
207
+ marginRight: paddingHorizontalVariants[size]
208
+ // TODO check if it looks OK with the new buttons. With this it does not look OK with new icons
209
+ //...(sizeVariants[size!] && {
210
+ // lineHeight: sizeVariants[size!]?.lineHeight
211
+ //})
212
+ },
213
+ display: 'flex',
214
+ alignItems: 'center',
215
+ // Spread all sizeVariants except lineHeight (handled above)
216
+ ...(sizeVariants[size] ?
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
+ (({
219
+ lineHeight,
220
+ ...rest
221
+ }) => rest)(sizeVariants[size]) : {}),
222
+ label: 'textInput__afterElement',
223
+ ...viewBase,
224
+ borderRadius: componentTheme.borderRadius,
225
+ flexShrink: 0,
226
+ // we only override the padding once the width is calculated,
227
+ // it needs the padding on render
228
+ ...(afterElementHasWidth === false && {
229
+ paddingInlineEnd: 0
230
+ })
231
+ }
232
+ };
233
+ };
234
+ export default generateStyle;
@@ -0,0 +1,73 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * Generates the theme object for the component from the theme and provided additional information
27
+ * @param {Object} theme The actual theme object.
28
+ * @return {Object} The final theme object with the overrides and component variables
29
+ */
30
+ const generateComponentTheme = theme => {
31
+ var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6, _colors$contrasts7, _colors$contrasts8;
32
+ const colors = theme.colors,
33
+ typography = theme.typography,
34
+ borders = theme.borders,
35
+ spacing = theme.spacing,
36
+ forms = theme.forms,
37
+ themeName = theme.key;
38
+ const themeSpecificStyle = {
39
+ canvas: {
40
+ color: theme['ic-brand-font-color-dark'],
41
+ focusOutlineColor: theme['ic-brand-primary']
42
+ }
43
+ };
44
+ const componentVariables = {
45
+ fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
46
+ fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
47
+ borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
48
+ borderStyle: borders === null || borders === void 0 ? void 0 : borders.style,
49
+ borderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.grey3045,
50
+ borderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium,
51
+ color: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.grey125125,
52
+ background: colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.white1010,
53
+ requiredInvalidColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.red5782,
54
+ padding: spacing === null || spacing === void 0 ? void 0 : spacing.small,
55
+ focusOutlineWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
56
+ focusOutlineStyle: borders === null || borders === void 0 ? void 0 : borders.style,
57
+ focusOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.blue4570,
58
+ errorBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.red4570,
59
+ errorOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts7 = colors.contrasts) === null || _colors$contrasts7 === void 0 ? void 0 : _colors$contrasts7.red4570,
60
+ placeholderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts8 = colors.contrasts) === null || _colors$contrasts8 === void 0 ? void 0 : _colors$contrasts8.grey4570,
61
+ smallFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeSmall,
62
+ smallHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightSmall,
63
+ mediumFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
64
+ mediumHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightMedium,
65
+ largeFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeLarge,
66
+ largeHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightLarge
67
+ };
68
+ return {
69
+ ...componentVariables,
70
+ ...themeSpecificStyle[themeName]
71
+ };
72
+ };
73
+ export default generateComponentTheme;
@@ -21,4 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { TextInput } from "./TextInput/index.js";
24
+ export { TextInput } from "../TextInput/v1/index.js";
@@ -21,5 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { TextInput } from './TextInput'
25
- export type { TextInputProps } from './TextInput/props'
24
+ export { TextInput } from "../TextInput/v2/index.js";