@instructure/ui-number-input 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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 +5 -2
- package/es/NumberInput/v1/index.js +114 -112
- package/es/NumberInput/v1/styles.js +9 -5
- package/es/NumberInput/v1/theme.js +33 -32
- package/es/NumberInput/v2/index.js +45 -67
- package/es/NumberInput/v2/styles.js +7 -5
- package/lib/NumberInput/v1/index.js +115 -113
- package/lib/NumberInput/v1/styles.js +9 -5
- package/lib/NumberInput/v1/theme.js +33 -32
- package/lib/NumberInput/v2/index.js +46 -67
- package/lib/NumberInput/v2/styles.js +7 -5
- package/package.json +13 -13
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -9,7 +9,7 @@ var _react = require("react");
|
|
|
9
9
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
10
10
|
var _v11_ = require("@instructure/ui-form-field/v11_6");
|
|
11
11
|
var _IconArrowOpenDownLine = require("@instructure/ui-icons/lib/generated/IconArrowOpenDownLine.js");
|
|
12
|
-
var
|
|
12
|
+
var _IconArrowOpenUpLine = require("@instructure/ui-icons/lib/generated/IconArrowOpenUpLine.js");
|
|
13
13
|
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
14
14
|
var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
|
|
15
15
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
@@ -21,7 +21,7 @@ var _styles = _interopRequireDefault(require("./styles"));
|
|
|
21
21
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
22
22
|
var _props = require("./props");
|
|
23
23
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
24
|
-
var _dec, _dec2, _class
|
|
24
|
+
var _dec, _dec2, _class;
|
|
25
25
|
/*
|
|
26
26
|
* The MIT License (MIT)
|
|
27
27
|
*
|
|
@@ -51,72 +51,31 @@ category: components
|
|
|
51
51
|
id: NumberInput
|
|
52
52
|
---
|
|
53
53
|
**/
|
|
54
|
-
let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
this.handleBlur = event => {
|
|
81
|
-
this.setState({
|
|
82
|
-
hasFocus: false
|
|
83
|
-
});
|
|
84
|
-
if (typeof this.props.onBlur === 'function') {
|
|
85
|
-
this.props.onBlur(event);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
this.handleChange = event => {
|
|
89
|
-
if (typeof this.props.onChange === 'function') {
|
|
90
|
-
this.props.onChange(event, event.target.value);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
this.handleKeyDown = event => {
|
|
94
|
-
const _this$props = this.props,
|
|
95
|
-
onKeyDown = _this$props.onKeyDown,
|
|
96
|
-
onDecrement = _this$props.onDecrement,
|
|
97
|
-
onIncrement = _this$props.onIncrement;
|
|
98
|
-
if (typeof onKeyDown === 'function') {
|
|
99
|
-
onKeyDown(event);
|
|
100
|
-
}
|
|
101
|
-
if (event.keyCode === _keycode.default.codes.down) {
|
|
102
|
-
event.preventDefault();
|
|
103
|
-
if (typeof onDecrement === 'function') {
|
|
104
|
-
onDecrement(event);
|
|
105
|
-
}
|
|
106
|
-
} else if (event.keyCode === _keycode.default.codes.up) {
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
if (typeof onIncrement === 'function') {
|
|
109
|
-
onIncrement(event);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
this.handleClickUpArrow = event => {
|
|
114
|
-
this.arrowClicked(event, this.props.onIncrement);
|
|
115
|
-
};
|
|
116
|
-
this.handleClickDownArrow = event => {
|
|
117
|
-
this.arrowClicked(event, this.props.onDecrement);
|
|
118
|
-
};
|
|
119
|
-
}
|
|
54
|
+
let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = class NumberInput extends _react.Component {
|
|
55
|
+
static displayName = "NumberInput";
|
|
56
|
+
static componentId = 'NumberInput';
|
|
57
|
+
static allowedProps = _props.allowedProps;
|
|
58
|
+
static defaultProps = {
|
|
59
|
+
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
60
|
+
interaction: undefined,
|
|
61
|
+
messages: [],
|
|
62
|
+
isRequired: false,
|
|
63
|
+
showArrows: true,
|
|
64
|
+
size: 'medium',
|
|
65
|
+
display: 'block',
|
|
66
|
+
textAlign: 'start',
|
|
67
|
+
inputMode: 'numeric',
|
|
68
|
+
allowStringValue: false
|
|
69
|
+
};
|
|
70
|
+
state = {
|
|
71
|
+
hasFocus: false
|
|
72
|
+
};
|
|
73
|
+
ref = null;
|
|
74
|
+
_input = null;
|
|
75
|
+
_id;
|
|
76
|
+
handleRef = el => {
|
|
77
|
+
this.ref = el;
|
|
78
|
+
};
|
|
120
79
|
get id() {
|
|
121
80
|
if (this.props.id) {
|
|
122
81
|
return this.props.id;
|
|
@@ -135,12 +94,10 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
135
94
|
});
|
|
136
95
|
}
|
|
137
96
|
componentDidMount() {
|
|
138
|
-
|
|
139
|
-
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2, this.makeStyleVariables);
|
|
97
|
+
this.props.makeStyles?.(this.makeStyleVariables);
|
|
140
98
|
}
|
|
141
99
|
componentDidUpdate() {
|
|
142
|
-
|
|
143
|
-
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3, this.makeStyleVariables);
|
|
100
|
+
this.props.makeStyles?.(this.makeStyleVariables);
|
|
144
101
|
}
|
|
145
102
|
get makeStyleVariables() {
|
|
146
103
|
return {
|
|
@@ -149,57 +106,113 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
149
106
|
invalid: this.invalid
|
|
150
107
|
};
|
|
151
108
|
}
|
|
109
|
+
handleInputRef = element => {
|
|
110
|
+
this._input = element;
|
|
111
|
+
if (typeof this.props.inputRef === 'function') {
|
|
112
|
+
this.props.inputRef(element);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
handleFocus = event => {
|
|
116
|
+
this.setState({
|
|
117
|
+
hasFocus: true
|
|
118
|
+
});
|
|
119
|
+
if (typeof this.props.onFocus === 'function') {
|
|
120
|
+
this.props.onFocus(event);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
handleBlur = event => {
|
|
124
|
+
this.setState({
|
|
125
|
+
hasFocus: false
|
|
126
|
+
});
|
|
127
|
+
if (typeof this.props.onBlur === 'function') {
|
|
128
|
+
this.props.onBlur(event);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
handleChange = event => {
|
|
132
|
+
if (typeof this.props.onChange === 'function') {
|
|
133
|
+
this.props.onChange(event, event.target.value);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
handleKeyDown = event => {
|
|
137
|
+
const {
|
|
138
|
+
onKeyDown,
|
|
139
|
+
onDecrement,
|
|
140
|
+
onIncrement
|
|
141
|
+
} = this.props;
|
|
142
|
+
if (typeof onKeyDown === 'function') {
|
|
143
|
+
onKeyDown(event);
|
|
144
|
+
}
|
|
145
|
+
if (event.keyCode === _keycode.default.codes.down) {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
if (typeof onDecrement === 'function') {
|
|
148
|
+
onDecrement(event);
|
|
149
|
+
}
|
|
150
|
+
} else if (event.keyCode === _keycode.default.codes.up) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
if (typeof onIncrement === 'function') {
|
|
153
|
+
onIncrement(event);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
handleClickUpArrow = event => {
|
|
158
|
+
this.arrowClicked(event, this.props.onIncrement);
|
|
159
|
+
};
|
|
160
|
+
handleClickDownArrow = event => {
|
|
161
|
+
this.arrowClicked(event, this.props.onDecrement);
|
|
162
|
+
};
|
|
152
163
|
arrowClicked(event, callback) {
|
|
153
|
-
const
|
|
164
|
+
const {
|
|
165
|
+
interaction
|
|
166
|
+
} = this;
|
|
154
167
|
event.preventDefault();
|
|
155
168
|
if (interaction === 'enabled') {
|
|
156
|
-
|
|
157
|
-
(_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
|
|
169
|
+
this._input?.focus();
|
|
158
170
|
if (typeof callback === 'function') {
|
|
159
171
|
callback(event);
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
174
|
}
|
|
163
175
|
renderArrows(customIcons) {
|
|
164
|
-
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
165
176
|
return (0, _jsxRuntime.jsxs)("span", {
|
|
166
|
-
css:
|
|
177
|
+
css: this.props.styles?.arrowContainer,
|
|
167
178
|
children: [(0, _jsxRuntime.jsx)("button", {
|
|
168
179
|
"aria-hidden": true,
|
|
169
|
-
css:
|
|
180
|
+
css: this.props.styles?.arrow,
|
|
170
181
|
onMouseDown: this.handleClickUpArrow,
|
|
171
182
|
tabIndex: -1,
|
|
172
183
|
type: "button",
|
|
173
|
-
children: customIcons
|
|
184
|
+
children: customIcons?.increase ? (0, _callRenderProp.callRenderProp)(customIcons.increase) : (0, _jsxRuntime.jsx)(_IconArrowOpenUpLine.IconArrowOpenUpLine, {})
|
|
174
185
|
}), (0, _jsxRuntime.jsx)("button", {
|
|
175
186
|
"aria-hidden": true,
|
|
176
|
-
css:
|
|
187
|
+
css: this.props.styles?.arrow,
|
|
177
188
|
onMouseDown: this.handleClickDownArrow,
|
|
178
189
|
tabIndex: -1,
|
|
179
190
|
type: "button",
|
|
180
|
-
children: customIcons
|
|
191
|
+
children: customIcons?.decrease ? (0, _callRenderProp.callRenderProp)(customIcons.decrease) : (0, _jsxRuntime.jsx)(_IconArrowOpenDownLine.IconArrowOpenDownLine, {})
|
|
181
192
|
})]
|
|
182
193
|
});
|
|
183
194
|
}
|
|
184
195
|
render() {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
196
|
+
const {
|
|
197
|
+
renderLabel,
|
|
198
|
+
display,
|
|
199
|
+
placeholder,
|
|
200
|
+
isRequired,
|
|
201
|
+
showArrows,
|
|
202
|
+
value,
|
|
203
|
+
width,
|
|
204
|
+
styles,
|
|
205
|
+
allowStringValue,
|
|
206
|
+
renderIcons,
|
|
207
|
+
margin
|
|
208
|
+
} = this.props;
|
|
209
|
+
const {
|
|
210
|
+
interaction
|
|
211
|
+
} = this;
|
|
199
212
|
const rawLabel = (0, _callRenderProp.callRenderProp)(renderLabel);
|
|
200
213
|
const label = (0, _hasVisibleChildren.hasVisibleChildren)(rawLabel) ? (0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
201
214
|
children: [rawLabel, isRequired && (0, _jsxRuntime.jsxs)("span", {
|
|
202
|
-
css: this.invalid ? styles
|
|
215
|
+
css: this.invalid ? styles?.requiredInvalid : {},
|
|
203
216
|
"aria-hidden": true,
|
|
204
217
|
children: [' ', "*"]
|
|
205
218
|
})]
|
|
@@ -213,16 +226,16 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
213
226
|
margin: margin,
|
|
214
227
|
"data-cid": "NumberInput",
|
|
215
228
|
children: (0, _jsxRuntime.jsx)("span", {
|
|
216
|
-
css:
|
|
229
|
+
css: this.props.styles?.inputWidth,
|
|
217
230
|
style: width ? {
|
|
218
231
|
width
|
|
219
|
-
} :
|
|
232
|
+
} : undefined,
|
|
220
233
|
children: (0, _jsxRuntime.jsxs)("span", {
|
|
221
|
-
css:
|
|
234
|
+
css: this.props.styles?.inputContainer,
|
|
222
235
|
children: [(0, _jsxRuntime.jsx)("input", {
|
|
223
236
|
...(0, _omitProps.omitProps)(this.props, [..._v11_.FormField.allowedProps, ...NumberInput.allowedProps]),
|
|
224
|
-
css:
|
|
225
|
-
"aria-invalid": this.invalid ? 'true' :
|
|
237
|
+
css: this.props.styles?.input,
|
|
238
|
+
"aria-invalid": this.invalid ? 'true' : undefined,
|
|
226
239
|
id: this.id,
|
|
227
240
|
type: allowStringValue ? 'text' : 'number',
|
|
228
241
|
inputMode: this.props.inputMode,
|
|
@@ -241,16 +254,5 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
241
254
|
})
|
|
242
255
|
});
|
|
243
256
|
}
|
|
244
|
-
}
|
|
245
|
-
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
246
|
-
interaction: void 0,
|
|
247
|
-
messages: [],
|
|
248
|
-
isRequired: false,
|
|
249
|
-
showArrows: true,
|
|
250
|
-
size: 'medium',
|
|
251
|
-
display: 'block',
|
|
252
|
-
textAlign: 'start',
|
|
253
|
-
inputMode: 'numeric',
|
|
254
|
-
allowStringValue: false
|
|
255
|
-
}, _NumberInput)) || _class) || _class);
|
|
257
|
+
}) || _class) || _class);
|
|
256
258
|
var _default = exports.default = NumberInput;
|
|
@@ -39,11 +39,15 @@ exports.default = void 0;
|
|
|
39
39
|
* @return {Object} The final style object, which will be used in the component
|
|
40
40
|
*/
|
|
41
41
|
const generateStyle = (componentTheme, props, state) => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const {
|
|
43
|
+
size,
|
|
44
|
+
textAlign
|
|
45
|
+
} = props;
|
|
46
|
+
const {
|
|
47
|
+
interaction,
|
|
48
|
+
hasFocus,
|
|
49
|
+
invalid
|
|
50
|
+
} = state;
|
|
47
51
|
const disabledStyles = interaction === 'disabled' ? {
|
|
48
52
|
cursor: 'not-allowed',
|
|
49
53
|
pointerEvents: 'none',
|
|
@@ -34,13 +34,14 @@ exports.default = void 0;
|
|
|
34
34
|
* @return {Object} The final theme object with the overrides and component variables
|
|
35
35
|
*/
|
|
36
36
|
const generateComponentTheme = theme => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
spacing
|
|
40
|
-
borders
|
|
41
|
-
typography
|
|
42
|
-
forms
|
|
43
|
-
themeName
|
|
37
|
+
const {
|
|
38
|
+
colors,
|
|
39
|
+
spacing,
|
|
40
|
+
borders,
|
|
41
|
+
typography,
|
|
42
|
+
forms,
|
|
43
|
+
key: themeName
|
|
44
|
+
} = theme;
|
|
44
45
|
const themeSpecificStyle = {
|
|
45
46
|
canvas: {
|
|
46
47
|
color: theme['ic-brand-font-color-dark'],
|
|
@@ -49,32 +50,32 @@ const generateComponentTheme = theme => {
|
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
const componentVariables = {
|
|
52
|
-
fontFamily: typography
|
|
53
|
-
fontWeight: typography
|
|
54
|
-
borderWidth: borders
|
|
55
|
-
borderStyle: borders
|
|
56
|
-
borderColor: colors
|
|
57
|
-
borderRadius: borders
|
|
58
|
-
color: colors
|
|
59
|
-
background: colors
|
|
60
|
-
requiredInvalidColor: colors
|
|
61
|
-
padding: `0 ${spacing
|
|
53
|
+
fontFamily: typography?.fontFamily,
|
|
54
|
+
fontWeight: typography?.fontWeightNormal,
|
|
55
|
+
borderWidth: borders?.widthSmall,
|
|
56
|
+
borderStyle: borders?.style,
|
|
57
|
+
borderColor: colors?.contrasts?.grey3045,
|
|
58
|
+
borderRadius: borders?.radiusMedium,
|
|
59
|
+
color: colors?.contrasts?.grey125125,
|
|
60
|
+
background: colors?.contrasts?.white1010,
|
|
61
|
+
requiredInvalidColor: colors?.contrasts?.red5782,
|
|
62
|
+
padding: `0 ${spacing?.small}`,
|
|
62
63
|
arrowsContainerWidth: '2rem',
|
|
63
|
-
arrowsColor: colors
|
|
64
|
-
arrowsBackgroundColor: colors
|
|
65
|
-
arrowsHoverBackgroundColor: colors
|
|
66
|
-
arrowsBorderColor: colors
|
|
67
|
-
arrowsActiveBoxShadow: `inset 0 0 3px 1px ${colors
|
|
68
|
-
focusOutlineWidth: borders
|
|
69
|
-
focusOutlineStyle: borders
|
|
70
|
-
focusOutlineColor: colors
|
|
71
|
-
errorBorderColor: colors
|
|
72
|
-
errorOutlineColor: colors
|
|
73
|
-
placeholderColor: colors
|
|
74
|
-
mediumFontSize: typography
|
|
75
|
-
mediumHeight: forms
|
|
76
|
-
largeFontSize: typography
|
|
77
|
-
largeHeight: forms
|
|
64
|
+
arrowsColor: colors?.contrasts?.grey125125,
|
|
65
|
+
arrowsBackgroundColor: colors?.contrasts?.grey1111,
|
|
66
|
+
arrowsHoverBackgroundColor: colors?.contrasts?.grey1214,
|
|
67
|
+
arrowsBorderColor: colors?.contrasts?.grey3045,
|
|
68
|
+
arrowsActiveBoxShadow: `inset 0 0 3px 1px ${colors?.contrasts?.grey1214}`,
|
|
69
|
+
focusOutlineWidth: borders?.widthMedium,
|
|
70
|
+
focusOutlineStyle: borders?.style,
|
|
71
|
+
focusOutlineColor: colors?.contrasts?.blue4570,
|
|
72
|
+
errorBorderColor: colors?.contrasts?.red4570,
|
|
73
|
+
errorOutlineColor: colors?.contrasts?.red4570,
|
|
74
|
+
placeholderColor: colors?.contrasts?.grey4570,
|
|
75
|
+
mediumFontSize: typography?.fontSizeMedium,
|
|
76
|
+
mediumHeight: forms?.inputHeightMedium,
|
|
77
|
+
largeFontSize: typography?.fontSizeLarge,
|
|
78
|
+
largeHeight: forms?.inputHeightLarge
|
|
78
79
|
};
|
|
79
80
|
return {
|
|
80
81
|
...componentVariables,
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.NumberInput = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
8
|
var _react = require("react");
|
|
11
9
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
12
10
|
var _latest = require("@instructure/ui-form-field/latest");
|
|
@@ -19,7 +17,6 @@ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProp
|
|
|
19
17
|
var _emotion = require("@instructure/emotion");
|
|
20
18
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
21
19
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
22
|
-
const _excluded = ["messages", "isRequired", "showArrows", "size", "display", "textAlign", "inputMode", "allowStringValue", "renderLabel", "placeholder", "value", "width", "renderIcons", "margin", "inputRef", "onFocus", "onBlur", "onChange", "onKeyDown", "onDecrement", "onIncrement", "id", "themeOverride"];
|
|
23
20
|
/*
|
|
24
21
|
* The MIT License (MIT)
|
|
25
22
|
*
|
|
@@ -43,6 +40,7 @@ const _excluded = ["messages", "isRequired", "showArrows", "size", "display", "t
|
|
|
43
40
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
44
41
|
* SOFTWARE.
|
|
45
42
|
*/
|
|
43
|
+
|
|
46
44
|
/**
|
|
47
45
|
---
|
|
48
46
|
category: components
|
|
@@ -50,58 +48,42 @@ id: NumberInput
|
|
|
50
48
|
---
|
|
51
49
|
**/
|
|
52
50
|
const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onChange = props.onChange,
|
|
80
|
-
onKeyDown = props.onKeyDown,
|
|
81
|
-
onDecrement = props.onDecrement,
|
|
82
|
-
onIncrement = props.onIncrement,
|
|
83
|
-
idProp = props.id,
|
|
84
|
-
themeOverride = props.themeOverride,
|
|
85
|
-
rest = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
51
|
+
const {
|
|
52
|
+
messages = [],
|
|
53
|
+
isRequired = false,
|
|
54
|
+
showArrows = true,
|
|
55
|
+
size = 'medium',
|
|
56
|
+
display = 'block',
|
|
57
|
+
textAlign = 'start',
|
|
58
|
+
inputMode = 'numeric',
|
|
59
|
+
allowStringValue = false,
|
|
60
|
+
renderLabel,
|
|
61
|
+
placeholder,
|
|
62
|
+
value,
|
|
63
|
+
width,
|
|
64
|
+
renderIcons,
|
|
65
|
+
margin,
|
|
66
|
+
inputRef: inputRefProp,
|
|
67
|
+
onFocus,
|
|
68
|
+
onBlur,
|
|
69
|
+
onChange,
|
|
70
|
+
onKeyDown,
|
|
71
|
+
onDecrement,
|
|
72
|
+
onIncrement,
|
|
73
|
+
id: idProp,
|
|
74
|
+
themeOverride,
|
|
75
|
+
...rest
|
|
76
|
+
} = props;
|
|
86
77
|
// these are icon tokens
|
|
87
78
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
upButtonState = _useState2[0],
|
|
91
|
-
setUpButtonState = _useState2[1];
|
|
92
|
-
const _useState3 = (0, _react.useState)('actionSecondaryBaseColor'),
|
|
93
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
94
|
-
downButtonState = _useState4[0],
|
|
95
|
-
setDownButtonState = _useState4[1];
|
|
79
|
+
const [upButtonState, setUpButtonState] = (0, _react.useState)('actionSecondaryBaseColor');
|
|
80
|
+
const [downButtonState, setDownButtonState] = (0, _react.useState)('actionSecondaryBaseColor');
|
|
96
81
|
// Refs
|
|
97
82
|
const containerRef = (0, _react.useRef)(null);
|
|
98
83
|
const inputRef = (0, _react.useRef)(null);
|
|
99
84
|
|
|
100
85
|
// Deterministic ID generation
|
|
101
|
-
const
|
|
102
|
-
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
103
|
-
deterministicId = _useState6[0],
|
|
104
|
-
setDeterministicId = _useState6[1];
|
|
86
|
+
const [deterministicId, setDeterministicId] = (0, _react.useState)();
|
|
105
87
|
const getId = (0, _useDeterministicId.useDeterministicId)('NumberInput');
|
|
106
88
|
(0, _react.useEffect)(() => {
|
|
107
89
|
setDeterministicId(getId());
|
|
@@ -182,8 +164,7 @@ const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((p
|
|
|
182
164
|
const arrowClicked = (0, _react.useCallback)((event, callback) => {
|
|
183
165
|
event.preventDefault();
|
|
184
166
|
if (interaction === 'enabled') {
|
|
185
|
-
|
|
186
|
-
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
167
|
+
inputRef.current?.focus();
|
|
187
168
|
if (typeof callback === 'function') {
|
|
188
169
|
callback(event);
|
|
189
170
|
}
|
|
@@ -201,8 +182,7 @@ const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((p
|
|
|
201
182
|
// Expose imperative API via ref
|
|
202
183
|
(0, _react.useImperativeHandle)(ref, () => ({
|
|
203
184
|
focus: () => {
|
|
204
|
-
|
|
205
|
-
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
|
|
185
|
+
inputRef.current?.focus();
|
|
206
186
|
},
|
|
207
187
|
get id() {
|
|
208
188
|
return id;
|
|
@@ -214,8 +194,7 @@ const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((p
|
|
|
214
194
|
return interaction;
|
|
215
195
|
},
|
|
216
196
|
get value() {
|
|
217
|
-
|
|
218
|
-
return (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.value;
|
|
197
|
+
return inputRef.current?.value;
|
|
219
198
|
},
|
|
220
199
|
ref: containerRef
|
|
221
200
|
}), [id, invalid, interaction]);
|
|
@@ -223,31 +202,31 @@ const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((p
|
|
|
223
202
|
// Render methods
|
|
224
203
|
const renderArrows = customIcons => {
|
|
225
204
|
return (0, _jsxRuntime.jsxs)("span", {
|
|
226
|
-
css: styles
|
|
205
|
+
css: styles?.arrowContainer,
|
|
227
206
|
children: [(0, _jsxRuntime.jsx)("button", {
|
|
228
207
|
"aria-hidden": true,
|
|
229
|
-
css: styles
|
|
208
|
+
css: styles?.arrow,
|
|
230
209
|
onMouseDown: handleClickUpArrow,
|
|
231
210
|
onMouseOver: () => setUpButtonState('actionSecondaryHoverColor'),
|
|
232
211
|
onMouseOut: () => setUpButtonState('actionSecondaryBaseColor'),
|
|
233
212
|
tabIndex: -1,
|
|
234
213
|
type: "button",
|
|
235
|
-
children: customIcons
|
|
214
|
+
children: customIcons?.increase ? (0, _callRenderProp.callRenderProp)(customIcons.increase) : (0, _jsxRuntime.jsx)(_uiIcons.ChevronUpInstUIIcon, {
|
|
236
215
|
size: "sm",
|
|
237
216
|
color: upButtonState
|
|
238
|
-
})
|
|
217
|
+
})
|
|
239
218
|
}), (0, _jsxRuntime.jsx)("button", {
|
|
240
219
|
"aria-hidden": true,
|
|
241
|
-
css: styles
|
|
220
|
+
css: styles?.arrow,
|
|
242
221
|
onMouseDown: handleClickDownArrow,
|
|
243
222
|
onMouseOver: () => setDownButtonState('actionSecondaryHoverColor'),
|
|
244
223
|
onMouseOut: () => setDownButtonState('actionSecondaryBaseColor'),
|
|
245
224
|
tabIndex: -1,
|
|
246
225
|
type: "button",
|
|
247
|
-
children: customIcons
|
|
226
|
+
children: customIcons?.decrease ? (0, _callRenderProp.callRenderProp)(customIcons.decrease) : (0, _jsxRuntime.jsx)(_uiIcons.ChevronDownInstUIIcon, {
|
|
248
227
|
size: "sm",
|
|
249
228
|
color: downButtonState
|
|
250
|
-
})
|
|
229
|
+
})
|
|
251
230
|
})]
|
|
252
231
|
});
|
|
253
232
|
};
|
|
@@ -270,20 +249,20 @@ const NumberInput = exports.NumberInput = /*#__PURE__*/(0, _react.forwardRef)((p
|
|
|
270
249
|
readOnly: interaction === 'readonly',
|
|
271
250
|
"data-cid": "NumberInput",
|
|
272
251
|
children: (0, _jsxRuntime.jsx)("span", {
|
|
273
|
-
css: styles
|
|
252
|
+
css: styles?.inputWidth,
|
|
274
253
|
style: width ? {
|
|
275
254
|
width
|
|
276
|
-
} :
|
|
255
|
+
} : undefined,
|
|
277
256
|
children: (0, _jsxRuntime.jsxs)("span", {
|
|
278
|
-
css: styles
|
|
257
|
+
css: styles?.inputContainer,
|
|
279
258
|
children: [(0, _jsxRuntime.jsx)("input", {
|
|
280
259
|
...passedProps,
|
|
281
|
-
css: styles
|
|
282
|
-
"aria-invalid": invalid ? 'true' :
|
|
260
|
+
css: styles?.input,
|
|
261
|
+
"aria-invalid": invalid ? 'true' : undefined,
|
|
283
262
|
id: id,
|
|
284
263
|
type: allowStringValue ? 'text' : 'number',
|
|
285
264
|
inputMode: inputMode,
|
|
286
|
-
placeholder: interaction === 'enabled' ? placeholder :
|
|
265
|
+
placeholder: interaction === 'enabled' ? placeholder : undefined,
|
|
287
266
|
ref: handleInputRef,
|
|
288
267
|
required: isRequired,
|
|
289
268
|
value: value,
|
|
@@ -40,11 +40,13 @@ var _emotion = require("@instructure/emotion");
|
|
|
40
40
|
* @return The final style object, which will be used in the component
|
|
41
41
|
*/
|
|
42
42
|
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const {
|
|
44
|
+
size,
|
|
45
|
+
textAlign,
|
|
46
|
+
interaction,
|
|
47
|
+
success,
|
|
48
|
+
invalid
|
|
49
|
+
} = params;
|
|
48
50
|
const containerInteractionStates = {
|
|
49
51
|
...(interaction === 'enabled' && {
|
|
50
52
|
backgroundColor: componentTheme.backgroundColor,
|