@instructure/ui-number-input 11.0.1-snapshot-1 → 11.0.1-snapshot-3
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 +1 -1
- package/package.json +11 -11
- package/src/NumberInput/README.md +119 -251
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
|
-
## [11.0.1-snapshot-
|
|
6
|
+
## [11.0.1-snapshot-3](https://github.com/instructure/instructure-ui/compare/v11.0.0...v11.0.1-snapshot-3) (2025-10-10)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-number-input
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-number-input",
|
|
3
|
-
"version": "11.0.1-snapshot-
|
|
3
|
+
"version": "11.0.1-snapshot-3",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"homepage": "https://instructure.github.io/instructure-ui/",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "11.0.1-snapshot-
|
|
27
|
-
"@instructure/ui-scripts": "11.0.1-snapshot-
|
|
28
|
-
"@instructure/ui-themes": "11.0.1-snapshot-
|
|
26
|
+
"@instructure/ui-babel-preset": "11.0.1-snapshot-3",
|
|
27
|
+
"@instructure/ui-scripts": "11.0.1-snapshot-3",
|
|
28
|
+
"@instructure/ui-themes": "11.0.1-snapshot-3",
|
|
29
29
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
30
|
"@testing-library/react": "15.0.7",
|
|
31
31
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "^7.27.6",
|
|
36
|
-
"@instructure/emotion": "11.0.1-snapshot-
|
|
37
|
-
"@instructure/shared-types": "11.0.1-snapshot-
|
|
38
|
-
"@instructure/ui-form-field": "11.0.1-snapshot-
|
|
39
|
-
"@instructure/ui-icons": "11.0.1-snapshot-
|
|
40
|
-
"@instructure/ui-react-utils": "11.0.1-snapshot-
|
|
41
|
-
"@instructure/ui-utils": "11.0.1-snapshot-
|
|
42
|
-
"@instructure/uid": "11.0.1-snapshot-
|
|
36
|
+
"@instructure/emotion": "11.0.1-snapshot-3",
|
|
37
|
+
"@instructure/shared-types": "11.0.1-snapshot-3",
|
|
38
|
+
"@instructure/ui-form-field": "11.0.1-snapshot-3",
|
|
39
|
+
"@instructure/ui-icons": "11.0.1-snapshot-3",
|
|
40
|
+
"@instructure/ui-react-utils": "11.0.1-snapshot-3",
|
|
41
|
+
"@instructure/ui-utils": "11.0.1-snapshot-3",
|
|
42
|
+
"@instructure/uid": "11.0.1-snapshot-3",
|
|
43
43
|
"keycode": "^2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
@@ -12,273 +12,141 @@ This example handles arrow buttons, up/down arrow keys, and typing into
|
|
|
12
12
|
the input. It also includes an `onBlur` handler that displays an error message
|
|
13
13
|
if the input is invalid or missing.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
handleDecrement = (event) =>
|
|
38
|
-
this.setState(({ number }) => {
|
|
39
|
-
if (isNaN(number)) return
|
|
40
|
-
if (number === null) return this.setNumber(this.MIN)
|
|
41
|
-
if (Number.isInteger(number)) return this.setNumber(number - 1)
|
|
42
|
-
return this.setNumber(Math.floor(number))
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
handleIncrement = (event) =>
|
|
46
|
-
this.setState(({ number }) => {
|
|
47
|
-
if (isNaN(number)) return
|
|
48
|
-
if (number === null) return this.setNumber(this.MIN + 1)
|
|
49
|
-
if (Number.isInteger(number)) return this.setNumber(number + 1)
|
|
50
|
-
return this.setNumber(Math.ceil(number))
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
handleBlur = (event) =>
|
|
54
|
-
this.setState(({ number, value }) => {
|
|
55
|
-
if (isNaN(number)) return this.invalidNumber(value)
|
|
56
|
-
if (number === null) return this.required()
|
|
57
|
-
return this.setNumber(Math.round(number))
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
setNumber(n) {
|
|
61
|
-
const number = this.bound(n)
|
|
62
|
-
return {
|
|
63
|
-
messages: null,
|
|
64
|
-
number,
|
|
65
|
-
value: number
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
bound(n) {
|
|
70
|
-
if (n < this.MIN) return this.MIN
|
|
71
|
-
if (n > this.MAX) return this.MAX
|
|
72
|
-
return n
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
invalidNumber(value) {
|
|
76
|
-
return {
|
|
77
|
-
messages: [{ text: `'${value}' is not a valid number.`, type: 'error' }]
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
required() {
|
|
82
|
-
return {
|
|
83
|
-
messages: [{ text: 'This is required.', type: 'error' }]
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
toggleDisabled = (event) =>
|
|
88
|
-
this.setState(({ disabled }) => ({ disabled: !disabled }))
|
|
89
|
-
|
|
90
|
-
toggleInline = (event) =>
|
|
91
|
-
this.setState(({ inline }) => ({ inline: !inline }))
|
|
92
|
-
|
|
93
|
-
toggleReadOnly = (event) =>
|
|
94
|
-
this.setState(({ readOnly }) => ({ readOnly: !readOnly }))
|
|
95
|
-
|
|
96
|
-
toggleShowArrows = (event) =>
|
|
97
|
-
this.setState(({ showArrows }) => ({ showArrows: !showArrows }))
|
|
98
|
-
|
|
99
|
-
render() {
|
|
100
|
-
return (
|
|
101
|
-
<FormFieldGroup description="Controlled NumberInput example">
|
|
102
|
-
<Checkbox
|
|
103
|
-
checked={this.state.showArrows}
|
|
104
|
-
label="Show arrows"
|
|
105
|
-
onChange={this.toggleShowArrows}
|
|
106
|
-
/>
|
|
107
|
-
<Checkbox
|
|
108
|
-
checked={this.state.disabled}
|
|
109
|
-
label="Disabled"
|
|
110
|
-
onChange={this.toggleDisabled}
|
|
111
|
-
/>
|
|
112
|
-
<Checkbox
|
|
113
|
-
checked={this.state.readOnly}
|
|
114
|
-
label="Read only"
|
|
115
|
-
onChange={this.toggleReadOnly}
|
|
116
|
-
/>
|
|
117
|
-
<Checkbox
|
|
118
|
-
checked={this.state.inline}
|
|
119
|
-
label="Inline display"
|
|
120
|
-
onChange={this.toggleInline}
|
|
121
|
-
/>
|
|
122
|
-
<NumberInput
|
|
123
|
-
renderLabel={`How old are you? (${this.MIN}-${this.MAX})`}
|
|
124
|
-
display={this.state.inline ? 'inline-block' : null}
|
|
125
|
-
messages={this.state.messages}
|
|
126
|
-
onBlur={this.handleBlur}
|
|
127
|
-
onChange={this.handleChange}
|
|
128
|
-
onDecrement={this.handleDecrement}
|
|
129
|
-
onIncrement={this.handleIncrement}
|
|
130
|
-
placeholder="Age (in years)"
|
|
131
|
-
interaction={
|
|
132
|
-
this.state.disabled
|
|
133
|
-
? 'disabled'
|
|
134
|
-
: this.state.readOnly
|
|
135
|
-
? 'readonly'
|
|
136
|
-
: 'enabled'
|
|
137
|
-
}
|
|
138
|
-
isRequired
|
|
139
|
-
showArrows={this.state.showArrows}
|
|
140
|
-
value={this.state.value}
|
|
141
|
-
/>
|
|
142
|
-
</FormFieldGroup>
|
|
143
|
-
)
|
|
144
|
-
}
|
|
15
|
+
```js
|
|
16
|
+
---
|
|
17
|
+
type: example
|
|
18
|
+
---
|
|
19
|
+
const Example = () => {
|
|
20
|
+
const MIN = 0
|
|
21
|
+
const MAX = 999
|
|
22
|
+
|
|
23
|
+
const [disabled, setDisabled] = useState(false)
|
|
24
|
+
const [inline, setInline] = useState(false)
|
|
25
|
+
const [messages, setMessages] = useState(null)
|
|
26
|
+
const [number, setNumber] = useState(null)
|
|
27
|
+
const [readOnly, setReadOnly] = useState(false)
|
|
28
|
+
const [showArrows, setShowArrows] = useState(true)
|
|
29
|
+
const [value, setValue] = useState('')
|
|
30
|
+
|
|
31
|
+
const handleChange = (event, value) => {
|
|
32
|
+
setMessages(null)
|
|
33
|
+
setNumber(value ? Number(value) : null)
|
|
34
|
+
setValue(value)
|
|
145
35
|
}
|
|
146
36
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const [inline, setInline] = useState(false)
|
|
157
|
-
const [messages, setMessages] = useState(null)
|
|
158
|
-
const [number, setNumber] = useState(null)
|
|
159
|
-
const [readOnly, setReadOnly] = useState(false)
|
|
160
|
-
const [showArrows, setShowArrows] = useState(true)
|
|
161
|
-
const [value, setValue] = useState('')
|
|
162
|
-
|
|
163
|
-
const handleChange = (event, value) => {
|
|
164
|
-
setMessages(null)
|
|
165
|
-
setNumber(value ? Number(value) : null)
|
|
166
|
-
setValue(value)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const handleDecrement = (event) => {
|
|
170
|
-
if (!isNaN(number)) {
|
|
171
|
-
const newNumber =
|
|
172
|
-
number === null
|
|
173
|
-
? MIN
|
|
174
|
-
: Number.isInteger(number)
|
|
175
|
-
? number - 1
|
|
176
|
-
: Math.floor(number)
|
|
177
|
-
updateNumber(newNumber)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const handleIncrement = (event) => {
|
|
182
|
-
if (!isNaN(number)) {
|
|
183
|
-
const newNumber =
|
|
184
|
-
number === null
|
|
185
|
-
? MIN + 1
|
|
186
|
-
: Number.isInteger(number)
|
|
187
|
-
? number + 1
|
|
188
|
-
: Math.ceil(number)
|
|
189
|
-
updateNumber(newNumber)
|
|
190
|
-
}
|
|
37
|
+
const handleDecrement = (event) => {
|
|
38
|
+
if (!isNaN(number)) {
|
|
39
|
+
const newNumber =
|
|
40
|
+
number === null
|
|
41
|
+
? MIN
|
|
42
|
+
: Number.isInteger(number)
|
|
43
|
+
? number - 1
|
|
44
|
+
: Math.floor(number)
|
|
45
|
+
updateNumber(newNumber)
|
|
191
46
|
}
|
|
47
|
+
}
|
|
192
48
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
49
|
+
const handleIncrement = (event) => {
|
|
50
|
+
if (!isNaN(number)) {
|
|
51
|
+
const newNumber =
|
|
52
|
+
number === null
|
|
53
|
+
? MIN + 1
|
|
54
|
+
: Number.isInteger(number)
|
|
55
|
+
? number + 1
|
|
56
|
+
: Math.ceil(number)
|
|
57
|
+
updateNumber(newNumber)
|
|
197
58
|
}
|
|
59
|
+
}
|
|
198
60
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
61
|
+
const handleBlur = (event) => {
|
|
62
|
+
if (isNaN(number)) return invalidNumber(value)
|
|
63
|
+
if (number === null) return required()
|
|
64
|
+
return updateNumber(Math.round(number))
|
|
65
|
+
}
|
|
205
66
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
67
|
+
const updateNumber = (n) => {
|
|
68
|
+
const number = bound(n)
|
|
69
|
+
setMessages(null)
|
|
70
|
+
setNumber(number)
|
|
71
|
+
setValue(number)
|
|
72
|
+
}
|
|
211
73
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
74
|
+
const bound = (n) => {
|
|
75
|
+
if (n < MIN) return MIN
|
|
76
|
+
if (n > MAX) return MAX
|
|
77
|
+
return n
|
|
78
|
+
}
|
|
217
79
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
80
|
+
const invalidNumber = (value) => {
|
|
81
|
+
setMessages([
|
|
82
|
+
{ text: `'${value}' is not a valid number.`, type: 'error' }
|
|
83
|
+
])
|
|
84
|
+
}
|
|
221
85
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
86
|
+
const required = () => {
|
|
87
|
+
setMessages([{ text: 'This is required.', type: 'error' }])
|
|
88
|
+
}
|
|
225
89
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
90
|
+
const toggleDisabled = (event) => {
|
|
91
|
+
setDisabled((prevDisabled) => !prevDisabled)
|
|
92
|
+
}
|
|
229
93
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
94
|
+
const toggleInline = (event) => {
|
|
95
|
+
setInline((prevInline) => !prevInline)
|
|
96
|
+
}
|
|
233
97
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
98
|
+
const toggleReadOnly = (event) => {
|
|
99
|
+
setReadOnly((prevReadOnly) => !prevReadOnly)
|
|
100
|
+
}
|
|
237
101
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
<Checkbox
|
|
241
|
-
checked={showArrows}
|
|
242
|
-
label="Show arrows"
|
|
243
|
-
onChange={toggleShowArrows}
|
|
244
|
-
/>
|
|
245
|
-
<Checkbox
|
|
246
|
-
checked={disabled}
|
|
247
|
-
label="Disabled"
|
|
248
|
-
onChange={toggleDisabled}
|
|
249
|
-
/>
|
|
250
|
-
<Checkbox
|
|
251
|
-
checked={readOnly}
|
|
252
|
-
label="Read only"
|
|
253
|
-
onChange={toggleReadOnly}
|
|
254
|
-
/>
|
|
255
|
-
<Checkbox
|
|
256
|
-
checked={inline}
|
|
257
|
-
label="Inline display"
|
|
258
|
-
onChange={toggleInline}
|
|
259
|
-
/>
|
|
260
|
-
<NumberInput
|
|
261
|
-
renderLabel={`How old are you? (${MIN}-${MAX})`}
|
|
262
|
-
display={inline ? 'inline-block' : null}
|
|
263
|
-
messages={messages}
|
|
264
|
-
onBlur={handleBlur}
|
|
265
|
-
onChange={handleChange}
|
|
266
|
-
onDecrement={handleDecrement}
|
|
267
|
-
onIncrement={handleIncrement}
|
|
268
|
-
placeholder="Age (in years)"
|
|
269
|
-
interaction={
|
|
270
|
-
disabled ? 'disabled' : readOnly ? 'readonly' : 'enabled'
|
|
271
|
-
}
|
|
272
|
-
isRequired
|
|
273
|
-
showArrows={showArrows}
|
|
274
|
-
value={value}
|
|
275
|
-
/>
|
|
276
|
-
</FormFieldGroup>
|
|
277
|
-
)
|
|
102
|
+
const toggleShowArrows = (event) => {
|
|
103
|
+
setShowArrows((prevShowArrows) => !prevShowArrows)
|
|
278
104
|
}
|
|
279
105
|
|
|
280
|
-
|
|
281
|
-
|
|
106
|
+
return (
|
|
107
|
+
<FormFieldGroup description="Controlled NumberInput example">
|
|
108
|
+
<Checkbox
|
|
109
|
+
checked={showArrows}
|
|
110
|
+
label="Show arrows"
|
|
111
|
+
onChange={toggleShowArrows}
|
|
112
|
+
/>
|
|
113
|
+
<Checkbox
|
|
114
|
+
checked={disabled}
|
|
115
|
+
label="Disabled"
|
|
116
|
+
onChange={toggleDisabled}
|
|
117
|
+
/>
|
|
118
|
+
<Checkbox
|
|
119
|
+
checked={readOnly}
|
|
120
|
+
label="Read only"
|
|
121
|
+
onChange={toggleReadOnly}
|
|
122
|
+
/>
|
|
123
|
+
<Checkbox
|
|
124
|
+
checked={inline}
|
|
125
|
+
label="Inline display"
|
|
126
|
+
onChange={toggleInline}
|
|
127
|
+
/>
|
|
128
|
+
<NumberInput
|
|
129
|
+
renderLabel={`How old are you? (${MIN}-${MAX})`}
|
|
130
|
+
display={inline ? 'inline-block' : null}
|
|
131
|
+
messages={messages}
|
|
132
|
+
onBlur={handleBlur}
|
|
133
|
+
onChange={handleChange}
|
|
134
|
+
onDecrement={handleDecrement}
|
|
135
|
+
onIncrement={handleIncrement}
|
|
136
|
+
placeholder="Age (in years)"
|
|
137
|
+
interaction={
|
|
138
|
+
disabled ? 'disabled' : readOnly ? 'readonly' : 'enabled'
|
|
139
|
+
}
|
|
140
|
+
isRequired
|
|
141
|
+
showArrows={showArrows}
|
|
142
|
+
value={value}
|
|
143
|
+
/>
|
|
144
|
+
</FormFieldGroup>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
render(<Example />)
|
|
149
|
+
```
|
|
282
150
|
|
|
283
151
|
> Note: `NumberInput` accepts a string or number as its `value`. However, the value returned by the `onChange` callback is always a string and should be converted to a number before attempting to augment it.
|
|
284
152
|
|