@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,183 @@
1
+ var _dec, _dec2, _class, _RangeInput;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
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 { omitProps, pickProps, withDeterministicId } from '@instructure/ui-react-utils';
33
+ import generateStyle from "./styles.js";
34
+ import { allowedProps } from "./props.js";
35
+ /**
36
+ ---
37
+ category: components
38
+ ---
39
+ **/
40
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
41
+ let RangeInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_RangeInput = class RangeInput extends Component {
42
+ constructor(props) {
43
+ super(props);
44
+ this.ref = null;
45
+ this._input = null;
46
+ this._inputListener = null;
47
+ this._changeListener = null;
48
+ this.defaultId = void 0;
49
+ this.handleRef = el => {
50
+ this.ref = el;
51
+ };
52
+ this.handleInputRef = el => {
53
+ this._input = el;
54
+ if (typeof this.props.inputRef === 'function') {
55
+ this.props.inputRef(el);
56
+ }
57
+ };
58
+ this.handleChange = event => {
59
+ const _this$props = this.props,
60
+ onChange = _this$props.onChange,
61
+ value = _this$props.value;
62
+ if (typeof value === 'undefined') {
63
+ this.setState({
64
+ value: event.target.value
65
+ });
66
+ }
67
+ if (typeof onChange === 'function') {
68
+ onChange(event.target.value);
69
+ }
70
+ };
71
+ // controlled input must have an onChange, but we're handling it with native events
72
+ this.noopChange = () => {};
73
+ if (typeof props.value === 'undefined') {
74
+ this.state = {
75
+ value: props.defaultValue
76
+ };
77
+ }
78
+ this.defaultId = props.deterministicId();
79
+ }
80
+
81
+ /* workaround for https://github.com/facebook/react/issues/554 */
82
+ componentDidMount() {
83
+ var _this$props$makeStyle, _this$props2;
84
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
85
+ if (this._input !== null) {
86
+ // https://connect.microsoft.com/IE/Feedback/Details/856998
87
+ this._inputListener = addEventListener(this._input, 'input', this.handleChange);
88
+ this._changeListener = addEventListener(this._input, 'change', this.handleChange);
89
+ }
90
+ }
91
+ componentWillUnmount() {
92
+ var _this$_inputListener, _this$_changeListener;
93
+ if (!this._input) {
94
+ return;
95
+ }
96
+ (_this$_inputListener = this._inputListener) === null || _this$_inputListener === void 0 ? void 0 : _this$_inputListener.remove();
97
+ (_this$_changeListener = this._changeListener) === null || _this$_changeListener === void 0 ? void 0 : _this$_changeListener.remove();
98
+ }
99
+ /* end workaround */
100
+
101
+ componentDidUpdate() {
102
+ var _this$props$makeStyle2, _this$props3;
103
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
104
+ }
105
+ get value() {
106
+ const value = typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
107
+ return typeof value === 'string' ? parseInt(value) : value;
108
+ }
109
+ get id() {
110
+ return this.props.id || this.defaultId;
111
+ }
112
+ renderValue() {
113
+ if (this.props.displayValue) {
114
+ var _this$props$styles;
115
+ if (!this.value) {
116
+ warn(false, 'RangeInput should have a `value` or `defaultValue` set for the value to be displayed. If no value has to be displayed, set `displayValue={false}`.');
117
+ return null;
118
+ }
119
+ const props = {
120
+ [RangeInput.outputLocatorAttribute]: this.id
121
+ };
122
+ return _jsx(ContextView, {
123
+ background: "inverse",
124
+ placement: "end center",
125
+ children: _jsx("div", {
126
+ ...props,
127
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rangeInputInputValue,
128
+ children: this.props.formatValue(this.value, this.props.max)
129
+ })
130
+ });
131
+ }
132
+ return null;
133
+ }
134
+ render() {
135
+ var _this$props$styles2, _this$props$styles3;
136
+ const _this$props4 = this.props,
137
+ formatValue = _this$props4.formatValue,
138
+ disabled = _this$props4.disabled,
139
+ readOnly = _this$props4.readOnly;
140
+ const props = omitProps(this.props, RangeInput.allowedProps);
141
+ return _jsx(FormField, {
142
+ ...pickProps(this.props, FormField.allowedProps),
143
+ label: this.props.label,
144
+ id: this.id,
145
+ elementRef: this.handleRef,
146
+ "data-cid": "RangeInput",
147
+ children: _jsxs("div", {
148
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.rangeInput,
149
+ children: [_jsx("input", {
150
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.rangeInputInput,
151
+ ref: this.handleInputRef,
152
+ type: "range",
153
+ id: this.id,
154
+ min: this.props.min,
155
+ max: this.props.max,
156
+ step: this.props.step,
157
+ value: this.value,
158
+ onChange: this.noopChange,
159
+ "aria-valuetext": formatValue(this.value, this.props.max),
160
+ ...props,
161
+ disabled: disabled || readOnly,
162
+ "aria-disabled": disabled || readOnly ? 'true' : void 0
163
+ }), this.renderValue()]
164
+ })
165
+ });
166
+ }
167
+ }, _RangeInput.displayName = "RangeInput", _RangeInput.componentId = 'RangeInput', _RangeInput.outputLocatorAttribute = 'data-range-output', _RangeInput.allowedProps = allowedProps, _RangeInput.defaultProps = {
168
+ step: 1,
169
+ formatValue: val => val,
170
+ // If min and max has default value, they don't give a warning if not set, even if they are required props.
171
+ // TODO: figure out if they don't need to be required or remove defaults in V9.
172
+ max: 0,
173
+ min: 0,
174
+ inline: false,
175
+ size: 'medium',
176
+ layout: 'stacked',
177
+ displayValue: true,
178
+ disabled: false,
179
+ readOnly: false,
180
+ thumbVariant: 'deprecated'
181
+ }, _RangeInput)) || _class) || _class);
182
+ export default RangeInput;
183
+ export { RangeInput };
@@ -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
+ const allowedProps = ['min', 'max', 'defaultValue', 'value', 'onChange', 'messages', 'size', 'layout', 'id', 'label', 'displayValue', 'step', 'formatValue', 'inline', 'disabled', 'readOnly', 'thumbVariant', 'inputRef'];
26
+ export { allowedProps };
@@ -0,0 +1,169 @@
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 { darken, alpha } from '@instructure/ui-color-utils';
26
+ import { boxShadowObjectsToCSSString } from '@instructure/ui-themes';
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (componentTheme, props, sharedTokens) => {
39
+ const size = props.size,
40
+ thumbVariant = props.thumbVariant;
41
+ const valueSizeVariants = {
42
+ small: {
43
+ fontSize: componentTheme.valueSmallFontSize,
44
+ paddingInline: componentTheme.valueSmallPadding,
45
+ lineHeight: componentTheme.valueSmallLineHeight
46
+ },
47
+ medium: {
48
+ fontSize: componentTheme.valueMediumFontSize,
49
+ paddingInline: componentTheme.valueMediumPadding,
50
+ lineHeight: componentTheme.valueMediumLineHeight
51
+ },
52
+ large: {
53
+ fontSize: componentTheme.valueLargeFontSize,
54
+ paddingInline: componentTheme.valueLargePadding,
55
+ lineHeight: componentTheme.valueLargeLineHeight
56
+ }
57
+ };
58
+ const trackBorderWidth = '1px';
59
+ const trackStyle = {
60
+ borderRadius: '0.312em',
61
+ borderWidth: trackBorderWidth,
62
+ borderStyle: 'solid',
63
+ borderColor: componentTheme.trackBorderColor,
64
+ color: 'transparent',
65
+ cursor: 'pointer',
66
+ background: componentTheme.trackBackground,
67
+ height: `calc(${componentTheme.handleSize} / 2)`
68
+ };
69
+ const borderedHandleSize = `calc(${componentTheme.handleSize} + (${componentTheme.handleBorderSize} * 2))`;
70
+ const thumbVariantStyle = {
71
+ deprecated: {
72
+ width: componentTheme.handleSize,
73
+ height: componentTheme.handleSize,
74
+ boxShadow: `0 0.0625rem 0 ${darken(componentTheme.handleShadowColor)}`
75
+ },
76
+ accessible: {
77
+ width: borderedHandleSize,
78
+ height: borderedHandleSize,
79
+ borderWidth: componentTheme.handleBorderSize,
80
+ borderColor: componentTheme.handleBorderColor,
81
+ borderStyle: 'solid',
82
+ boxSizing: 'border-box',
83
+ boxShadow: boxShadowObjectsToCSSString(componentTheme.boxShadow)
84
+ }
85
+ };
86
+ const thumbStyle = {
87
+ appearance: 'none',
88
+ borderRadius: '50%',
89
+ cursor: 'pointer',
90
+ transition: 'all 0.15s ease-in-out',
91
+ background: componentTheme.handleBackground,
92
+ ...thumbVariantStyle[thumbVariant],
93
+ '&:hover': {
94
+ background: componentTheme.handleHoverBackground
95
+ }
96
+ };
97
+
98
+ // Center the thumb vertically on the track by accounting for the track borders
99
+ const thumbPosition = {
100
+ deprecated: {
101
+ marginTop: `calc(-1 * ${componentTheme.handleSize} / 4 - ${trackBorderWidth})`
102
+ },
103
+ accessible: {
104
+ marginTop: `calc(-1 * ${borderedHandleSize} / 4 - ${trackBorderWidth})`
105
+ }
106
+ };
107
+ const thumbFocusActiveStyle = {
108
+ deprecated: {
109
+ background: componentTheme.handleFocusBackground,
110
+ boxShadow: `0 0.0625rem 0 ${darken(componentTheme.handleShadowColor)}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${alpha(componentTheme.handleFocusOutlineColor, 40)}`
111
+ },
112
+ accessible: {
113
+ background: componentTheme.handleFocusBackground,
114
+ boxShadow: `${boxShadowObjectsToCSSString(componentTheme.boxShadow)}, ` + `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` + `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${sharedTokens.focusOutline.width}) ${sharedTokens.focusOutline.onColor}`
115
+ }
116
+ };
117
+ return {
118
+ rangeInput: {
119
+ label: 'rangeInput',
120
+ display: 'flex',
121
+ justifyContent: 'center',
122
+ alignItems: 'center',
123
+ minWidth: componentTheme.minWidth
124
+ },
125
+ rangeInputInput: {
126
+ label: 'rangeInput__input',
127
+ all: 'initial',
128
+ flex: 'auto',
129
+ boxSizing: 'border-box',
130
+ appearance: 'none',
131
+ width: '100%',
132
+ // for Firefox
133
+ outline: 'none',
134
+ margin: 0,
135
+ '&::-webkit-slider-thumb': {
136
+ ...thumbStyle,
137
+ ...thumbPosition[thumbVariant]
138
+ },
139
+ '&::-moz-range-thumb': thumbStyle,
140
+ '&:focus, &:active': {
141
+ outline: 'none',
142
+ '&::-webkit-slider-thumb': thumbFocusActiveStyle[thumbVariant],
143
+ '&::-moz-range-thumb': thumbFocusActiveStyle[thumbVariant]
144
+ },
145
+ // remove outline in FF
146
+ '&::-moz-focus-inner, &::-moz-focus-outer': {
147
+ border: 0,
148
+ outline: 'none'
149
+ },
150
+ '&::-webkit-slider-runnable-track': trackStyle,
151
+ '&::-moz-range-track': trackStyle,
152
+ '[dir="rtl"] &': {
153
+ direction: 'rtl'
154
+ }
155
+ },
156
+ rangeInputInputValue: {
157
+ label: 'rangeInput__value',
158
+ all: 'initial',
159
+ boxSizing: 'border-box',
160
+ display: 'block',
161
+ color: 'inherit',
162
+ fontFamily: componentTheme.valueFontFamily,
163
+ fontWeight: componentTheme.valueFontWeight,
164
+ textAlign: 'center',
165
+ ...valueSizeVariants[size]
166
+ }
167
+ };
168
+ };
169
+ export default generateStyle;
@@ -21,4 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { RangeInput } from "./RangeInput/index.js";
24
+ export { RangeInput } from "../RangeInput/v1/index.js";
@@ -21,6 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
-
25
- export { RangeInput } from './RangeInput'
26
- export type { RangeInputProps } from './RangeInput/props'
24
+ export { RangeInput } from "../RangeInput/v2/index.js";
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.RangeInput = void 0;
8
+ var _react = require("react");
9
+ var _console = require("@instructure/console");
10
+ var _v11_ = require("@instructure/ui-view/v11_6");
11
+ var _v11_2 = require("@instructure/ui-form-field/v11_6");
12
+ var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
13
+ var _emotion = require("@instructure/emotion");
14
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
15
+ var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
16
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
17
+ var _styles = _interopRequireDefault(require("./styles"));
18
+ var _theme = _interopRequireDefault(require("./theme"));
19
+ var _props = require("./props");
20
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
+ var _dec, _dec2, _class, _RangeInput;
22
+ /*
23
+ * The MIT License (MIT)
24
+ *
25
+ * Copyright (c) 2015 - present Instructure, Inc.
26
+ *
27
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ * of this software and associated documentation files (the "Software"), to deal
29
+ * in the Software without restriction, including without limitation the rights
30
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ * copies of the Software, and to permit persons to whom the Software is
32
+ * furnished to do so, subject to the following conditions:
33
+ *
34
+ * The above copyright notice and this permission notice shall be included in all
35
+ * copies or substantial portions of the Software.
36
+ *
37
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ * SOFTWARE.
44
+ */
45
+ /**
46
+ ---
47
+ category: components
48
+ ---
49
+ **/
50
+ let RangeInput = exports.RangeInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_RangeInput = class RangeInput extends _react.Component {
51
+ constructor(props) {
52
+ super(props);
53
+ this.ref = null;
54
+ this._input = null;
55
+ this._inputListener = null;
56
+ this._changeListener = null;
57
+ this.defaultId = void 0;
58
+ this.handleRef = el => {
59
+ this.ref = el;
60
+ };
61
+ this.handleInputRef = el => {
62
+ this._input = el;
63
+ if (typeof this.props.inputRef === 'function') {
64
+ this.props.inputRef(el);
65
+ }
66
+ };
67
+ this.handleChange = event => {
68
+ const _this$props = this.props,
69
+ onChange = _this$props.onChange,
70
+ value = _this$props.value;
71
+ if (typeof value === 'undefined') {
72
+ this.setState({
73
+ value: event.target.value
74
+ });
75
+ }
76
+ if (typeof onChange === 'function') {
77
+ onChange(event.target.value);
78
+ }
79
+ };
80
+ // controlled input must have an onChange, but we're handling it with native events
81
+ this.noopChange = () => {};
82
+ if (typeof props.value === 'undefined') {
83
+ this.state = {
84
+ value: props.defaultValue
85
+ };
86
+ }
87
+ this.defaultId = props.deterministicId();
88
+ }
89
+
90
+ /* workaround for https://github.com/facebook/react/issues/554 */
91
+ componentDidMount() {
92
+ var _this$props$makeStyle, _this$props2;
93
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
94
+ if (this._input !== null) {
95
+ // https://connect.microsoft.com/IE/Feedback/Details/856998
96
+ this._inputListener = (0, _addEventListener.addEventListener)(this._input, 'input', this.handleChange);
97
+ this._changeListener = (0, _addEventListener.addEventListener)(this._input, 'change', this.handleChange);
98
+ }
99
+ }
100
+ componentWillUnmount() {
101
+ var _this$_inputListener, _this$_changeListener;
102
+ if (!this._input) {
103
+ return;
104
+ }
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();
107
+ }
108
+ /* end workaround */
109
+
110
+ componentDidUpdate() {
111
+ var _this$props$makeStyle2, _this$props3;
112
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
113
+ }
114
+ get value() {
115
+ const value = typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
116
+ return typeof value === 'string' ? parseInt(value) : value;
117
+ }
118
+ get id() {
119
+ return this.props.id || this.defaultId;
120
+ }
121
+ renderValue() {
122
+ if (this.props.displayValue) {
123
+ var _this$props$styles;
124
+ if (!this.value) {
125
+ (0, _console.warn)(false, 'RangeInput should have a `value` or `defaultValue` set for the value to be displayed. If no value has to be displayed, set `displayValue={false}`.');
126
+ return null;
127
+ }
128
+ const props = {
129
+ [RangeInput.outputLocatorAttribute]: this.id
130
+ };
131
+ return (0, _jsxRuntime.jsx)(_v11_.ContextView, {
132
+ background: "inverse",
133
+ placement: "end center",
134
+ children: (0, _jsxRuntime.jsx)("div", {
135
+ ...props,
136
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rangeInputInputValue,
137
+ children: this.props.formatValue(this.value, this.props.max)
138
+ })
139
+ });
140
+ }
141
+ return null;
142
+ }
143
+ render() {
144
+ var _this$props$styles2, _this$props$styles3;
145
+ const _this$props4 = this.props,
146
+ formatValue = _this$props4.formatValue,
147
+ disabled = _this$props4.disabled,
148
+ readOnly = _this$props4.readOnly;
149
+ const props = (0, _omitProps.omitProps)(this.props, RangeInput.allowedProps);
150
+ return (0, _jsxRuntime.jsx)(_v11_2.FormField, {
151
+ ...(0, _pickProps.pickProps)(this.props, _v11_2.FormField.allowedProps),
152
+ label: this.props.label,
153
+ id: this.id,
154
+ elementRef: this.handleRef,
155
+ "data-cid": "RangeInput",
156
+ children: (0, _jsxRuntime.jsxs)("div", {
157
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.rangeInput,
158
+ children: [(0, _jsxRuntime.jsx)("input", {
159
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.rangeInputInput,
160
+ ref: this.handleInputRef,
161
+ type: "range",
162
+ id: this.id,
163
+ min: this.props.min,
164
+ max: this.props.max,
165
+ step: this.props.step,
166
+ value: this.value,
167
+ onChange: this.noopChange,
168
+ "aria-valuetext": formatValue(this.value, this.props.max),
169
+ ...props,
170
+ disabled: disabled || readOnly,
171
+ "aria-disabled": disabled || readOnly ? 'true' : void 0
172
+ }), this.renderValue()]
173
+ })
174
+ });
175
+ }
176
+ }, _RangeInput.displayName = "RangeInput", _RangeInput.componentId = 'RangeInput', _RangeInput.outputLocatorAttribute = 'data-range-output', _RangeInput.allowedProps = _props.allowedProps, _RangeInput.defaultProps = {
177
+ step: 1,
178
+ formatValue: val => val,
179
+ // If min and max has default value, they don't give a warning if not set, even if they are required props.
180
+ // TODO: figure out if they don't need to be required or remove defaults in V9.
181
+ max: 0,
182
+ min: 0,
183
+ inline: false,
184
+ size: 'medium',
185
+ layout: 'stacked',
186
+ displayValue: true,
187
+ disabled: false,
188
+ readOnly: false,
189
+ thumbVariant: 'deprecated'
190
+ }, _RangeInput)) || _class) || _class);
191
+ var _default = exports.default = RangeInput;
@@ -7,15 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.RangeInput = void 0;
8
8
  var _react = require("react");
