@instructure/ui-range-input 11.6.0 → 11.6.1-snapshot-129

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +36 -286
  2. package/es/RangeInput/{index.js → v1/index.js} +3 -3
  3. package/es/RangeInput/v2/index.js +183 -0
  4. package/es/RangeInput/v2/props.js +26 -0
  5. package/es/RangeInput/v2/styles.js +169 -0
  6. package/es/{index.js → exports/a.js} +1 -1
  7. package/{src/index.ts → es/exports/b.js} +1 -3
  8. package/lib/RangeInput/v1/index.js +191 -0
  9. package/lib/RangeInput/{index.js → v2/index.js} +6 -7
  10. package/lib/RangeInput/v2/props.js +31 -0
  11. package/lib/RangeInput/v2/styles.js +175 -0
  12. package/lib/{index.js → exports/a.js} +2 -2
  13. package/lib/exports/b.js +12 -0
  14. package/package.json +44 -22
  15. package/src/RangeInput/{index.tsx → v1/index.tsx} +3 -3
  16. package/src/RangeInput/{props.ts → v1/props.ts} +1 -1
  17. package/src/RangeInput/v2/README.md +73 -0
  18. package/src/RangeInput/v2/index.tsx +223 -0
  19. package/src/RangeInput/v2/props.ts +149 -0
  20. package/src/RangeInput/v2/styles.ts +191 -0
  21. package/src/exports/a.ts +26 -0
  22. package/src/exports/b.ts +26 -0
  23. package/tsconfig.build.tsbuildinfo +1 -1
  24. package/types/RangeInput/{index.d.ts → v1/index.d.ts} +1 -1
  25. package/types/RangeInput/v1/index.d.ts.map +1 -0
  26. package/types/RangeInput/{props.d.ts → v1/props.d.ts} +1 -1
  27. package/types/RangeInput/v1/props.d.ts.map +1 -0
  28. package/types/RangeInput/v1/styles.d.ts.map +1 -0
  29. package/types/RangeInput/v1/theme.d.ts.map +1 -0
  30. package/types/RangeInput/v2/index.d.ts +64 -0
  31. package/types/RangeInput/v2/index.d.ts.map +1 -0
  32. package/types/RangeInput/v2/props.d.ts +62 -0
  33. package/types/RangeInput/v2/props.d.ts.map +1 -0
  34. package/types/RangeInput/v2/styles.d.ts +15 -0
  35. package/types/RangeInput/v2/styles.d.ts.map +1 -0
  36. package/types/exports/a.d.ts +3 -0
  37. package/types/exports/a.d.ts.map +1 -0
  38. package/types/exports/b.d.ts +3 -0
  39. package/types/exports/b.d.ts.map +1 -0
  40. package/types/RangeInput/index.d.ts.map +0 -1
  41. package/types/RangeInput/props.d.ts.map +0 -1
  42. package/types/RangeInput/styles.d.ts.map +0 -1
  43. package/types/RangeInput/theme.d.ts.map +0 -1
  44. package/types/index.d.ts +0 -3
  45. package/types/index.d.ts.map +0 -1
  46. /package/es/RangeInput/{props.js → v1/props.js} +0 -0
  47. /package/es/RangeInput/{styles.js → v1/styles.js} +0 -0
  48. /package/es/RangeInput/{theme.js → v1/theme.js} +0 -0
  49. /package/lib/RangeInput/{props.js → v1/props.js} +0 -0
  50. /package/lib/RangeInput/{styles.js → v1/styles.js} +0 -0
  51. /package/lib/RangeInput/{theme.js → v1/theme.js} +0 -0
  52. /package/src/RangeInput/{README.md → v1/README.md} +0 -0
  53. /package/src/RangeInput/{styles.ts → v1/styles.ts} +0 -0
  54. /package/src/RangeInput/{theme.ts → v1/theme.ts} +0 -0
  55. /package/types/RangeInput/{styles.d.ts → v1/styles.d.ts} +0 -0
  56. /package/types/RangeInput/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,149 @@
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
+ import React from 'react'
26
+
27
+ import type {
28
+ OtherHTMLAttributes,
29
+ RangeInputTheme,
30
+ PickPropsWithExceptions
31
+ } from '@instructure/shared-types'
32
+ import type { FormFieldOwnProps, FormMessage } from '@instructure/ui-form-field/latest'
33
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
34
+ import type { InputHTMLAttributes } from 'react'
35
+ import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
36
+
37
+ type RangeInputOwnProps = {
38
+ min: number
39
+
40
+ max: number
41
+
42
+ /**
43
+ * value to set on initial render
44
+ */
45
+ defaultValue?: number
46
+
47
+ /**
48
+ * the selected value (must be accompanied by an `onChange` prop)
49
+ */
50
+ value?: number // TODO: controllable(PropTypes.number)
51
+
52
+ /**
53
+ * when used with the `value` prop, the component will not control its own state
54
+ */
55
+ onChange?: (value: number | string) => void
56
+
57
+ messages?: FormMessage[]
58
+
59
+ /**
60
+ * The size of the value label
61
+ */
62
+ size?: 'small' | 'medium' | 'large'
63
+
64
+ layout?: 'stacked' | 'inline'
65
+
66
+ id?: string
67
+
68
+ label: React.ReactNode
69
+
70
+ /**
71
+ * whether to display the current value
72
+ */
73
+ displayValue?: boolean
74
+
75
+ step?: number
76
+
77
+ /**
78
+ * A function to format the displayed value
79
+ */
80
+ formatValue?: (value?: number, max?: number) => string
81
+
82
+ inline?: boolean
83
+
84
+ disabled?: boolean
85
+
86
+ readOnly?: boolean
87
+
88
+ /**
89
+ * The "deprecated" variant has an outer shadow on focus.
90
+ * The "accessible" variant has better color contrast, border and inset focus ring for better accessibility.
91
+ */
92
+ thumbVariant?:
93
+ | 'deprecated' // TODO: deprecated, remove in V9.
94
+ | 'accessible'
95
+
96
+ /**
97
+ * A function that provides a reference to the actual underlying input element
98
+ */
99
+ inputRef?: (inputElement: HTMLInputElement | null) => void
100
+ }
101
+
102
+ type PropKeys = keyof RangeInputOwnProps
103
+
104
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
105
+
106
+ type RangeInputProps =
107
+ // pickProps passes through FormField.allowedProps, except the ones set manually
108
+ PickPropsWithExceptions<
109
+ FormFieldOwnProps,
110
+ 'label' | 'inline' | 'id' | 'elementRef'
111
+ > &
112
+ RangeInputOwnProps &
113
+ WithStyleProps<RangeInputTheme, RangeInputStyle> &
114
+ OtherHTMLAttributes<
115
+ RangeInputOwnProps,
116
+ InputHTMLAttributes<RangeInputOwnProps & Element>
117
+ > &
118
+ WithDeterministicIdProps
119
+
120
+ type RangeInputStyle = ComponentStyle<
121
+ 'rangeInput' | 'rangeInputInput' | 'rangeInputInputValue'
122
+ >
123
+
124
+ type RangeInputState = {
125
+ value?: number | string
126
+ }
127
+ const allowedProps: AllowedPropKeys = [
128
+ 'min',
129
+ 'max',
130
+ 'defaultValue',
131
+ 'value',
132
+ 'onChange',
133
+ 'messages',
134
+ 'size',
135
+ 'layout',
136
+ 'id',
137
+ 'label',
138
+ 'displayValue',
139
+ 'step',
140
+ 'formatValue',
141
+ 'inline',
142
+ 'disabled',
143
+ 'readOnly',
144
+ 'thumbVariant',
145
+ 'inputRef'
146
+ ]
147
+
148
+ export type { RangeInputProps, RangeInputState, RangeInputStyle }
149
+ export { allowedProps }
@@ -0,0 +1,191 @@
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
+ import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
26
+ import type { RangeInputProps, RangeInputStyle } from './props'
27
+ import { darken, alpha } from '@instructure/ui-color-utils'
28
+ import { boxShadowObjectsToCSSString } from '@instructure/ui-themes'
29
+
30
+ /**
31
+ * ---
32
+ * private: true
33
+ * ---
34
+ * Generates the style object from the theme and provided additional information
35
+ * @param {Object} componentTheme The theme variable object.
36
+ * @param {Object} props the props of the component, the style is applied to
37
+ * @param {Object} state the state of the component, the style is applied to
38
+ * @return {Object} The final style object, which will be used in the component
39
+ */
40
+ const generateStyle = (
41
+ componentTheme: NewComponentTypes['RangeInput'],
42
+ props: RangeInputProps,
43
+ sharedTokens: SharedTokens
44
+ ): RangeInputStyle => {
45
+ const { size, thumbVariant } = props
46
+ const valueSizeVariants = {
47
+ small: {
48
+ fontSize: componentTheme.valueSmallFontSize,
49
+ paddingInline: componentTheme.valueSmallPadding,
50
+ lineHeight: componentTheme.valueSmallLineHeight
51
+ },
52
+ medium: {
53
+ fontSize: componentTheme.valueMediumFontSize,
54
+ paddingInline: componentTheme.valueMediumPadding,
55
+ lineHeight: componentTheme.valueMediumLineHeight
56
+ },
57
+ large: {
58
+ fontSize: componentTheme.valueLargeFontSize,
59
+ paddingInline: componentTheme.valueLargePadding,
60
+ lineHeight: componentTheme.valueLargeLineHeight
61
+ }
62
+ }
63
+
64
+ const trackBorderWidth = '1px'
65
+
66
+ const trackStyle = {
67
+ borderRadius: '0.312em',
68
+ borderWidth: trackBorderWidth,
69
+ borderStyle: 'solid',
70
+ borderColor: componentTheme.trackBorderColor,
71
+ color: 'transparent',
72
+ cursor: 'pointer',
73
+ background: componentTheme.trackBackground,
74
+ height: `calc(${componentTheme.handleSize} / 2)`
75
+ }
76
+
77
+ const borderedHandleSize = `calc(${componentTheme.handleSize} + (${componentTheme.handleBorderSize} * 2))`
78
+
79
+ const thumbVariantStyle = {
80
+ deprecated: {
81
+ width: componentTheme.handleSize,
82
+ height: componentTheme.handleSize,
83
+ boxShadow: `0 0.0625rem 0 ${darken(componentTheme.handleShadowColor)}`
84
+ },
85
+ accessible: {
86
+ width: borderedHandleSize,
87
+ height: borderedHandleSize,
88
+ borderWidth: componentTheme.handleBorderSize,
89
+ borderColor: componentTheme.handleBorderColor,
90
+ borderStyle: 'solid',
91
+ boxSizing: 'border-box',
92
+ boxShadow: boxShadowObjectsToCSSString(componentTheme.boxShadow)
93
+ }
94
+ }
95
+
96
+ const thumbStyle = {
97
+ appearance: 'none',
98
+ borderRadius: '50%',
99
+ cursor: 'pointer',
100
+ transition: 'all 0.15s ease-in-out',
101
+ background: componentTheme.handleBackground,
102
+ ...thumbVariantStyle[thumbVariant!],
103
+
104
+ '&:hover': {
105
+ background: componentTheme.handleHoverBackground
106
+ }
107
+ }
108
+
109
+ // Center the thumb vertically on the track by accounting for the track borders
110
+ const thumbPosition = {
111
+ deprecated: {
112
+ marginTop: `calc(-1 * ${componentTheme.handleSize} / 4 - ${trackBorderWidth})`
113
+ },
114
+ accessible: {
115
+ marginTop: `calc(-1 * ${borderedHandleSize} / 4 - ${trackBorderWidth})`
116
+ }
117
+ }
118
+
119
+ const thumbFocusActiveStyle = {
120
+ deprecated: {
121
+ background: componentTheme.handleFocusBackground,
122
+ boxShadow: `0 0.0625rem 0 ${darken(
123
+ componentTheme.handleShadowColor
124
+ )}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${alpha(
125
+ componentTheme.handleFocusOutlineColor,
126
+ 40
127
+ )}`
128
+ },
129
+ accessible: {
130
+ background: componentTheme.handleFocusBackground,
131
+ boxShadow:
132
+ `${boxShadowObjectsToCSSString(componentTheme.boxShadow)}, ` +
133
+ `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` +
134
+ `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${sharedTokens.focusOutline.width}) ${sharedTokens.focusOutline.onColor}`
135
+ }
136
+ }
137
+
138
+ return {
139
+ rangeInput: {
140
+ label: 'rangeInput',
141
+ display: 'flex',
142
+ justifyContent: 'center',
143
+ alignItems: 'center',
144
+ minWidth: componentTheme.minWidth
145
+ },
146
+ rangeInputInput: {
147
+ label: 'rangeInput__input',
148
+ all: 'initial',
149
+ flex: 'auto',
150
+ boxSizing: 'border-box',
151
+ appearance: 'none',
152
+ width: '100%', // for Firefox
153
+ outline: 'none',
154
+ margin: 0,
155
+
156
+ '&::-webkit-slider-thumb': {
157
+ ...thumbStyle,
158
+ ...thumbPosition[thumbVariant!]
159
+ },
160
+ '&::-moz-range-thumb': thumbStyle,
161
+ '&:focus, &:active': {
162
+ outline: 'none',
163
+ '&::-webkit-slider-thumb': thumbFocusActiveStyle[thumbVariant!],
164
+ '&::-moz-range-thumb': thumbFocusActiveStyle[thumbVariant!]
165
+ },
166
+ // remove outline in FF
167
+ '&::-moz-focus-inner, &::-moz-focus-outer': {
168
+ border: 0,
169
+ outline: 'none'
170
+ },
171
+ '&::-webkit-slider-runnable-track': trackStyle,
172
+ '&::-moz-range-track': trackStyle,
173
+ '[dir="rtl"] &': {
174
+ direction: 'rtl'
175
+ }
176
+ },
177
+ rangeInputInputValue: {
178
+ label: 'rangeInput__value',
179
+ all: 'initial',
180
+ boxSizing: 'border-box',
181
+ display: 'block',
182
+ color: 'inherit',
183
+ fontFamily: componentTheme.valueFontFamily,
184
+ fontWeight: componentTheme.valueFontWeight,
185
+ textAlign: 'center',
186
+ ...valueSizeVariants[size!]
187
+ }
188
+ }
189
+ }
190
+
191
+ export default generateStyle
@@ -0,0 +1,26 @@
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
+ export { RangeInput } from '../RangeInput/v1'
26
+ export type { RangeInputProps } from '../RangeInput/v1/props'
@@ -0,0 +1,26 @@
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
+ export { RangeInput } from '../RangeInput/v2'
26
+ export type { RangeInputProps } from '../RangeInput/v2/props'