@instructure/ui-number-input 8.13.1-snapshot.48 → 8.14.0
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 +6 -0
- package/es/NumberInput/NumberInputLocator.js +2 -1
- package/es/NumberInput/index.js +56 -35
- package/es/NumberInput/props.js +0 -90
- package/lib/NumberInput/NumberInputLocator.js +1 -0
- package/lib/NumberInput/index.js +57 -34
- package/lib/NumberInput/props.js +0 -90
- package/package.json +14 -15
- package/src/NumberInput/index.tsx +53 -59
- package/src/NumberInput/props.ts +109 -77
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/NumberInput/index.d.ts +29 -36
- package/types/NumberInput/index.d.ts.map +1 -1
- package/types/NumberInput/props.d.ts +83 -11
- package/types/NumberInput/props.d.ts.map +1 -1
- package/LICENSE.md +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [8.14.0](https://github.com/instructure/instructure-ui/compare/v8.13.0...v8.14.0) (2021-12-16)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **ui-number-input,ui-pagination:** add Pagination `input` variant, NumberInput `textAlign` prop ([5b90d60](https://github.com/instructure/instructure-ui/commit/5b90d608fd51296ae04e353e991f50a373c592c5))
|
|
11
|
+
|
|
6
12
|
# [8.13.0](https://github.com/instructure/instructure-ui/compare/v8.12.0...v8.13.0) (2021-12-01)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
|
-
import { NumberInput } from './index';
|
|
25
|
+
import { NumberInput } 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 NumberInputLocator = locator(NumberInput.selector, {
|
|
27
28
|
findInput: function () {
|
|
28
29
|
return locator('input').find(...arguments);
|
package/es/NumberInput/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var _dec, _dec2, _class, _class2, _temp, _IconArrowOpenUpLine, _IconArrowOpenDow
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/** @jsx jsx */
|
|
28
|
-
import { Component } from 'react';
|
|
28
|
+
import React, { Component } from 'react';
|
|
29
29
|
import keycode from 'keycode';
|
|
30
30
|
import { FormField } from '@instructure/ui-form-field';
|
|
31
31
|
import { IconArrowOpenDownLine, IconArrowOpenUpLine } from '@instructure/ui-icons';
|
|
@@ -36,21 +36,23 @@ import { withStyle, jsx } from '@instructure/emotion';
|
|
|
36
36
|
import generateStyle from './styles';
|
|
37
37
|
import generateComponentTheme from './theme';
|
|
38
38
|
import { allowedProps, propTypes } from './props';
|
|
39
|
+
|
|
39
40
|
/**
|
|
40
41
|
---
|
|
41
42
|
category: components
|
|
42
43
|
id: NumberInput
|
|
43
44
|
---
|
|
45
|
+
@tsProps
|
|
44
46
|
**/
|
|
45
|
-
|
|
46
47
|
let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class NumberInput extends Component {
|
|
47
48
|
constructor() {
|
|
48
49
|
super(...arguments);
|
|
49
50
|
this.state = {
|
|
50
51
|
hasFocus: false
|
|
51
52
|
};
|
|
52
|
-
this._input = null;
|
|
53
53
|
this.ref = null;
|
|
54
|
+
this._input = null;
|
|
55
|
+
this._id = void 0;
|
|
54
56
|
|
|
55
57
|
this.handleRef = el => {
|
|
56
58
|
this.ref = el;
|
|
@@ -58,36 +60,60 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
58
60
|
|
|
59
61
|
this.handleInputRef = element => {
|
|
60
62
|
this._input = element;
|
|
61
|
-
|
|
63
|
+
|
|
64
|
+
if (typeof this.props.inputRef === 'function') {
|
|
65
|
+
this.props.inputRef(element);
|
|
66
|
+
}
|
|
62
67
|
};
|
|
63
68
|
|
|
64
69
|
this.handleFocus = event => {
|
|
65
70
|
this.setState({
|
|
66
71
|
hasFocus: true
|
|
67
72
|
});
|
|
68
|
-
|
|
73
|
+
|
|
74
|
+
if (typeof this.props.onFocus === 'function') {
|
|
75
|
+
this.props.onFocus(event);
|
|
76
|
+
}
|
|
69
77
|
};
|
|
70
78
|
|
|
71
79
|
this.handleBlur = event => {
|
|
72
80
|
this.setState({
|
|
73
81
|
hasFocus: false
|
|
74
82
|
});
|
|
75
|
-
|
|
83
|
+
|
|
84
|
+
if (typeof this.props.onBlur === 'function') {
|
|
85
|
+
this.props.onBlur(event);
|
|
86
|
+
}
|
|
76
87
|
};
|
|
77
88
|
|
|
78
89
|
this.handleChange = event => {
|
|
79
|
-
this.props.onChange
|
|
90
|
+
if (typeof this.props.onChange === 'function') {
|
|
91
|
+
this.props.onChange(event, event.target.value);
|
|
92
|
+
}
|
|
80
93
|
};
|
|
81
94
|
|
|
82
95
|
this.handleKeyDown = event => {
|
|
83
|
-
this.props
|
|
96
|
+
const _this$props = this.props,
|
|
97
|
+
onKeyDown = _this$props.onKeyDown,
|
|
98
|
+
onDecrement = _this$props.onDecrement,
|
|
99
|
+
onIncrement = _this$props.onIncrement;
|
|
100
|
+
|
|
101
|
+
if (typeof onKeyDown === 'function') {
|
|
102
|
+
onKeyDown(event);
|
|
103
|
+
}
|
|
84
104
|
|
|
85
105
|
if (event.keyCode === keycode.codes.down) {
|
|
86
106
|
event.preventDefault();
|
|
87
|
-
|
|
107
|
+
|
|
108
|
+
if (typeof onDecrement === 'function') {
|
|
109
|
+
onDecrement(event);
|
|
110
|
+
}
|
|
88
111
|
} else if (event.keyCode === keycode.codes.up) {
|
|
89
112
|
event.preventDefault();
|
|
90
|
-
|
|
113
|
+
|
|
114
|
+
if (typeof onIncrement === 'function') {
|
|
115
|
+
onIncrement(event);
|
|
116
|
+
}
|
|
91
117
|
}
|
|
92
118
|
};
|
|
93
119
|
|
|
@@ -123,15 +149,15 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
componentDidMount() {
|
|
126
|
-
var _this$props$makeStyle, _this$
|
|
152
|
+
var _this$props$makeStyle, _this$props2;
|
|
127
153
|
|
|
128
|
-
(_this$props$makeStyle = (_this$
|
|
154
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2, this.makeStyleVariables);
|
|
129
155
|
}
|
|
130
156
|
|
|
131
157
|
componentDidUpdate() {
|
|
132
|
-
var _this$props$makeStyle2, _this$
|
|
158
|
+
var _this$props$makeStyle2, _this$props3;
|
|
133
159
|
|
|
134
|
-
(_this$props$makeStyle2 = (_this$
|
|
160
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3, this.makeStyleVariables);
|
|
135
161
|
}
|
|
136
162
|
|
|
137
163
|
get makeStyleVariables() {
|
|
@@ -147,9 +173,13 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
147
173
|
event.preventDefault();
|
|
148
174
|
|
|
149
175
|
if (interaction === 'enabled') {
|
|
150
|
-
|
|
176
|
+
var _this$_input;
|
|
151
177
|
|
|
152
|
-
|
|
178
|
+
(_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
|
|
179
|
+
|
|
180
|
+
if (typeof callback === 'function') {
|
|
181
|
+
callback(event);
|
|
182
|
+
}
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
185
|
|
|
@@ -162,13 +192,13 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
162
192
|
"aria-hidden": true,
|
|
163
193
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.arrow,
|
|
164
194
|
onMouseDown: this.handleClickUpArrow,
|
|
165
|
-
tabIndex:
|
|
195
|
+
tabIndex: -1,
|
|
166
196
|
type: "button"
|
|
167
197
|
}, _IconArrowOpenUpLine || (_IconArrowOpenUpLine = jsx(IconArrowOpenUpLine, null))), jsx("button", {
|
|
168
198
|
"aria-hidden": true,
|
|
169
199
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.arrow,
|
|
170
200
|
onMouseDown: this.handleClickDownArrow,
|
|
171
|
-
tabIndex:
|
|
201
|
+
tabIndex: -1,
|
|
172
202
|
type: "button"
|
|
173
203
|
}, _IconArrowOpenDownLin || (_IconArrowOpenDownLin = jsx(IconArrowOpenDownLine, null))));
|
|
174
204
|
}
|
|
@@ -176,14 +206,14 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
176
206
|
render() {
|
|
177
207
|
var _this$props$styles4, _this$props$styles5, _this$props$styles6;
|
|
178
208
|
|
|
179
|
-
const _this$
|
|
180
|
-
renderLabel = _this$
|
|
181
|
-
display = _this$
|
|
182
|
-
placeholder = _this$
|
|
183
|
-
isRequired = _this$
|
|
184
|
-
showArrows = _this$
|
|
185
|
-
value = _this$
|
|
186
|
-
width = _this$
|
|
209
|
+
const _this$props4 = this.props,
|
|
210
|
+
renderLabel = _this$props4.renderLabel,
|
|
211
|
+
display = _this$props4.display,
|
|
212
|
+
placeholder = _this$props4.placeholder,
|
|
213
|
+
isRequired = _this$props4.isRequired,
|
|
214
|
+
showArrows = _this$props4.showArrows,
|
|
215
|
+
value = _this$props4.value,
|
|
216
|
+
width = _this$props4.width;
|
|
187
217
|
const interaction = this.interaction;
|
|
188
218
|
return jsx(FormField, Object.assign({}, pickProps(this.props, FormField.allowedProps), {
|
|
189
219
|
label: callRenderProp(renderLabel),
|
|
@@ -217,23 +247,14 @@ let NumberInput = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
217
247
|
}
|
|
218
248
|
|
|
219
249
|
}, _class2.displayName = "NumberInput", _class2.componentId = 'NumberInput', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
220
|
-
id: null,
|
|
221
250
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
222
251
|
interaction: void 0,
|
|
223
252
|
messages: [],
|
|
224
|
-
placeholder: null,
|
|
225
253
|
isRequired: false,
|
|
226
254
|
showArrows: true,
|
|
227
255
|
size: 'medium',
|
|
228
256
|
display: 'block',
|
|
229
257
|
textAlign: 'start',
|
|
230
|
-
inputRef: event => {},
|
|
231
|
-
onFocus: event => {},
|
|
232
|
-
onBlur: event => {},
|
|
233
|
-
onChange: (event, value) => {},
|
|
234
|
-
onDecrement: event => {},
|
|
235
|
-
onIncrement: event => {},
|
|
236
|
-
onKeyDown: event => {},
|
|
237
258
|
inputMode: 'numeric'
|
|
238
259
|
}, _temp)) || _class) || _class);
|
|
239
260
|
export default NumberInput;
|
package/es/NumberInput/props.js
CHANGED
|
@@ -24,115 +24,25 @@
|
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
import { FormPropTypes } from '@instructure/ui-form-field';
|
|
26
26
|
const propTypes = {
|
|
27
|
-
/**
|
|
28
|
-
* The form field label.
|
|
29
|
-
*/
|
|
30
27
|
renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The id of the input. One is generated if not supplied.
|
|
34
|
-
*/
|
|
35
28
|
id: PropTypes.string,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Specifies if interaction with the input is enabled, disabled, or readonly.
|
|
39
|
-
* When "disabled", the input changes visibly to indicate that it cannot
|
|
40
|
-
* receive user interactions. When "readonly" the input still cannot receive
|
|
41
|
-
* user interactions but it keeps the same styles as if it were enabled.
|
|
42
|
-
*/
|
|
43
29
|
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Object with shape: `{
|
|
47
|
-
* text: PropTypes.node,
|
|
48
|
-
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
49
|
-
* }`
|
|
50
|
-
*/
|
|
51
30
|
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Html placeholder text to display when the input has no value. This
|
|
55
|
-
* should be hint text, not a label replacement.
|
|
56
|
-
*/
|
|
57
31
|
placeholder: PropTypes.string,
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Whether or not the text input is required.
|
|
61
|
-
*/
|
|
62
32
|
isRequired: PropTypes.bool,
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Whether or not to display the up/down arrow buttons.
|
|
66
|
-
*/
|
|
67
33
|
showArrows: PropTypes.bool,
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The size of the input.
|
|
71
|
-
*/
|
|
72
34
|
size: PropTypes.oneOf(['medium', 'large']),
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The value of the input (should be accompanied by an `onChange` prop).
|
|
76
|
-
*/
|
|
77
35
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The width of the input.
|
|
81
|
-
*/
|
|
82
36
|
width: PropTypes.string,
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The display of the root element.
|
|
86
|
-
*/
|
|
87
37
|
display: PropTypes.oneOf(['inline-block', 'block']),
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A function that provides a reference to the actual input element.
|
|
91
|
-
*/
|
|
92
38
|
inputRef: PropTypes.func,
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Callback fired when input receives focus.
|
|
96
|
-
*/
|
|
97
39
|
onFocus: PropTypes.func,
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Callback fired when the input loses focus.
|
|
101
|
-
*/
|
|
102
40
|
onBlur: PropTypes.func,
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Callback executed when the input fires a change event.
|
|
106
|
-
* @param {Object} event - the event object
|
|
107
|
-
* @param {Object} value - the string value of the input
|
|
108
|
-
*/
|
|
109
41
|
onChange: PropTypes.func,
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Called when the down arrow button is clicked, or the down arrow key is
|
|
113
|
-
* pressed.
|
|
114
|
-
*/
|
|
115
42
|
onDecrement: PropTypes.func,
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Called when the up arrow button is clicked, or the up arrow key is
|
|
119
|
-
* pressed.
|
|
120
|
-
*/
|
|
121
43
|
onIncrement: PropTypes.func,
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Callback fired when a key is pressed.
|
|
125
|
-
*/
|
|
126
44
|
onKeyDown: PropTypes.func,
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The inputMode attribute of the underlying `input` element can be one of ['numeric', 'decimal', 'tel']
|
|
130
|
-
*/
|
|
131
45
|
inputMode: PropTypes.oneOf(['numeric', 'decimal', 'tel']),
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* The text alignment of the input.
|
|
135
|
-
*/
|
|
136
46
|
textAlign: PropTypes.oneOf(['start', 'center'])
|
|
137
47
|
};
|
|
138
48
|
const allowedProps = ['renderLabel', 'id', 'interaction', 'messages', 'placeholder', 'isRequired', 'showArrows', 'size', 'value', 'width', 'display', 'inputRef', 'onFocus', 'onBlur', 'onChange', 'onDecrement', 'onIncrement', 'onKeyDown', 'inputMode', 'textAlign'];
|
|
@@ -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 NumberInputLocator = (0, _locator.locator)(_index.NumberInput.selector, {
|
|
36
37
|
findInput: function () {
|
|
37
38
|
return (0, _locator.locator)('input').find(...arguments);
|
package/lib/NumberInput/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.NumberInput = void 0;
|
|
9
11
|
|
|
10
|
-
var _react = require("react");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
13
|
|
|
12
14
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
13
15
|
|
|
@@ -44,6 +46,7 @@ var _dec, _dec2, _class, _class2, _temp, _IconArrowOpenUpLine, _IconArrowOpenDow
|
|
|
44
46
|
category: components
|
|
45
47
|
id: NumberInput
|
|
46
48
|
---
|
|
49
|
+
@tsProps
|
|
47
50
|
**/
|
|
48
51
|
let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class NumberInput extends _react.Component {
|
|
49
52
|
constructor() {
|
|
@@ -51,8 +54,9 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
51
54
|
this.state = {
|
|
52
55
|
hasFocus: false
|
|
53
56
|
};
|
|
54
|
-
this._input = null;
|
|
55
57
|
this.ref = null;
|
|
58
|
+
this._input = null;
|
|
59
|
+
this._id = void 0;
|
|
56
60
|
|
|
57
61
|
this.handleRef = el => {
|
|
58
62
|
this.ref = el;
|
|
@@ -60,36 +64,60 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
60
64
|
|
|
61
65
|
this.handleInputRef = element => {
|
|
62
66
|
this._input = element;
|
|
63
|
-
|
|
67
|
+
|
|
68
|
+
if (typeof this.props.inputRef === 'function') {
|
|
69
|
+
this.props.inputRef(element);
|
|
70
|
+
}
|
|
64
71
|
};
|
|
65
72
|
|
|
66
73
|
this.handleFocus = event => {
|
|
67
74
|
this.setState({
|
|
68
75
|
hasFocus: true
|
|
69
76
|
});
|
|
70
|
-
|
|
77
|
+
|
|
78
|
+
if (typeof this.props.onFocus === 'function') {
|
|
79
|
+
this.props.onFocus(event);
|
|
80
|
+
}
|
|
71
81
|
};
|
|
72
82
|
|
|
73
83
|
this.handleBlur = event => {
|
|
74
84
|
this.setState({
|
|
75
85
|
hasFocus: false
|
|
76
86
|
});
|
|
77
|
-
|
|
87
|
+
|
|
88
|
+
if (typeof this.props.onBlur === 'function') {
|
|
89
|
+
this.props.onBlur(event);
|
|
90
|
+
}
|
|
78
91
|
};
|
|
79
92
|
|
|
80
93
|
this.handleChange = event => {
|
|
81
|
-
this.props.onChange
|
|
94
|
+
if (typeof this.props.onChange === 'function') {
|
|
95
|
+
this.props.onChange(event, event.target.value);
|
|
96
|
+
}
|
|
82
97
|
};
|
|
83
98
|
|
|
84
99
|
this.handleKeyDown = event => {
|
|
85
|
-
this.props
|
|
100
|
+
const _this$props = this.props,
|
|
101
|
+
onKeyDown = _this$props.onKeyDown,
|
|
102
|
+
onDecrement = _this$props.onDecrement,
|
|
103
|
+
onIncrement = _this$props.onIncrement;
|
|
104
|
+
|
|
105
|
+
if (typeof onKeyDown === 'function') {
|
|
106
|
+
onKeyDown(event);
|
|
107
|
+
}
|
|
86
108
|
|
|
87
109
|
if (event.keyCode === _keycode.default.codes.down) {
|
|
88
110
|
event.preventDefault();
|
|
89
|
-
|
|
111
|
+
|
|
112
|
+
if (typeof onDecrement === 'function') {
|
|
113
|
+
onDecrement(event);
|
|
114
|
+
}
|
|
90
115
|
} else if (event.keyCode === _keycode.default.codes.up) {
|
|
91
116
|
event.preventDefault();
|
|
92
|
-
|
|
117
|
+
|
|
118
|
+
if (typeof onIncrement === 'function') {
|
|
119
|
+
onIncrement(event);
|
|
120
|
+
}
|
|
93
121
|
}
|
|
94
122
|
};
|
|
95
123
|
|
|
@@ -125,15 +153,15 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
125
153
|
}
|
|
126
154
|
|
|
127
155
|
componentDidMount() {
|
|
128
|
-
var _this$props$makeStyle, _this$
|
|
156
|
+
var _this$props$makeStyle, _this$props2;
|
|
129
157
|
|
|
130
|
-
(_this$props$makeStyle = (_this$
|
|
158
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2, this.makeStyleVariables);
|
|
131
159
|
}
|
|
132
160
|
|
|
133
161
|
componentDidUpdate() {
|
|
134
|
-
var _this$props$makeStyle2, _this$
|
|
162
|
+
var _this$props$makeStyle2, _this$props3;
|
|
135
163
|
|
|
136
|
-
(_this$props$makeStyle2 = (_this$
|
|
164
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3, this.makeStyleVariables);
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
get makeStyleVariables() {
|
|
@@ -149,9 +177,13 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
149
177
|
event.preventDefault();
|
|
150
178
|
|
|
151
179
|
if (interaction === 'enabled') {
|
|
152
|
-
|
|
180
|
+
var _this$_input;
|
|
153
181
|
|
|
154
|
-
|
|
182
|
+
(_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
|
|
183
|
+
|
|
184
|
+
if (typeof callback === 'function') {
|
|
185
|
+
callback(event);
|
|
186
|
+
}
|
|
155
187
|
}
|
|
156
188
|
}
|
|
157
189
|
|
|
@@ -164,13 +196,13 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
164
196
|
"aria-hidden": true,
|
|
165
197
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.arrow,
|
|
166
198
|
onMouseDown: this.handleClickUpArrow,
|
|
167
|
-
tabIndex:
|
|
199
|
+
tabIndex: -1,
|
|
168
200
|
type: "button"
|
|
169
201
|
}, _IconArrowOpenUpLine || (_IconArrowOpenUpLine = (0, _emotion.jsx)(_IconArrowOpenUpLine2.IconArrowOpenUpLine, null))), (0, _emotion.jsx)("button", {
|
|
170
202
|
"aria-hidden": true,
|
|
171
203
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.arrow,
|
|
172
204
|
onMouseDown: this.handleClickDownArrow,
|
|
173
|
-
tabIndex:
|
|
205
|
+
tabIndex: -1,
|
|
174
206
|
type: "button"
|
|
175
207
|
}, _IconArrowOpenDownLin || (_IconArrowOpenDownLin = (0, _emotion.jsx)(_IconArrowOpenDownLine.IconArrowOpenDownLine, null))));
|
|
176
208
|
}
|
|
@@ -178,14 +210,14 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
178
210
|
render() {
|
|
179
211
|
var _this$props$styles4, _this$props$styles5, _this$props$styles6;
|
|
180
212
|
|
|
181
|
-
const _this$
|
|
182
|
-
renderLabel = _this$
|
|
183
|
-
display = _this$
|
|
184
|
-
placeholder = _this$
|
|
185
|
-
isRequired = _this$
|
|
186
|
-
showArrows = _this$
|
|
187
|
-
value = _this$
|
|
188
|
-
width = _this$
|
|
213
|
+
const _this$props4 = this.props,
|
|
214
|
+
renderLabel = _this$props4.renderLabel,
|
|
215
|
+
display = _this$props4.display,
|
|
216
|
+
placeholder = _this$props4.placeholder,
|
|
217
|
+
isRequired = _this$props4.isRequired,
|
|
218
|
+
showArrows = _this$props4.showArrows,
|
|
219
|
+
value = _this$props4.value,
|
|
220
|
+
width = _this$props4.width;
|
|
189
221
|
const interaction = this.interaction;
|
|
190
222
|
return (0, _emotion.jsx)(_FormField.FormField, Object.assign({}, (0, _pickProps.pickProps)(this.props, _FormField.FormField.allowedProps), {
|
|
191
223
|
label: (0, _callRenderProp.callRenderProp)(renderLabel),
|
|
@@ -219,23 +251,14 @@ let NumberInput = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
|
|
|
219
251
|
}
|
|
220
252
|
|
|
221
253
|
}, _class2.displayName = "NumberInput", _class2.componentId = 'NumberInput', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
|
222
|
-
id: null,
|
|
223
254
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
224
255
|
interaction: void 0,
|
|
225
256
|
messages: [],
|
|
226
|
-
placeholder: null,
|
|
227
257
|
isRequired: false,
|
|
228
258
|
showArrows: true,
|
|
229
259
|
size: 'medium',
|
|
230
260
|
display: 'block',
|
|
231
261
|
textAlign: 'start',
|
|
232
|
-
inputRef: event => {},
|
|
233
|
-
onFocus: event => {},
|
|
234
|
-
onBlur: event => {},
|
|
235
|
-
onChange: (event, value) => {},
|
|
236
|
-
onDecrement: event => {},
|
|
237
|
-
onIncrement: event => {},
|
|
238
|
-
onKeyDown: event => {},
|
|
239
262
|
inputMode: 'numeric'
|
|
240
263
|
}, _temp)) || _class) || _class);
|
|
241
264
|
exports.NumberInput = NumberInput;
|
package/lib/NumberInput/props.js
CHANGED
|
@@ -35,115 +35,25 @@ var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
|
|
|
35
35
|
* SOFTWARE.
|
|
36
36
|
*/
|
|
37
37
|
const propTypes = {
|
|
38
|
-
/**
|
|
39
|
-
* The form field label.
|
|
40
|
-
*/
|
|
41
38
|
renderLabel: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The id of the input. One is generated if not supplied.
|
|
45
|
-
*/
|
|
46
39
|
id: _propTypes.default.string,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Specifies if interaction with the input is enabled, disabled, or readonly.
|
|
50
|
-
* When "disabled", the input changes visibly to indicate that it cannot
|
|
51
|
-
* receive user interactions. When "readonly" the input still cannot receive
|
|
52
|
-
* user interactions but it keeps the same styles as if it were enabled.
|
|
53
|
-
*/
|
|
54
40
|
interaction: _propTypes.default.oneOf(['enabled', 'disabled', 'readonly']),
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Object with shape: `{
|
|
58
|
-
* text: PropTypes.node,
|
|
59
|
-
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
60
|
-
* }`
|
|
61
|
-
*/
|
|
62
41
|
messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Html placeholder text to display when the input has no value. This
|
|
66
|
-
* should be hint text, not a label replacement.
|
|
67
|
-
*/
|
|
68
42
|
placeholder: _propTypes.default.string,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Whether or not the text input is required.
|
|
72
|
-
*/
|
|
73
43
|
isRequired: _propTypes.default.bool,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Whether or not to display the up/down arrow buttons.
|
|
77
|
-
*/
|
|
78
44
|
showArrows: _propTypes.default.bool,
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The size of the input.
|
|
82
|
-
*/
|
|
83
45
|
size: _propTypes.default.oneOf(['medium', 'large']),
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The value of the input (should be accompanied by an `onChange` prop).
|
|
87
|
-
*/
|
|
88
46
|
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The width of the input.
|
|
92
|
-
*/
|
|
93
47
|
width: _propTypes.default.string,
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The display of the root element.
|
|
97
|
-
*/
|
|
98
48
|
display: _propTypes.default.oneOf(['inline-block', 'block']),
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* A function that provides a reference to the actual input element.
|
|
102
|
-
*/
|
|
103
49
|
inputRef: _propTypes.default.func,
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Callback fired when input receives focus.
|
|
107
|
-
*/
|
|
108
50
|
onFocus: _propTypes.default.func,
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Callback fired when the input loses focus.
|
|
112
|
-
*/
|
|
113
51
|
onBlur: _propTypes.default.func,
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Callback executed when the input fires a change event.
|
|
117
|
-
* @param {Object} event - the event object
|
|
118
|
-
* @param {Object} value - the string value of the input
|
|
119
|
-
*/
|
|
120
52
|
onChange: _propTypes.default.func,
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Called when the down arrow button is clicked, or the down arrow key is
|
|
124
|
-
* pressed.
|
|
125
|
-
*/
|
|
126
53
|
onDecrement: _propTypes.default.func,
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Called when the up arrow button is clicked, or the up arrow key is
|
|
130
|
-
* pressed.
|
|
131
|
-
*/
|
|
132
54
|
onIncrement: _propTypes.default.func,
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Callback fired when a key is pressed.
|
|
136
|
-
*/
|
|
137
55
|
onKeyDown: _propTypes.default.func,
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The inputMode attribute of the underlying `input` element can be one of ['numeric', 'decimal', 'tel']
|
|
141
|
-
*/
|
|
142
56
|
inputMode: _propTypes.default.oneOf(['numeric', 'decimal', 'tel']),
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The text alignment of the input.
|
|
146
|
-
*/
|
|
147
57
|
textAlign: _propTypes.default.oneOf(['start', 'center'])
|
|
148
58
|
};
|
|
149
59
|
exports.propTypes = propTypes;
|