@instructure/ui-text-input 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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 +5 -2
- package/es/TextInput/v1/index.js +128 -121
- package/es/TextInput/v1/styles.js +12 -8
- package/es/TextInput/v1/theme.js +30 -29
- package/es/TextInput/v2/index.js +104 -102
- package/es/TextInput/v2/styles.js +12 -8
- package/lib/TextInput/v1/index.js +128 -121
- package/lib/TextInput/v1/styles.js +12 -8
- package/lib/TextInput/v1/theme.js +30 -29
- package/lib/TextInput/v2/index.js +104 -102
- package/lib/TextInput/v2/styles.js +12 -8
- package/package.json +14 -14
- package/tsconfig.build.tsbuildinfo +1 -1
package/es/TextInput/v2/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const _excluded = ["type", "size", "htmlSize", "display", "textAlign", "placeholder", "value", "defaultValue", "isRequired", "onFocus"];
|
|
3
|
-
var _dec, _dec2, _class, _TextInput;
|
|
1
|
+
var _dec, _dec2, _class;
|
|
4
2
|
/*
|
|
5
3
|
* The MIT License (MIT)
|
|
6
4
|
*
|
|
@@ -39,61 +37,45 @@ category: components
|
|
|
39
37
|
tags: form, field, input
|
|
40
38
|
---
|
|
41
39
|
**/
|
|
42
|
-
let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class =
|
|
40
|
+
let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(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
|
+
display: 'block',
|
|
50
|
+
shouldNotWrap: false,
|
|
51
|
+
size: 'medium',
|
|
52
|
+
textAlign: 'start',
|
|
53
|
+
messages: []
|
|
54
|
+
};
|
|
43
55
|
constructor(props) {
|
|
44
56
|
super(props);
|
|
45
|
-
this.ref = null;
|
|
46
|
-
this._input = null;
|
|
47
|
-
this._defaultId = void 0;
|
|
48
|
-
this._messagesId = void 0;
|
|
49
|
-
this._focusListener = null;
|
|
50
|
-
this.handleRef = el => {
|
|
51
|
-
const elementRef = this.props.elementRef;
|
|
52
|
-
this.ref = el;
|
|
53
|
-
if (typeof elementRef === 'function') {
|
|
54
|
-
elementRef(el);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this.makeStyleProps = () => {
|
|
58
|
-
const beforeElement = this.props.renderBeforeInput ? callRenderProp(this.props.renderBeforeInput) : null;
|
|
59
|
-
const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
|
|
60
|
-
return {
|
|
61
|
-
interaction: this.interaction,
|
|
62
|
-
invalid: this.invalid,
|
|
63
|
-
success: success,
|
|
64
|
-
beforeElementExists: !!beforeElement
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
this.handleInputRef = node => {
|
|
68
|
-
this._input = node;
|
|
69
|
-
if (typeof this.props.inputRef === 'function') {
|
|
70
|
-
this.props.inputRef(node);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
this.handleChange = event => {
|
|
74
|
-
if (typeof this.props.onChange === 'function') {
|
|
75
|
-
this.props.onChange(event, event.target.value);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
this.handleBlur = event => {
|
|
79
|
-
if (typeof this.props.onBlur === 'function') {
|
|
80
|
-
this.props.onBlur(event);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
this.handleFocus = event => {
|
|
84
|
-
if (typeof this.props.onFocus === 'function') {
|
|
85
|
-
this.props.onFocus(event);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
57
|
this._defaultId = props.deterministicId();
|
|
89
58
|
this._messagesId = props.deterministicId('TextInput-messages');
|
|
90
59
|
}
|
|
60
|
+
ref = null;
|
|
61
|
+
_input = null;
|
|
62
|
+
_defaultId;
|
|
63
|
+
_messagesId;
|
|
64
|
+
_focusListener = null;
|
|
65
|
+
handleRef = el => {
|
|
66
|
+
const {
|
|
67
|
+
elementRef
|
|
68
|
+
} = this.props;
|
|
69
|
+
this.ref = el;
|
|
70
|
+
if (typeof elementRef === 'function') {
|
|
71
|
+
elementRef(el);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
91
74
|
componentDidMount() {
|
|
92
|
-
var _this$props$makeStyle, _this$props;
|
|
93
75
|
if (this._input) {
|
|
94
76
|
this._focusListener = addEventListener(this._input, 'focus', this.handleFocus);
|
|
95
77
|
}
|
|
96
|
-
|
|
78
|
+
this.props.makeStyles?.(this.makeStyleProps());
|
|
97
79
|
}
|
|
98
80
|
componentWillUnmount() {
|
|
99
81
|
if (this._focusListener) {
|
|
@@ -101,11 +83,9 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle),
|
|
|
101
83
|
}
|
|
102
84
|
}
|
|
103
85
|
componentDidUpdate() {
|
|
104
|
-
|
|
105
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
|
|
86
|
+
this.props.makeStyles?.(this.makeStyleProps());
|
|
106
87
|
}
|
|
107
88
|
renderInstUIIcon(elementToRender) {
|
|
108
|
-
var _type;
|
|
109
89
|
if (!elementToRender) {
|
|
110
90
|
return null;
|
|
111
91
|
}
|
|
@@ -117,16 +97,25 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle),
|
|
|
117
97
|
large: 'lg'
|
|
118
98
|
};
|
|
119
99
|
const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
|
|
120
|
-
if (/*#__PURE__*/isValidElement(elementToRender) &&
|
|
100
|
+
if (/*#__PURE__*/isValidElement(elementToRender) && elementToRender.type?.name === 'WrappedIcon') {
|
|
121
101
|
return safeCloneElement(rendered, {
|
|
122
102
|
size: iconSize
|
|
123
103
|
});
|
|
124
104
|
}
|
|
125
105
|
return rendered;
|
|
126
106
|
}
|
|
107
|
+
makeStyleProps = () => {
|
|
108
|
+
const beforeElement = this.props.renderBeforeInput ? callRenderProp(this.props.renderBeforeInput) : null;
|
|
109
|
+
const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
|
|
110
|
+
return {
|
|
111
|
+
interaction: this.interaction,
|
|
112
|
+
invalid: this.invalid,
|
|
113
|
+
success: success,
|
|
114
|
+
beforeElementExists: !!beforeElement
|
|
115
|
+
};
|
|
116
|
+
};
|
|
127
117
|
focus() {
|
|
128
|
-
|
|
129
|
-
(_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
|
|
118
|
+
this._input?.focus();
|
|
130
119
|
}
|
|
131
120
|
get interaction() {
|
|
132
121
|
return getInteraction({
|
|
@@ -145,65 +134,88 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle),
|
|
|
145
134
|
return isActiveElement(this._input);
|
|
146
135
|
}
|
|
147
136
|
get value() {
|
|
148
|
-
|
|
149
|
-
return (_this$_input2 = this._input) === null || _this$_input2 === void 0 ? void 0 : _this$_input2.value;
|
|
137
|
+
return this._input?.value;
|
|
150
138
|
}
|
|
151
139
|
get id() {
|
|
152
140
|
return this.props.id || this._defaultId;
|
|
153
141
|
}
|
|
142
|
+
handleInputRef = node => {
|
|
143
|
+
this._input = node;
|
|
144
|
+
if (typeof this.props.inputRef === 'function') {
|
|
145
|
+
this.props.inputRef(node);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
handleChange = event => {
|
|
149
|
+
if (typeof this.props.onChange === 'function') {
|
|
150
|
+
this.props.onChange(event, event.target.value);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
handleBlur = event => {
|
|
154
|
+
if (typeof this.props.onBlur === 'function') {
|
|
155
|
+
this.props.onBlur(event);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
handleFocus = event => {
|
|
159
|
+
if (typeof this.props.onFocus === 'function') {
|
|
160
|
+
this.props.onFocus(event);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
154
163
|
renderInput() {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
const {
|
|
165
|
+
type,
|
|
166
|
+
size,
|
|
167
|
+
htmlSize,
|
|
168
|
+
display,
|
|
169
|
+
textAlign,
|
|
170
|
+
placeholder,
|
|
171
|
+
value,
|
|
172
|
+
defaultValue,
|
|
173
|
+
isRequired,
|
|
174
|
+
onFocus,
|
|
175
|
+
...rest
|
|
176
|
+
} = this.props;
|
|
168
177
|
const props = passthroughProps(rest);
|
|
169
|
-
const
|
|
178
|
+
const {
|
|
179
|
+
interaction
|
|
180
|
+
} = this;
|
|
170
181
|
let descriptionIds = '';
|
|
171
182
|
if (props['aria-describedby']) {
|
|
172
183
|
descriptionIds = `${props['aria-describedby']}`;
|
|
173
184
|
}
|
|
174
185
|
return _jsx("input", {
|
|
175
186
|
...props,
|
|
176
|
-
css:
|
|
187
|
+
css: this.props.styles?.textInput,
|
|
177
188
|
defaultValue: defaultValue,
|
|
178
189
|
value: value,
|
|
179
|
-
placeholder: interaction === 'enabled' ? placeholder :
|
|
190
|
+
placeholder: interaction === 'enabled' ? placeholder : undefined,
|
|
180
191
|
ref: this.handleInputRef,
|
|
181
192
|
type: type,
|
|
182
193
|
id: this.id,
|
|
183
194
|
required: isRequired,
|
|
184
|
-
"aria-invalid": this.invalid ? 'true' :
|
|
195
|
+
"aria-invalid": this.invalid ? 'true' : undefined,
|
|
185
196
|
disabled: interaction === 'disabled',
|
|
186
197
|
readOnly: interaction === 'readonly',
|
|
187
|
-
"aria-describedby": descriptionIds !== '' ? descriptionIds :
|
|
198
|
+
"aria-describedby": descriptionIds !== '' ? descriptionIds : undefined,
|
|
188
199
|
size: htmlSize,
|
|
189
200
|
onChange: this.handleChange,
|
|
190
201
|
onBlur: this.handleBlur
|
|
191
202
|
});
|
|
192
203
|
}
|
|
193
204
|
render() {
|
|
194
|
-
const
|
|
195
|
-
width
|
|
196
|
-
display
|
|
197
|
-
renderLabel
|
|
198
|
-
renderBeforeInput
|
|
199
|
-
renderAfterInput
|
|
200
|
-
messages
|
|
201
|
-
inputContainerRef
|
|
202
|
-
isRequired
|
|
203
|
-
styles
|
|
205
|
+
const {
|
|
206
|
+
width,
|
|
207
|
+
display,
|
|
208
|
+
renderLabel,
|
|
209
|
+
renderBeforeInput,
|
|
210
|
+
renderAfterInput,
|
|
211
|
+
messages,
|
|
212
|
+
inputContainerRef,
|
|
213
|
+
isRequired,
|
|
214
|
+
styles
|
|
215
|
+
} = this.props;
|
|
204
216
|
const beforeElement = this.renderInstUIIcon(renderBeforeInput);
|
|
205
217
|
const afterElement = this.renderInstUIIcon(renderAfterInput);
|
|
206
|
-
const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !==
|
|
218
|
+
const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== undefined || renderAfterInput !== undefined;
|
|
207
219
|
const label = callRenderProp(renderLabel);
|
|
208
220
|
return _jsx(FormField, {
|
|
209
221
|
id: this.id,
|
|
@@ -221,16 +233,16 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle),
|
|
|
221
233
|
readOnly: this.interaction === 'readonly',
|
|
222
234
|
"data-cid": "TextInput",
|
|
223
235
|
children: _jsx("span", {
|
|
224
|
-
css: styles
|
|
236
|
+
css: styles?.facade,
|
|
225
237
|
children: renderBeforeOrAfter ? _jsxs("span", {
|
|
226
|
-
css: styles
|
|
238
|
+
css: styles?.layout,
|
|
227
239
|
children: [beforeElement && _jsx("span", {
|
|
228
|
-
css: styles
|
|
240
|
+
css: styles?.beforeElement,
|
|
229
241
|
children: beforeElement
|
|
230
242
|
}), _jsxs("span", {
|
|
231
|
-
css: styles
|
|
243
|
+
css: styles?.inputLayout,
|
|
232
244
|
children: [this.renderInput(), afterElement && _jsx("span", {
|
|
233
|
-
css: styles
|
|
245
|
+
css: styles?.afterElement,
|
|
234
246
|
children: afterElement
|
|
235
247
|
})]
|
|
236
248
|
})]
|
|
@@ -239,16 +251,6 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle),
|
|
|
239
251
|
})
|
|
240
252
|
});
|
|
241
253
|
}
|
|
242
|
-
}
|
|
243
|
-
type: 'text',
|
|
244
|
-
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
245
|
-
interaction: void 0,
|
|
246
|
-
isRequired: false,
|
|
247
|
-
display: 'block',
|
|
248
|
-
shouldNotWrap: false,
|
|
249
|
-
size: 'medium',
|
|
250
|
-
textAlign: 'start',
|
|
251
|
-
messages: []
|
|
252
|
-
}, _TextInput)) || _class) || _class);
|
|
254
|
+
}) || _class) || _class);
|
|
253
255
|
export default TextInput;
|
|
254
256
|
export { TextInput };
|
|
@@ -36,13 +36,17 @@ import { calcFocusOutlineStyles } from '@instructure/emotion';
|
|
|
36
36
|
* @return The final style object, which will be used in the component
|
|
37
37
|
*/
|
|
38
38
|
const generateStyle = (componentTheme, props, sharedTokens, state) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const {
|
|
40
|
+
size,
|
|
41
|
+
textAlign,
|
|
42
|
+
shouldNotWrap
|
|
43
|
+
} = props;
|
|
44
|
+
const {
|
|
45
|
+
interaction,
|
|
46
|
+
success,
|
|
47
|
+
invalid,
|
|
48
|
+
beforeElementExists
|
|
49
|
+
} = state;
|
|
46
50
|
const sizeVariants = {
|
|
47
51
|
small: {
|
|
48
52
|
fontSize: componentTheme.fontSizeSm,
|
|
@@ -150,7 +154,7 @@ const generateStyle = (componentTheme, props, sharedTokens, state) => {
|
|
|
150
154
|
})
|
|
151
155
|
};
|
|
152
156
|
const focusOutline = calcFocusOutlineStyles(sharedTokens.focusOutline, {
|
|
153
|
-
focusColor: invalid ? 'danger' : success ? 'success' :
|
|
157
|
+
focusColor: invalid ? 'danger' : success ? 'success' : undefined,
|
|
154
158
|
// Only display the focus outline when the input is focused.
|
|
155
159
|
// This is to prevent double focus ring when e.g., a Button is rendered in
|
|
156
160
|
// `renderBeforeInput`
|