@instructure/ui-text-input 11.7.8 → 11.7.9-pr-snapshot-1792147648392

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.
@@ -1,28 +1,5 @@
1
- var _dec, _dec2, _class;
2
- /*
3
- * The MIT License (MIT)
4
- *
5
- * Copyright (c) 2015 - present Instructure, Inc.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
1
+ import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
26
3
  import { Component, isValidElement } from 'react';
27
4
  import { callRenderProp, getInteraction, passthroughProps, withDeterministicId, safeCloneElement } from '@instructure/ui-react-utils';
28
5
  import { isActiveElement, addEventListener } from '@instructure/ui-dom-utils';
@@ -30,242 +7,211 @@ import { FormField } from '@instructure/ui-form-field/latest';
30
7
  import { withStyleNew } from '@instructure/emotion';
31
8
  import generateStyle from './styles.js';
32
9
  import { allowedProps } from './props.js';
33
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
34
- /**
35
- ---
36
- category: components
37
- tags: form, field, input
38
- ---
39
- **/
40
- let TextInput = (_dec = withDeterministicId(), _dec2 = withStyleNew(generateStyle), _dec(_class = _dec2(_class = class TextInput extends Component {
41
- static displayName = 'TextInput';
42
- static componentId = 'TextInput';
43
- static allowedProps = allowedProps;
44
- static defaultProps = {
45
- type: 'text',
46
- // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
47
- interaction: undefined,
48
- isRequired: false,
49
- forcePlaceholder: false,
50
- display: 'block',
51
- shouldNotWrap: false,
52
- renderBeforeInputElementGap: 'default',
53
- size: 'medium',
54
- textAlign: 'start',
55
- messages: []
56
- };
57
- constructor(props) {
58
- super(props);
59
- this._defaultId = props.deterministicId();
60
- this._messagesId = props.deterministicId('TextInput-messages');
61
- this._labelId = props.labelId ?? props.deterministicId('TextInput-label');
62
- }
63
- ref = null;
64
- _input = null;
65
- _defaultId;
66
- _messagesId;
67
- _labelId;
68
- _focusListener = null;
69
- handleRef = el => {
70
- const {
71
- elementRef
72
- } = this.props;
73
- this.ref = el;
74
- if (typeof elementRef === 'function') {
75
- elementRef(el);
10
+ class TextInput extends Component {
11
+ static{
12
+ this.displayName = 'TextInput';
13
+ }
14
+ static{
15
+ this.componentId = 'TextInput';
16
+ }
17
+ static{
18
+ this.allowedProps = allowedProps;
19
+ }
20
+ static{
21
+ this.defaultProps = {
22
+ type: 'text',
23
+ interaction: undefined,
24
+ isRequired: false,
25
+ forcePlaceholder: false,
26
+ display: 'block',
27
+ shouldNotWrap: false,
28
+ renderBeforeInputElementGap: 'default',
29
+ size: 'medium',
30
+ textAlign: 'start',
31
+ messages: []
32
+ };
33
+ }
34
+ constructor(props){
35
+ super(props), this.ref = null, this._input = null, this._focusListener = null, this.handleRef = (el)=>{
36
+ const { elementRef } = this.props;
37
+ this.ref = el;
38
+ if (typeof elementRef === 'function') {
39
+ elementRef(el);
40
+ }
41
+ }, this.makeStyleProps = ()=>{
42
+ const beforeElement = this.props.renderBeforeInput ? callRenderProp(this.props.renderBeforeInput) : null;
43
+ const success = !!this.props.messages && this.props.messages.some((message)=>message.type === 'success');
44
+ return {
45
+ interaction: this.interaction,
46
+ invalid: this.invalid,
47
+ success: success,
48
+ beforeElementExists: !!beforeElement
49
+ };
50
+ }, this.handleInputRef = (node)=>{
51
+ this._input = node;
52
+ if (typeof this.props.inputRef === 'function') {
53
+ this.props.inputRef(node);
54
+ }
55
+ }, this.handleChange = (event)=>{
56
+ if (typeof this.props.onChange === 'function') {
57
+ this.props.onChange(event, event.target.value);
58
+ }
59
+ }, this.handleBlur = (event)=>{
60
+ if (typeof this.props.onBlur === 'function') {
61
+ this.props.onBlur(event);
62
+ }
63
+ }, this.handleFocus = (event)=>{
64
+ if (typeof this.props.onFocus === 'function') {
65
+ this.props.onFocus(event);
66
+ }
67
+ };
68
+ this._defaultId = props.deterministicId();
69
+ this._messagesId = props.deterministicId('TextInput-messages');
70
+ this._labelId = props.labelId ?? props.deterministicId('TextInput-label');
71
+ }
72
+ componentDidMount() {
73
+ if (this._input) {
74
+ this._focusListener = addEventListener(this._input, 'focus', this.handleFocus);
75
+ }
76
+ this.props.makeStyles?.(this.makeStyleProps());
77
+ }
78
+ componentWillUnmount() {
79
+ if (this._focusListener) {
80
+ this._focusListener.remove();
81
+ }
82
+ }
83
+ componentDidUpdate() {
84
+ this.props.makeStyles?.(this.makeStyleProps());
76
85
  }
77
- };
78
- componentDidMount() {
79
- if (this._input) {
80
- this._focusListener = addEventListener(this._input, 'focus', this.handleFocus);
86
+ renderInstUIIcon(elementToRender) {
87
+ if (!elementToRender) {
88
+ return null;
89
+ }
90
+ const rendered = callRenderProp(elementToRender);
91
+ const linkSizeToIconSize = {
92
+ small: 'sm',
93
+ medium: 'md',
94
+ large: 'lg'
95
+ };
96
+ const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
97
+ if (/*#__PURE__*/ isValidElement(elementToRender) && elementToRender.type?.name === 'WrappedIcon') {
98
+ return safeCloneElement(rendered, {
99
+ size: iconSize
100
+ });
101
+ }
102
+ return rendered;
81
103
  }
82
- this.props.makeStyles?.(this.makeStyleProps());
83
- }
84
- componentWillUnmount() {
85
- if (this._focusListener) {
86
- this._focusListener.remove();
104
+ focus() {
105
+ this._input?.focus();
87
106
  }
88
- }
89
- componentDidUpdate() {
90
- this.props.makeStyles?.(this.makeStyleProps());
91
- }
92
- renderInstUIIcon(elementToRender) {
93
- if (!elementToRender) {
94
- return null;
107
+ get interaction() {
108
+ return getInteraction({
109
+ props: this.props
110
+ });
95
111
  }
96
- const rendered = callRenderProp(elementToRender);
97
- // Map sizes to Lucide icon semantic size tokens
98
- const linkSizeToIconSize = {
99
- small: 'sm',
100
- medium: 'md',
101
- large: 'lg'
102
- };
103
- const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
104
- if (/*#__PURE__*/isValidElement(elementToRender) && elementToRender.type?.name === 'WrappedIcon') {
105
- return safeCloneElement(rendered, {
106
- size: iconSize
107
- });
112
+ get hasMessages() {
113
+ return !!this.props.messages?.some((m)=>!!m.text);
108
114
  }
109
- return rendered;
110
- }
111
- makeStyleProps = () => {
112
- const beforeElement = this.props.renderBeforeInput ? callRenderProp(this.props.renderBeforeInput) : null;
113
- const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
114
- return {
115
- interaction: this.interaction,
116
- invalid: this.invalid,
117
- success: success,
118
- beforeElementExists: !!beforeElement
119
- };
120
- };
121
- focus() {
122
- this._input?.focus();
123
- }
124
- get interaction() {
125
- return getInteraction({
126
- props: this.props
127
- });
128
- }
129
- get hasMessages() {
130
- return !!this.props.messages?.some(m => !!m.text);
131
- }
132
- get invalid() {
133
- return !!this.props.messages && this.props.messages.findIndex(message => {
134
- return message.type === 'error' || message.type === 'newError';
135
- }) >= 0;
136
- }
137
- get focused() {
138
- return isActiveElement(this._input);
139
- }
140
- get value() {
141
- return this._input?.value;
142
- }
143
- get id() {
144
- return this.props.id || this._defaultId;
145
- }
146
- handleInputRef = node => {
147
- this._input = node;
148
- if (typeof this.props.inputRef === 'function') {
149
- this.props.inputRef(node);
115
+ get invalid() {
116
+ return !!this.props.messages && this.props.messages.findIndex((message)=>{
117
+ return message.type === 'error' || message.type === 'newError';
118
+ }) >= 0;
150
119
  }
151
- };
152
- handleChange = event => {
153
- if (typeof this.props.onChange === 'function') {
154
- this.props.onChange(event, event.target.value);
120
+ get focused() {
121
+ return isActiveElement(this._input);
155
122
  }
156
- };
157
- handleBlur = event => {
158
- if (typeof this.props.onBlur === 'function') {
159
- this.props.onBlur(event);
123
+ get value() {
124
+ return this._input?.value;
160
125
  }
161
- };
162
- handleFocus = event => {
163
- if (typeof this.props.onFocus === 'function') {
164
- this.props.onFocus(event);
126
+ get id() {
127
+ return this.props.id || this._defaultId;
165
128
  }
166
- };
167
- renderInput() {
168
- const {
169
- type,
170
- size,
171
- htmlSize,
172
- display,
173
- textAlign,
174
- placeholder,
175
- value,
176
- defaultValue,
177
- isRequired,
178
- forcePlaceholder,
179
- onFocus,
180
- ...rest
181
- } = this.props;
182
- const props = passthroughProps(rest);
183
- const {
184
- interaction
185
- } = this;
186
- let descriptionIds = '';
187
- if (props['aria-describedby']) {
188
- descriptionIds = `${props['aria-describedby']}`;
129
+ renderInput() {
130
+ const { type, size, htmlSize, display, textAlign, placeholder, value, defaultValue, isRequired, forcePlaceholder, onFocus, ...rest } = this.props;
131
+ const props = passthroughProps(rest);
132
+ const { interaction } = this;
133
+ let descriptionIds = '';
134
+ if (props['aria-describedby']) {
135
+ descriptionIds = `${props['aria-describedby']}`;
136
+ }
137
+ let labelledById = props['aria-labelledby'];
138
+ if (this.hasMessages) {
139
+ descriptionIds = [
140
+ descriptionIds,
141
+ this._messagesId
142
+ ].filter(Boolean).join(' ');
143
+ labelledById = labelledById || this._labelId;
144
+ }
145
+ return /*#__PURE__*/ _jsx("input", {
146
+ ...props,
147
+ css: this.props.styles?.textInput,
148
+ defaultValue: defaultValue,
149
+ value: value,
150
+ placeholder: forcePlaceholder || interaction === 'enabled' ? placeholder : undefined,
151
+ ref: this.handleInputRef,
152
+ type: type,
153
+ id: this.id,
154
+ required: isRequired,
155
+ "aria-invalid": this.invalid ? 'true' : undefined,
156
+ disabled: interaction === 'disabled',
157
+ readOnly: interaction === 'readonly',
158
+ "aria-describedby": descriptionIds !== '' ? descriptionIds : undefined,
159
+ "aria-labelledby": labelledById,
160
+ size: htmlSize,
161
+ onChange: this.handleChange,
162
+ onBlur: this.handleBlur
163
+ });
189
164
  }
190
- // Keep messages in the description, not the accessible name.
191
- // A consumer-provided aria-labelledby wins.
192
- let labelledById = props['aria-labelledby'];
193
- if (this.hasMessages) {
194
- descriptionIds = [descriptionIds, this._messagesId].filter(Boolean).join(' ');
195
- labelledById = labelledById || this._labelId;
165
+ render() {
166
+ const { width, display, renderLabel, renderBeforeInput, renderAfterInput, messages, inputContainerRef, isRequired, forceMessages, styles } = this.props;
167
+ const beforeElement = this.renderInstUIIcon(renderBeforeInput);
168
+ const afterElement = this.renderInstUIIcon(renderAfterInput);
169
+ const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== undefined || renderAfterInput !== undefined;
170
+ const label = callRenderProp(renderLabel);
171
+ return /*#__PURE__*/ _jsx(FormField, {
172
+ id: this.id,
173
+ label: label,
174
+ messagesId: this._messagesId,
175
+ labelId: this._labelId,
176
+ messages: messages,
177
+ inline: display === 'inline-block',
178
+ width: width,
179
+ inputContainerRef: inputContainerRef,
180
+ layout: this.props.layout,
181
+ elementRef: this.handleRef,
182
+ margin: this.props.margin,
183
+ isRequired: isRequired,
184
+ disabled: this.interaction === 'disabled',
185
+ readOnly: this.interaction === 'readonly' && !forceMessages,
186
+ "data-cid": "TextInput",
187
+ children: /*#__PURE__*/ _jsx("span", {
188
+ css: styles?.facade,
189
+ children: renderBeforeOrAfter ? /*#__PURE__*/ _jsxs("span", {
190
+ css: styles?.layout,
191
+ children: [
192
+ beforeElement && /*#__PURE__*/ _jsx("span", {
193
+ css: styles?.beforeElement,
194
+ children: beforeElement
195
+ }),
196
+ /*#__PURE__*/ _jsxs("span", {
197
+ css: styles?.inputLayout,
198
+ children: [
199
+ this.renderInput(),
200
+ afterElement && /*#__PURE__*/ _jsx("span", {
201
+ css: styles?.afterElement,
202
+ children: afterElement
203
+ })
204
+ ]
205
+ })
206
+ ]
207
+ }) : this.renderInput()
208
+ })
209
+ });
196
210
  }
197
- return _jsx("input", {
198
- ...props,
199
- css: this.props.styles?.textInput,
200
- defaultValue: defaultValue,
201
- value: value,
202
- placeholder: forcePlaceholder || interaction === 'enabled' ? placeholder : undefined,
203
- ref: this.handleInputRef,
204
- type: type,
205
- id: this.id,
206
- required: isRequired,
207
- "aria-invalid": this.invalid ? 'true' : undefined,
208
- disabled: interaction === 'disabled',
209
- readOnly: interaction === 'readonly',
210
- "aria-describedby": descriptionIds !== '' ? descriptionIds : undefined,
211
- "aria-labelledby": labelledById,
212
- size: htmlSize,
213
- onChange: this.handleChange,
214
- onBlur: this.handleBlur
215
- });
216
- }
217
- render() {
218
- const {
219
- width,
220
- display,
221
- renderLabel,
222
- renderBeforeInput,
223
- renderAfterInput,
224
- messages,
225
- inputContainerRef,
226
- isRequired,
227
- forceMessages,
228
- styles
229
- } = this.props;
230
- const beforeElement = this.renderInstUIIcon(renderBeforeInput);
231
- const afterElement = this.renderInstUIIcon(renderAfterInput);
232
- const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== undefined || renderAfterInput !== undefined;
233
- const label = callRenderProp(renderLabel);
234
- return _jsx(FormField, {
235
- id: this.id,
236
- label: label,
237
- messagesId: this._messagesId,
238
- labelId: this._labelId,
239
- messages: messages,
240
- inline: display === 'inline-block',
241
- width: width,
242
- inputContainerRef: inputContainerRef,
243
- layout: this.props.layout,
244
- elementRef: this.handleRef,
245
- margin: this.props.margin,
246
- isRequired: isRequired,
247
- disabled: this.interaction === 'disabled',
248
- readOnly: this.interaction === 'readonly' && !forceMessages,
249
- "data-cid": "TextInput",
250
- children: _jsx("span", {
251
- css: styles?.facade,
252
- children: renderBeforeOrAfter ? _jsxs("span", {
253
- css: styles?.layout,
254
- children: [beforeElement && _jsx("span", {
255
- css: styles?.beforeElement,
256
- children: beforeElement
257
- }), _jsxs("span", {
258
- css: styles?.inputLayout,
259
- children: [this.renderInput(), afterElement && _jsx("span", {
260
- css: styles?.afterElement,
261
- children: afterElement
262
- })]
263
- })]
264
- }) : (/* If no prepended or appended content, don't render Flex layout */
265
- this.renderInput())
266
- })
267
- });
268
- }
269
- }) || _class) || _class);
211
+ }
212
+ TextInput = _ts_decorate([
213
+ withDeterministicId(),
214
+ withStyleNew(generateStyle)
215
+ ], TextInput);
270
216
  export default TextInput;
271
- export { TextInput };
217
+ export { TextInput };
@@ -1,26 +1,31 @@
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', 'labelId', 'value', 'defaultValue', 'interaction', 'messages', 'size', 'textAlign', 'width', 'htmlSize', 'display', 'shouldNotWrap', 'renderBeforeInputElementGap', 'placeholder', 'isRequired', 'forcePlaceholder', 'forceMessages', 'elementRef', 'inputRef', 'inputContainerRef', 'renderBeforeInput', 'renderAfterInput', 'onChange', 'onBlur', 'onFocus', 'margin'];
26
- export { allowedProps };
1
+ const allowedProps = [
2
+ 'renderLabel',
3
+ 'type',
4
+ 'id',
5
+ 'labelId',
6
+ 'value',
7
+ 'defaultValue',
8
+ 'interaction',
9
+ 'messages',
10
+ 'size',
11
+ 'textAlign',
12
+ 'width',
13
+ 'htmlSize',
14
+ 'display',
15
+ 'shouldNotWrap',
16
+ 'renderBeforeInputElementGap',
17
+ 'placeholder',
18
+ 'isRequired',
19
+ 'forcePlaceholder',
20
+ 'forceMessages',
21
+ 'elementRef',
22
+ 'inputRef',
23
+ 'inputContainerRef',
24
+ 'renderBeforeInput',
25
+ 'renderAfterInput',
26
+ 'onChange',
27
+ 'onBlur',
28
+ 'onFocus',
29
+ 'margin'
30
+ ];
31
+ export { allowedProps };