@jobber/components-native 0.112.0 → 0.112.1

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.
@@ -1,20 +1,410 @@
1
1
  # InputNumber
2
2
 
3
- InputNumber is used in forms that accept numbers as an answer.
3
+ ## Summary
4
4
 
5
- ## Design & usage guidelines
5
+ `InputNumber` collects a single numeric value in a form. Reach for it when the
6
+ value benefits from being nudged up or down, such as quantities, prices,
7
+ durations, or counts.
6
8
 
7
- This is best suited for input data that benefits from being modified in
8
- increments, such as quantity, price, or days (ie 2 days -> 3 days).
9
+ Most fields only need the props shown below. For rare layouts the props can't
10
+ handle, you can build the same field from smaller pieces. See the **Implement**
11
+ tab.
9
12
 
10
- While some types of data may technically be numbers, they can be ill-suited for
11
- using a number input. For example, phone numbers and credit card numbers provide
12
- no value to the user by offering an incrementer.
13
+ ### When to use
13
14
 
14
- ## Clearable
15
+ * The value is a number the user increments or decrements, like a quantity,
16
+ price, day count, or number of repetitions
17
+ * A stepper, min/max bounds, or number formatting would help the user
15
18
 
16
- InputNumber does not show a clear button. The component enforces
17
- `clearable="never"` to align with numeric, increment/decrement-focused usage.
19
+ ### When not to use
20
+
21
+ * The value is a sequence of digits that is never calculated with, such as phone
22
+ numbers, credit-card numbers, or postal codes. A stepper adds no value there;
23
+ use [InputText](../InputText/InputText.md) instead.
24
+
25
+ ## Anatomy
26
+
27
+ `InputNumber` typically includes:
28
+
29
+ * Label (required): names the value the field collects
30
+ * Value field (required): the number the user types or steps through
31
+ * Stepper (optional): increment and decrement controls that change the value by
32
+ `step`
33
+ * Prefix or suffix (optional): a unit or symbol shown alongside the value, like
34
+ $ or kg
35
+ * Loading indicator (optional): replaces the stepper while background work runs
36
+
37
+ ## Behavior
38
+
39
+ * The field is controlled through `value`, where a number sets the value and
40
+ `null` leaves it empty.
41
+ * `onValueCommitted` fires when the user commits a value: on blur, on Enter, or
42
+ when they use the stepper or arrow keys. Use `onValueChange` for per-keystroke
43
+ updates.
44
+ * The stepper buttons and the Up and Down arrow keys change the value by `step`
45
+ (default 1).
46
+ * `min` and `max` bound the value, and the stepper stops at each limit.
47
+ * `loading` hides the stepper and shows an indicator in its place. The field
48
+ stays editable, so use `readOnly` or `disabled` to lock it.
49
+
50
+ ## Options
51
+
52
+ ### Basic
53
+
54
+ Pass `label`, a controlled `value`, and `onValueCommitted`. Bounds (`min` /
55
+ `max`) and `step` are optional.
56
+
57
+ ```tsx
58
+ import React, { useState } from "react";
59
+ import type { InputNumberProps } from "@jobber/components";
60
+ import { InputNumber } from "@jobber/components";
61
+
62
+ export function InputNumberBasicExample(props: Partial<InputNumberProps>) {
63
+ const [value, setValue] = useState<number | null>(3);
64
+
65
+ return (
66
+ <InputNumber
67
+ label="Quantity"
68
+ min={0}
69
+ max={100}
70
+ {...props}
71
+ value={value}
72
+ onValueCommitted={setValue}
73
+ />
74
+ );
75
+ }
76
+ ```
77
+
78
+ ### Prefixes and suffixes
79
+
80
+ Use `prefix` or `suffix` to add a unit or symbol. A suffix can be a label, an
81
+ icon, or a clickable icon that runs an action (give it an `ariaLabel`).
82
+
83
+ ```tsx
84
+ import React, { useState } from "react";
85
+ import { InputNumber } from "@jobber/components";
86
+ import { Content } from "@jobber/components/Content";
87
+
88
+ export function InputNumberAffixesExample() {
89
+ const [price, setPrice] = useState<number | null>(42);
90
+ const [days, setDays] = useState<number | null>(7);
91
+ const [reps, setReps] = useState<number | null>(3);
92
+
93
+ return (
94
+ <Content>
95
+ <InputNumber
96
+ label="Price"
97
+ prefix={{ label: "$" }}
98
+ suffix={{ label: "USD" }}
99
+ value={price}
100
+ onValueCommitted={setPrice}
101
+ />
102
+
103
+ <InputNumber
104
+ label="Follow-up in"
105
+ suffix={{ icon: "calendar", label: "days" }}
106
+ value={days}
107
+ onValueCommitted={setDays}
108
+ />
109
+
110
+ <InputNumber
111
+ label="Repetitions"
112
+ suffix={{
113
+ icon: "cross",
114
+ ariaLabel: "Clear value",
115
+ onClick: () => setReps(null),
116
+ }}
117
+ value={reps}
118
+ onValueCommitted={setReps}
119
+ />
120
+ </Content>
121
+ );
122
+ }
123
+ ```
124
+
125
+ ### Sizes
126
+
127
+ 3 sizes are available. `default` fits almost every form; use `small` only in
128
+ tight spaces and `large` only in especially spacious layouts.
129
+
130
+ ```tsx
131
+ import React, { useState } from "react";
132
+ import { InputNumber } from "@jobber/components";
133
+ import { Content } from "@jobber/components/Content";
134
+
135
+ export function InputNumberSizesExample() {
136
+ const [small, setSmall] = useState<number | null>(42);
137
+ const [base, setBase] = useState<number | null>(42);
138
+ const [large, setLarge] = useState<number | null>(42);
139
+
140
+ return (
141
+ <Content>
142
+ <InputNumber
143
+ label="Small"
144
+ size="small"
145
+ suffix={{ label: "items" }}
146
+ value={small}
147
+ onValueCommitted={setSmall}
148
+ />
149
+ <InputNumber
150
+ label="Default"
151
+ size="default"
152
+ suffix={{ label: "items" }}
153
+ value={base}
154
+ onValueCommitted={setBase}
155
+ />
156
+ <InputNumber
157
+ label="Large"
158
+ size="large"
159
+ suffix={{ label: "items" }}
160
+ value={large}
161
+ onValueCommitted={setLarge}
162
+ />
163
+ </Content>
164
+ );
165
+ }
166
+ ```
167
+
168
+ ### Formatting
169
+
170
+ `format` takes any `Intl.NumberFormatOptions` and controls only how the value is
171
+ displayed; the committed value stays a plain number. See the **Implement** tab
172
+ for how percent and currency values map to the underlying number.
173
+
174
+ ```tsx
175
+ import React, { useState } from "react";
176
+ import { InputNumber } from "@jobber/components";
177
+ import { Content } from "@jobber/components/Content";
178
+
179
+ export function InputNumberFormattingExample() {
180
+ const [currency, setCurrency] = useState<number | null>(1234.5);
181
+ const [percent, setPercent] = useState<number | null>(0.5);
182
+ const [decimal, setDecimal] = useState<number | null>(11.13);
183
+
184
+ return (
185
+ <Content>
186
+ <InputNumber
187
+ label="Currency"
188
+ description='{ style: "currency", currency: "USD" }'
189
+ format={{ style: "currency", currency: "USD" }}
190
+ value={currency}
191
+ onValueCommitted={setCurrency}
192
+ />
193
+ <InputNumber
194
+ label="Percent"
195
+ description='{ style: "percent" } — value is a ratio: 0.5 → 50%'
196
+ format={{ style: "percent", maximumFractionDigits: 2 }}
197
+ value={percent}
198
+ onValueCommitted={setPercent}
199
+ />
200
+ <InputNumber
201
+ label="Decimal"
202
+ description="{ maximumFractionDigits: 2 }"
203
+ format={{ maximumFractionDigits: 2 }}
204
+ value={decimal}
205
+ onValueCommitted={setDecimal}
206
+ />
207
+ </Content>
208
+ );
209
+ }
210
+ ```
211
+
212
+ ### Loading
213
+
214
+ `loading` shows a non-blocking indicator in the stepper's slot for background
215
+ work, like saving. The field stays editable and the stepper is hidden while
216
+ loading.
217
+
218
+ ```tsx
219
+ import React, { useState } from "react";
220
+ import { InputNumber } from "@jobber/components";
221
+
222
+ export function InputNumberLoadingExample() {
223
+ const [value, setValue] = useState<number | null>(42);
224
+
225
+ return (
226
+ <InputNumber
227
+ loading
228
+ label="Quantity"
229
+ suffix={{ label: "items" }}
230
+ value={value}
231
+ onValueCommitted={setValue}
232
+ />
233
+ );
234
+ }
235
+ ```
236
+
237
+ ## Content guidelines
238
+
239
+ ### Label the unit, don't repeat it
240
+
241
+ Put the unit in the label or an affix, not both.
242
+
243
+ | ✅ Do | ❌ Don't |
244
+ | ------------------------------- | --------------------------------------- |
245
+ | Label "Weight", suffix "kg" | Label "Weight (kg)", suffix "kg" |
246
+ | Label "Duration", suffix "days" | Label "Duration in days", suffix "days" |
247
+
248
+ ### Keep labels short and sentence case
249
+
250
+ | ✅ Do | ❌ Don't |
251
+ | -------- | ----------------------- |
252
+ | Quantity | Enter the quantity here |
253
+ | Discount | DISCOUNT % |
254
+
255
+ ### Put the symbol where it's read
256
+
257
+ Use a prefix for a leading symbol and a suffix for a trailing unit, matching how
258
+ the value is spoken.
259
+
260
+ | ✅ Do | ❌ Don't |
261
+ | -------------------- | -------------------- |
262
+ | Prefix "$", value 40 | Suffix "$", value 40 |
263
+ | Suffix "%", value 15 | Prefix "%", value 15 |
264
+
265
+ ### Keep validation errors helpful
266
+
267
+ When a value breaks `min` or `max`, provide helpful guidance on what values will
268
+ be accepted as opposed to just providing a generic error.
269
+
270
+ | ✅ Do | ❌ Don't |
271
+ | ------------------------------ | ------------- |
272
+ | Enter a value between 1 and 99 | Invalid input |
273
+ | Quantity can't be more than 50 | Error |
274
+
275
+ ### Use numbers as opposed to spelling them
276
+
277
+ Use numerals in labels, helper text, affixes, and bounds.
278
+
279
+ | ✅ Do | ❌ Don't |
280
+ | ----------- | --------------- |
281
+ | Max 3 items | Max three items |
282
+
283
+ ## Do's and Don'ts
284
+
285
+ #### Do:
286
+
287
+ * ✅ Use for values the user increments or decrements
288
+ * ✅ Set `min` and `max` when the value has real bounds
289
+ * ✅ Use `format` for currency, percent, and decimals rather than formatting the
290
+ value yourself
291
+ * ✅ Use `loading` for background work so the field stays usable
292
+
293
+ #### Don't:
294
+
295
+ * ❌ Use it for digit sequences that are never calculated with, like phone or
296
+ credit card numbers
297
+ * ❌ Disable the field to communicate an error; show an `error` message instead
298
+ * ❌ Repeat the unit in both the label and an affix
299
+
300
+ ## Accessibility notes
301
+
302
+ The field is a native number input, so it is reachable and operable by keyboard
303
+ and assistive technology.
304
+
305
+ | Key | Behavior |
306
+ | ---------------- | ------------------------------- |
307
+ | Tab | Moves focus to the field |
308
+ | Up / Down arrows | Increment / decrement by `step` |
309
+ | Enter | Commits the current value |
310
+ | Type | Replaces the value |
311
+
312
+ Give a clickable affix a clear `ariaLabel` describing its action, like "Clear
313
+ value".
314
+
315
+ ## Related components
316
+
317
+ * For digit sequences that are not calculated with, like phone or credit card
318
+ numbers, use [InputText](../InputText/InputText.md).
319
+ * For dates, use [InputDate](../InputDate/InputDate.md).
320
+
321
+
322
+ ## Anatomy
323
+
324
+ The prop-driven `<InputNumber>` composes a set of parts. You only need these
325
+ when the props can't express a layout; otherwise reach for the props shown on
326
+ the **Design** tab.
327
+
328
+ | Part | Description |
329
+ | ----------------------- | -------------------------------------------------------------------- |
330
+ | `Wrapper` | Owns the field configuration and state; provides it to the parts |
331
+ | `Group` | The bordered field row |
332
+ | `Input` | The input area; holds the `Label` and the `Stepper` / `Loading` slot |
333
+ | `Label` | Floating field label |
334
+ | `Stepper` | The increment / decrement button pair |
335
+ | `Increment` `Decrement` | The individual stepper buttons |
336
+ | `Affix` | Prefix / suffix content (label, icon, or clickable icon) |
337
+ | `Loading` | Non-blocking loading indicator slot |
338
+ | `Footer` | Below-field row that holds `Description` and `Error` |
339
+ | `Description` | Helper text below the field |
340
+ | `Error` | Styled error message below the field |
341
+
342
+ ## Composition
343
+
344
+ The prop-driven component is sugar: it renders exactly the tree you would write
345
+ by hand with `<InputNumber.Wrapper>` and the parts. To customize a single piece,
346
+ compose the tree yourself and swap that one part — the other parts keep their
347
+ defaults. The sugar does not merge consumer-provided parts into its render, so
348
+ there is no per-slot precedence to reason about.
349
+
350
+ `Wrapper` owns the field state and shares it with the parts through context, so
351
+ every part must be rendered inside a `Wrapper` (a part used outside one throws).
352
+
353
+ The example below replaces the default stepper icons with `+` / `−` and leaves
354
+ everything else as the default:
355
+
356
+ ```tsx
357
+ import React, { useState } from "react";
358
+ import { InputNumber } from "@jobber/components";
359
+
360
+ export function InputNumberCompositionExample() {
361
+ const [value, setValue] = useState<number | null>(3);
362
+
363
+ return (
364
+ <InputNumber.Wrapper value={value} onValueCommitted={setValue}>
365
+ <InputNumber.Group>
366
+ <InputNumber.Input>
367
+ <InputNumber.Label>Quantity</InputNumber.Label>
368
+ <InputNumber.Stepper>
369
+ <InputNumber.Increment ariaLabel="Increase Quantity">
370
+ +
371
+ </InputNumber.Increment>
372
+ <InputNumber.Decrement ariaLabel="Decrease Quantity">
373
+
374
+ </InputNumber.Decrement>
375
+ </InputNumber.Stepper>
376
+ </InputNumber.Input>
377
+ </InputNumber.Group>
378
+ </InputNumber.Wrapper>
379
+ );
380
+ }
381
+ ```
382
+
383
+ ## Controlled usage
384
+
385
+ The field is controlled: pass `value` (a `number`, or `null` for empty) and read
386
+ changes back through one of two callbacks.
387
+
388
+ | Callback | Fires | Use for |
389
+ | ------------------ | ----------------------------------------------------------- | ---------------------------------- |
390
+ | `onValueChange` | On every parsed change (typing, paste, stepper, arrow step) | Live-updating UI as the user types |
391
+ | `onValueCommitted` | When the user commits (blur, Enter, stepper, arrow step) | Saving / validating a final value |
392
+
393
+ Both emit `null` when the field is empty. Prefer `onValueCommitted` for
394
+ persistence so you are not writing on every keystroke.
395
+
396
+ ## Formatting semantics
397
+
398
+ `format` is forwarded to Base UI's `NumberField` `format` and accepts any
399
+ `Intl.NumberFormatOptions`. It changes the display only; the committed value is
400
+ always a plain number. Two things to know:
401
+
402
+ * **Percent** (`{ style: "percent" }`) treats the value as a ratio: `0.5`
403
+ renders `50%`, and the stepper moves in ratio units. If you want the value to
404
+ be the number itself (`50` → `50%`), use `{ style: "unit", unit: "percent" }`.
405
+ * With no `format`, typed decimals are preserved (up to 12 fractional digits)
406
+ and thousands grouping follows the locale default, so `1234.5` renders as
407
+ `1,234.5`. Pass `{ useGrouping: false }` to render without separators.
18
408
 
19
409
 
20
410
  ## Props
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.112.0",
3
+ "version": "0.112.1",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -74,7 +74,7 @@
74
74
  "@babel/runtime": "^7.29.2",
75
75
  "@gorhom/bottom-sheet": "^5.2.8",
76
76
  "@jobber/design": "0.111.0",
77
- "@jobber/hooks": "2.21.0",
77
+ "@jobber/hooks": "2.21.1",
78
78
  "@react-native-community/datetimepicker": "^8.4.5",
79
79
  "@react-native/babel-preset": "^0.82.1",
80
80
  "@storybook/addon-a11y": "10.3.5",
@@ -124,5 +124,5 @@
124
124
  "react-native-screens": ">=4.18.0",
125
125
  "react-native-svg": ">=12.0.0"
126
126
  },
127
- "gitHead": "71ed27026cd539889c5ce6c627bd74a8d283112e"
127
+ "gitHead": "2557e3892ae9903c706aebba90ff44bbb349618c"
128
128
  }