@instructure/ui-range-input 8.14.0 → 8.14.1-snapshot.5
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/LICENSE.md +27 -0
- package/es/RangeInput/RangeInputLocator.js +2 -1
- package/es/RangeInput/__examples__/RangeInput.examples.js +1 -1
- package/es/RangeInput/index.js +14 -7
- package/es/RangeInput/props.js +0 -24
- package/lib/RangeInput/RangeInputLocator.js +1 -0
- package/lib/RangeInput/__examples__/RangeInput.examples.js +1 -1
- package/lib/RangeInput/index.js +16 -7
- package/lib/RangeInput/props.js +0 -24
- package/package.json +20 -19
- package/src/RangeInput/__examples__/RangeInput.examples.ts +5 -3
- package/src/RangeInput/index.tsx +33 -31
- package/src/RangeInput/props.ts +59 -31
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/RangeInput/__examples__/RangeInput.examples.d.ts +3 -8
- package/types/RangeInput/__examples__/RangeInput.examples.d.ts.map +1 -1
- package/types/RangeInput/index.d.ts +23 -25
- package/types/RangeInput/index.d.ts.map +1 -1
- package/types/RangeInput/props.d.ts +30 -8
- package/types/RangeInput/props.d.ts.map +1 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The MIT License (MIT)
|
|
3
|
+
category: Getting Started
|
|
4
|
+
order: 9
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2015 Instructure, Inc.
|
|
10
|
+
|
|
11
|
+
**Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions.**
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
|
-
import { RangeInput } from './index';
|
|
25
|
+
import { RangeInput } from './index'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
26
|
+
|
|
26
27
|
export const RangeInputLocator = locator(RangeInput.selector, {
|
|
27
28
|
findInput: function () {
|
|
28
29
|
return locator('input[type=range]').find(...arguments);
|
package/es/RangeInput/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var _dec, _dec2, _class, _class2, _temp;
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/** @jsx jsx */
|
|
28
|
-
import { Component } from 'react';
|
|
28
|
+
import React, { Component } from 'react';
|
|
29
29
|
import { ContextView } from '@instructure/ui-view';
|
|
30
30
|
import { FormField } from '@instructure/ui-form-field';
|
|
31
31
|
import { addEventListener } from '@instructure/ui-dom-utils';
|
|
@@ -40,15 +40,17 @@ import { allowedProps, propTypes } from './props';
|
|
|
40
40
|
---
|
|
41
41
|
category: components
|
|
42
42
|
---
|
|
43
|
+
@tsProps
|
|
43
44
|
**/
|
|
44
45
|
|
|
45
46
|
let RangeInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class RangeInput extends Component {
|
|
46
47
|
constructor(props) {
|
|
47
|
-
super();
|
|
48
|
+
super(props);
|
|
48
49
|
this.ref = null;
|
|
49
50
|
this._input = null;
|
|
50
51
|
this._inputListener = null;
|
|
51
52
|
this._changeListener = null;
|
|
53
|
+
this.defaultId = void 0;
|
|
52
54
|
|
|
53
55
|
this.handleRef = el => {
|
|
54
56
|
this.ref = el;
|
|
@@ -96,13 +98,14 @@ let RangeInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
componentWillUnmount() {
|
|
101
|
+
var _this$_inputListener, _this$_changeListener;
|
|
102
|
+
|
|
99
103
|
if (!this._input) {
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
this._inputListener.remove();
|
|
104
|
-
|
|
105
|
-
this._changeListener.remove();
|
|
107
|
+
(_this$_inputListener = this._inputListener) === null || _this$_inputListener === void 0 ? void 0 : _this$_inputListener.remove();
|
|
108
|
+
(_this$_changeListener = this._changeListener) === null || _this$_changeListener === void 0 ? void 0 : _this$_changeListener.remove();
|
|
106
109
|
}
|
|
107
110
|
/* end workaround */
|
|
108
111
|
|
|
@@ -114,7 +117,8 @@ let RangeInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
get value() {
|
|
117
|
-
|
|
120
|
+
const value = typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
|
|
121
|
+
return typeof value === 'string' ? parseInt(value) : value;
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
get invalid() {
|
|
@@ -137,8 +141,10 @@ let RangeInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
137
141
|
}, jsx("output", {
|
|
138
142
|
htmlFor: this.id,
|
|
139
143
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rangeInputInputValue
|
|
140
|
-
}, this.props.formatValue(this.value)));
|
|
144
|
+
}, this.props.formatValue(this.value, this.props.max)));
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
return null;
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
render() {
|
|
@@ -152,6 +158,7 @@ let RangeInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2
|
|
|
152
158
|
/* eslint-disable jsx-a11y/no-redundant-roles */
|
|
153
159
|
|
|
154
160
|
return jsx(FormField, Object.assign({}, pickProps(this.props, FormField.allowedProps), {
|
|
161
|
+
label: this.props.label,
|
|
155
162
|
id: this.id,
|
|
156
163
|
elementRef: this.handleRef
|
|
157
164
|
}), jsx("div", {
|
package/es/RangeInput/props.js
CHANGED
|
@@ -27,40 +27,16 @@ import { FormPropTypes } from '@instructure/ui-form-field';
|
|
|
27
27
|
const propTypes = {
|
|
28
28
|
min: PropTypes.number.isRequired,
|
|
29
29
|
max: PropTypes.number.isRequired,
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* value to set on initial render
|
|
33
|
-
*/
|
|
34
30
|
defaultValue: PropTypes.number,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* the selected value (must be accompanied by an `onChange` prop)
|
|
38
|
-
*/
|
|
39
31
|
value: controllable(PropTypes.number),
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* when used with the `value` prop, the component will not control its own state
|
|
43
|
-
*/
|
|
44
32
|
onChange: PropTypes.func,
|
|
45
33
|
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The size of the value label
|
|
49
|
-
*/
|
|
50
34
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
51
35
|
layout: PropTypes.oneOf(['stacked', 'inline']),
|
|
52
36
|
id: PropTypes.string,
|
|
53
37
|
label: PropTypes.node.isRequired,
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* whether to display the current value
|
|
57
|
-
*/
|
|
58
38
|
displayValue: PropTypes.bool,
|
|
59
39
|
step: PropTypes.number,
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* A function to format the displayed value
|
|
63
|
-
*/
|
|
64
40
|
formatValue: PropTypes.func,
|
|
65
41
|
inline: PropTypes.bool,
|
|
66
42
|
disabled: PropTypes.bool,
|
|
@@ -32,6 +32,7 @@ var _index = require("./index");
|
|
|
32
32
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
33
|
* SOFTWARE.
|
|
34
34
|
*/
|
|
35
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
35
36
|
const RangeInputLocator = (0, _locator.locator)(_index.RangeInput.selector, {
|
|
36
37
|
findInput: function () {
|
|
37
38
|
return (0, _locator.locator)('input[type=range]').find(...arguments);
|
package/lib/RangeInput/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
|
|
3
5
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7,7 +9,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
9
|
});
|
|
8
10
|
exports.default = exports.RangeInput = void 0;
|
|
9
11
|
|
|
10
|
-
var _react = require("react");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
13
|
|
|
12
14
|
var _ContextView = require("@instructure/ui-view/lib/ContextView");
|
|
13
15
|
|
|
@@ -37,14 +39,16 @@ var _dec, _dec2, _class, _class2, _temp;
|
|
|
37
39
|
---
|
|
38
40
|
category: components
|
|
39
41
|
---
|
|
42
|
+
@tsProps
|
|
40
43
|
**/
|
|
41
44
|
let RangeInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class RangeInput extends _react.Component {
|
|
42
45
|
constructor(props) {
|
|
43
|
-
super();
|
|
46
|
+
super(props);
|
|
44
47
|
this.ref = null;
|
|
45
48
|
this._input = null;
|
|
46
49
|
this._inputListener = null;
|
|
47
50
|
this._changeListener = null;
|
|
51
|
+
this.defaultId = void 0;
|
|
48
52
|
|
|
49
53
|
this.handleRef = el => {
|
|
50
54
|
this.ref = el;
|
|
@@ -92,13 +96,14 @@ let RangeInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
componentWillUnmount() {
|
|
99
|
+
var _this$_inputListener, _this$_changeListener;
|
|
100
|
+
|
|
95
101
|
if (!this._input) {
|
|
96
102
|
return;
|
|
97
103
|
}
|
|
98
104
|
|
|
99
|
-
this._inputListener.remove();
|
|
100
|
-
|
|
101
|
-
this._changeListener.remove();
|
|
105
|
+
(_this$_inputListener = this._inputListener) === null || _this$_inputListener === void 0 ? void 0 : _this$_inputListener.remove();
|
|
106
|
+
(_this$_changeListener = this._changeListener) === null || _this$_changeListener === void 0 ? void 0 : _this$_changeListener.remove();
|
|
102
107
|
}
|
|
103
108
|
/* end workaround */
|
|
104
109
|
|
|
@@ -110,7 +115,8 @@ let RangeInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
get value() {
|
|
113
|
-
|
|
118
|
+
const value = typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
|
|
119
|
+
return typeof value === 'string' ? parseInt(value) : value;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
get invalid() {
|
|
@@ -133,8 +139,10 @@ let RangeInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
133
139
|
}, (0, _emotion.jsx)("output", {
|
|
134
140
|
htmlFor: this.id,
|
|
135
141
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rangeInputInputValue
|
|
136
|
-
}, this.props.formatValue(this.value)));
|
|
142
|
+
}, this.props.formatValue(this.value, this.props.max)));
|
|
137
143
|
}
|
|
144
|
+
|
|
145
|
+
return null;
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
render() {
|
|
@@ -148,6 +156,7 @@ let RangeInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
|
|
|
148
156
|
/* eslint-disable jsx-a11y/no-redundant-roles */
|
|
149
157
|
|
|
150
158
|
return (0, _emotion.jsx)(_FormField.FormField, Object.assign({}, (0, _pickProps.pickProps)(this.props, _FormField.FormField.allowedProps), {
|
|
159
|
+
label: this.props.label,
|
|
151
160
|
id: this.id,
|
|
152
161
|
elementRef: this.handleRef
|
|
153
162
|
}), (0, _emotion.jsx)("div", {
|
package/lib/RangeInput/props.js
CHANGED
|
@@ -39,40 +39,16 @@ var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
|
|
|
39
39
|
const propTypes = {
|
|
40
40
|
min: _propTypes.default.number.isRequired,
|
|
41
41
|
max: _propTypes.default.number.isRequired,
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* value to set on initial render
|
|
45
|
-
*/
|
|
46
42
|
defaultValue: _propTypes.default.number,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* the selected value (must be accompanied by an `onChange` prop)
|
|
50
|
-
*/
|
|
51
43
|
value: (0, _controllable.controllable)(_propTypes.default.number),
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* when used with the `value` prop, the component will not control its own state
|
|
55
|
-
*/
|
|
56
44
|
onChange: _propTypes.default.func,
|
|
57
45
|
messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The size of the value label
|
|
61
|
-
*/
|
|
62
46
|
size: _propTypes.default.oneOf(['small', 'medium', 'large']),
|
|
63
47
|
layout: _propTypes.default.oneOf(['stacked', 'inline']),
|
|
64
48
|
id: _propTypes.default.string,
|
|
65
49
|
label: _propTypes.default.node.isRequired,
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* whether to display the current value
|
|
69
|
-
*/
|
|
70
50
|
displayValue: _propTypes.default.bool,
|
|
71
51
|
step: _propTypes.default.number,
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A function to format the displayed value
|
|
75
|
-
*/
|
|
76
52
|
formatValue: _propTypes.default.func,
|
|
77
53
|
inline: _propTypes.default.bool,
|
|
78
54
|
disabled: _propTypes.default.bool,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-range-input",
|
|
3
|
-
"version": "8.14.
|
|
3
|
+
"version": "8.14.1-snapshot.5+63bca0bc9",
|
|
4
4
|
"description": "A styled HTML range input",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,26 +25,26 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/runtime": "^7.13.10",
|
|
28
|
-
"@instructure/console": "8.14.
|
|
29
|
-
"@instructure/emotion": "8.14.
|
|
30
|
-
"@instructure/shared-types": "8.14.
|
|
31
|
-
"@instructure/ui-color-utils": "8.14.
|
|
32
|
-
"@instructure/ui-dom-utils": "8.14.
|
|
33
|
-
"@instructure/ui-form-field": "8.14.
|
|
34
|
-
"@instructure/ui-i18n": "8.14.
|
|
35
|
-
"@instructure/ui-prop-types": "8.14.
|
|
36
|
-
"@instructure/ui-react-utils": "8.14.
|
|
37
|
-
"@instructure/ui-testable": "8.14.
|
|
38
|
-
"@instructure/ui-utils": "8.14.
|
|
39
|
-
"@instructure/ui-view": "8.14.
|
|
40
|
-
"@instructure/uid": "8.14.
|
|
28
|
+
"@instructure/console": "8.14.1-snapshot.5+63bca0bc9",
|
|
29
|
+
"@instructure/emotion": "8.14.1-snapshot.5+63bca0bc9",
|
|
30
|
+
"@instructure/shared-types": "8.14.1-snapshot.5+63bca0bc9",
|
|
31
|
+
"@instructure/ui-color-utils": "8.14.1-snapshot.5+63bca0bc9",
|
|
32
|
+
"@instructure/ui-dom-utils": "8.14.1-snapshot.5+63bca0bc9",
|
|
33
|
+
"@instructure/ui-form-field": "8.14.1-snapshot.5+63bca0bc9",
|
|
34
|
+
"@instructure/ui-i18n": "8.14.1-snapshot.5+63bca0bc9",
|
|
35
|
+
"@instructure/ui-prop-types": "8.14.1-snapshot.5+63bca0bc9",
|
|
36
|
+
"@instructure/ui-react-utils": "8.14.1-snapshot.5+63bca0bc9",
|
|
37
|
+
"@instructure/ui-testable": "8.14.1-snapshot.5+63bca0bc9",
|
|
38
|
+
"@instructure/ui-utils": "8.14.1-snapshot.5+63bca0bc9",
|
|
39
|
+
"@instructure/ui-view": "8.14.1-snapshot.5+63bca0bc9",
|
|
40
|
+
"@instructure/uid": "8.14.1-snapshot.5+63bca0bc9",
|
|
41
41
|
"prop-types": "^15"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@instructure/ui-babel-preset": "8.14.
|
|
45
|
-
"@instructure/ui-test-locator": "8.14.
|
|
46
|
-
"@instructure/ui-test-utils": "8.14.
|
|
47
|
-
"@instructure/ui-themes": "8.14.
|
|
44
|
+
"@instructure/ui-babel-preset": "8.14.1-snapshot.5+63bca0bc9",
|
|
45
|
+
"@instructure/ui-test-locator": "8.14.1-snapshot.5+63bca0bc9",
|
|
46
|
+
"@instructure/ui-test-utils": "8.14.1-snapshot.5+63bca0bc9",
|
|
47
|
+
"@instructure/ui-themes": "8.14.1-snapshot.5+63bca0bc9"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=16.8 <=17"
|
|
@@ -52,5 +52,6 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"sideEffects": false
|
|
55
|
+
"sideEffects": false,
|
|
56
|
+
"gitHead": "63bca0bc94ad7c10cdba1f7a88a9755ab74208d6"
|
|
56
57
|
}
|
|
@@ -22,14 +22,16 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import type { StoryConfig } from '@instructure/ui-test-utils'
|
|
26
|
+
import type { RangeInputProps } from '../props'
|
|
27
|
+
|
|
25
28
|
export default {
|
|
26
29
|
sectionProp: 'layout',
|
|
27
30
|
maxExamplesPerPage: 50,
|
|
28
|
-
|
|
29
|
-
getComponentProps: (props) => {
|
|
31
|
+
getComponentProps: () => {
|
|
30
32
|
return {
|
|
31
33
|
label: 'Opacity',
|
|
32
34
|
onChange: () => {}
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
}
|
|
37
|
+
} as StoryConfig<RangeInputProps>
|
package/src/RangeInput/index.tsx
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
|
-
import { Component } from 'react'
|
|
26
|
+
import React, { Component } from 'react'
|
|
27
27
|
|
|
28
28
|
import { ContextView } from '@instructure/ui-view'
|
|
29
29
|
import { FormField } from '@instructure/ui-form-field'
|
|
@@ -35,17 +35,19 @@ import { omitProps, pickProps } from '@instructure/ui-react-utils'
|
|
|
35
35
|
|
|
36
36
|
import generateStyle from './styles'
|
|
37
37
|
import generateComponentTheme from './theme'
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
import type { RangeInputProps, RangeInputState } from './props'
|
|
39
40
|
import { allowedProps, propTypes } from './props'
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
---
|
|
43
44
|
category: components
|
|
44
45
|
---
|
|
46
|
+
@tsProps
|
|
45
47
|
**/
|
|
46
48
|
@withStyle(generateStyle, generateComponentTheme)
|
|
47
49
|
@testable()
|
|
48
|
-
class RangeInput extends Component<RangeInputProps> {
|
|
50
|
+
class RangeInput extends Component<RangeInputProps, RangeInputState> {
|
|
49
51
|
static readonly componentId = 'RangeInput'
|
|
50
52
|
|
|
51
53
|
static allowedProps = allowedProps
|
|
@@ -53,8 +55,7 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
53
55
|
|
|
54
56
|
static defaultProps = {
|
|
55
57
|
step: 1,
|
|
56
|
-
|
|
57
|
-
formatValue: (val) => val,
|
|
58
|
+
formatValue: (val?: number) => val,
|
|
58
59
|
max: 0,
|
|
59
60
|
min: 0,
|
|
60
61
|
inline: false,
|
|
@@ -66,18 +67,18 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
ref: Element | null = null
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
|
|
71
|
+
private _input: HTMLInputElement | null = null
|
|
72
|
+
private _inputListener: { remove(): void } | null = null
|
|
73
|
+
private _changeListener: { remove(): void } | null = null
|
|
74
|
+
private readonly defaultId: string
|
|
72
75
|
|
|
73
76
|
handleRef = (el: Element | null) => {
|
|
74
77
|
this.ref = el
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1-2 arguments, but got 0.
|
|
80
|
-
super()
|
|
80
|
+
constructor(props: RangeInputProps) {
|
|
81
|
+
super(props)
|
|
81
82
|
|
|
82
83
|
if (typeof props.value === 'undefined') {
|
|
83
84
|
this.state = {
|
|
@@ -85,7 +86,6 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'defaultId' does not exist on type 'Range... Remove this comment to see the full error message
|
|
89
89
|
this.defaultId = uid('RangeInput')
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -112,10 +112,8 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
112
112
|
if (!this._input) {
|
|
113
113
|
return
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_changeListener' does not exist on type '... Remove this comment to see the full error message
|
|
118
|
-
this._changeListener.remove()
|
|
115
|
+
this._inputListener?.remove()
|
|
116
|
+
this._changeListener?.remove()
|
|
119
117
|
}
|
|
120
118
|
/* end workaround */
|
|
121
119
|
|
|
@@ -123,8 +121,7 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
123
121
|
this.props.makeStyles?.()
|
|
124
122
|
}
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
handleChange = (event) => {
|
|
124
|
+
handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
128
125
|
const { onChange, value } = this.props
|
|
129
126
|
|
|
130
127
|
if (typeof value === 'undefined') {
|
|
@@ -137,13 +134,15 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
// controlled input must have an onChange, but we're handling it with native events
|
|
140
|
-
noopChange = () => {}
|
|
137
|
+
noopChange: React.ChangeEventHandler<HTMLInputElement> = () => {}
|
|
141
138
|
|
|
142
139
|
get value() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.state.value
|
|
146
|
-
|
|
140
|
+
const value =
|
|
141
|
+
typeof this.props.value === 'undefined'
|
|
142
|
+
? this.state.value!
|
|
143
|
+
: this.props.value
|
|
144
|
+
|
|
145
|
+
return typeof value === 'string' ? parseInt(value) : value
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
get invalid() {
|
|
@@ -156,11 +155,9 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
get id() {
|
|
159
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'defaultId' does not exist on type 'Range... Remove this comment to see the full error message
|
|
160
158
|
return this.props.id || this.defaultId
|
|
161
159
|
}
|
|
162
160
|
|
|
163
|
-
// @ts-expect-error ts-migrate(7030) FIXME: Not all code paths return a value.
|
|
164
161
|
renderValue() {
|
|
165
162
|
if (this.props.displayValue) {
|
|
166
163
|
return (
|
|
@@ -169,12 +166,18 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
169
166
|
htmlFor={this.id}
|
|
170
167
|
css={this.props.styles?.rangeInputInputValue}
|
|
171
168
|
>
|
|
172
|
-
{
|
|
173
|
-
|
|
169
|
+
{/**
|
|
170
|
+
* Value can be undefined when no value or defaultValue is given,
|
|
171
|
+
* and then it renders an empty ContextView
|
|
172
|
+
* TODO: Ask a designer what the intended behaviour is
|
|
173
|
+
*/}
|
|
174
|
+
{this.props.formatValue!(this.value, this.props.max)}
|
|
174
175
|
</output>
|
|
175
176
|
</ContextView>
|
|
176
177
|
)
|
|
177
178
|
}
|
|
179
|
+
|
|
180
|
+
return null
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
render() {
|
|
@@ -184,9 +187,9 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
184
187
|
|
|
185
188
|
/* eslint-disable jsx-a11y/no-redundant-roles */
|
|
186
189
|
return (
|
|
187
|
-
// @ts-expect-error ts-migrate(2554) FIXME: no overload..
|
|
188
190
|
<FormField
|
|
189
191
|
{...pickProps(this.props, FormField.allowedProps)}
|
|
192
|
+
label={this.props.label}
|
|
190
193
|
id={this.id}
|
|
191
194
|
elementRef={this.handleRef}
|
|
192
195
|
>
|
|
@@ -207,8 +210,7 @@ class RangeInput extends Component<RangeInputProps> {
|
|
|
207
210
|
aria-valuenow={this.value}
|
|
208
211
|
aria-valuemin={this.props.min}
|
|
209
212
|
aria-valuemax={this.props.max}
|
|
210
|
-
|
|
211
|
-
aria-valuetext={formatValue(this.value, this.props.max)}
|
|
213
|
+
aria-valuetext={formatValue!(this.value, this.props.max)}
|
|
212
214
|
{...props}
|
|
213
215
|
disabled={disabled || readOnly}
|
|
214
216
|
aria-disabled={disabled || readOnly ? 'true' : undefined}
|