@instructure/ui-range-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,163 +1,124 @@
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) => {
36
- const {
37
- size,
38
- thumbVariant
39
- } = props;
40
- const valueSizeVariants = {
41
- small: {
42
- fontSize: componentTheme.valueSmallFontSize,
43
- padding: componentTheme.valueSmallPadding,
44
- lineHeight: componentTheme.valueSmallLineHeight
45
- },
46
- medium: {
47
- fontSize: componentTheme.valueMediumFontSize,
48
- padding: componentTheme.valueMediumPadding,
49
- lineHeight: componentTheme.valueMediumLineHeight
50
- },
51
- large: {
52
- fontSize: componentTheme.valueLargeFontSize,
53
- padding: componentTheme.valueLargePadding,
54
- lineHeight: componentTheme.valueLargeLineHeight
55
- }
56
- };
57
- const trackStyle = {
58
- borderRadius: '0.312em',
59
- borderColor: 'transparent',
60
- color: 'transparent',
61
- cursor: 'pointer',
62
- background: componentTheme.trackBackground,
63
- height: `calc(${componentTheme.handleSize} / 2)`
64
- };
65
- const borderedHandleSize = `calc(${componentTheme.handleSize} + (${componentTheme.handleBorderSize} * 2))`;
66
- const thumbVariantStyle = {
67
- deprecated: {
68
- width: componentTheme.handleSize,
69
- height: componentTheme.handleSize,
70
- boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}`
71
- },
72
- accessible: {
73
- width: borderedHandleSize,
74
- height: borderedHandleSize,
75
- borderWidth: componentTheme.handleBorderSize,
76
- borderColor: componentTheme.handleBorderColor,
77
- borderStyle: 'solid',
78
- boxSizing: 'border-box',
79
- boxShadow: componentTheme.handleShadow
80
- }
81
- };
82
- const thumbStyle = {
83
- appearance: 'none',
84
- borderRadius: '50%',
85
- cursor: 'pointer',
86
- transition: 'all 0.15s ease-in-out',
87
- background: componentTheme.handleBackground,
88
- ...thumbVariantStyle[thumbVariant],
89
- '&:hover': {
90
- background: componentTheme.handleHoverBackground
91
- }
92
- };
93
- const thumbPosition = {
94
- deprecated: {
95
- marginTop: `calc(-1 * ${componentTheme.handleSize} / 4)`
96
- },
97
- accessible: {
98
- marginTop: `calc(-1 * ${borderedHandleSize} / 4)`
99
- }
100
- };
101
- const thumbFocusActiveStyle = {
102
- deprecated: {
103
- background: componentTheme.handleFocusBackground,
104
- boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${componentTheme.handleFocusOutlineColor}`
105
- },
106
- accessible: {
107
- background: componentTheme.handleFocusBackground,
108
- boxShadow: componentTheme.handleShadow + ', ' + `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` + `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${componentTheme.handleFocusRingSize}) ${componentTheme.handleFocusRingColor}`
109
- }
110
- };
111
- return {
112
- rangeInput: {
113
- label: 'rangeInput',
114
- display: 'flex',
115
- justifyContent: 'center',
116
- alignItems: 'center',
117
- minWidth: componentTheme.minWidth
118
- },
119
- rangeInputInput: {
120
- label: 'rangeInput__input',
121
- all: 'initial',
122
- flex: 'auto',
123
- boxSizing: 'border-box',
124
- appearance: 'none',
125
- width: '100%',
126
- // for Firefox
127
- outline: 'none',
128
- margin: 0,
129
- '&::-webkit-slider-thumb': {
130
- ...thumbStyle,
131
- ...thumbPosition[thumbVariant]
132
- },
133
- '&::-moz-range-thumb': thumbStyle,
134
- '&:focus, &:active': {
135
- outline: 'none',
136
- '&::-webkit-slider-thumb': thumbFocusActiveStyle[thumbVariant],
137
- '&::-moz-range-thumb': thumbFocusActiveStyle[thumbVariant]
138
- },
139
- // remove outline in FF
140
- '&::-moz-focus-inner, &::-moz-focus-outer': {
141
- border: 0,
142
- outline: 'none'
143
- },
144
- '&::-webkit-slider-runnable-track': trackStyle,
145
- '&::-moz-range-track': trackStyle,
146
- '[dir="rtl"] &': {
147
- direction: 'rtl'
148
- }
149
- },
150
- rangeInputInputValue: {
151
- label: 'rangeInput__value',
152
- all: 'initial',
153
- boxSizing: 'border-box',
154
- display: 'block',
155
- color: 'inherit',
156
- fontFamily: componentTheme.valueFontFamily,
157
- fontWeight: componentTheme.valueFontWeight,
158
- textAlign: 'center',
159
- ...valueSizeVariants[size]
160
- }
161
- };
1
+ const generateStyle = (componentTheme, props)=>{
2
+ const { size, thumbVariant } = props;
3
+ const valueSizeVariants = {
4
+ small: {
5
+ fontSize: componentTheme.valueSmallFontSize,
6
+ padding: componentTheme.valueSmallPadding,
7
+ lineHeight: componentTheme.valueSmallLineHeight
8
+ },
9
+ medium: {
10
+ fontSize: componentTheme.valueMediumFontSize,
11
+ padding: componentTheme.valueMediumPadding,
12
+ lineHeight: componentTheme.valueMediumLineHeight
13
+ },
14
+ large: {
15
+ fontSize: componentTheme.valueLargeFontSize,
16
+ padding: componentTheme.valueLargePadding,
17
+ lineHeight: componentTheme.valueLargeLineHeight
18
+ }
19
+ };
20
+ const trackStyle = {
21
+ borderRadius: '0.312em',
22
+ borderColor: 'transparent',
23
+ color: 'transparent',
24
+ cursor: 'pointer',
25
+ background: componentTheme.trackBackground,
26
+ height: `calc(${componentTheme.handleSize} / 2)`
27
+ };
28
+ const borderedHandleSize = `calc(${componentTheme.handleSize} + (${componentTheme.handleBorderSize} * 2))`;
29
+ const thumbVariantStyle = {
30
+ deprecated: {
31
+ width: componentTheme.handleSize,
32
+ height: componentTheme.handleSize,
33
+ boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}`
34
+ },
35
+ accessible: {
36
+ width: borderedHandleSize,
37
+ height: borderedHandleSize,
38
+ borderWidth: componentTheme.handleBorderSize,
39
+ borderColor: componentTheme.handleBorderColor,
40
+ borderStyle: 'solid',
41
+ boxSizing: 'border-box',
42
+ boxShadow: componentTheme.handleShadow
43
+ }
44
+ };
45
+ const thumbStyle = {
46
+ appearance: 'none',
47
+ borderRadius: '50%',
48
+ cursor: 'pointer',
49
+ transition: 'all 0.15s ease-in-out',
50
+ background: componentTheme.handleBackground,
51
+ ...thumbVariantStyle[thumbVariant],
52
+ '&:hover': {
53
+ background: componentTheme.handleHoverBackground
54
+ }
55
+ };
56
+ const thumbPosition = {
57
+ deprecated: {
58
+ marginTop: `calc(-1 * ${componentTheme.handleSize} / 4)`
59
+ },
60
+ accessible: {
61
+ marginTop: `calc(-1 * ${borderedHandleSize} / 4)`
62
+ }
63
+ };
64
+ const thumbFocusActiveStyle = {
65
+ deprecated: {
66
+ background: componentTheme.handleFocusBackground,
67
+ boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${componentTheme.handleFocusOutlineColor}`
68
+ },
69
+ accessible: {
70
+ background: componentTheme.handleFocusBackground,
71
+ boxShadow: componentTheme.handleShadow + ', ' + `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` + `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${componentTheme.handleFocusRingSize}) ${componentTheme.handleFocusRingColor}`
72
+ }
73
+ };
74
+ return {
75
+ rangeInput: {
76
+ label: 'rangeInput',
77
+ display: 'flex',
78
+ justifyContent: 'center',
79
+ alignItems: 'center',
80
+ minWidth: componentTheme.minWidth
81
+ },
82
+ rangeInputInput: {
83
+ label: 'rangeInput__input',
84
+ all: 'initial',
85
+ flex: 'auto',
86
+ boxSizing: 'border-box',
87
+ appearance: 'none',
88
+ width: '100%',
89
+ outline: 'none',
90
+ margin: 0,
91
+ '&::-webkit-slider-thumb': {
92
+ ...thumbStyle,
93
+ ...thumbPosition[thumbVariant]
94
+ },
95
+ '&::-moz-range-thumb': thumbStyle,
96
+ '&:focus, &:active': {
97
+ outline: 'none',
98
+ '&::-webkit-slider-thumb': thumbFocusActiveStyle[thumbVariant],
99
+ '&::-moz-range-thumb': thumbFocusActiveStyle[thumbVariant]
100
+ },
101
+ '&::-moz-focus-inner, &::-moz-focus-outer': {
102
+ border: 0,
103
+ outline: 'none'
104
+ },
105
+ '&::-webkit-slider-runnable-track': trackStyle,
106
+ '&::-moz-range-track': trackStyle,
107
+ '[dir="rtl"] &': {
108
+ direction: 'rtl'
109
+ }
110
+ },
111
+ rangeInputInputValue: {
112
+ label: 'rangeInput__value',
113
+ all: 'initial',
114
+ boxSizing: 'border-box',
115
+ display: 'block',
116
+ color: 'inherit',
117
+ fontFamily: componentTheme.valueFontFamily,
118
+ fontWeight: componentTheme.valueFontWeight,
119
+ textAlign: 'center',
120
+ ...valueSizeVariants[size]
121
+ }
122
+ };
162
123
  };
