@instructure/ui-text-input 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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,80 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = 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
- /**
32
- * Generates the theme object for the component from the theme and provided additional information
33
- * @param {Object} theme The actual theme object.
34
- * @return {Object} The final theme object with the overrides and component variables
35
- */
36
- const generateComponentTheme = theme => {
37
- const {
38
- colors,
39
- typography,
40
- borders,
41
- spacing,
42
- forms,
43
- key: themeName
44
- } = theme;
45
- const themeSpecificStyle = {
46
- canvas: {
47
- color: theme['ic-brand-font-color-dark'],
48
- focusOutlineColor: theme['ic-brand-primary']
49
- }
50
- };
51
- const componentVariables = {
52
- fontFamily: typography?.fontFamily,
53
- fontWeight: typography?.fontWeightNormal,
54
- borderWidth: borders?.widthSmall,
55
- borderStyle: borders?.style,
56
- borderColor: colors?.contrasts?.grey3045,
57
- borderRadius: borders?.radiusMedium,
58
- color: colors?.contrasts?.grey125125,
59
- background: colors?.contrasts?.white1010,
60
- requiredInvalidColor: colors?.contrasts?.red5782,
61
- padding: spacing?.small,
62
- focusOutlineWidth: borders?.widthMedium,
63
- focusOutlineStyle: borders?.style,
64
- focusOutlineColor: colors?.contrasts?.blue4570,
65
- errorBorderColor: colors?.contrasts?.red4570,
66
- errorOutlineColor: colors?.contrasts?.red4570,
67
- placeholderColor: colors?.contrasts?.grey4570,
68
- smallFontSize: typography?.fontSizeSmall,
69
- smallHeight: forms?.inputHeightSmall,
70
- mediumFontSize: typography?.fontSizeMedium,
71
- mediumHeight: forms?.inputHeightMedium,
72
- largeFontSize: typography?.fontSizeLarge,
73
- largeHeight: forms?.inputHeightLarge
74
- };
75
- return {
76
- ...componentVariables,
77
- ...themeSpecificStyle[themeName]
78
- };
79
- };
80
- var _default = exports.default = generateComponentTheme;
@@ -1,266 +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"));
19
- var _props = require("./props");
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
- display: 'block',
61
- shouldNotWrap: false,
62
- size: 'medium',
63
- textAlign: 'start',
64
- messages: []
65
- };
66
- constructor(props) {
67
- super(props);
68
- this._defaultId = props.deterministicId();
69
- this._messagesId = props.deterministicId('TextInput-messages');
70
- }
71
- ref = null;
72
- _input = null;
73
- _defaultId;
74
- _messagesId;
75
- _focusListener = null;
76
- handleRef = el => {
77
- const {
78
- elementRef
79
- } = this.props;
80
- this.ref = el;
81
- if (typeof elementRef === 'function') {
82
- elementRef(el);
83
- }
84
- };
85
- componentDidMount() {
86
- if (this._input) {
87
- this._focusListener = (0, _addEventListener.addEventListener)(this._input, 'focus', this.handleFocus);
88
- }
89
- this.props.makeStyles?.(this.makeStyleProps());
90
- }
91
- componentWillUnmount() {
92
- if (this._focusListener) {
93
- this._focusListener.remove();
94
- }
95
- }
96
- componentDidUpdate() {
97
- this.props.makeStyles?.(this.makeStyleProps());
98
- }
99
- renderInstUIIcon(elementToRender) {
100
- if (!elementToRender) {
101
- return null;
102
- }
103
- const rendered = (0, _callRenderProp.callRenderProp)(elementToRender);
104
- // Map sizes to Lucide icon semantic size tokens
105
- const linkSizeToIconSize = {
106
- small: 'sm',
107
- medium: 'md',
108
- large: 'lg'
109
- };
110
- const iconSize = linkSizeToIconSize[this.props.size || 'medium'];
111
- if (/*#__PURE__*/(0, _react.isValidElement)(elementToRender) && elementToRender.type?.name === 'WrappedIcon') {
112
- return (0, _safeCloneElement.safeCloneElement)(rendered, {
113
- size: iconSize
114
- });
115
- }
116
- return rendered;
117
- }
118
- makeStyleProps = () => {
119
- const beforeElement = this.props.renderBeforeInput ? (0, _callRenderProp.callRenderProp)(this.props.renderBeforeInput) : null;
120
- const success = !!this.props.messages && this.props.messages.some(message => message.type === 'success');
121
- return {
122
- interaction: this.interaction,
123
- invalid: this.invalid,
124
- success: success,
125
- beforeElementExists: !!beforeElement
126
- };
127
- };
128
- focus() {
129
- this._input?.focus();
130
- }
131
- get interaction() {
132
- return (0, _getInteraction.getInteraction)({
133
- props: this.props
134
- });
135
- }
136
- get hasMessages() {
137
- return !!this.props.messages && this.props.messages.length > 0;
138
- }
139
- get invalid() {
140
- return !!this.props.messages && this.props.messages.findIndex(message => {
141
- return message.type === 'error' || message.type === 'newError';
142
- }) >= 0;
143
- }
144
- get focused() {
145
- return (0, _isActiveElement.isActiveElement)(this._input);
146
- }
147
- get value() {
148
- return this._input?.value;
149
- }
150
- get id() {
151
- return this.props.id || this._defaultId;
152
- }
153
- handleInputRef = node => {
154
- this._input = node;
155
- if (typeof this.props.inputRef === 'function') {
156
- this.props.inputRef(node);
157
- }
158
- };
159
- handleChange = event => {
160
- if (typeof this.props.onChange === 'function') {
161
- this.props.onChange(event, event.target.value);
162
- }
163
- };
164
- handleBlur = event => {
165
- if (typeof this.props.onBlur === 'function') {
166
- this.props.onBlur(event);
167
- }
168
- };
169
- handleFocus = event => {
170
- if (typeof this.props.onFocus === 'function') {
171
- this.props.onFocus(event);
172
- }
173
- };
174
- renderInput() {
175
- const {
176
- type,
177
- size,
178
- htmlSize,
179
- display,
180
- textAlign,
181
- placeholder,
182
- value,
183
- defaultValue,
184
- isRequired,
185
- onFocus,
186
- ...rest
187
- } = this.props;
188
- const props = (0, _passthroughProps.passthroughProps)(rest);
189
- const {
190
- interaction
191
- } = this;
192
- let descriptionIds = '';
193
- if (props['aria-describedby']) {
194
- descriptionIds = `${props['aria-describedby']}`;
195
- }
196
- return (0, _jsxRuntime.jsx)("input", {
197
- ...props,
198
- css: this.props.styles?.textInput,
199
- defaultValue: defaultValue,
200
- value: value,
201
- placeholder: interaction === 'enabled' ? placeholder : undefined,
202
- ref: this.handleInputRef,
203
- type: type,
204
- id: this.id,
205
- required: isRequired,
206
- "aria-invalid": this.invalid ? 'true' : undefined,
207
- disabled: interaction === 'disabled',
208
- readOnly: interaction === 'readonly',
209
- "aria-describedby": descriptionIds !== '' ? descriptionIds : undefined,
210
- size: htmlSize,
211
- onChange: this.handleChange,
212
- onBlur: this.handleBlur
213
- });
214
- }
215
- render() {
216
- const {
217
- width,
218
- display,
219
- renderLabel,
220
- renderBeforeInput,
221
- renderAfterInput,
222
- messages,
223
- inputContainerRef,
224
- isRequired,
225
- styles
226
- } = this.props;
227
- const beforeElement = this.renderInstUIIcon(renderBeforeInput);
228
- const afterElement = this.renderInstUIIcon(renderAfterInput);
229
- const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== undefined || renderAfterInput !== undefined;
230
- const label = (0, _callRenderProp.callRenderProp)(renderLabel);
231
- return (0, _jsxRuntime.jsx)(_latest.FormField, {
232
- id: this.id,
233
- label: label,
234
- messagesId: this._messagesId,
235
- messages: messages,
236
- inline: display === 'inline-block',
237
- width: width,
238
- inputContainerRef: inputContainerRef,
239
- layout: this.props.layout,
240
- elementRef: this.handleRef,
241
- margin: this.props.margin,
242
- isRequired: isRequired,
243
- disabled: this.interaction === 'disabled',
244
- readOnly: this.interaction === 'readonly',
245
- "data-cid": "TextInput",
246
- children: (0, _jsxRuntime.jsx)("span", {
247
- css: styles?.facade,
248
- children: renderBeforeOrAfter ? (0, _jsxRuntime.jsxs)("span", {
249
- css: styles?.layout,
250
- children: [beforeElement && (0, _jsxRuntime.jsx)("span", {
251
- css: styles?.beforeElement,
252
- children: beforeElement
253
- }), (0, _jsxRuntime.jsxs)("span", {
254
- css: styles?.inputLayout,
255
- children: [this.renderInput(), afterElement && (0, _jsxRuntime.jsx)("span", {
256
- css: styles?.afterElement,
257
- children: afterElement
258
- })]
259
- })]
260
- }) : (/* If no prepended or appended content, don't render Flex layout */
261
- this.renderInput())
262
- })
263
- });
264
- }
265
- }) || _class) || _class);
266
- var _default = exports.default = TextInput;
@@ -1,230 +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
- } = props;
49
- const {
50
- interaction,
51
- success,
52
- invalid,
53
- beforeElementExists
54
- } = state;
55
- const sizeVariants = {
56
- small: {
57
- fontSize: componentTheme.fontSizeSm,
58
- height: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`,
59
- lineHeight: `calc(${componentTheme.heightSm} - (2 * ${componentTheme.borderWidth}))`
60
- },
61
- medium: {
62
- fontSize: componentTheme.fontSizeMd,
63
- height: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`,
64
- lineHeight: `calc(${componentTheme.heightMd} - (2 * ${componentTheme.borderWidth}))`
65
- },
66
- large: {
67
- fontSize: componentTheme.fontSizeLg,
68
- height: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`,
69
- lineHeight: `calc(${componentTheme.heightLg} - (2 * ${componentTheme.borderWidth}))`
70
- }
71
- };
72
- const paddingHorizontalVariants = {
73
- small: componentTheme.paddingHorizontalSm,
74
- medium: componentTheme.paddingHorizontalMd,
75
- large: componentTheme.paddingHorizontalLg
76
- };
77
- const inputInteractionStates = {
78
- ...(interaction === 'enabled' && {
79
- color: componentTheme.textColor,
80
- '&::placeholder': {
81
- color: componentTheme.placeholderColor
82
- },
83
- '&:hover::placeholder': {
84
- color: componentTheme.placeholderHoverColor
85
- }
86
- // placeholder is not rendered in the `readOnly` and `disabled` state
87
- }),
88
- ...(interaction === 'readonly' && {
89
- color: componentTheme.textReadonlyColor
90
- }),
91
- ...(interaction === 'disabled' && {
92
- color: componentTheme.textDisabledColor
93
- })
94
- };
95
- const inputStyle = {
96
- all: 'initial',
97
- width: '100%',
98
- WebkitFontSmoothing: 'antialiased',
99
- MozOsxFontSmoothing: 'grayscale',
100
- appearance: 'none',
101
- margin: 0,
102
- display: 'block',
103
- boxSizing: 'border-box',
104
- outline: 'none',
105
- fontFamily: componentTheme.fontFamily,
106
- fontWeight: componentTheme.fontWeight,
107
- // padding of the text in the input
108
- padding: `0 ${componentTheme.gapContent} 0 ${componentTheme.gapContent}`,
109
- background: 'transparent',
110
- border: 'none',
111
- verticalAlign: 'baseline',
112
- '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
113
- display: 'none !important'
114
- },
115
- '&:focus': {
116
- boxShadow: 'initial'
117
- },
118
- ...sizeVariants[size],
119
- textAlign: textAlign,
120
- ...inputInteractionStates
121
- };
122
- const viewBase = {
123
- boxSizing: 'border-box',
124
- fontFamily: componentTheme.fontFamily,
125
- maxWidth: '100%',
126
- overflow: 'visible',
127
- unicodeBidi: 'isolate'
128
- };
129
- const containerInteractionStates = {
130
- ...(interaction === 'enabled' && {
131
- backgroundColor: componentTheme.backgroundColor,
132
- borderColor: componentTheme.borderColor,
133
- ...(success && {
134
- borderColor: componentTheme.successBorderColor
135
- }),
136
- ...(invalid && {
137
- borderColor: componentTheme.errorBorderColor
138
- }),
139
- '&:hover': {
140
- backgroundColor: componentTheme.backgroundHoverColor,
141
- borderColor: componentTheme.borderHoverColor,
142
- ...(success && {
143
- borderColor: componentTheme.successBorderColor
144
- }),
145
- ...(invalid && {
146
- borderColor: componentTheme.errorBorderColor
147
- })
148
- }
149
- }),
150
- ...(interaction === 'readonly' && {
151
- backgroundColor: componentTheme.backgroundReadonlyColor,
152
- borderColor: componentTheme.borderReadonlyColor
153
- }),
154
- ...(interaction === 'disabled' && {
155
- cursor: 'not-allowed',
156
- pointerEvents: 'none',
157
- backgroundColor: componentTheme.backgroundDisabledColor,
158
- borderColor: componentTheme.borderDisabledColor
159
- })
160
- };
161
- const focusOutline = (0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
162
- focusColor: invalid ? 'danger' : success ? 'success' : undefined,
163
- // Only display the focus outline when the input is focused.
164
- // This is to prevent double focus ring when e.g., a Button is rendered in
165
- // `renderBeforeInput`
166
- customCSSSelector: '&:has(input:focus)'
167
- });
168
- return {
169
- textInput: {
170
- label: 'textInput',
171
- ...inputStyle,
172
- '&:is(input)[type]': inputStyle,
173
- '&:-webkit-any(input)[type]': inputStyle
174
- },
175
- facade: {
176
- label: 'textInput__facade',
177
- position: 'relative',
178
- display: 'block',
179
- boxSizing: 'border-box',
180
- border: `${componentTheme.borderWidth} solid`,
181
- borderRadius: componentTheme.borderRadius,
182
- color: componentTheme.textColor,
183
- ...containerInteractionStates,
184
- ...focusOutline
185
- },
186
- layout: {
187
- label: 'textInput__layout',
188
- ...viewBase,
189
- display: 'flex',
190
- alignItems: 'center',
191
- justifyContent: 'flex-start',
192
- flexDirection: 'row',
193
- ...(!shouldNotWrap && {
194
- flexWrap: 'wrap'
195
- }),
196
- // left padding of the `renderBeforeInput` element
197
- ...(beforeElementExists && {
198
- paddingInlineStart: paddingHorizontalVariants[size]
199
- })
200
- },
201
- inputLayout: {
202
- label: 'textInput__inputLayout',
203
- flexGrow: 1,
204
- ...viewBase,
205
- display: 'flex',
206
- alignItems: 'center',
207
- justifyContent: 'flex-start',
208
- flexDirection: 'row'
209
- },
210
- beforeElement: {
211
- ...(interaction === 'disabled' && {
212
- opacity: 0.5
213
- }),
214
- label: 'textInput__beforeElement'
215
- },
216
- afterElement: {
217
- ...(interaction === 'disabled' && {
218
- opacity: 0.5
219
- }),
220
- display: 'flex',
221
- alignItems: 'center',
222
- paddingInlineEnd: paddingHorizontalVariants[size],
223
- label: 'textInput__afterElement',
224
- ...viewBase,
225
- borderRadius: componentTheme.borderRadius,
226
- flexShrink: 0
227
- }
228
- };
229
- };
230
- 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 _v.TextInput;
10
- }
11
- });
12
- var _v = require("../TextInput/v1");
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 _v.TextInput;
10
- }
11
- });
12
- var _v = require("../TextInput/v2");
package/lib/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}