@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.
@@ -1,6 +1,4 @@
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;
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 = (_TextInput = class TextInput extends Component {
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
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
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
- var _this$props$makeStyle2, _this$props2;
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) && ((_type = elementToRender.type) === null || _type === void 0 ? void 0 : _type.name) === 'WrappedIcon') {
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
- var _this$_input;
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
- var _this$_input2;
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
- var _this$props$styles;
156
- const _this$props3 = this.props,
157
- type = _this$props3.type,
158
- size = _this$props3.size,
159
- htmlSize = _this$props3.htmlSize,
160
- display = _this$props3.display,
161
- textAlign = _this$props3.textAlign,
162
- placeholder = _this$props3.placeholder,
163
- value = _this$props3.value,
164
- defaultValue = _this$props3.defaultValue,
165
- isRequired = _this$props3.isRequired,
166
- onFocus = _this$props3.onFocus,
167
- rest = _objectWithoutProperties(_this$props3, _excluded);
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 interaction = this.interaction;
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: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.textInput,
187
+ css: this.props.styles?.textInput,
177
188
  defaultValue: defaultValue,
178
189
  value: value,
179
- placeholder: interaction === 'enabled' ? placeholder : void 0,
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' : void 0,
195
+ "aria-invalid": this.invalid ? 'true' : undefined,
185
196
  disabled: interaction === 'disabled',
186
197
  readOnly: interaction === 'readonly',
187
- "aria-describedby": descriptionIds !== '' ? descriptionIds : void 0,
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 _this$props4 = this.props,
195
- width = _this$props4.width,
196
- display = _this$props4.display,
197
- renderLabel = _this$props4.renderLabel,
198
- renderBeforeInput = _this$props4.renderBeforeInput,
199
- renderAfterInput = _this$props4.renderAfterInput,
200
- messages = _this$props4.messages,
201
- inputContainerRef = _this$props4.inputContainerRef,
202
- isRequired = _this$props4.isRequired,
203
- styles = _this$props4.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 !== void 0 || renderAfterInput !== void 0;
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 === null || styles === void 0 ? void 0 : styles.facade,
236
+ css: styles?.facade,
225
237
  children: renderBeforeOrAfter ? _jsxs("span", {
226
- css: styles === null || styles === void 0 ? void 0 : styles.layout,
238
+ css: styles?.layout,
227
239
  children: [beforeElement && _jsx("span", {
228
- css: styles === null || styles === void 0 ? void 0 : styles.beforeElement,
240
+ css: styles?.beforeElement,
229
241
  children: beforeElement
230
242
  }), _jsxs("span", {
231
- css: styles === null || styles === void 0 ? void 0 : styles.inputLayout,
243
+ css: styles?.inputLayout,
232
244
  children: [this.renderInput(), afterElement && _jsx("span", {
233
- css: styles === null || styles === void 0 ? void 0 : styles.afterElement,
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
- }, _TextInput.displayName = "TextInput", _TextInput.componentId = 'TextInput', _TextInput.allowedProps = allowedProps, _TextInput.defaultProps = {
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 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
- beforeElementExists = state.beforeElementExists;
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' : void 0,
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`