@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.
- package/CHANGELOG.md +36 -286
- package/es/RangeInput/{index.js → v1/index.js} +3 -3
- package/es/RangeInput/v2/index.js +183 -0
- package/es/RangeInput/v2/props.js +26 -0
- package/es/RangeInput/v2/styles.js +169 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/RangeInput/v1/index.js +191 -0
- package/lib/RangeInput/{index.js → v2/index.js} +6 -7
- package/lib/RangeInput/v2/props.js +31 -0
- package/lib/RangeInput/v2/styles.js +175 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +44 -22
- package/src/RangeInput/{index.tsx → v1/index.tsx} +3 -3
- package/src/RangeInput/{props.ts → v1/props.ts} +1 -1
- package/src/RangeInput/v2/README.md +73 -0
- package/src/RangeInput/v2/index.tsx +223 -0
- package/src/RangeInput/v2/props.ts +149 -0
- package/src/RangeInput/v2/styles.ts +191 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/RangeInput/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/RangeInput/v1/index.d.ts.map +1 -0
- package/types/RangeInput/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/RangeInput/v1/props.d.ts.map +1 -0
- package/types/RangeInput/v1/styles.d.ts.map +1 -0
- package/types/RangeInput/v1/theme.d.ts.map +1 -0
- package/types/RangeInput/v2/index.d.ts +64 -0
- package/types/RangeInput/v2/index.d.ts.map +1 -0
- package/types/RangeInput/v2/props.d.ts +62 -0
- package/types/RangeInput/v2/props.d.ts.map +1 -0
- package/types/RangeInput/v2/styles.d.ts +15 -0
- package/types/RangeInput/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/RangeInput/index.d.ts.map +0 -1
- package/types/RangeInput/props.d.ts.map +0 -1
- package/types/RangeInput/styles.d.ts.map +0 -1
- package/types/RangeInput/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/RangeInput/{props.js → v1/props.js} +0 -0
- /package/es/RangeInput/{styles.js → v1/styles.js} +0 -0
- /package/es/RangeInput/{theme.js → v1/theme.js} +0 -0
- /package/lib/RangeInput/{props.js → v1/props.js} +0 -0
- /package/lib/RangeInput/{styles.js → v1/styles.js} +0 -0
- /package/lib/RangeInput/{theme.js → v1/theme.js} +0 -0
- /package/src/RangeInput/{README.md → v1/README.md} +0 -0
- /package/src/RangeInput/{styles.ts → v1/styles.ts} +0 -0
- /package/src/RangeInput/{theme.ts → v1/theme.ts} +0 -0
- /package/types/RangeInput/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/RangeInput/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _darken = require("@instructure/ui-color-utils/lib/darken.js");
|
|
8
|
+
var _alpha = require("@instructure/ui-color-utils/lib/alpha.js");
|
|
9
|
+
var _uiThemes = require("@instructure/ui-themes");
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ---
|
|
36
|
+
* private: true
|
|
37
|
+
* ---
|
|
38
|
+
* Generates the style object from the theme and provided additional information
|
|
39
|
+
* @param {Object} componentTheme The theme variable object.
|
|
40
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
41
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
42
|
+
* @return {Object} The final style object, which will be used in the component
|
|
43
|
+
*/
|
|
44
|
+
const generateStyle = (componentTheme, props, sharedTokens) => {
|
|
45
|
+
const size = props.size,
|
|
46
|
+
thumbVariant = props.thumbVariant;
|
|
47
|
+
const valueSizeVariants = {
|
|
48
|
+
small: {
|
|
49
|
+
fontSize: componentTheme.valueSmallFontSize,
|
|
50
|
+
paddingInline: componentTheme.valueSmallPadding,
|
|
51
|
+
lineHeight: componentTheme.valueSmallLineHeight
|
|
52
|
+
},
|
|
53
|
+
medium: {
|
|
54
|
+
fontSize: componentTheme.valueMediumFontSize,
|
|
55
|
+
paddingInline: componentTheme.valueMediumPadding,
|
|
56
|
+
lineHeight: componentTheme.valueMediumLineHeight
|
|
57
|
+
},
|
|
58
|
+
large: {
|
|
59
|
+
fontSize: componentTheme.valueLargeFontSize,
|
|
60
|
+
paddingInline: componentTheme.valueLargePadding,
|
|
61
|
+
lineHeight: componentTheme.valueLargeLineHeight
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const trackBorderWidth = '1px';
|
|
65
|
+
const trackStyle = {
|
|
66
|
+
borderRadius: '0.312em',
|
|
67
|
+
borderWidth: trackBorderWidth,
|
|
68
|
+
borderStyle: 'solid',
|
|
69
|
+
borderColor: componentTheme.trackBorderColor,
|
|
70
|
+
color: 'transparent',
|
|
71
|
+
cursor: 'pointer',
|
|
72
|
+
background: componentTheme.trackBackground,
|
|
73
|
+
height: `calc(${componentTheme.handleSize} / 2)`
|
|
74
|
+
};
|
|
75
|
+
const borderedHandleSize = `calc(${componentTheme.handleSize} + (${componentTheme.handleBorderSize} * 2))`;
|
|
76
|
+
const thumbVariantStyle = {
|
|
77
|
+
deprecated: {
|
|
78
|
+
width: componentTheme.handleSize,
|
|
79
|
+
height: componentTheme.handleSize,
|
|
80
|
+
boxShadow: `0 0.0625rem 0 ${(0, _darken.darken)(componentTheme.handleShadowColor)}`
|
|
81
|
+
},
|
|
82
|
+
accessible: {
|
|
83
|
+
width: borderedHandleSize,
|
|
84
|
+
height: borderedHandleSize,
|
|
85
|
+
borderWidth: componentTheme.handleBorderSize,
|
|
86
|
+
borderColor: componentTheme.handleBorderColor,
|
|
87
|
+
borderStyle: 'solid',
|
|
88
|
+
boxSizing: 'border-box',
|
|
89
|
+
boxShadow: (0, _uiThemes.boxShadowObjectsToCSSString)(componentTheme.boxShadow)
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const thumbStyle = {
|
|
93
|
+
appearance: 'none',
|
|
94
|
+
borderRadius: '50%',
|
|
95
|
+
cursor: 'pointer',
|
|
96
|
+
transition: 'all 0.15s ease-in-out',
|
|
97
|
+
background: componentTheme.handleBackground,
|
|
98
|
+
...thumbVariantStyle[thumbVariant],
|
|
99
|
+
'&:hover': {
|
|
100
|
+
background: componentTheme.handleHoverBackground
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Center the thumb vertically on the track by accounting for the track borders
|
|
105
|
+
const thumbPosition = {
|
|
106
|
+
deprecated: {
|
|
107
|
+
marginTop: `calc(-1 * ${componentTheme.handleSize} / 4 - ${trackBorderWidth})`
|
|
108
|
+
},
|
|
109
|
+
accessible: {
|
|
110
|
+
marginTop: `calc(-1 * ${borderedHandleSize} / 4 - ${trackBorderWidth})`
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const thumbFocusActiveStyle = {
|
|
114
|
+
deprecated: {
|
|
115
|
+
background: componentTheme.handleFocusBackground,
|
|
116
|
+
boxShadow: `0 0.0625rem 0 ${(0, _darken.darken)(componentTheme.handleShadowColor)}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${(0, _alpha.alpha)(componentTheme.handleFocusOutlineColor, 40)}`
|
|
117
|
+
},
|
|
118
|
+
accessible: {
|
|
119
|
+
background: componentTheme.handleFocusBackground,
|
|
120
|
+
boxShadow: `${(0, _uiThemes.boxShadowObjectsToCSSString)(componentTheme.boxShadow)}, ` + `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` + `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${sharedTokens.focusOutline.width}) ${sharedTokens.focusOutline.onColor}`
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
rangeInput: {
|
|
125
|
+
label: 'rangeInput',
|
|
126
|
+
display: 'flex',
|
|
127
|
+
justifyContent: 'center',
|
|
128
|
+
alignItems: 'center',
|
|
129
|
+
minWidth: componentTheme.minWidth
|
|
130
|
+
},
|
|
131
|
+
rangeInputInput: {
|
|
132
|
+
label: 'rangeInput__input',
|
|
133
|
+
all: 'initial',
|
|
134
|
+
flex: 'auto',
|
|
135
|
+
boxSizing: 'border-box',
|
|
136
|
+
appearance: 'none',
|
|
137
|
+
width: '100%',
|
|
138
|
+
// for Firefox
|
|
139
|
+
outline: 'none',
|
|
140
|
+
margin: 0,
|
|
141
|
+
'&::-webkit-slider-thumb': {
|
|
142
|
+
...thumbStyle,
|
|
143
|
+
...thumbPosition[thumbVariant]
|
|
144
|
+
},
|
|
145
|
+
'&::-moz-range-thumb': thumbStyle,
|
|
146
|
+
'&:focus, &:active': {
|
|
147
|
+
outline: 'none',
|
|
148
|
+
'&::-webkit-slider-thumb': thumbFocusActiveStyle[thumbVariant],
|
|
149
|
+
'&::-moz-range-thumb': thumbFocusActiveStyle[thumbVariant]
|
|
150
|
+
},
|
|
151
|
+
// remove outline in FF
|
|
152
|
+
'&::-moz-focus-inner, &::-moz-focus-outer': {
|
|
153
|
+
border: 0,
|
|
154
|
+
outline: 'none'
|
|
155
|
+
},
|
|
156
|
+
'&::-webkit-slider-runnable-track': trackStyle,
|
|
157
|
+
'&::-moz-range-track': trackStyle,
|
|
158
|
+
'[dir="rtl"] &': {
|
|
159
|
+
direction: 'rtl'
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
rangeInputInputValue: {
|
|
163
|
+
label: 'rangeInput__value',
|
|
164
|
+
all: 'initial',
|
|
165
|
+
boxSizing: 'border-box',
|
|
166
|
+
display: 'block',
|
|
167
|
+
color: 'inherit',
|
|
168
|
+
fontFamily: componentTheme.valueFontFamily,
|
|
169
|
+
fontWeight: componentTheme.valueFontWeight,
|
|
170
|
+
textAlign: 'center',
|
|
171
|
+
...valueSizeVariants[size]
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
var _default = exports.default = generateStyle;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "RangeInput", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _v.RangeInput;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _v = require("../RangeInput/v1");
|
package/lib/exports/b.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-range-input",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A styled HTML range input",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,25 +15,25 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/console": "11.6.
|
|
19
|
-
"@instructure/emotion": "11.6.
|
|
20
|
-
"@instructure/shared-types": "11.6.
|
|
21
|
-
"@instructure/ui-
|
|
22
|
-
"@instructure/ui-
|
|
23
|
-
"@instructure/ui-form-field": "11.6.
|
|
24
|
-
"@instructure/ui-
|
|
25
|
-
"@instructure/ui-
|
|
26
|
-
"@instructure/ui-utils": "11.6.
|
|
27
|
-
"@instructure/
|
|
28
|
-
"@instructure/
|
|
18
|
+
"@instructure/console": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/ui-dom-utils": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-form-field": "11.6.1-snapshot-129",
|
|
24
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129",
|
|
25
|
+
"@instructure/ui-i18n": "11.6.1-snapshot-129",
|
|
26
|
+
"@instructure/ui-utils": "11.6.1-snapshot-129",
|
|
27
|
+
"@instructure/ui-view": "11.6.1-snapshot-129",
|
|
28
|
+
"@instructure/uid": "11.6.1-snapshot-129"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@testing-library/jest-dom": "^6.6.3",
|
|
32
32
|
"@testing-library/react": "15.0.7",
|
|
33
33
|
"vitest": "^3.2.2",
|
|
34
|
-
"@instructure/ui-
|
|
35
|
-
"@instructure/ui-
|
|
36
|
-
"@instructure/ui-themes": "11.6.
|
|
34
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129",
|
|
35
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
36
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": ">=18 <=19"
|
|
@@ -43,17 +43,39 @@
|
|
|
43
43
|
},
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"exports": {
|
|
46
|
-
".": {
|
|
47
|
-
"types": "./types/index.d.ts",
|
|
48
|
-
"import": "./es/index.js",
|
|
49
|
-
"require": "./lib/index.js",
|
|
50
|
-
"default": "./es/index.js"
|
|
51
|
-
},
|
|
52
46
|
"./lib/*": "./lib/*",
|
|
53
47
|
"./es/*": "./es/*",
|
|
54
48
|
"./types/*": "./types/*",
|
|
55
49
|
"./package.json": "./package.json",
|
|
56
|
-
"./src/*": "./src/*"
|
|
50
|
+
"./src/*": "./src/*",
|
|
51
|
+
".": {
|
|
52
|
+
"src": "./src/exports/a.ts",
|
|
53
|
+
"types": "./types/exports/a.d.ts",
|
|
54
|
+
"import": "./es/exports/a.js",
|
|
55
|
+
"require": "./lib/exports/a.js",
|
|
56
|
+
"default": "./es/exports/a.js"
|
|
57
|
+
},
|
|
58
|
+
"./v11_6": {
|
|
59
|
+
"src": "./src/exports/a.ts",
|
|
60
|
+
"types": "./types/exports/a.d.ts",
|
|
61
|
+
"import": "./es/exports/a.js",
|
|
62
|
+
"require": "./lib/exports/a.js",
|
|
63
|
+
"default": "./es/exports/a.js"
|
|
64
|
+
},
|
|
65
|
+
"./v11_7": {
|
|
66
|
+
"src": "./src/exports/b.ts",
|
|
67
|
+
"types": "./types/exports/b.d.ts",
|
|
68
|
+
"import": "./es/exports/b.js",
|
|
69
|
+
"require": "./lib/exports/b.js",
|
|
70
|
+
"default": "./es/exports/b.js"
|
|
71
|
+
},
|
|
72
|
+
"./latest": {
|
|
73
|
+
"src": "./src/exports/b.ts",
|
|
74
|
+
"types": "./types/exports/b.d.ts",
|
|
75
|
+
"import": "./es/exports/b.js",
|
|
76
|
+
"require": "./lib/exports/b.js",
|
|
77
|
+
"default": "./es/exports/b.js"
|
|
78
|
+
}
|
|
57
79
|
},
|
|
58
80
|
"scripts": {
|
|
59
81
|
"lint": "ui-scripts lint",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
import { Component } from 'react'
|
|
26
26
|
|
|
27
27
|
import { warn } from '@instructure/console'
|
|
28
|
-
import { ContextView } from '@instructure/ui-view'
|
|
29
|
-
import { FormField } from '@instructure/ui-form-field'
|
|
28
|
+
import { ContextView } from '@instructure/ui-view/v11_6'
|
|
29
|
+
import { FormField } from '@instructure/ui-form-field/v11_6'
|
|
30
30
|
import { addEventListener } from '@instructure/ui-dom-utils'
|
|
31
|
-
import { withStyle } from '@instructure/emotion'
|
|
31
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
32
32
|
import {
|
|
33
33
|
omitProps,
|
|
34
34
|
pickProps,
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
RangeInputTheme,
|
|
30
30
|
PickPropsWithExceptions
|
|
31
31
|
} from '@instructure/shared-types'
|
|
32
|
-
import type { FormFieldOwnProps, FormMessage } from '@instructure/ui-form-field'
|
|
32
|
+
import type { FormFieldOwnProps, FormMessage } from '@instructure/ui-form-field/v11_6'
|
|
33
33
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
34
34
|
import type { InputHTMLAttributes } from 'react'
|
|
35
35
|
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: RangeInput
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
An html5 range input/slider component.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
---
|
|
9
|
+
type: example
|
|
10
|
+
---
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const [size, setSize] = useState('small')
|
|
13
|
+
const [thumbVariant, setThumbVariant] = useState('accessible')
|
|
14
|
+
|
|
15
|
+
const handleSizeChange = (event, value) => {
|
|
16
|
+
setSize(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const handleThumbVariantChange = (event, value) => {
|
|
20
|
+
setThumbVariant(value)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<View as="div" padding="medium" background="primary">
|
|
26
|
+
<RangeInput
|
|
27
|
+
label="Grading range"
|
|
28
|
+
defaultValue={30}
|
|
29
|
+
max={100}
|
|
30
|
+
min={0}
|
|
31
|
+
size={size}
|
|
32
|
+
thumbVariant={thumbVariant}
|
|
33
|
+
/>
|
|
34
|
+
</View>
|
|
35
|
+
|
|
36
|
+
<View as="div" margin="medium 0 0">
|
|
37
|
+
<FormFieldGroup
|
|
38
|
+
description={
|
|
39
|
+
<ScreenReaderContent>
|
|
40
|
+
RangeInput Example Settings
|
|
41
|
+
</ScreenReaderContent>
|
|
42
|
+
}
|
|
43
|
+
layout="columns"
|
|
44
|
+
vAlign="top"
|
|
45
|
+
>
|
|
46
|
+
<RadioInputGroup
|
|
47
|
+
onChange={handleSizeChange}
|
|
48
|
+
name="labelSize"
|
|
49
|
+
value={size}
|
|
50
|
+
description="Label size"
|
|
51
|
+
>
|
|
52
|
+
<RadioInput label="small" value="small" />
|
|
53
|
+
<RadioInput label="medium" value="medium" />
|
|
54
|
+
<RadioInput label="large" value="large" />
|
|
55
|
+
</RadioInputGroup>
|
|
56
|
+
|
|
57
|
+
<RadioInputGroup
|
|
58
|
+
onChange={handleThumbVariantChange}
|
|
59
|
+
name="thumbVariant"
|
|
60
|
+
value={thumbVariant}
|
|
61
|
+
description="Thumb variant"
|
|
62
|
+
>
|
|
63
|
+
<RadioInput label="accessible" value="accessible" />
|
|
64
|
+
<RadioInput label="deprecated" value="deprecated" />
|
|
65
|
+
</RadioInputGroup>
|
|
66
|
+
</FormFieldGroup>
|
|
67
|
+
</View>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
render(<Example />)
|
|
73
|
+
```
|
|
@@ -0,0 +1,223 @@
|
|
|
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 { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { warn } from '@instructure/console'
|
|
28
|
+
import { ContextView } from '@instructure/ui-view/latest'
|
|
29
|
+
import { FormField } from '@instructure/ui-form-field/latest'
|
|
30
|
+
import { addEventListener } from '@instructure/ui-dom-utils'
|
|
31
|
+
import { withStyle } from '@instructure/emotion'
|
|
32
|
+
import {
|
|
33
|
+
omitProps,
|
|
34
|
+
pickProps,
|
|
35
|
+
withDeterministicId
|
|
36
|
+
} from '@instructure/ui-react-utils'
|
|
37
|
+
|
|
38
|
+
import generateStyle from './styles'
|
|
39
|
+
|
|
40
|
+
import type { RangeInputProps, RangeInputState } from './props'
|
|
41
|
+
import { allowedProps } from './props'
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
---
|
|
45
|
+
category: components
|
|
46
|
+
---
|
|
47
|
+
**/
|
|
48
|
+
@withDeterministicId()
|
|
49
|
+
@withStyle(generateStyle)
|
|
50
|
+
class RangeInput extends Component<RangeInputProps, RangeInputState> {
|
|
51
|
+
static readonly componentId = 'RangeInput'
|
|
52
|
+
static outputLocatorAttribute = 'data-range-output'
|
|
53
|
+
|
|
54
|
+
static allowedProps = allowedProps
|
|
55
|
+
|
|
56
|
+
static defaultProps = {
|
|
57
|
+
step: 1,
|
|
58
|
+
formatValue: (val?: number) => val,
|
|
59
|
+
|
|
60
|
+
// If min and max has default value, they don't give a warning if not set, even if they are required props.
|
|
61
|
+
// TODO: figure out if they don't need to be required or remove defaults in V9.
|
|
62
|
+
max: 0,
|
|
63
|
+
min: 0,
|
|
64
|
+
|
|
65
|
+
inline: false,
|
|
66
|
+
size: 'medium',
|
|
67
|
+
layout: 'stacked',
|
|
68
|
+
displayValue: true,
|
|
69
|
+
disabled: false,
|
|
70
|
+
readOnly: false,
|
|
71
|
+
thumbVariant: 'deprecated'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ref: Element | null = null
|
|
75
|
+
|
|
76
|
+
private _input: HTMLInputElement | null = null
|
|
77
|
+
private _inputListener: { remove(): void } | null = null
|
|
78
|
+
private _changeListener: { remove(): void } | null = null
|
|
79
|
+
private readonly defaultId: string
|
|
80
|
+
|
|
81
|
+
handleRef = (el: Element | null) => {
|
|
82
|
+
this.ref = el
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
handleInputRef = (el: HTMLInputElement | null) => {
|
|
86
|
+
this._input = el
|
|
87
|
+
if (typeof this.props.inputRef === 'function') {
|
|
88
|
+
this.props.inputRef(el)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
constructor(props: RangeInputProps) {
|
|
93
|
+
super(props)
|
|
94
|
+
|
|
95
|
+
if (typeof props.value === 'undefined') {
|
|
96
|
+
this.state = {
|
|
97
|
+
value: props.defaultValue
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.defaultId = props.deterministicId!()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* workaround for https://github.com/facebook/react/issues/554 */
|
|
105
|
+
componentDidMount() {
|
|
106
|
+
this.props.makeStyles?.()
|
|
107
|
+
|
|
108
|
+
if (this._input !== null) {
|
|
109
|
+
// https://connect.microsoft.com/IE/Feedback/Details/856998
|
|
110
|
+
this._inputListener = addEventListener(
|
|
111
|
+
this._input,
|
|
112
|
+
'input',
|
|
113
|
+
this.handleChange
|
|
114
|
+
)
|
|
115
|
+
this._changeListener = addEventListener(
|
|
116
|
+
this._input,
|
|
117
|
+
'change',
|
|
118
|
+
this.handleChange
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
componentWillUnmount() {
|
|
124
|
+
if (!this._input) {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
this._inputListener?.remove()
|
|
128
|
+
this._changeListener?.remove()
|
|
129
|
+
}
|
|
130
|
+
/* end workaround */
|
|
131
|
+
|
|
132
|
+
componentDidUpdate() {
|
|
133
|
+
this.props.makeStyles?.()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
137
|
+
const { onChange, value } = this.props
|
|
138
|
+
|
|
139
|
+
if (typeof value === 'undefined') {
|
|
140
|
+
this.setState({ value: event.target.value })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (typeof onChange === 'function') {
|
|
144
|
+
onChange(event.target.value)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// controlled input must have an onChange, but we're handling it with native events
|
|
149
|
+
noopChange: React.ChangeEventHandler<HTMLInputElement> = () => {}
|
|
150
|
+
|
|
151
|
+
get value() {
|
|
152
|
+
const value =
|
|
153
|
+
typeof this.props.value === 'undefined'
|
|
154
|
+
? this.state.value
|
|
155
|
+
: this.props.value
|
|
156
|
+
|
|
157
|
+
return typeof value === 'string' ? parseInt(value) : value
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get id() {
|
|
161
|
+
return this.props.id || this.defaultId
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
renderValue() {
|
|
165
|
+
if (this.props.displayValue) {
|
|
166
|
+
if (!this.value) {
|
|
167
|
+
warn(
|
|
168
|
+
false,
|
|
169
|
+
'RangeInput should have a `value` or `defaultValue` set for the value to be displayed. If no value has to be displayed, set `displayValue={false}`.'
|
|
170
|
+
)
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
const props = { [RangeInput.outputLocatorAttribute]: this.id }
|
|
174
|
+
return (
|
|
175
|
+
<ContextView background="inverse" placement="end center">
|
|
176
|
+
<div {...props} css={this.props.styles?.rangeInputInputValue}>
|
|
177
|
+
{this.props.formatValue!(this.value, this.props.max)}
|
|
178
|
+
</div>
|
|
179
|
+
</ContextView>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return null
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
render() {
|
|
187
|
+
const { formatValue, disabled, readOnly } = this.props
|
|
188
|
+
|
|
189
|
+
const props = omitProps(this.props, RangeInput.allowedProps)
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<FormField
|
|
193
|
+
{...pickProps(this.props, FormField.allowedProps)}
|
|
194
|
+
label={this.props.label}
|
|
195
|
+
id={this.id}
|
|
196
|
+
elementRef={this.handleRef}
|
|
197
|
+
data-cid="RangeInput"
|
|
198
|
+
>
|
|
199
|
+
<div css={this.props.styles?.rangeInput}>
|
|
200
|
+
<input
|
|
201
|
+
css={this.props.styles?.rangeInputInput}
|
|
202
|
+
ref={this.handleInputRef}
|
|
203
|
+
type="range"
|
|
204
|
+
id={this.id}
|
|
205
|
+
min={this.props.min}
|
|
206
|
+
max={this.props.max}
|
|
207
|
+
step={this.props.step}
|
|
208
|
+
value={this.value}
|
|
209
|
+
onChange={this.noopChange}
|
|
210
|
+
aria-valuetext={formatValue!(this.value, this.props.max)}
|
|
211
|
+
{...props}
|
|
212
|
+
disabled={disabled || readOnly}
|
|
213
|
+
aria-disabled={disabled || readOnly ? 'true' : undefined}
|
|
214
|
+
/>
|
|
215
|
+
{this.renderValue()}
|
|
216
|
+
</div>
|
|
217
|
+
</FormField>
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export default RangeInput
|
|
223
|
+
export { RangeInput }
|