@instructure/ui-number-input 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -299
- package/es/NumberInput/{index.js → v1/index.js} +2 -2
- package/es/NumberInput/v2/index.js +292 -0
- package/es/NumberInput/v2/props.js +26 -0
- package/es/NumberInput/v2/styles.js +208 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/NumberInput/{index.js → v1/index.js} +7 -7
- package/lib/NumberInput/v2/index.js +301 -0
- package/lib/NumberInput/v2/props.js +31 -0
- package/lib/NumberInput/v2/styles.js +214 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +41 -19
- package/src/NumberInput/{index.tsx → v1/index.tsx} +2 -2
- package/src/NumberInput/{props.ts → v1/props.ts} +4 -1
- package/src/NumberInput/v2/README.md +205 -0
- package/src/NumberInput/v2/index.tsx +382 -0
- package/src/NumberInput/v2/props.ts +240 -0
- package/src/NumberInput/v2/styles.ts +219 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/NumberInput/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/NumberInput/v1/index.d.ts.map +1 -0
- package/types/NumberInput/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/NumberInput/v1/props.d.ts.map +1 -0
- package/types/NumberInput/v1/styles.d.ts.map +1 -0
- package/types/NumberInput/v1/theme.d.ts.map +1 -0
- package/types/NumberInput/v2/index.d.ts +104 -0
- package/types/NumberInput/v2/index.d.ts.map +1 -0
- package/types/NumberInput/v2/props.d.ts +127 -0
- package/types/NumberInput/v2/props.d.ts.map +1 -0
- package/types/NumberInput/v2/styles.d.ts +22 -0
- package/types/NumberInput/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/NumberInput/index.d.ts.map +0 -1
- package/types/NumberInput/props.d.ts.map +0 -1
- package/types/NumberInput/styles.d.ts.map +0 -1
- package/types/NumberInput/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/NumberInput/{props.js → v1/props.js} +0 -0
- /package/es/NumberInput/{styles.js → v1/styles.js} +0 -0
- /package/es/NumberInput/{theme.js → v1/theme.js} +0 -0
- /package/lib/NumberInput/{props.js → v1/props.js} +0 -0
- /package/lib/NumberInput/{styles.js → v1/styles.js} +0 -0
- /package/lib/NumberInput/{theme.js → v1/theme.js} +0 -0
- /package/src/NumberInput/{README.md → v1/README.md} +0 -0
- /package/src/NumberInput/{styles.ts → v1/styles.ts} +0 -0
- /package/src/NumberInput/{theme.ts → v1/theme.ts} +0 -0
- /package/types/NumberInput/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/NumberInput/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
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"];
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useState, useRef, useCallback, useImperativeHandle, forwardRef, useEffect } from 'react';
|
|
29
|
+
import keycode from 'keycode';
|
|
30
|
+
import { FormField } from '@instructure/ui-form-field/latest';
|
|
31
|
+
import { ChevronUpInstUIIcon, ChevronDownInstUIIcon } from '@instructure/ui-icons';
|
|
32
|
+
import { pickProps, callRenderProp, getInteraction, useDeterministicId, passthroughProps } from '@instructure/ui-react-utils';
|
|
33
|
+
import { useStyle } from '@instructure/emotion';
|
|
34
|
+
import generateStyle from "./styles.js";
|
|
35
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
36
|
+
/**
|
|
37
|
+
---
|
|
38
|
+
category: components
|
|
39
|
+
id: NumberInput
|
|
40
|
+
---
|
|
41
|
+
**/
|
|
42
|
+
const NumberInput = /*#__PURE__*/forwardRef((props, ref) => {
|
|
43
|
+
var _ChevronUpInstUIIcon, _ChevronDownInstUIIco;
|
|
44
|
+
const _props$messages = props.messages,
|
|
45
|
+
messages = _props$messages === void 0 ? [] : _props$messages,
|
|
46
|
+
_props$isRequired = props.isRequired,
|
|
47
|
+
isRequired = _props$isRequired === void 0 ? false : _props$isRequired,
|
|
48
|
+
_props$showArrows = props.showArrows,
|
|
49
|
+
showArrows = _props$showArrows === void 0 ? true : _props$showArrows,
|
|
50
|
+
_props$size = props.size,
|
|
51
|
+
size = _props$size === void 0 ? 'medium' : _props$size,
|
|
52
|
+
_props$display = props.display,
|
|
53
|
+
display = _props$display === void 0 ? 'block' : _props$display,
|
|
54
|
+
_props$textAlign = props.textAlign,
|
|
55
|
+
textAlign = _props$textAlign === void 0 ? 'start' : _props$textAlign,
|
|
56
|
+
_props$inputMode = props.inputMode,
|
|
57
|
+
inputMode = _props$inputMode === void 0 ? 'numeric' : _props$inputMode,
|
|
58
|
+
_props$allowStringVal = props.allowStringValue,
|
|
59
|
+
allowStringValue = _props$allowStringVal === void 0 ? false : _props$allowStringVal,
|
|
60
|
+
renderLabel = props.renderLabel,
|
|
61
|
+
placeholder = props.placeholder,
|
|
62
|
+
value = props.value,
|
|
63
|
+
width = props.width,
|
|
64
|
+
renderIcons = props.renderIcons,
|
|
65
|
+
margin = props.margin,
|
|
66
|
+
inputRefProp = props.inputRef,
|
|
67
|
+
onFocus = props.onFocus,
|
|
68
|
+
onBlur = props.onBlur,
|
|
69
|
+
onChange = props.onChange,
|
|
70
|
+
onKeyDown = props.onKeyDown,
|
|
71
|
+
onDecrement = props.onDecrement,
|
|
72
|
+
onIncrement = props.onIncrement,
|
|
73
|
+
idProp = props.id,
|
|
74
|
+
themeOverride = props.themeOverride,
|
|
75
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
76
|
+
// these are icon tokens
|
|
77
|
+
|
|
78
|
+
const _useState = useState('actionSecondaryBaseColor'),
|
|
79
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
80
|
+
upButtonState = _useState2[0],
|
|
81
|
+
setUpButtonState = _useState2[1];
|
|
82
|
+
const _useState3 = useState('actionSecondaryBaseColor'),
|
|
83
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
84
|
+
downButtonState = _useState4[0],
|
|
85
|
+
setDownButtonState = _useState4[1];
|
|
86
|
+
// Refs
|
|
87
|
+
const containerRef = useRef(null);
|
|
88
|
+
const inputRef = useRef(null);
|
|
89
|
+
|
|
90
|
+
// Deterministic ID generation
|
|
91
|
+
const _useState5 = useState(),
|
|
92
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
93
|
+
deterministicId = _useState6[0],
|
|
94
|
+
setDeterministicId = _useState6[1];
|
|
95
|
+
const getId = useDeterministicId('NumberInput');
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
setDeterministicId(getId());
|
|
98
|
+
}, []); // Empty deps array - only run once on mount
|
|
99
|
+
const id = idProp || deterministicId;
|
|
100
|
+
|
|
101
|
+
// Computed values
|
|
102
|
+
const invalid = !!messages && messages.some(message => message.type === 'error' || message.type === 'newError');
|
|
103
|
+
const success = !!messages && messages.some(message => message.type === 'success');
|
|
104
|
+
const interaction = getInteraction({
|
|
105
|
+
props
|
|
106
|
+
});
|
|
107
|
+
if (interaction === 'disabled' && upButtonState !== 'actionSecondaryDisabledColor') {
|
|
108
|
+
setUpButtonState('actionSecondaryDisabledColor');
|
|
109
|
+
setDownButtonState('actionSecondaryDisabledColor');
|
|
110
|
+
} else if (interaction === 'enabled' && downButtonState !== 'actionSecondaryBaseColor') {
|
|
111
|
+
setUpButtonState('actionSecondaryBaseColor');
|
|
112
|
+
setDownButtonState('actionSecondaryBaseColor');
|
|
113
|
+
}
|
|
114
|
+
// Styles - useStyle will pass these to generateStyle(componentTheme, params as props, params as state)
|
|
115
|
+
// We need to provide all values that generateStyle needs from both props and state
|
|
116
|
+
const styles = useStyle({
|
|
117
|
+
generateStyle,
|
|
118
|
+
themeOverride,
|
|
119
|
+
params: {
|
|
120
|
+
size,
|
|
121
|
+
textAlign,
|
|
122
|
+
interaction,
|
|
123
|
+
invalid,
|
|
124
|
+
success
|
|
125
|
+
},
|
|
126
|
+
componentId: 'NumberInput',
|
|
127
|
+
displayName: 'NumberInput',
|
|
128
|
+
useTokensFrom: 'TextInput'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Event handlers
|
|
132
|
+
const handleInputRef = useCallback(element => {
|
|
133
|
+
inputRef.current = element;
|
|
134
|
+
if (typeof inputRefProp === 'function') {
|
|
135
|
+
inputRefProp(element);
|
|
136
|
+
}
|
|
137
|
+
}, [inputRefProp]);
|
|
138
|
+
const handleRef = useCallback(el => {
|
|
139
|
+
containerRef.current = el;
|
|
140
|
+
}, []);
|
|
141
|
+
const handleFocus = useCallback(event => {
|
|
142
|
+
if (typeof onFocus === 'function') {
|
|
143
|
+
onFocus(event);
|
|
144
|
+
}
|
|
145
|
+
}, [onFocus]);
|
|
146
|
+
const handleBlur = useCallback(event => {
|
|
147
|
+
if (typeof onBlur === 'function') {
|
|
148
|
+
onBlur(event);
|
|
149
|
+
}
|
|
150
|
+
}, [onBlur]);
|
|
151
|
+
const handleChange = useCallback(event => {
|
|
152
|
+
if (typeof onChange === 'function') {
|
|
153
|
+
onChange(event, event.target.value);
|
|
154
|
+
}
|
|
155
|
+
}, [onChange]);
|
|
156
|
+
const handleKeyDown = useCallback(event => {
|
|
157
|
+
if (typeof onKeyDown === 'function') {
|
|
158
|
+
onKeyDown(event);
|
|
159
|
+
}
|
|
160
|
+
if (event.keyCode === keycode.codes.down) {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
if (typeof onDecrement === 'function') {
|
|
163
|
+
onDecrement(event);
|
|
164
|
+
}
|
|
165
|
+
} else if (event.keyCode === keycode.codes.up) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
if (typeof onIncrement === 'function') {
|
|
168
|
+
onIncrement(event);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, [onKeyDown, onDecrement, onIncrement]);
|
|
172
|
+
const arrowClicked = useCallback((event, callback) => {
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
if (interaction === 'enabled') {
|
|
175
|
+
var _inputRef$current;
|
|
176
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
177
|
+
if (typeof callback === 'function') {
|
|
178
|
+
callback(event);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}, [interaction]);
|
|
182
|
+
const handleClickUpArrow = useCallback(event => {
|
|
183
|
+
setUpButtonState('actionSecondaryActiveColor');
|
|
184
|
+
arrowClicked(event, onIncrement);
|
|
185
|
+
}, [arrowClicked, onIncrement]);
|
|
186
|
+
const handleClickDownArrow = useCallback(event => {
|
|
187
|
+
setDownButtonState('actionSecondaryActiveColor');
|
|
188
|
+
arrowClicked(event, onDecrement);
|
|
189
|
+
}, [arrowClicked, onDecrement]);
|
|
190
|
+
|
|
191
|
+
// Expose imperative API via ref
|
|
192
|
+
useImperativeHandle(ref, () => ({
|
|
193
|
+
focus: () => {
|
|
194
|
+
var _inputRef$current2;
|
|
195
|
+
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
|
|
196
|
+
},
|
|
197
|
+
get id() {
|
|
198
|
+
return id;
|
|
199
|
+
},
|
|
200
|
+
get invalid() {
|
|
201
|
+
return invalid;
|
|
202
|
+
},
|
|
203
|
+
get interaction() {
|
|
204
|
+
return interaction;
|
|
205
|
+
},
|
|
206
|
+
get value() {
|
|
207
|
+
var _inputRef$current3;
|
|
208
|
+
return (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.value;
|
|
209
|
+
}
|
|
210
|
+
}), [id, invalid, interaction]);
|
|
211
|
+
|
|
212
|
+
// Render methods
|
|
213
|
+
const renderArrows = customIcons => {
|
|
214
|
+
return _jsxs("span", {
|
|
215
|
+
css: styles === null || styles === void 0 ? void 0 : styles.arrowContainer,
|
|
216
|
+
children: [_jsx("button", {
|
|
217
|
+
"aria-hidden": true,
|
|
218
|
+
css: styles === null || styles === void 0 ? void 0 : styles.arrow,
|
|
219
|
+
onMouseDown: handleClickUpArrow,
|
|
220
|
+
onMouseOver: () => setUpButtonState('actionSecondaryHoverColor'),
|
|
221
|
+
onMouseOut: () => setUpButtonState('actionSecondaryBaseColor'),
|
|
222
|
+
tabIndex: -1,
|
|
223
|
+
type: "button",
|
|
224
|
+
children: customIcons !== null && customIcons !== void 0 && customIcons.increase ? callRenderProp(customIcons.increase) : _ChevronUpInstUIIcon || (_ChevronUpInstUIIcon = _jsx(ChevronUpInstUIIcon, {
|
|
225
|
+
size: "sm",
|
|
226
|
+
color: upButtonState
|
|
227
|
+
}))
|
|
228
|
+
}), _jsx("button", {
|
|
229
|
+
"aria-hidden": true,
|
|
230
|
+
css: styles === null || styles === void 0 ? void 0 : styles.arrow,
|
|
231
|
+
onMouseDown: handleClickDownArrow,
|
|
232
|
+
onMouseOver: () => setDownButtonState('actionSecondaryHoverColor'),
|
|
233
|
+
onMouseOut: () => setDownButtonState('actionSecondaryBaseColor'),
|
|
234
|
+
tabIndex: -1,
|
|
235
|
+
type: "button",
|
|
236
|
+
children: customIcons !== null && customIcons !== void 0 && customIcons.decrease ? callRenderProp(customIcons.decrease) : _ChevronDownInstUIIco || (_ChevronDownInstUIIco = _jsx(ChevronDownInstUIIcon, {
|
|
237
|
+
size: "sm",
|
|
238
|
+
color: downButtonState
|
|
239
|
+
}))
|
|
240
|
+
})]
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
const label = callRenderProp(renderLabel);
|
|
244
|
+
const passedProps = passthroughProps(rest);
|
|
245
|
+
|
|
246
|
+
// Don't render until we have an ID
|
|
247
|
+
if (!id) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return _jsx(FormField, {
|
|
251
|
+
...pickProps(props, FormField.allowedProps),
|
|
252
|
+
label: label,
|
|
253
|
+
inline: display === 'inline-block',
|
|
254
|
+
id: id,
|
|
255
|
+
elementRef: handleRef,
|
|
256
|
+
margin: margin,
|
|
257
|
+
isRequired: isRequired,
|
|
258
|
+
disabled: interaction === 'disabled',
|
|
259
|
+
readOnly: interaction === 'readonly',
|
|
260
|
+
"data-cid": "NumberInput",
|
|
261
|
+
children: _jsx("span", {
|
|
262
|
+
css: styles === null || styles === void 0 ? void 0 : styles.inputWidth,
|
|
263
|
+
style: width ? {
|
|
264
|
+
width
|
|
265
|
+
} : void 0,
|
|
266
|
+
children: _jsxs("span", {
|
|
267
|
+
css: styles === null || styles === void 0 ? void 0 : styles.inputContainer,
|
|
268
|
+
children: [_jsx("input", {
|
|
269
|
+
...passedProps,
|
|
270
|
+
css: styles === null || styles === void 0 ? void 0 : styles.input,
|
|
271
|
+
"aria-invalid": invalid ? 'true' : void 0,
|
|
272
|
+
id: id,
|
|
273
|
+
type: allowStringValue ? 'text' : 'number',
|
|
274
|
+
inputMode: inputMode,
|
|
275
|
+
placeholder: interaction === 'enabled' ? placeholder : void 0,
|
|
276
|
+
ref: handleInputRef,
|
|
277
|
+
required: isRequired,
|
|
278
|
+
value: value,
|
|
279
|
+
disabled: interaction === 'disabled',
|
|
280
|
+
readOnly: interaction === 'readonly',
|
|
281
|
+
onFocus: handleFocus,
|
|
282
|
+
onBlur: handleBlur,
|
|
283
|
+
onChange: handleChange,
|
|
284
|
+
onKeyDown: handleKeyDown
|
|
285
|
+
}), showArrows && interaction !== 'readonly' ? renderArrows(renderIcons) : null]
|
|
286
|
+
})
|
|
287
|
+
})
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
NumberInput.displayName = 'NumberInput';
|
|
291
|
+
export default NumberInput;
|
|
292
|
+
export { NumberInput };
|
|
@@ -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 = ['renderLabel', 'id', 'interaction', 'messages', 'placeholder', 'isRequired', 'showArrows', 'size', 'value', 'width', 'display', 'inputRef', 'onFocus', 'onBlur', 'onChange', 'onDecrement', 'onIncrement', 'onKeyDown', 'inputMode', 'textAlign', 'allowStringValue', 'renderIcons', 'margin'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,208 @@
|
|
|
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 { calcFocusOutlineStyles } from '@instructure/emotion';
|
|
26
|
+
/**
|
|
27
|
+
* ---
|
|
28
|
+
* private: true
|
|
29
|
+
* ---
|
|
30
|
+
* Generates the style object from the theme and provided additional information
|
|
31
|
+
* @param componentTheme The theme variable object.
|
|
32
|
+
* @param params Additional parameters to customize the style.
|
|
33
|
+
* @param sharedTokens Shared token object that stores common values for the theme.
|
|
34
|
+
* @return The final style object, which will be used in the component
|
|
35
|
+
*/
|
|
36
|
+
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
37
|
+
const size = params.size,
|
|
38
|
+
textAlign = params.textAlign,
|
|
39
|
+
interaction = params.interaction,
|
|
40
|
+
success = params.success,
|
|
41
|
+
invalid = params.invalid;
|
|
42
|
+
const containerInteractionStates = {
|
|
43
|
+
...(interaction === 'enabled' && {
|
|
44
|
+
backgroundColor: componentTheme.backgroundColor,
|
|
45
|
+
borderColor: componentTheme.borderColor,
|
|
46
|
+
...(success && {
|
|
47
|
+
borderColor: componentTheme.successBorderColor
|
|
48
|
+
}),
|
|
49
|
+
...(invalid && {
|
|
50
|
+
borderColor: componentTheme.errorBorderColor
|
|
51
|
+
}),
|
|
52
|
+
'&:hover': {
|
|
53
|
+
backgroundColor: componentTheme.backgroundHoverColor,
|
|
54
|
+
borderColor: componentTheme.borderHoverColor,
|
|
55
|
+
...(success && {
|
|
56
|
+
borderColor: componentTheme.successBorderColor
|
|
57
|
+
}),
|
|
58
|
+
...(invalid && {
|
|
59
|
+
borderColor: componentTheme.errorBorderColor
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
...(interaction === 'readonly' && {
|
|
64
|
+
backgroundColor: componentTheme.backgroundReadonlyColor,
|
|
65
|
+
borderColor: componentTheme.borderReadonlyColor
|
|
66
|
+
}),
|
|
67
|
+
...(interaction === 'disabled' && {
|
|
68
|
+
cursor: 'not-allowed',
|
|
69
|
+
pointerEvents: 'none',
|
|
70
|
+
backgroundColor: componentTheme.backgroundDisabledColor,
|
|
71
|
+
borderColor: componentTheme.borderDisabledColor
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
const arrowInteractionStates = {
|
|
75
|
+
...(interaction === 'enabled' && {
|
|
76
|
+
backgroundColor: componentTheme.arrowsBackgroundColor,
|
|
77
|
+
borderColor: componentTheme.arrowsBorderColor,
|
|
78
|
+
'&:hover': {
|
|
79
|
+
backgroundColor: componentTheme.arrowsBackgroundHoverColor,
|
|
80
|
+
borderColor: componentTheme.arrowsBorderHoverColor
|
|
81
|
+
},
|
|
82
|
+
'&:active': {
|
|
83
|
+
backgroundColor: componentTheme.arrowsBackgroundActiveColor,
|
|
84
|
+
borderColor: componentTheme.arrowsBorderActiveColor
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
...(interaction === 'disabled' && {
|
|
88
|
+
cursor: 'not-allowed',
|
|
89
|
+
pointerEvents: 'none',
|
|
90
|
+
backgroundColor: componentTheme.arrowsBackgroundDisabledColor,
|
|
91
|
+
borderColor: componentTheme.arrowsBorderDisabledColor
|
|
92
|
+
})
|
|
93
|
+
// arrow buttons are not rendered in the `readOnly` state
|
|
94
|
+
};
|
|
95
|
+
const inputInteractionStates = {
|
|
96
|
+
...(interaction === 'enabled' && {
|
|
97
|
+
color: componentTheme.textColor,
|
|
98
|
+
'&::placeholder': {
|
|
99
|
+
color: componentTheme.placeholderColor
|
|
100
|
+
},
|
|
101
|
+
'&:hover::placeholder': {
|
|
102
|
+
color: componentTheme.placeholderHoverColor
|
|
103
|
+
}
|
|
104
|
+
// placeholder is not rendered in the `readOnly` and `disabled` state
|
|
105
|
+
}),
|
|
106
|
+
...(interaction === 'readonly' && {
|
|
107
|
+
color: componentTheme.textReadonlyColor
|
|
108
|
+
}),
|
|
109
|
+
...(interaction === 'disabled' && {
|
|
110
|
+
color: componentTheme.textDisabledColor
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
const inputStyle = {
|
|
114
|
+
all: 'initial',
|
|
115
|
+
textAlign: textAlign,
|
|
116
|
+
direction: 'inherit',
|
|
117
|
+
WebkitFontSmoothing: 'antialiased',
|
|
118
|
+
MozOsxFontSmoothing: 'grayscale',
|
|
119
|
+
appearance: 'none',
|
|
120
|
+
lineHeight: 1,
|
|
121
|
+
margin: '0',
|
|
122
|
+
flex: 1,
|
|
123
|
+
minWidth: '0.0625rem',
|
|
124
|
+
boxSizing: 'border-box',
|
|
125
|
+
fontFamily: 'inherit',
|
|
126
|
+
fontSize: 'inherit',
|
|
127
|
+
fontWeight: 'inherit',
|
|
128
|
+
...(size === 'medium' ? {
|
|
129
|
+
padding: componentTheme.paddingHorizontalMd
|
|
130
|
+
} : {
|
|
131
|
+
padding: componentTheme.paddingHorizontalLg
|
|
132
|
+
}),
|
|
133
|
+
...inputInteractionStates
|
|
134
|
+
};
|
|
135
|
+
const focusOutline = calcFocusOutlineStyles(sharedTokens.focusOutline, {
|
|
136
|
+
focusWithin: true
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
numberInput: {
|
|
140
|
+
label: 'numberInput'
|
|
141
|
+
},
|
|
142
|
+
arrowContainer: {
|
|
143
|
+
label: 'numberInput_arrowContainer',
|
|
144
|
+
flex: `0 0 ${componentTheme.arrowsContainerWidth}`,
|
|
145
|
+
display: 'flex',
|
|
146
|
+
flexDirection: 'column'
|
|
147
|
+
},
|
|
148
|
+
arrow: {
|
|
149
|
+
label: 'numberInput_arrow',
|
|
150
|
+
cursor: 'pointer',
|
|
151
|
+
userSelect: 'none',
|
|
152
|
+
textAlign: 'center',
|
|
153
|
+
flex: 1,
|
|
154
|
+
display: 'flex',
|
|
155
|
+
justifyContent: 'center',
|
|
156
|
+
alignItems: 'center',
|
|
157
|
+
borderTop: 'none',
|
|
158
|
+
borderInlineEnd: 'none',
|
|
159
|
+
borderInlineStart: `${componentTheme.borderWidth} solid`,
|
|
160
|
+
borderBottom: `${componentTheme.borderWidth} solid`,
|
|
161
|
+
'&:last-child': {
|
|
162
|
+
borderBottom: 'none'
|
|
163
|
+
},
|
|
164
|
+
...arrowInteractionStates
|
|
165
|
+
},
|
|
166
|
+
inputWidth: {
|
|
167
|
+
label: 'numberInput_inputWidth',
|
|
168
|
+
display: 'block',
|
|
169
|
+
position: 'relative'
|
|
170
|
+
},
|
|
171
|
+
inputContainer: {
|
|
172
|
+
label: 'numberInput_inputContainer',
|
|
173
|
+
display: 'flex',
|
|
174
|
+
margin: '0',
|
|
175
|
+
boxSizing: 'border-box',
|
|
176
|
+
overflow: 'hidden',
|
|
177
|
+
fontFamily: componentTheme.fontFamily,
|
|
178
|
+
fontWeight: componentTheme.fontWeight,
|
|
179
|
+
border: `${componentTheme.borderWidth} solid`,
|
|
180
|
+
borderRadius: componentTheme.borderRadius,
|
|
181
|
+
...containerInteractionStates,
|
|
182
|
+
...focusOutline,
|
|
183
|
+
...(size === 'medium' ? {
|
|
184
|
+
fontSize: componentTheme.fontSizeMd,
|
|
185
|
+
height: componentTheme.heightMd
|
|
186
|
+
} : {
|
|
187
|
+
fontSize: componentTheme.fontSizeLg,
|
|
188
|
+
height: componentTheme.heightLg
|
|
189
|
+
})
|
|
190
|
+
},
|
|
191
|
+
input: {
|
|
192
|
+
label: 'numberInput_input',
|
|
193
|
+
...inputStyle,
|
|
194
|
+
'&:is(input)[type]': inputStyle,
|
|
195
|
+
'&:-webkit-any(input)[type]': inputStyle,
|
|
196
|
+
'&::-webkit-inner-spin-button': {
|
|
197
|
+
display: 'none'
|
|
198
|
+
},
|
|
199
|
+
'&::-webkit-outer-spin-button': {
|
|
200
|
+
display: 'none'
|
|
201
|
+
},
|
|
202
|
+
'&:is(input)[type="number"]': {
|
|
203
|
+
MozAppearance: 'textfield'
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
export default generateStyle;
|
|
@@ -21,5 +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 { NumberInput } from
|
|
25
|
-
export type { NumberInputProps } from './NumberInput/props'
|
|
24
|
+
export { NumberInput } from "../NumberInput/v2/index.js";
|
|
@@ -7,9 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.NumberInput = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
10
|
-
var
|
|
11
|
-
var _IconArrowOpenDownLine = require("@instructure/ui-icons/lib/IconArrowOpenDownLine.js");
|
|
12
|
-
var _IconArrowOpenUpLine2 = require("@instructure/ui-icons/lib/IconArrowOpenUpLine.js");
|
|
10
|
+
var _v11_ = require("@instructure/ui-form-field/v11_6");
|
|
11
|
+
var _IconArrowOpenDownLine = require("@instructure/ui-icons/lib/generated/IconArrowOpenDownLine.js");
|
|
12
|
+
var _IconArrowOpenUpLine2 = 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");
|
|
@@ -51,7 +51,7 @@ category: components
|
|
|
51
51
|
id: NumberInput
|
|
52
52
|
---
|
|
53
53
|
**/
|
|
54
|
-
let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.
|
|
54
|
+
let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_NumberInput = class NumberInput extends _react.Component {
|
|
55
55
|
constructor(...args) {
|
|
56
56
|
super(...args);
|
|
57
57
|
this.state = {
|
|
@@ -204,8 +204,8 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
204
204
|
children: [' ', "*"]
|
|
205
205
|
})]
|
|
206
206
|
}) : rawLabel;
|
|
207
|
-
return (0, _jsxRuntime.jsx)(
|
|
208
|
-
...(0, _pickProps.pickProps)(this.props,
|
|
207
|
+
return (0, _jsxRuntime.jsx)(_v11_.FormField, {
|
|
208
|
+
...(0, _pickProps.pickProps)(this.props, _v11_.FormField.allowedProps),
|
|
209
209
|
label: label,
|
|
210
210
|
inline: display === 'inline-block',
|
|
211
211
|
id: this.id,
|
|
@@ -220,7 +220,7 @@ let NumberInput = exports.NumberInput = (_dec = (0, _withDeterministicId.withDet
|
|
|
220
220
|
children: (0, _jsxRuntime.jsxs)("span", {
|
|
221
221
|
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.inputContainer,
|
|
222
222
|
children: [(0, _jsxRuntime.jsx)("input", {
|
|
223
|
-
...(0, _omitProps.omitProps)(this.props, [...
|
|
223
|
+
...(0, _omitProps.omitProps)(this.props, [..._v11_.FormField.allowedProps, ...NumberInput.allowedProps]),
|
|
224
224
|
css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.input,
|
|
225
225
|
"aria-invalid": this.invalid ? 'true' : void 0,
|
|
226
226
|
id: this.id,
|