@slotted/react 0.1.0-beta.42 → 0.1.0-beta.43
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/dist/{app-shell-D54YkU7E.js → app-shell-DsWhsSMU.js} +3 -2
- package/dist/app-shell.js +1 -1
- package/dist/attachment-TZykYNu5.js +300 -0
- package/dist/attachment.js +2 -2
- package/dist/{avatar-group-bJaZE1_C.js → avatar-group-Bzmmj2HI.js} +2 -1
- package/dist/avatar-group.js +1 -1
- package/dist/{carousel-B9nMK7Yf.js → carousel-CRNz-T3g.js} +1 -1
- package/dist/carousel.js +1 -1
- package/dist/{command-palette-C90CzfQi.js → command-palette-Bgf5tfCI.js} +160 -156
- package/dist/command-palette.js +1 -1
- package/dist/{data-grid-D106baPp.js → data-grid-DUft3rJb.js} +1 -1
- package/dist/data-grid.js +1 -1
- package/dist/{data-list-BA0xrySM.js → data-list-Dv3orBtf.js} +15 -15
- package/dist/data-list.js +1 -1
- package/dist/detail-panel-Cke3ZFU3.js +342 -0
- package/dist/detail-panel.js +2 -2
- package/dist/docs/action-bar.examples.md +768 -0
- package/dist/docs/action-bar.json +74 -50
- package/dist/docs/action-bar.md +49 -311
- package/dist/docs/app-shell.examples.md +1221 -64
- package/dist/docs/app-shell.json +92 -60
- package/dist/docs/app-shell.md +92 -57
- package/dist/docs/attachment.examples.md +689 -0
- package/dist/docs/attachment.json +69 -37
- package/dist/docs/attachment.md +44 -203
- package/dist/docs/avatar-group.json +111 -23
- package/dist/docs/avatar-group.md +487 -28
- package/dist/docs/button-group.json +98 -2
- package/dist/docs/button-group.md +411 -8
- package/dist/docs/calendar.examples.md +512 -0
- package/dist/docs/calendar.json +72 -24
- package/dist/docs/calendar.md +18 -147
- package/dist/docs/carousel.examples.md +868 -0
- package/dist/docs/carousel.json +58 -50
- package/dist/docs/carousel.md +66 -300
- package/dist/docs/cascader.examples.md +1269 -0
- package/dist/docs/cascader.json +72 -16
- package/dist/docs/cascader.md +78 -154
- package/dist/docs/chart.examples.md +734 -24
- package/dist/docs/chart.json +93 -13
- package/dist/docs/chart.md +28 -7
- package/dist/docs/clock.json +71 -15
- package/dist/docs/clock.md +326 -21
- package/dist/docs/code-block.json +79 -55
- package/dist/docs/code-block.md +417 -74
- package/dist/docs/color-picker.json +60 -12
- package/dist/docs/color-picker.md +245 -22
- package/dist/docs/column-manager.examples.md +764 -0
- package/dist/docs/column-manager.json +68 -12
- package/dist/docs/column-manager.md +44 -203
- package/dist/docs/command-palette.examples.md +747 -0
- package/dist/docs/command-palette.json +48 -24
- package/dist/docs/command-palette.md +60 -339
- package/dist/docs/currency-field.examples.md +355 -73
- package/dist/docs/currency-field.json +96 -64
- package/dist/docs/currency-field.md +57 -50
- package/dist/docs/dashboard-grid.examples.md +629 -0
- package/dist/docs/dashboard-grid.json +64 -16
- package/dist/docs/dashboard-grid.md +34 -152
- package/dist/docs/data-list.examples.md +1556 -0
- package/dist/docs/data-list.json +58 -18
- package/dist/docs/data-list.md +139 -224
- package/dist/docs/date-field.examples.md +543 -0
- package/dist/docs/date-field.json +64 -24
- package/dist/docs/date-field.md +22 -168
- package/dist/docs/datetime-field.examples.md +699 -0
- package/dist/docs/datetime-field.json +79 -31
- package/dist/docs/datetime-field.md +24 -269
- package/dist/docs/datetime-range-picker.examples.md +682 -0
- package/dist/docs/datetime-range-picker.json +117 -61
- package/dist/docs/datetime-range-picker.md +59 -224
- package/dist/docs/description-list.examples.md +652 -0
- package/dist/docs/description-list.json +49 -25
- package/dist/docs/description-list.md +33 -188
- package/dist/docs/detail-panel.examples.md +1177 -0
- package/dist/docs/detail-panel.json +69 -53
- package/dist/docs/detail-panel.md +114 -324
- package/dist/docs/entity-picker.examples.md +1037 -0
- package/dist/docs/entity-picker.json +66 -18
- package/dist/docs/entity-picker.md +56 -246
- package/dist/docs/event-calendar.examples.md +749 -49
- package/dist/docs/event-calendar.json +46 -22
- package/dist/docs/event-calendar.md +81 -11
- package/dist/docs/field-group.examples.md +554 -0
- package/dist/docs/field-group.json +98 -34
- package/dist/docs/field-group.md +55 -133
- package/dist/docs/filter-bar.examples.md +772 -0
- package/dist/docs/filter-bar.json +41 -25
- package/dist/docs/filter-bar.md +42 -246
- package/dist/docs/form.examples.md +579 -0
- package/dist/docs/form.json +87 -39
- package/dist/docs/form.md +53 -177
- package/dist/docs/fullscreen.examples.md +558 -0
- package/dist/docs/fullscreen.json +58 -18
- package/dist/docs/fullscreen.md +50 -169
- package/dist/docs/highlight.json +57 -25
- package/dist/docs/highlight.md +402 -50
- package/dist/docs/icon.json +85 -5
- package/dist/docs/icon.md +401 -10
- package/dist/docs/image.examples.md +670 -0
- package/dist/docs/image.json +44 -28
- package/dist/docs/image.md +24 -176
- package/dist/docs/import-export-center.examples.md +1280 -0
- package/dist/docs/import-export-center.json +67 -27
- package/dist/docs/import-export-center.md +121 -226
- package/dist/docs/list-item.examples.md +769 -0
- package/dist/docs/list-item.json +110 -38
- package/dist/docs/list-item.md +84 -201
- package/dist/docs/listbox.examples.md +858 -0
- package/dist/docs/listbox.json +76 -28
- package/dist/docs/listbox.md +41 -263
- package/dist/docs/markdown.json +79 -55
- package/dist/docs/markdown.md +581 -85
- package/dist/docs/media-viewer.examples.md +1038 -0
- package/dist/docs/media-viewer.json +70 -15
- package/dist/docs/media-viewer.md +84 -135
- package/dist/docs/message-scroller.examples.md +1193 -0
- package/dist/docs/message-scroller.json +41 -17
- package/dist/docs/message-scroller.md +80 -134
- package/dist/docs/message.examples.md +944 -0
- package/dist/docs/message.json +64 -16
- package/dist/docs/message.md +34 -326
- package/dist/docs/meter.json +58 -26
- package/dist/docs/meter.md +312 -32
- package/dist/docs/navigation-menu.examples.md +1107 -0
- package/dist/docs/navigation-menu.json +57 -41
- package/dist/docs/navigation-menu.md +105 -298
- package/dist/docs/notification-center.examples.md +1045 -0
- package/dist/docs/notification-center.json +71 -15
- package/dist/docs/notification-center.md +76 -266
- package/dist/docs/otp-input.examples.md +490 -0
- package/dist/docs/otp-input.json +65 -25
- package/dist/docs/otp-input.md +20 -191
- package/dist/docs/page-header.examples.md +1041 -0
- package/dist/docs/page-header.json +75 -43
- package/dist/docs/page-header.md +79 -291
- package/dist/docs/page.examples.md +633 -0
- package/dist/docs/page.json +48 -16
- package/dist/docs/page.md +62 -129
- package/dist/docs/prompt-composer.examples.md +630 -0
- package/dist/docs/prompt-composer.json +66 -18
- package/dist/docs/prompt-composer.md +35 -161
- package/dist/docs/prose.json +69 -37
- package/dist/docs/prose.md +393 -75
- package/dist/docs/rating.examples.md +525 -0
- package/dist/docs/rating.json +92 -28
- package/dist/docs/rating.md +27 -241
- package/dist/docs/saved-views.examples.md +1108 -0
- package/dist/docs/saved-views.json +53 -21
- package/dist/docs/saved-views.md +86 -171
- package/dist/docs/scroll-area.examples.md +837 -0
- package/dist/docs/scroll-area.json +64 -24
- package/dist/docs/scroll-area.md +57 -140
- package/dist/docs/section.examples.md +676 -0
- package/dist/docs/section.json +68 -20
- package/dist/docs/section.md +39 -162
- package/dist/docs/segmented-control.examples.md +480 -0
- package/dist/docs/segmented-control.json +76 -28
- package/dist/docs/segmented-control.md +20 -191
- package/dist/docs/side-navigation.examples.md +1468 -0
- package/dist/docs/side-navigation.json +53 -53
- package/dist/docs/side-navigation.md +79 -354
- package/dist/docs/slider.examples.md +505 -0
- package/dist/docs/slider.json +91 -51
- package/dist/docs/slider.md +47 -212
- package/dist/docs/sparkline.json +60 -36
- package/dist/docs/sparkline.md +447 -71
- package/dist/docs/split-button.examples.md +509 -0
- package/dist/docs/split-button.json +73 -41
- package/dist/docs/split-button.md +64 -194
- package/dist/docs/splitter.examples.md +921 -0
- package/dist/docs/splitter.json +94 -46
- package/dist/docs/splitter.md +75 -182
- package/dist/docs/stat-card.examples.md +725 -0
- package/dist/docs/stat-card.json +89 -41
- package/dist/docs/stat-card.md +55 -227
- package/dist/docs/status-indicator.json +80 -32
- package/dist/docs/status-indicator.md +409 -65
- package/dist/docs/stepper.json +53 -21
- package/dist/docs/stepper.md +369 -48
- package/dist/docs/table-of-contents.examples.md +550 -0
- package/dist/docs/table-of-contents.json +60 -28
- package/dist/docs/table-of-contents.md +70 -205
- package/dist/docs/tags-input.examples.md +541 -0
- package/dist/docs/tags-input.json +64 -16
- package/dist/docs/tags-input.md +15 -262
- package/dist/docs/time-field.examples.md +587 -0
- package/dist/docs/time-field.json +69 -29
- package/dist/docs/time-field.md +21 -223
- package/dist/docs/time-picker.json +117 -53
- package/dist/docs/time-picker.md +499 -54
- package/dist/docs/time-range-picker.examples.md +750 -0
- package/dist/docs/time-range-picker.json +139 -75
- package/dist/docs/time-range-picker.md +63 -225
- package/dist/docs/timeline.examples.md +617 -0
- package/dist/docs/timeline.json +44 -28
- package/dist/docs/timeline.md +34 -208
- package/dist/docs/toolbar.json +56 -16
- package/dist/docs/toolbar.md +357 -63
- package/dist/docs/top-navigation.examples.md +1206 -140
- package/dist/docs/top-navigation.json +49 -33
- package/dist/docs/top-navigation.md +87 -36
- package/dist/docs/tour.examples.md +960 -0
- package/dist/docs/tour.json +57 -25
- package/dist/docs/tour.md +60 -244
- package/dist/docs/transfer.examples.md +631 -0
- package/dist/docs/transfer.json +80 -16
- package/dist/docs/transfer.md +41 -170
- package/dist/docs/typography.json +96 -0
- package/dist/docs/typography.md +352 -4
- package/dist/docs/upload.examples.md +555 -53
- package/dist/docs/upload.json +62 -30
- package/dist/docs/upload.md +46 -11
- package/dist/docs/wizard.examples.md +1389 -0
- package/dist/docs/wizard.json +89 -49
- package/dist/docs/wizard.md +122 -263
- package/dist/{entity-picker-CC4VoC3p.js → entity-picker-C78f3Z0o.js} +9 -6
- package/dist/entity-picker.js +1 -1
- package/dist/{event-calendar-CjmF_e0H.js → event-calendar-DJPoCi-O.js} +1 -1
- package/dist/event-calendar.js +1 -1
- package/dist/{filter-bar-B3QJD7SZ.js → filter-bar-D61wiQFP.js} +1 -1
- package/dist/filter-bar.js +1 -1
- package/dist/{import-export-center-CW8YVZev.js → import-export-center-mqvmlzwB.js} +44 -36
- package/dist/import-export-center.js +1 -1
- package/dist/index.js +58 -58
- package/dist/{markdown-BdskE4-L.js → markdown-8CtV4k44.js} +2 -2
- package/dist/markdown.js +1 -1
- package/dist/{media-viewer-zEXcwfEY.js → media-viewer-C_cbuAq-.js} +64 -60
- package/dist/media-viewer.js +2 -2
- package/dist/message-P91bEGyV.js +455 -0
- package/dist/message.js +2 -2
- package/dist/{page-header-DmwBGwlm.js → page-header-jeAIQSZM.js} +103 -108
- package/dist/page-header.js +1 -1
- package/dist/section-CVTQdWBl.js +216 -0
- package/dist/section.js +2 -2
- package/dist/{segmented-control-CbK7SurB.js → segmented-control-BSMVjukr.js} +1 -1
- package/dist/segmented-control.js +1 -1
- package/dist/{side-navigation-CKRETc8E.js → side-navigation-BQzBxz2B.js} +179 -179
- package/dist/side-navigation.js +1 -1
- package/dist/{stat-card-CL3Xe6pV.js → stat-card-BpGZiFbG.js} +12 -14
- package/dist/stat-card.js +1 -1
- package/dist/{stepper-DHdrANZI.js → stepper-Cxb_tHnA.js} +130 -127
- package/dist/stepper.js +2 -2
- package/dist/styles/carousel.css +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/{timeline-BiL2CXfn.js → timeline-ZngK6zLC.js} +9 -6
- package/dist/timeline.js +1 -1
- package/dist/top-navigation-YSEQzBhD.js +744 -0
- package/dist/top-navigation.js +2 -2
- package/dist/{transfer-sKUvmEKe.js → transfer-Cv5yQuTN.js} +1 -1
- package/dist/transfer.js +1 -1
- package/dist/types/attachment/attachment-parts.d.ts +24 -11
- package/dist/types/attachment/attachment-parts.d.ts.map +1 -1
- package/dist/types/attachment/attachment.d.ts +3 -3
- package/dist/types/attachment/attachment.d.ts.map +1 -1
- package/dist/types/avatar-group/avatar-group.d.ts.map +1 -1
- package/dist/types/carousel/carousel-parts.d.ts +2 -2
- package/dist/types/command-palette/command-palette.d.ts.map +1 -1
- package/dist/types/data-list/data-list.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel-parts.d.ts +10 -3
- package/dist/types/detail-panel/detail-panel-parts.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel.types.d.ts +7 -0
- package/dist/types/detail-panel/detail-panel.types.d.ts.map +1 -1
- package/dist/types/entity-picker/entity-picker.d.ts.map +1 -1
- package/dist/types/import-export-center/import-export-center.d.ts.map +1 -1
- package/dist/types/media-viewer/index.d.ts +2 -2
- package/dist/types/media-viewer/index.d.ts.map +1 -1
- package/dist/types/media-viewer/media-viewer-bar.d.ts +3 -1
- package/dist/types/media-viewer/media-viewer-bar.d.ts.map +1 -1
- package/dist/types/media-viewer/media-viewer.types.d.ts +1 -0
- package/dist/types/media-viewer/media-viewer.types.d.ts.map +1 -1
- package/dist/types/message/message-parts.d.ts +7 -0
- package/dist/types/message/message-parts.d.ts.map +1 -1
- package/dist/types/message/message.d.ts.map +1 -1
- package/dist/types/page-header/page-header-parts.d.ts.map +1 -1
- package/dist/types/section/section-parts.d.ts +16 -8
- package/dist/types/section/section-parts.d.ts.map +1 -1
- package/dist/types/section/section.d.ts.map +1 -1
- package/dist/types/segmented-control/segmented-control-parts.d.ts.map +1 -1
- package/dist/types/side-navigation/side-navigation-parts.d.ts.map +1 -1
- package/dist/types/stat-card/stat-card-delta.d.ts.map +1 -1
- package/dist/types/stat-card/stat-card-parts.d.ts +3 -3
- package/dist/types/stat-card/stat-card-parts.d.ts.map +1 -1
- package/dist/types/stepper/stepper-parts.d.ts +11 -2
- package/dist/types/stepper/stepper-parts.d.ts.map +1 -1
- package/dist/types/stepper/stepper.d.ts.map +1 -1
- package/dist/types/timeline/timeline-parts.d.ts.map +1 -1
- package/dist/types/top-navigation/top-navigation.d.ts.map +1 -1
- package/dist/{wizard-4c0X7Bx_.js → wizard-Dfryz1id.js} +214 -214
- package/dist/wizard.js +1 -1
- package/package.json +6 -6
- package/dist/attachment-MqczA38F.js +0 -292
- package/dist/detail-panel-EImAtksY.js +0 -327
- package/dist/message-D1Dd6Y2k.js +0 -452
- package/dist/section-D_qOfdxR.js +0 -213
- package/dist/top-navigation-D8IHPOmm.js +0 -744
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
<!-- index: ./index.md -->
|
|
2
|
+
# otp-input
|
|
3
|
+
|
|
4
|
+
`data-ui="otp-input"` · One-time code split across several boxes.
|
|
5
|
+
|
|
6
|
+
## Examples
|
|
7
|
+
|
|
8
|
+
### Playground
|
|
9
|
+
|
|
10
|
+
The second step of a sign-in, driven by the controls below the canvas. Type into it: the value is one string, the boxes paint it, and the sixth digit completes it.
|
|
11
|
+
|
|
12
|
+
Excerpt — not a complete module
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
<Field>
|
|
16
|
+
<FieldLabel>Verification code</FieldLabel>
|
|
17
|
+
<OtpInput name="code" groups={[3, 3]} onComplete={verify} />
|
|
18
|
+
<FieldDescription>We sent an SMS to +1 206 •••-4821.</FieldDescription>
|
|
19
|
+
</Field>;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### The step the boxes sit at
|
|
23
|
+
|
|
24
|
+
A box is a square on the control height of its step, so a code beside a text field in the same form sits on the same row. Inside a field the control takes the field’s step rather than its own.
|
|
25
|
+
|
|
26
|
+
Example
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
30
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
31
|
+
import { Stack } from '@slotted/react/stack';
|
|
32
|
+
|
|
33
|
+
export default function OtpInputSizes() {
|
|
34
|
+
return (
|
|
35
|
+
<Stack gap={5}>
|
|
36
|
+
<Field>
|
|
37
|
+
<FieldLabel>Dock PIN</FieldLabel>
|
|
38
|
+
<OtpInput length={4} size="sm" />
|
|
39
|
+
</Field>
|
|
40
|
+
<Field>
|
|
41
|
+
<FieldLabel>Delivery code</FieldLabel>
|
|
42
|
+
<OtpInput size="md" />
|
|
43
|
+
</Field>
|
|
44
|
+
<Field>
|
|
45
|
+
<FieldLabel>Return authorization</FieldLabel>
|
|
46
|
+
<OtpInput size="lg" />
|
|
47
|
+
</Field>
|
|
48
|
+
</Stack>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### How much frame each box shows
|
|
54
|
+
|
|
55
|
+
outline takes the ground it is placed on; subtle sinks into the page. The two steps a text field draws, with the same tokens, so a code under a text field in one form shares its frame.
|
|
56
|
+
|
|
57
|
+
Example
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
61
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
62
|
+
import { Stack } from '@slotted/react/stack';
|
|
63
|
+
|
|
64
|
+
export default function OtpInputVariants() {
|
|
65
|
+
return (
|
|
66
|
+
<Stack gap={5}>
|
|
67
|
+
<Field>
|
|
68
|
+
<FieldLabel>Outline</FieldLabel>
|
|
69
|
+
<OtpInput defaultValue="482" variant="outline" />
|
|
70
|
+
</Field>
|
|
71
|
+
<Field>
|
|
72
|
+
<FieldLabel>Subtle</FieldLabel>
|
|
73
|
+
<OtpInput defaultValue="482" variant="subtle" />
|
|
74
|
+
</Field>
|
|
75
|
+
</Stack>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Groups, separators and joined boxes
|
|
81
|
+
|
|
82
|
+
groups partitions the boxes the way the SMS is written — 482-915 — and attached joins the boxes of a group along one seam, which is how a PIN pad reads.
|
|
83
|
+
|
|
84
|
+
Example
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
88
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
89
|
+
import { Stack } from '@slotted/react/stack';
|
|
90
|
+
|
|
91
|
+
export default function OtpInputGroups() {
|
|
92
|
+
return (
|
|
93
|
+
<Stack gap={5}>
|
|
94
|
+
<Field>
|
|
95
|
+
<FieldLabel>Verification code</FieldLabel>
|
|
96
|
+
<OtpInput groups={[3, 3]} />
|
|
97
|
+
</Field>
|
|
98
|
+
<Field>
|
|
99
|
+
<FieldLabel>Backup code</FieldLabel>
|
|
100
|
+
<OtpInput attached groups={[4, 4]} length={8} type="alphanumeric" />
|
|
101
|
+
</Field>
|
|
102
|
+
<Field>
|
|
103
|
+
<FieldLabel>Dock PIN</FieldLabel>
|
|
104
|
+
<OtpInput attached length={4} />
|
|
105
|
+
</Field>
|
|
106
|
+
</Stack>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### What the code accepts
|
|
112
|
+
|
|
113
|
+
type decides the characters and the keyboard a phone offers; pattern outranks it per character; transform runs over every edit before the filter. What an edit loses is reported, so the page can say why nothing appeared.
|
|
114
|
+
|
|
115
|
+
Example
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { useState } from 'react';
|
|
119
|
+
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';
|
|
120
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
121
|
+
import { Stack } from '@slotted/react/stack';
|
|
122
|
+
|
|
123
|
+
const HINT = 'Letters and digits only. The printed G- prefix is dropped.';
|
|
124
|
+
|
|
125
|
+
export default function OtpInputTypes() {
|
|
126
|
+
const [hint, setHint] = useState(HINT);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Stack gap={5}>
|
|
130
|
+
<Field>
|
|
131
|
+
<FieldLabel>Backup code</FieldLabel>
|
|
132
|
+
<OtpInput length={8} type="alphanumeric" />
|
|
133
|
+
</Field>
|
|
134
|
+
<Field>
|
|
135
|
+
<FieldLabel>Scanner pairing code</FieldLabel>
|
|
136
|
+
<OtpInput pattern={/[0-9a-f]/i} />
|
|
137
|
+
<FieldDescription>Hexadecimal characters only.</FieldDescription>
|
|
138
|
+
</Field>
|
|
139
|
+
<Field>
|
|
140
|
+
<FieldLabel>Printed backup code</FieldLabel>
|
|
141
|
+
<OtpInput
|
|
142
|
+
length={8}
|
|
143
|
+
onRejected={(text) => setHint(`“${text}” is not part of the code.`)}
|
|
144
|
+
transform={(text) => text.replace(/^G-/i, '').toUpperCase()}
|
|
145
|
+
type="alphanumeric"
|
|
146
|
+
/>
|
|
147
|
+
<FieldDescription>{hint}</FieldDescription>
|
|
148
|
+
</Field>
|
|
149
|
+
</Stack>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### A code nobody should read over your shoulder
|
|
155
|
+
|
|
156
|
+
mask makes the control type="password": the platform treats the value as a secret — the screen reader counts characters instead of reading them — and each filled box shows a bullet.
|
|
157
|
+
|
|
158
|
+
Example
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';
|
|
162
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
163
|
+
|
|
164
|
+
export default function OtpInputMask() {
|
|
165
|
+
return (
|
|
166
|
+
<Field>
|
|
167
|
+
<FieldLabel>Authorization PIN</FieldLabel>
|
|
168
|
+
<OtpInput attached autoComplete="off" defaultValue="539" length={4} mask />
|
|
169
|
+
<FieldDescription>Required to release a held shipment.</FieldDescription>
|
|
170
|
+
</Field>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### The four states the frame paints
|
|
176
|
+
|
|
177
|
+
Invalid keeps its danger edge on every box while the ring says where the cursor is; read-only keeps full-strength ink and only its ground changes; disabled is muted to a measured color rather than faded, so a disabled form still says what it holds; a full code sets data-complete on the frame.
|
|
178
|
+
|
|
179
|
+
Example
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { Field, FieldDescription, FieldError, FieldLabel } from '@slotted/react/field';
|
|
183
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
184
|
+
import { Stack } from '@slotted/react/stack';
|
|
185
|
+
|
|
186
|
+
export default function OtpInputStates() {
|
|
187
|
+
return (
|
|
188
|
+
<Stack gap={5}>
|
|
189
|
+
<Field invalid>
|
|
190
|
+
<FieldLabel>Delivery code</FieldLabel>
|
|
191
|
+
<OtpInput defaultValue="482910" groups={[3, 3]} />
|
|
192
|
+
<FieldError>The code does not match the one sent to this phone.</FieldError>
|
|
193
|
+
</Field>
|
|
194
|
+
<Field readOnly>
|
|
195
|
+
<FieldLabel>Pickup code</FieldLabel>
|
|
196
|
+
<OtpInput defaultValue="482915" groups={[3, 3]} />
|
|
197
|
+
<FieldDescription>Issued with the shipment and fixed after that.</FieldDescription>
|
|
198
|
+
</Field>
|
|
199
|
+
<Field disabled>
|
|
200
|
+
<FieldLabel>Return authorization</FieldLabel>
|
|
201
|
+
<OtpInput defaultValue="48" groups={[3, 3]} />
|
|
202
|
+
<FieldDescription>Available once the carrier scans the parcel.</FieldDescription>
|
|
203
|
+
</Field>
|
|
204
|
+
</Stack>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### The sixth digit
|
|
210
|
+
|
|
211
|
+
onComplete fires the moment the value reaches length, once per value; autoSubmit calls requestSubmit() on the owning form in the same moment. A code edited into another full code reports again.
|
|
212
|
+
|
|
213
|
+
Excerpt — not a complete module
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<form action={verify}>
|
|
217
|
+
<OtpInput name="code" autoSubmit />
|
|
218
|
+
</form>;
|
|
219
|
+
|
|
220
|
+
// Or hold the value and react to it.
|
|
221
|
+
<OtpInput value={code} onValueChange={setCode} onComplete={verify} />;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Content the component did not choose
|
|
225
|
+
|
|
226
|
+
A value longer than the code is cut; a paste with hyphens and spaces keeps its digits; in a right-to-left page the boxes stay left-to-right, because a code is a number and a number does not mirror; and at 240 pixels the boxes give up width before the row overflows.
|
|
227
|
+
|
|
228
|
+
Excerpt — not a complete module
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
// "12-3456789" becomes "123456".
|
|
232
|
+
<OtpInput defaultValue="12-3456789" />;
|
|
233
|
+
|
|
234
|
+
// Paste "482-915": the hyphen is dropped and reported, the digits land.
|
|
235
|
+
<OtpInput onRejected={(text) => console.log(text)} />;
|
|
236
|
+
|
|
237
|
+
// The row is left-to-right whatever the page does.
|
|
238
|
+
<div dir="rtl">
|
|
239
|
+
<OtpInput groups={[3, 3]} />
|
|
240
|
+
</div>;
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### One entry in FormData
|
|
244
|
+
|
|
245
|
+
The control is one native input, so name and form work as they do on any input, a native reset restores defaultValue, and where the WebOTP API exists the code arrives from the SMS with reason "programmatic".
|
|
246
|
+
|
|
247
|
+
Excerpt — not a complete module
|
|
248
|
+
|
|
249
|
+
```tsx
|
|
250
|
+
<form onSubmit={submit}>
|
|
251
|
+
<OtpInput name="code" webOtp />
|
|
252
|
+
<Button type="submit">Verify</Button>
|
|
253
|
+
<Button type="reset" variant="ghost">
|
|
254
|
+
Clear
|
|
255
|
+
</Button>
|
|
256
|
+
</form>;
|
|
257
|
+
|
|
258
|
+
// new FormData(form).get('code') === '482915'
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### In a field, with a resend
|
|
262
|
+
|
|
263
|
+
The field names the control, describes it and carries its error; the resend is a button and a countdown the page owns, because OtpInput has no clock. The provider sets the length once for an application whose codes are all four digits.
|
|
264
|
+
|
|
265
|
+
Example
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
import { useEffect, useState } from 'react';
|
|
269
|
+
import { Button } from '@slotted/react/button';
|
|
270
|
+
import { Field, FieldDescription, FieldError, FieldLabel } from '@slotted/react/field';
|
|
271
|
+
import { Inline } from '@slotted/react/inline';
|
|
272
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
273
|
+
import { Stack } from '@slotted/react/stack';
|
|
274
|
+
import { Text } from '@slotted/react/typography';
|
|
275
|
+
|
|
276
|
+
const CODE = '482915';
|
|
277
|
+
|
|
278
|
+
export default function OtpInputComposition() {
|
|
279
|
+
const [error, setError] = useState('');
|
|
280
|
+
const [verified, setVerified] = useState(false);
|
|
281
|
+
const [seconds, setSeconds] = useState(30);
|
|
282
|
+
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
if (seconds === 0) return;
|
|
285
|
+
const timer = setTimeout(() => setSeconds(seconds - 1), 1000);
|
|
286
|
+
return () => clearTimeout(timer);
|
|
287
|
+
}, [seconds]);
|
|
288
|
+
|
|
289
|
+
const verify = (code: string) => {
|
|
290
|
+
const valid = code === CODE;
|
|
291
|
+
setVerified(valid);
|
|
292
|
+
setError(valid ? '' : 'That code is not valid. Check the SMS and try again.');
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const resend = () => {
|
|
296
|
+
setSeconds(30);
|
|
297
|
+
setError('');
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Stack gap={4}>
|
|
302
|
+
<Field invalid={error !== '' ? true : undefined} required size="lg">
|
|
303
|
+
<FieldLabel>Verification code</FieldLabel>
|
|
304
|
+
<OtpInput groups={[3, 3]} onComplete={verify} onValueChange={() => setError('')} />
|
|
305
|
+
<FieldDescription>
|
|
306
|
+
Sent to +1 206 •••-4821. In this example the code is 482915.
|
|
307
|
+
</FieldDescription>
|
|
308
|
+
<FieldError live="polite" reserve>
|
|
309
|
+
{error}
|
|
310
|
+
</FieldError>
|
|
311
|
+
</Field>
|
|
312
|
+
<Inline align="center" gap={3}>
|
|
313
|
+
<Button disabled={seconds > 0} onClick={resend} variant="ghost">
|
|
314
|
+
{seconds > 0 ? `Resend in 0:${String(seconds).padStart(2, '0')}` : 'Resend code'}
|
|
315
|
+
</Button>
|
|
316
|
+
{verified && (
|
|
317
|
+
<Text role="status" size="sm" tone="muted">
|
|
318
|
+
Phone number confirmed.
|
|
319
|
+
</Text>
|
|
320
|
+
)}
|
|
321
|
+
</Inline>
|
|
322
|
+
</Stack>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### One tab stop, every key the browser’s
|
|
328
|
+
|
|
329
|
+
Tab lands on one control. Arrows move the cursor across the boxes, Backspace and Delete edit, Shift+arrows select a range, Ctrl+A selects all, and typing on a full code replaces the selected character instead of being refused.
|
|
330
|
+
|
|
331
|
+
Excerpt — not a complete module
|
|
332
|
+
|
|
333
|
+
```tsx
|
|
334
|
+
// Inside the value there is always one character selected: the one in
|
|
335
|
+
// front of a collapsed cursor, the last one at the end of a full code. The
|
|
336
|
+
// next key replaces it. A cursor after the last character inserts.
|
|
337
|
+
<OtpInput defaultValue="482915" />;
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### controlled.tsx
|
|
341
|
+
|
|
342
|
+
Example
|
|
343
|
+
|
|
344
|
+
```tsx
|
|
345
|
+
import { useState } from 'react';
|
|
346
|
+
import { Button } from '@slotted/react/button';
|
|
347
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
348
|
+
import { Inline } from '@slotted/react/inline';
|
|
349
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
350
|
+
import { Stack } from '@slotted/react/stack';
|
|
351
|
+
import { Text } from '@slotted/react/typography';
|
|
352
|
+
|
|
353
|
+
export default function OtpInputControlled() {
|
|
354
|
+
const [code, setCode] = useState('');
|
|
355
|
+
const [completed, setCompleted] = useState('');
|
|
356
|
+
|
|
357
|
+
const fill = () => {
|
|
358
|
+
setCode('482915');
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const clear = () => {
|
|
362
|
+
setCode('');
|
|
363
|
+
setCompleted('');
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<Stack gap={4}>
|
|
368
|
+
<Field>
|
|
369
|
+
<FieldLabel>Delivery code</FieldLabel>
|
|
370
|
+
<OtpInput
|
|
371
|
+
groups={[3, 3]}
|
|
372
|
+
onComplete={setCompleted}
|
|
373
|
+
onValueChange={(next) => {
|
|
374
|
+
setCode(next);
|
|
375
|
+
setCompleted('');
|
|
376
|
+
}}
|
|
377
|
+
value={code}
|
|
378
|
+
/>
|
|
379
|
+
</Field>
|
|
380
|
+
<Inline gap={3}>
|
|
381
|
+
<Button onClick={fill} variant="ghost">
|
|
382
|
+
Fill 482915
|
|
383
|
+
</Button>
|
|
384
|
+
<Button onClick={clear} variant="ghost">
|
|
385
|
+
Clear
|
|
386
|
+
</Button>
|
|
387
|
+
</Inline>
|
|
388
|
+
<Text size="sm" tone="muted">
|
|
389
|
+
{completed === '' ? `${code.length} of 6 digits entered.` : `Complete: ${completed}.`}
|
|
390
|
+
</Text>
|
|
391
|
+
</Stack>
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### defaults.tsx
|
|
397
|
+
|
|
398
|
+
Example
|
|
399
|
+
|
|
400
|
+
```tsx
|
|
401
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
402
|
+
import { OtpInput, OtpInputDefaultsProvider } from '@slotted/react/otp-input';
|
|
403
|
+
import { Stack } from '@slotted/react/stack';
|
|
404
|
+
|
|
405
|
+
export default function OtpInputDefaults() {
|
|
406
|
+
return (
|
|
407
|
+
<OtpInputDefaultsProvider attached length={4} variant="subtle">
|
|
408
|
+
<Stack gap={5}>
|
|
409
|
+
<Field>
|
|
410
|
+
<FieldLabel>Dock PIN</FieldLabel>
|
|
411
|
+
<OtpInput />
|
|
412
|
+
</Field>
|
|
413
|
+
<Field>
|
|
414
|
+
<FieldLabel>Pallet seal code</FieldLabel>
|
|
415
|
+
<OtpInput attached={false} length={6} />
|
|
416
|
+
</Field>
|
|
417
|
+
</Stack>
|
|
418
|
+
</OtpInputDefaultsProvider>
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### forms.tsx
|
|
424
|
+
|
|
425
|
+
Example
|
|
426
|
+
|
|
427
|
+
```tsx
|
|
428
|
+
import { useState, type SubmitEvent } from 'react';
|
|
429
|
+
import { Button } from '@slotted/react/button';
|
|
430
|
+
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';
|
|
431
|
+
import { Inline } from '@slotted/react/inline';
|
|
432
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
433
|
+
import { Stack } from '@slotted/react/stack';
|
|
434
|
+
import { Text } from '@slotted/react/typography';
|
|
435
|
+
|
|
436
|
+
export default function OtpInputForms() {
|
|
437
|
+
const [sent, setSent] = useState('');
|
|
438
|
+
|
|
439
|
+
const submit = (event: SubmitEvent<HTMLFormElement>) => {
|
|
440
|
+
event.preventDefault();
|
|
441
|
+
setSent(String(new FormData(event.currentTarget).get('code')));
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
return (
|
|
445
|
+
<form onReset={() => setSent('')} onSubmit={submit}>
|
|
446
|
+
<Stack gap={4}>
|
|
447
|
+
<Field>
|
|
448
|
+
<FieldLabel>Verification code</FieldLabel>
|
|
449
|
+
<OtpInput autoSubmit groups={[3, 3]} name="code" webOtp />
|
|
450
|
+
<FieldDescription>The form submits when the sixth digit is typed.</FieldDescription>
|
|
451
|
+
</Field>
|
|
452
|
+
<Inline align="center" gap={3}>
|
|
453
|
+
<Button type="submit">Verify</Button>
|
|
454
|
+
<Button type="reset" variant="ghost">
|
|
455
|
+
Clear
|
|
456
|
+
</Button>
|
|
457
|
+
<Text size="sm" tone="muted">
|
|
458
|
+
{sent === '' ? 'Nothing sent.' : `code=${sent}`}
|
|
459
|
+
</Text>
|
|
460
|
+
</Inline>
|
|
461
|
+
</Stack>
|
|
462
|
+
</form>
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### placeholder.tsx
|
|
468
|
+
|
|
469
|
+
Example
|
|
470
|
+
|
|
471
|
+
```tsx
|
|
472
|
+
import { Field, FieldLabel } from '@slotted/react/field';
|
|
473
|
+
import { OtpInput } from '@slotted/react/otp-input';
|
|
474
|
+
import { Stack } from '@slotted/react/stack';
|
|
475
|
+
|
|
476
|
+
export default function OtpInputPlaceholder() {
|
|
477
|
+
return (
|
|
478
|
+
<Stack gap={5}>
|
|
479
|
+
<Field>
|
|
480
|
+
<FieldLabel>Delivery code</FieldLabel>
|
|
481
|
+
<OtpInput placeholder="0" />
|
|
482
|
+
</Field>
|
|
483
|
+
<Field>
|
|
484
|
+
<FieldLabel>Backup code</FieldLabel>
|
|
485
|
+
<OtpInput length={8} placeholder="A1B2C3D4" type="alphanumeric" />
|
|
486
|
+
</Field>
|
|
487
|
+
</Stack>
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
```
|