9
9
  var _console = require("@instructure/console");
10
- var _ContextView = require("@instructure/ui-view/lib/ContextView");
11
- var _FormField = require("@instructure/ui-form-field/lib/FormField");
10
+ var _latest = require("@instructure/ui-view/latest");
11
+ var _latest2 = require("@instructure/ui-form-field/latest");
12
12
  var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
13
13
  var _emotion = require("@instructure/emotion");
14
14
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
15
15
  var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
16
16
  var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
17
17
  var _styles = _interopRequireDefault(require("./styles"));
18
- var _theme = _interopRequireDefault(require("./theme"));
19
18
  var _props = require("./props");
20
19
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
20
  var _dec, _dec2, _class, _RangeInput;
@@ -47,7 +46,7 @@ var _dec, _dec2, _class, _RangeInput;
47
46
  category: components
48
47
  ---
49
48
  **/
50
- let RangeInput = exports.RangeInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_RangeInput = class RangeInput extends _react.Component {
49
+ let RangeInput = exports.RangeInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_RangeInput = class RangeInput extends _react.Component {
51
50
  constructor(props) {
52
51
  super(props);
53
52
  this.ref = null;
@@ -128,7 +127,7 @@ let RangeInput = exports.RangeInput = (_dec = (0, _withDeterministicId.withDeter
128
127
  const props = {
129
128
  [RangeInput.outputLocatorAttribute]: this.id
130
129
  };
131
- return (0, _jsxRuntime.jsx)(_ContextView.ContextView, {
130
+ return (0, _jsxRuntime.jsx)(_latest.ContextView, {
132
131
  background: "inverse",
133
132
  placement: "end center",
134
133
  children: (0, _jsxRuntime.jsx)("div", {
@@ -147,8 +146,8 @@ let RangeInput = exports.RangeInput = (_dec = (0, _withDeterministicId.withDeter
147
146
  disabled = _this$props4.disabled,
148
147
  readOnly = _this$props4.readOnly;
149
148
  const props = (0, _omitProps.omitProps)(this.props, RangeInput.allowedProps);
150
- return (0, _jsxRuntime.jsx)(_FormField.FormField, {
151
- ...(0, _pickProps.pickProps)(this.props, _FormField.FormField.allowedProps),
149
+ return (0, _jsxRuntime.jsx)(_latest2.FormField, {
150
+ ...(0, _pickProps.pickProps)(this.props, _latest2.FormField.allowedProps),
152
151
  label: this.props.label,
153
152
  id: this.id,
154
153
  elementRef: this.handleRef,
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.allowedProps = ['min', 'max', 'defaultValue', 'value', 'onChange', 'messages', 'size', 'layout', 'id', 'label', 'displayValue', 'step', 'formatValue', 'inline', 'disabled', 'readOnly', 'thumbVariant', 'inputRef'];