@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,218 +1,162 @@
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
- /**
26
- * ---
27
- * private: true
28
- * ---
29
- * Generates the style object from the theme and provided additional information
30
- * @param {Object} componentTheme The theme variable object.
31
- * @param {Object} props the props of the component, the style is applied to
32
- * @param {Object} state the state of the component, the style is applied to
33
- * @return {Object} The final style object, which will be used in the component
34
- */
35
- const generateStyle = (componentTheme, props, state) => {
36
- const {
37
- size,
38
- textAlign,
39
- shouldNotWrap
40
- } = props;
41
- const {
42
- disabled,
43
- invalid,
44
- focused,
45
- afterElementHasWidth,
46
- beforeElementExists
47
- } = state;
48
- const sizeVariants = {
49
- small: {
50
- fontSize: componentTheme.smallFontSize,
51
- height: `calc(${componentTheme.smallHeight} - (2 * ${componentTheme.borderWidth}))`,
52
- lineHeight: `calc(${componentTheme.smallHeight} - (2 * ${componentTheme.borderWidth}))`
53
- },
54
- medium: {
55
- fontSize: componentTheme.mediumFontSize,
56
- height: `calc(${componentTheme.mediumHeight} - (2 * ${componentTheme.borderWidth}))`,
57
- lineHeight: `calc(${componentTheme.mediumHeight} - (2 * ${componentTheme.borderWidth}))`
58
- },
59
- large: {
60
- fontSize: componentTheme.largeFontSize,
61
- height: `calc(${componentTheme.largeHeight} - (2 * ${componentTheme.borderWidth}))`,
62
- lineHeight: `calc(${componentTheme.largeHeight} - (2 * ${componentTheme.borderWidth}))`
63
- }
64
- };
65
- const disabledStyle = disabled ? {
66
- cursor: 'not-allowed',
67
- pointerEvents: 'none',
68
- opacity: '0.5'
69
- } : {};
70
- const focusedStyle = focused ? {
71
- opacity: 1,
72
- transform: 'scale(1)'
73
- } : {
74
- opacity: 0,
75
- transform: 'scale(0.95)'
76
- };
77
- const invalidStyle = invalid ? {
78
- borderColor: componentTheme.errorBorderColor
79
- } : {};
80
- const invalidAndFocusedStyle = invalid && focused ? {
81
- borderColor: componentTheme.errorBorderColor
82
- } : {};
83
- const inputStyle = {
84
- all: 'initial',
85
- '&::-ms-clear': {
86
- display: 'none'
87
- },
88
- width: '100%',
89
- WebkitFontSmoothing: 'antialiased',
90
- MozOsxFontSmoothing: 'grayscale',
91
- appearance: 'none',
92
- margin: 0,
93
- display: 'block',
94
- boxSizing: 'border-box',
95
- outline: 'none',
96
- fontFamily: componentTheme.fontFamily,
97
- fontWeight: componentTheme.fontWeight,
98
- color: componentTheme.color,
99
- padding: `0 ${componentTheme.padding}`,
100
- background: 'transparent',
101
- border: 'none',
102
- verticalAlign: 'baseline',
103
- '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
104
- display: 'none !important'
105
- },
106
- '&:focus': {
107
- boxShadow: 'initial'
108
- },
109
- '&::placeholder': {
110
- color: componentTheme.placeholderColor
111
- },
112
- ...sizeVariants[size],
113
- textAlign: textAlign
114
- };
115
- const viewBase = {
116
- boxSizing: 'border-box',
117
- fontFamily: componentTheme.fontFamily,
118
- maxWidth: '100%',
119
- overflow: 'visible',
120
- unicodeBidi: 'isolate'
121
- };
122
- const flexBase = {
123
- ...viewBase,
124
- display: 'flex',
125
- alignItems: 'center',
126
- justifyContent: 'flex-start',
127
- flexDirection: 'row'
128
- };
129
- return {
130
- requiredInvalid: {
131
- color: componentTheme.requiredInvalidColor
132
- },
133
- textInput: {
134
- label: 'textInput',
135
- ...inputStyle,
136
- '&:is(input)[type]': inputStyle,
137
- '&:-webkit-any(input)[type]': inputStyle
138
- },
139
- facade: {
140
- label: 'textInput__facade',
141
- position: 'relative',
142
- display: 'block',
143
- boxSizing: 'border-box',
144
- border: `${componentTheme.borderWidth} ${componentTheme.borderStyle} ${componentTheme.borderColor}`,
145
- borderRadius: componentTheme.borderRadius,
146
- background: componentTheme.background,
147
- color: componentTheme.color,
148
- '&::before': {
149
- content: '""',
1
+ const generateStyle = (componentTheme, props, state)=>{
2
+ const { size, textAlign, shouldNotWrap } = props;
3
+ const { disabled, invalid, focused, afterElementHasWidth, beforeElementExists } = state;
4
+ const sizeVariants = {
5
+ small: {
6
+ fontSize: componentTheme.smallFontSize,
7
+ height: `calc(${componentTheme.smallHeight} - (2 * ${componentTheme.borderWidth}))`,
8
+ lineHeight: `calc(${componentTheme.smallHeight} - (2 * ${componentTheme.borderWidth}))`
9
+ },
10
+ medium: {
11
+ fontSize: componentTheme.mediumFontSize,
12
+ height: `calc(${componentTheme.mediumHeight} - (2 * ${componentTheme.borderWidth}))`,
13
+ lineHeight: `calc(${componentTheme.mediumHeight} - (2 * ${componentTheme.borderWidth}))`
14
+ },
15
+ large: {
16
+ fontSize: componentTheme.largeFontSize,
17
+ height: `calc(${componentTheme.largeHeight} - (2 * ${componentTheme.borderWidth}))`,
18
+ lineHeight: `calc(${componentTheme.largeHeight} - (2 * ${componentTheme.borderWidth}))`
19
+ }
20
+ };
21
+ const disabledStyle = disabled ? {
22
+ cursor: 'not-allowed',
150
23
  pointerEvents: 'none',
151
- position: 'absolute',
24
+ opacity: '0.5'
25
+ } : {};
26
+ const focusedStyle = focused ? {
27
+ opacity: 1,
28
+ transform: 'scale(1)'
29
+ } : {
30
+ opacity: 0,
31
+ transform: 'scale(0.95)'
32
+ };
33
+ const invalidStyle = invalid ? {
34
+ borderColor: componentTheme.errorBorderColor
35
+ } : {};
36
+ const invalidAndFocusedStyle = invalid && focused ? {
37
+ borderColor: componentTheme.errorBorderColor
38
+ } : {};
39
+ const inputStyle = {
40
+ all: 'initial',
41
+ '&::-ms-clear': {
42
+ display: 'none'
43
+ },
44
+ width: '100%',
45
+ WebkitFontSmoothing: 'antialiased',
46
+ MozOsxFontSmoothing: 'grayscale',
47
+ appearance: 'none',
48
+ margin: 0,
152
49
  display: 'block',
153
50
  boxSizing: 'border-box',
154
- top: '-0.25rem',
155
- bottom: '-0.25rem',
156
- left: '-0.25rem',
157
- right: '-0.25rem',
158
- border: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`,
159
- borderRadius: `calc(${componentTheme.borderRadius} * 1.5)`,
160
- transition: 'all 0.2s',
161
- ...focusedStyle,
162
- // properties to transition on :focus
163
- ...invalidAndFocusedStyle
164
- },
165
- ...disabledStyle,
166
- ...invalidStyle
167
- },
168
- layout: {
169
- label: 'textInput__layout',
170
- ...viewBase,
171
- display: 'flex',
172
- alignItems: 'center',
173
- justifyContent: 'flex-start',
174
- flexDirection: 'row',
175
- ...(!shouldNotWrap && {
176
- flexWrap: 'wrap'
177
- }),
178
- ...(beforeElementExists && {
179
- paddingInlineStart: componentTheme.padding
180
- })
181
- },
182
- inputLayout: {
183
- label: 'textInput__inputLayout',
184
- flexGrow: 1,
185
- ...flexBase
186
- },
187
- afterElement: {
188
- // the next couple lines (until the `label`) is needed so the IconButton looks OK inside the TextInput
189
- // explanation: if the content inside is not a button or a popover (which could contain a button) it should have some padding on the right
190
- // lineHeight is only needed if it is not popover or button
191
- '& > :not(button):not([data-position^="Popover"])': {
192
- marginRight: componentTheme.padding,
193
- ...(sizeVariants[size] && {
194
- lineHeight: sizeVariants[size].lineHeight
195
- })
196
- },
197
- display: 'flex',
198
- alignItems: 'center',
199
- // Spread all sizeVariants except lineHeight (handled above)
200
- ...(sizeVariants[size] ?
201
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
202
- (({
203
- lineHeight,
204
- ...rest
205
- }) => rest)(sizeVariants[size]) : {}),
206
- label: 'textInput__afterElement',
207
- ...viewBase,
208
- borderRadius: componentTheme.borderRadius,
209
- flexShrink: 0,
210
- // we only override the padding once the width is calculated,
211
- // it needs the padding on render
212
- ...(afterElementHasWidth === false && {
213
- paddingInlineEnd: 0
214
- })
215
- }
216
- };
51
+ outline: 'none',
52
+ fontFamily: componentTheme.fontFamily,
53
+ fontWeight: componentTheme.fontWeight,
54
+ color: componentTheme.color,
55
+ padding: `0 ${componentTheme.padding}`,
56
+ background: 'transparent',
57
+ border: 'none',
58
+ verticalAlign: 'baseline',
59
+ '&[autocomplete="off"]::-webkit-contacts-auto-fill-button': {
60
+ display: 'none !important'
61
+ },
62
+ '&:focus': {
63
+ boxShadow: 'initial'
64
+ },
65
+ '&::placeholder': {
66
+ color: componentTheme.placeholderColor
67
+ },
68
+ ...sizeVariants[size],
69
+ textAlign: textAlign
70
+ };
71
+ const viewBase = {
72
+ boxSizing: 'border-box',
73
+ fontFamily: componentTheme.fontFamily,
74
+ maxWidth: '100%',
75
+ overflow: 'visible',
76
+ unicodeBidi: 'isolate'
77
+ };
78
+ const flexBase = {
79
+ ...viewBase,
80
+ display: 'flex',
81
+ alignItems: 'center',
82
+ justifyContent: 'flex-start',
83
+ flexDirection: 'row'
84
+ };
85
+ return {
86
+ requiredInvalid: {
87
+ color: componentTheme.requiredInvalidColor
88
+ },
89
+ textInput: {
90
+ label: 'textInput',
91
+ ...inputStyle,
92
+ '&:is(input)[type]': inputStyle,
93
+ '&:-webkit-any(input)[type]': inputStyle
94
+ },
95
+ facade: {
96
+ label: 'textInput__facade',
97
+ position: 'relative',
98
+ display: 'block',
99
+ boxSizing: 'border-box',
100
+ border: `${componentTheme.borderWidth} ${componentTheme.borderStyle} ${componentTheme.borderColor}`,
101
+ borderRadius: componentTheme.borderRadius,
102
+ background: componentTheme.background,
103
+ color: componentTheme.color,
104
+ '&::before': {
105
+ content: '""',
106
+ pointerEvents: 'none',
107
+ position: 'absolute',
108
+ display: 'block',
109
+ boxSizing: 'border-box',
110
+ top: '-0.25rem',
111
+ bottom: '-0.25rem',
112
+ left: '-0.25rem',
113
+ right: '-0.25rem',
114
+ border: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`,
115
+ borderRadius: `calc(${componentTheme.borderRadius} * 1.5)`,
116
+ transition: 'all 0.2s',
117
+ ...focusedStyle,
118
+ ...invalidAndFocusedStyle
119
+ },
120
+ ...disabledStyle,
121
+ ...invalidStyle
122
+ },
123
+ layout: {
124
+ label: 'textInput__layout',
125
+ ...viewBase,
126
+ display: 'flex',
127
+ alignItems: 'center',
128
+ justifyContent: 'flex-start',
129
+ flexDirection: 'row',
130
+ ...!shouldNotWrap && {
131
+ flexWrap: 'wrap'
132
+ },
133
+ ...beforeElementExists && {
134
+ paddingInlineStart: componentTheme.padding
135
+ }
136
+ },
137
+ inputLayout: {
138
+ label: 'textInput__inputLayout',
139
+ flexGrow: 1,
140
+ ...flexBase
141
+ },
142
+ afterElement: {
143
+ '& > :not(button):not([data-position^="Popover"])': {
144
+ marginRight: componentTheme.padding,
145
+ ...sizeVariants[size] && {
146
+ lineHeight: sizeVariants[size].lineHeight
147
+ }
148
+ },
149
+ display: 'flex',
150
+ alignItems: 'center',
151
+ ...sizeVariants[size] ? (({ lineHeight, ...rest })=>rest)(sizeVariants[size]) : {},
152
+ label: 'textInput__afterElement',
153
+ ...viewBase,
154
+ borderRadius: componentTheme.borderRadius,
155
+ flexShrink: 0,
156
+ ...afterElementHasWidth === false && {
157
+ paddingInlineEnd: 0
158
+ }
159
+ }
160
+ };
217
161
  };
218
- export default generateStyle;
162
+ export default generateStyle;
@@ -1,74 +1,38 @@
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
- /**
26
- * Generates the theme object for the component from the theme and provided additional information
27
- * @param {Object} theme The actual theme object.
28
- * @return {Object} The final theme object with the overrides and component variables
29
- */
30
- const generateComponentTheme = theme => {
31
- const {
32
- colors,
33
- typography,
34
- borders,
35
- spacing,
36
- forms,
37
- key: themeName
38
- } = theme;
39
- const themeSpecificStyle = {
40
- canvas: {
41
- color: theme['ic-brand-font-color-dark'],
42
- focusOutlineColor: theme['ic-brand-primary']
43
- }
44
- };
45
- const componentVariables = {
46
- fontFamily: typography?.fontFamily,
47
- fontWeight: typography?.fontWeightNormal,
48
- borderWidth: borders?.widthSmall,
49
- borderStyle: borders?.style,
50
- borderColor: colors?.contrasts?.grey3045,
51
- borderRadius: borders?.radiusMedium,
52
- color: colors?.contrasts?.grey125125,
53
- background: colors?.contrasts?.white1010,
54
- requiredInvalidColor: colors?.contrasts?.red5782,
55
- padding: spacing?.small,
56
- focusOutlineWidth: borders?.widthMedium,
57
- focusOutlineStyle: borders?.style,
58
- focusOutlineColor: colors?.contrasts?.blue4570,
59
- errorBorderColor: colors?.contrasts?.red4570,
60
- errorOutlineColor: colors?.contrasts?.red4570,
61
- placeholderColor: colors?.contrasts?.grey4570,
62
- smallFontSize: typography?.fontSizeSmall,
63
- smallHeight: forms?.inputHeightSmall,
64
- mediumFontSize: typography?.fontSizeMedium,
65
- mediumHeight: forms?.inputHeightMedium,
66
- largeFontSize: typography?.fontSizeLarge,
67
- largeHeight: forms?.inputHeightLarge
68
- };
69
- return {
70
- ...componentVariables,
71
- ...themeSpecificStyle[themeName]
72
- };
1
+ const generateComponentTheme = (theme)=>{
2
+ const { colors, typography, borders, spacing, forms, key: themeName } = theme;
3
+ const themeSpecificStyle = {
4
+ canvas: {
5
+ color: theme['ic-brand-font-color-dark'],
6
+ focusOutlineColor: theme['ic-brand-primary']
7
+ }
8
+ };
9
+ const componentVariables = {
10
+ fontFamily: typography?.fontFamily,
11
+ fontWeight: typography?.fontWeightNormal,
12
+ borderWidth: borders?.widthSmall,
13
+ borderStyle: borders?.style,
14
+ borderColor: colors?.contrasts?.grey3045,
15
+ borderRadius: borders?.radiusMedium,
16
+ color: colors?.contrasts?.grey125125,
17
+ background: colors?.contrasts?.white1010,
18
+ requiredInvalidColor: colors?.contrasts?.red5782,
19
+ padding: spacing?.small,
20
+ focusOutlineWidth: borders?.widthMedium,
21
+ focusOutlineStyle: borders?.style,
22
+ focusOutlineColor: colors?.contrasts?.blue4570,
23
+ errorBorderColor: colors?.contrasts?.red4570,
24
+ errorOutlineColor: colors?.contrasts?.red4570,
25
+ placeholderColor: colors?.contrasts?.grey4570,
26
+ smallFontSize: typography?.fontSizeSmall,
27
+ smallHeight: forms?.inputHeightSmall,
28
+ mediumFontSize: typography?.fontSizeMedium,
29
+ mediumHeight: forms?.inputHeightMedium,
30
+ largeFontSize: typography?.fontSizeLarge,
31
+ largeHeight: forms?.inputHeightLarge
32
+ };
33
+ return {
34
+ ...componentVariables,
35
+ ...themeSpecificStyle[themeName]
36
+ };
73
37
  };
74
- export default generateComponentTheme;
38
+ export default generateComponentTheme;