@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,281 +0,0 @@
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 _react = require("react");
9
- var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
10
- var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
11
- var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
12
- var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
13
- var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
14
- var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
15
- var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
16
- var _latest = require("@instructure/ui-form-field/latest");
17
- var _emotion = require("@instructure/emotion");
18
- var _styles = _interopRequireDefault(require("./styles.js"));
19
- var _props = require("./props.js");
20
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
- var _dec, _dec2, _class;
22
- /*
23
- * The MIT License (MIT)
24
- *
25
- * Copyright (c) 2015 - present Instructure, Inc.
26
- *
27
- * Permission is hereby granted, free of charge, to any person obtaining a copy
28
- * of this software and associated documentation files (the "Software"), to deal
29
- * in the Software without restriction, including without limitation the rights
30
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
- * copies of the Software, and to permit persons to whom the Software is
32
- * furnished to do so, subject to the following conditions:
33
- *
34
- * The above copyright notice and this permission notice shall be included in all
35
- * copies or substantial portions of the Software.
36
- *
37
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
- * SOFTWARE.
44
- */
45
- /**
46
- ---
47
- category: components
48
- tags: form, field, input
49
- ---
50
- **/
51
- let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleNew)(_styles.default), _dec(_class = _dec2(_class = class TextInput extends _react.Component {
52
- static displayName = 'TextInput';
53
- static componentId = 'TextInput';
54
- static allowedProps = _props.allowedProps;
55
- static defaultProps = {
56
- type: 'text',
57
- // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
58
- interaction: undefined,
59
- isRequired: false,
60
- forcePlaceholder: false,
61
- display: 'block',
62
- shouldNotWrap: false,
63
- renderBeforeInputElementGap: 'default',
64
- size: 'medium',
65
- textAlign: 'start',
66
- messages: []
67
- };
68
- constructor(props) {
69
- super(props);
70
- this._defaultId = props.deterministicId();
71
- this._messagesId = props.deterministicId('TextInput-messages');
72
- this._labelId = props.labelId ?? props.deterministicId('TextInput-label');
73
- }
74
- ref = null;
75
- _input = null;
76
- _defaultId;
77
- _messagesId;
78
- _labelId;
79
- _focusListener = null;
80
- handleRef = el => {
81
- const {
82
- elementRef
83
- } = this.props;
84
- this.ref = el;
85
- if (typeof elementRef === 'function') {
86
- elementRef(el);
87
- }
88
- };
89
- componentDidMount() {
90
- if (this._input) {
91
- this._focusListener = (0, _addEventListener.addEventListener)(this._input, 'focus', this.handleFocus);
92
- }
93
- this.props.makeStyles?.(this.makeStyleProps());
94
- }
95
- componentWillUnmount() {
96
- if (this._focusListener) {
97
- this._focusListener.remove();
98
- }
99
- }
100
- componentDidUpdate() {
101
- this.props.makeStyles?.(this.makeStyleProps());
102
- }
103
- renderInstUIIcon(elementToRender) {
104
- if (!elementToRender) {
105
- return null;
106
- }
107
- const rendered = (0, _callRenderProp.callRenderProp)(elementToRender);
108
- // Map sizes to Lucide icon semantic size tokens
109
- const linkSizeToIconSize = {
110
- small: 'sm',
111
- medium: 'md',
112
- large: 'lg'
113
- };
114
- const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
115
- if (/*#__PURE__*/(0, _react.isValidElement)(elementToRender) && elementToRender.type?.name === 'WrappedIcon') {
116
- return (0, _safeCloneElement.safeCloneElement)(rendered, {
117
- size: iconSize
118
- });
119
- }
120
- return rendered;
121
- }
122
- makeStyleProps = () => {
123
- const beforeElement = this.props.renderBeforeInput ? (0, _callRenderProp.callRenderProp)(this.props.renderBeforeInput) : null;
124
- const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
125
- return {
126
- interaction: this.interaction,
127
- invalid: this.invalid,
128
- success: success,
129
- beforeElementExists: !!beforeElement
130
- };
131
- };
132
- focus() {
133
- this._input?.focus();
134
- }
135
- get interaction() {
136
- return (0, _getInteraction.getInteraction)({
137
- props: this.props
138
- });
139
- }
140
- get hasMessages() {
141
- return !!this.props.messages?.some(m => !!m.text);
142
- }
143
- get invalid() {
144
- return !!this.props.messages && this.props.messages.findIndex(message => {
145
- return message.type === 'error' || message.type === 'newError';
146
- }) >= 0;
147
- }
148
- get focused() {
149
- return (0, _isActiveElement.isActiveElement)(this._input);
150
- }
151
- get value() {
152
- return this._input?.value;
153
- }
154
- get id() {
155
- return this.props.id || this._defaultId;
156
- }
157
- handleInputRef = node => {
158
- this._input = node;
159
- if (typeof this.props.inputRef === 'function') {
160
- this.props.inputRef(node);
161
- }
162
- };
163
- handleChange = event => {
164
- if (typeof this.props.onChange === 'function') {
165
- this.props.onChange(event, event.target.value);
166
- }
167
- };
168
- handleBlur = event => {
169
- if (typeof this.props.onBlur === 'function') {
170
- this.props.onBlur(event);
171
- }
172
- };
173
- handleFocus = event => {
174
- if (typeof this.props.onFocus === 'function') {
175
- this.props.onFocus(event);
176
- }
177
- };
178
- renderInput() {
179
- const {
180
- type,
181
- size,
182
- htmlSize,
183
- display,
184
- textAlign,
185
- placeholder,
186
- value,
187
- defaultValue,
188
- isRequired,
189
- forcePlaceholder,
190
- onFocus,
191
- ...rest
192
- } = this.props;
193
- const props = (0, _passthroughProps.passthroughProps)(rest);
194
- const {
195
- interaction
196
- } = this;
197
- let descriptionIds = '';
198
- if (props['aria-describedby']) {
199
- descriptionIds = `${props['aria-describedby']}`;
200
- }
201
- // Keep messages in the description, not the accessible name.
202
- // A consumer-provided aria-labelledby wins.
203
- let labelledById = props['aria-labelledby'];
204
- if (this.hasMessages) {
205
- descriptionIds = [descriptionIds, this._messagesId].filter(Boolean).join(' ');
206
- labelledById = labelledById || this._labelId;
207
- }
208
- return (0, _jsxRuntime.jsx)("input", {
209
- ...props,
210
- css: this.props.styles?.textInput,
211
- defaultValue: defaultValue,
212
- value: value,
213
- placeholder: forcePlaceholder || interaction === 'enabled' ? placeholder : undefined,
214
- ref: this.handleInputRef,
215
- type: type,
216
- id: this.id,
217
- required: isRequired,
218
- "aria-invalid": this.invalid ? 'true' : undefined,
219
- disabled: interaction === 'disabled',
220
- readOnly: interaction === 'readonly',
221
- "aria-describedby": descriptionIds !== '' ? descriptionIds : undefined,
222
- "aria-labelledby": labelledById,
223
- size: htmlSize,
224
- onChange: this.handleChange,
225
- onBlur: this.handleBlur
226
- });
227
- }
228
- render() {
229
- const {
230
- width,
231
- display,
232
- renderLabel,
233
- renderBeforeInput,
234
- renderAfterInput,
235
- messages,
236
- inputContainerRef,
237
- isRequired,
238
- forceMessages,
239
- styles
240
- } = this.props;
241
- const beforeElement = this.renderInstUIIcon(renderBeforeInput);
242
- const afterElement = this.renderInstUIIcon(renderAfterInput);
243
- const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== undefined || renderAfterInput !== undefined;
244
- const label = (0, _callRenderProp.callRenderProp)(renderLabel);
245
- return (0, _jsxRuntime.jsx)(_latest.FormField, {
246
- id: this.id,
247
- label: label,
248
- messagesId: this._messagesId,
249
- labelId: this._labelId,
250
- messages: messages,
251
- inline: display === 'inline-block',
252
- width: width,
253
- inputContainerRef: inputContainerRef,
254
- layout: this.props.layout,
255
- elementRef: this.handleRef,
256
- margin: this.props.margin,
257
- isRequired: isRequired,
258
- disabled: this.interaction === 'disabled',
259
- readOnly: this.interaction === 'readonly' && !forceMessages,
260
- "data-cid": "TextInput",
261
- children: (0, _jsxRuntime.jsx)("span", {
262
- css: styles?.facade,
263
- children: renderBeforeOrAfter ? (0, _jsxRuntime.jsxs)("span", {
264
- css: styles?.layout,
265
- children: [beforeElement && (0, _jsxRuntime.jsx)("span", {
266
- css: styles?.beforeElement,
267
- children: beforeElement
268
- }), (0, _jsxRuntime.jsxs)("span", {
269
- css: styles?.inputLayout,
270
- children: [this.renderInput(), afterElement && (0, _jsxRuntime.jsx)("span", {
271
- css: styles?.afterElement,
272
- children: afterElement
273
- })]
274
- })]
275
- }) : (/* If no prepended or appended content, don't render Flex layout */
276
- this.renderInput())
277
- })
278
- });
279
- }
280
- }) || _class) || _class);
281
- var _default = exports.default = TextInput;
@@ -1,31 +0,0 @@
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', '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'];
@@ -1,262 +0,0 @@
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 {
45
- size,
46
- textAlign,
47
- shouldNotWrap,
48
- renderBeforeInputElementGap
49
- } = props;
50
- const {
51
- interaction,
52
- success,
53
- invalid,
54
- beforeElementExists
55
- } = state;
56
- const isEvenSpacing = renderBeforeInputElementGap === 'even';
57
- const contentGap = {
58
- small: sharedTokens.spacing.general.spaceXs,
59
- medium: sharedTokens.spacing.general.spaceXs,
60
- large: sharedTokens.spacing.general.spaceSm
61
- }[size];
62
- const contentPaddingBlock = {
63
- small: sharedTokens.spacing.general.space2xs,
64
- medium: sharedTokens.spacing.general.space2xs,
65
- large: sharedTokens.spacing.general.spaceXs
66
- }[size];
67
- const heightTokens = {
68
- small: componentTheme.heightSm,
69
- medium: componentTheme.heightMd,
70
- large: componentTheme.heightLg
71
- };
72
- const inputHeightStyle = sizeHeight => isEvenSpacing ? {
73
- height: 'auto'
74
- } : {
75
- height: `calc(${sizeHeight} - (2 * ${componentTheme.borderWidth}))`,
76
- lineHeight: `calc(${sizeHeight} - (2 * ${componentTheme.borderWidth}))`
77
- };
78
- const sizeVariants = {
79
- small: {
80
- fontSize: componentTheme.fontSizeSm,
81
- ...inputHeightStyle(componentTheme.heightSm)
82
- },
83
- medium: {
84
- fontSize: componentTheme.fontSizeMd,
85
- ...inputHeightStyle(componentTheme.heightMd)
86
- },
87
- large: {
88
- fontSize: componentTheme.fontSizeLg,
89
- ...inputHeightStyle(componentTheme.heightLg)
90
- }
91
- };
92
- const paddingHorizontalVariants = {
93
- small: componentTheme.paddingHorizontalSm,
94
- medium: componentTheme.paddingHorizontalMd,
95
- large: componentTheme.paddingHorizontalLg
96
- };
97
- const inputInteractionStates = {
98
- ...(interaction === 'enabled' && {
99
- color: componentTheme.textColor,
100
- '&::placeholder': {
101
- color: componentTheme.placeholderColor
102
- },
103
- '&:hover::placeholder': {
104
- color: componentTheme.placeholderHoverColor
105
- }
106
- // placeholder is not rendered in the `readOnly` and `disabled` state
107
- }),
108
- ...(interaction === 'readonly' && {
109
- color: componentTheme.textReadonlyColor
110
- }),
111
- ...(interaction === 'disabled' && {
112
- color: componentTheme.textDisabledColor
113
- })
114
- };
115
- const inputStyle = {
116
- all: 'initial',
117
- width: '100%',
118
- WebkitFontSmoothing: 'antialiased',
119
- MozOsxFontSmoothing: 'grayscale',
120
- appearance: 'none',
121
- margin: 0,
122
- display: 'block',
123
- boxSizing: 'border-box',
124
- outline: 'none',
125
- fontFamily: componentTheme.fontFamily,
126
- fontWeight: componentTheme.fontWeight,
127
- // padding of the text in the input
128
- padding: `0 ${componentTheme.gapContent} 0 ${componentTheme.gapContent}`,
129
- background: 'transparent',
130
- border: 'none',
131
- verticalAlign: 'baseline',
132
- '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
133
- display: 'none !important'
134
- },
135
- '&:focus': {
136
- boxShadow: 'initial'
137
- },
138
- ...sizeVariants[size],
139
- textAlign: textAlign,
140
- ...inputInteractionStates
141
- };
142
- const viewBase = {
143
- boxSizing: 'border-box',
144
- fontFamily: componentTheme.fontFamily,
145
- maxWidth: '100%',
146
- overflow: 'visible',
147
- unicodeBidi: 'isolate'
148
- };
149
- const containerInteractionStates = {
150
- ...(interaction === 'enabled' && {
151
- backgroundColor: componentTheme.backgroundColor,
152
- borderColor: componentTheme.borderColor,
153
- ...(success && {
154
- borderColor: componentTheme.successBorderColor
155
- }),
156
- ...(invalid && {
157
- borderColor: componentTheme.errorBorderColor
158
- }),
159
- '&:hover': {
160
- backgroundColor: componentTheme.backgroundHoverColor,
161
- borderColor: componentTheme.borderHoverColor,
162
- ...(success && {
163
- borderColor: componentTheme.successBorderColor
164
- }),
165
- ...(invalid && {
166
- borderColor: componentTheme.errorBorderColor
167
- })
168
- }
169
- }),
170
- ...(interaction === 'readonly' && {
171
- backgroundColor: componentTheme.backgroundReadonlyColor,
172
- borderColor: componentTheme.borderReadonlyColor
173
- }),
174
- ...(interaction === 'disabled' && {
175
- cursor: 'not-allowed',
176
- pointerEvents: 'none',
177
- backgroundColor: componentTheme.backgroundDisabledColor,
178
- borderColor: componentTheme.borderDisabledColor
179
- })
180
- };
181
- const focusOutline = (0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
182
- focusColor: invalid ? 'danger' : success ? 'success' : undefined,
183
- // Only display the focus outline when the input is focused.
184
- // This is to prevent double focus ring when e.g., a Button is rendered in
185
- // `renderBeforeInput`
186
- customCSSSelector: '&:has(input:focus)'
187
- });
188
- return {
189
- textInput: {
190
- label: 'textInput',
191
- ...inputStyle,
192
- '&:is(input)[type]': inputStyle,
193
- '&:-webkit-any(input)[type]': inputStyle
194
- },
195
- facade: {
196
- label: 'textInput__facade',
197
- position: 'relative',
198
- display: 'block',
199
- boxSizing: 'border-box',
200
- border: `${componentTheme.borderWidth} solid`,
201
- borderRadius: componentTheme.borderRadius,
202
- color: componentTheme.textColor,
203
- ...containerInteractionStates,
204
- ...focusOutline
205
- },
206
- layout: {
207
- label: 'textInput__layout',
208
- ...viewBase,
209
- display: 'flex',
210
- alignItems: 'center',
211
- justifyContent: 'flex-start',
212
- flexDirection: 'row',
213
- ...(!shouldNotWrap && {
214
- flexWrap: 'wrap'
215
- }),
216
- // left padding of the `renderBeforeInput` element
217
- ...(beforeElementExists && {
218
- paddingInlineStart: paddingHorizontalVariants[size]
219
- }),
220
- ...(isEvenSpacing && {
221
- minHeight: heightTokens[size],
222
- paddingBlock: contentPaddingBlock,
223
- gap: contentGap
224
- })
225
- },
226
- inputLayout: {
227
- label: 'textInput__inputLayout',
228
- flexGrow: 1,
229
- ...viewBase,
230
- display: 'flex',
231
- alignItems: 'center',
232
- justifyContent: 'flex-start',
233
- flexDirection: 'row'
234
- },
235
- beforeElement: {
236
- label: 'textInput__beforeElement',
237
- ...(interaction === 'disabled' && !isEvenSpacing ? {
238
- opacity: 0.5
239
- } : {
240
- display: 'contents'
241
- }),
242
- ...(interaction === 'disabled' && isEvenSpacing && {
243
- '& > *': {
244
- opacity: 0.5
245
- }
246
- })
247
- },
248
- afterElement: {
249
- ...(interaction === 'disabled' && {
250
- opacity: 0.5
251
- }),
252
- display: 'flex',
253
- alignItems: 'center',
254
- paddingInlineEnd: paddingHorizontalVariants[size],
255
- label: 'textInput__afterElement',
256
- ...viewBase,
257
- borderRadius: componentTheme.borderRadius,
258
- flexShrink: 0
259
- }
260
- };
261
- };
262
- var _default = exports.default = generateStyle;
package/lib/exports/a.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "TextInput", {
7
- enumerable: true,
8
- get: function () {
9
- return _index.TextInput;
10
- }
11
- });
12
- var _index = require("../TextInput/v1/index.js");
package/lib/exports/b.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "TextInput", {
7
- enumerable: true,
8
- get: function () {
9
- return _index.TextInput;
10
- }
11
- });
12
- var _index = require("../TextInput/v2/index.js");
package/lib/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}