163
- export default generateStyle;
124
+ export default generateStyle;
@@ -1,85 +1,47 @@
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
1
  import { alpha, darken } from '@instructure/ui-color-utils';
26
- /**
27
- * Generates the theme object for the component from the theme and provided additional information
28
- * @param {Object} theme The actual theme object.
29
- * @return {Object} The final theme object with the overrides and component variables
30
- */
31
- const generateComponentTheme = theme => {
32
- const {
33
- colors,
34
- borders,
35
- typography,
36
- spacing,
37
- forms,
38
- key: themeName
39
- } = theme;
40
- const themeSpecificStyle = {
41
- canvas: {
42
- handleBackground: theme['ic-brand-primary'],
43
- handleHoverBackground: theme['ic-brand-primary'],
44
- handleFocusBackground: theme['ic-brand-primary'],
45
- // Deprecated, remove with "deprecated" thumbVariant
46
- handleShadowColor: darken(theme['ic-brand-primary'], 15),
47
- handleFocusOutlineColor: alpha(theme['ic-brand-primary'], 40)
48
- }
49
- };
50
- const componentVariables = {
51
- minWidth: '12.5rem',
52
- handleSize: '1.5rem',
53
- handleBackground: colors?.contrasts?.blue4570,
54
- handleBorderColor: colors?.contrasts?.white1010,
55
- handleBorderSize: borders?.widthMedium,
56
- handleShadow: '0 0.0625rem 0.125rem rgba(0, 0, 0, .2), 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1)',
57
- handleFocusInset: borders?.widthSmall,
58
- handleFocusRingSize: borders?.widthMedium,
59
- handleFocusRingColor: colors?.contrasts?.white1010,
60
- handleFocusBackground: colors?.contrasts?.blue4570,
61
- handleHoverBackground: colors?.contrasts?.blue4570,
62
- // Deprecated, remove with "deprecated" thumbVariant
63
- handleShadowColor: darken(colors?.contrasts?.blue5782, 10),
64
- handleFocusOutlineColor: alpha(colors?.contrasts?.blue4570, 40),
65
- handleFocusOutlineWidth: '0.75em',
66
- trackBackground: colors?.contrasts?.grey4570,
67
- valueColor: colors?.contrasts?.white1010,
68
- valueFontFamily: typography?.fontFamily,
69
- valueFontWeight: typography?.fontWeightNormal,
70
- valueSmallFontSize: typography?.fontSizeSmall,
71
- valueSmallPadding: `0 ${spacing?.xSmall}`,
72
- valueSmallLineHeight: forms?.inputHeightSmall,
73
- valueMediumFontSize: typography?.fontSizeMedium,
74
- valueMediumPadding: `0 ${spacing?.small}`,
75
- valueMediumLineHeight: forms?.inputHeightMedium,
76
- valueLargeFontSize: typography?.fontSizeLarge,
77
- valueLargePadding: `0 ${spacing?.medium}`,
78
- valueLargeLineHeight: forms?.inputHeightLarge
79
- };
80
- return {
81
- ...componentVariables,
82
- ...themeSpecificStyle[themeName]
83
- };
2
+ const generateComponentTheme = (theme)=>{
3
+ const { colors, borders, typography, spacing, forms, key: themeName } = theme;
4
+ const themeSpecificStyle = {
5
+ canvas: {
6
+ handleBackground: theme['ic-brand-primary'],
7
+ handleHoverBackground: theme['ic-brand-primary'],
8
+ handleFocusBackground: theme['ic-brand-primary'],
9
+ handleShadowColor: darken(theme['ic-brand-primary'], 15),
10
+ handleFocusOutlineColor: alpha(theme['ic-brand-primary'], 40)
11
+ }
12
+ };
13
+ const componentVariables = {
14
+ minWidth: '12.5rem',
15
+ handleSize: '1.5rem',
16
+ handleBackground: colors?.contrasts?.blue4570,
17
+ handleBorderColor: colors?.contrasts?.white1010,
18
+ handleBorderSize: borders?.widthMedium,
19
+ handleShadow: '0 0.0625rem 0.125rem rgba(0, 0, 0, .2), 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1)',
20
+ handleFocusInset: borders?.widthSmall,
21
+ handleFocusRingSize: borders?.widthMedium,
22
+ handleFocusRingColor: colors?.contrasts?.white1010,
23
+ handleFocusBackground: colors?.contrasts?.blue4570,
24
+ handleHoverBackground: colors?.contrasts?.blue4570,
25
+ handleShadowColor: darken(colors?.contrasts?.blue5782, 10),
26
+ handleFocusOutlineColor: alpha(colors?.contrasts?.blue4570, 40),
27
+ handleFocusOutlineWidth: '0.75em',
28
+ trackBackground: colors?.contrasts?.grey4570,
29
+ valueColor: colors?.contrasts?.white1010,
30
+ valueFontFamily: typography?.fontFamily,
31
+ valueFontWeight: typography?.fontWeightNormal,
32
+ valueSmallFontSize: typography?.fontSizeSmall,
33
+ valueSmallPadding: `0 ${spacing?.xSmall}`,
34
+ valueSmallLineHeight: forms?.inputHeightSmall,
35
+ valueMediumFontSize: typography?.fontSizeMedium,
36
+ valueMediumPadding: `0 ${spacing?.small}`,
37
+ valueMediumLineHeight: forms?.inputHeightMedium,
38
+ valueLargeFontSize: typography?.fontSizeLarge,
39
+ valueLargePadding: `0 ${spacing?.medium}`,
40
+ valueLargeLineHeight: forms?.inputHeightLarge
41
+ };
42
+ return {
43
+ ...componentVariables,
44
+ ...themeSpecificStyle[themeName]
45
+ };
84
46
  };
85
- export default generateComponentTheme;
47
+ export default generateComponentTheme;