@passui/tanstack 0.0.0-stage → 0.2.0

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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -2
  3. package/package.json +165 -5
  4. package/src/auth-shell/auth-shell.tsx +26 -0
  5. package/src/auth-shell/index.ts +1 -0
  6. package/src/document/compose-viewport.tsx +96 -0
  7. package/src/document/index.ts +1 -0
  8. package/src/form-fields/fields.tsx +192 -0
  9. package/src/form-fields/index.ts +2 -0
  10. package/src/form-fields/selection.tsx +149 -0
  11. package/src/form-fields/submit.tsx +40 -0
  12. package/src/forms/contexts.ts +8 -0
  13. package/src/forms/elements/form-alert.tsx +30 -0
  14. package/src/forms/elements/submit.tsx +1 -0
  15. package/src/forms/fields/avatar-picker.tsx +399 -0
  16. package/src/forms/fields/avatar.tsx +299 -0
  17. package/src/forms/fields/checkbox.tsx +1 -0
  18. package/src/forms/fields/index.ts +32 -0
  19. package/src/forms/fields/input.tsx +1 -0
  20. package/src/forms/fields/multiselect.tsx +1 -0
  21. package/src/forms/fields/otp.tsx +1 -0
  22. package/src/forms/fields/radio-card.tsx +1 -0
  23. package/src/forms/fields/switch.tsx +1 -0
  24. package/src/forms/fields/textarea.tsx +1 -0
  25. package/src/forms/index.ts +30 -0
  26. package/src/mutation/index.ts +1 -0
  27. package/src/mutation/use-app-mutation.ts +156 -0
  28. package/src/route-boundary/default-boundary.tsx +61 -0
  29. package/src/route-boundary/default-loader.tsx +19 -0
  30. package/src/route-boundary/index.ts +3 -0
  31. package/src/route-boundary/not-founder.tsx +50 -0
  32. package/src/settings/index.ts +1 -0
  33. package/src/settings/setting-list.tsx +252 -0
  34. package/src/shared/index.ts +2 -0
  35. package/src/shared/optimistic.ts +7 -0
  36. package/src/shared/table.ts +30 -0
  37. package/src/solid/auth-shell/auth-shell.tsx +20 -0
  38. package/src/solid/auth-shell/index.ts +1 -0
  39. package/src/solid/document/compose-viewport.tsx +69 -0
  40. package/src/solid/document/index.ts +1 -0
  41. package/src/solid/form-fields/avatar.tsx +370 -0
  42. package/src/solid/form-fields/fields.tsx +336 -0
  43. package/src/solid/form-fields/index.ts +3 -0
  44. package/src/solid/form-fields/submit.tsx +31 -0
  45. package/src/solid/forms/contexts.ts +7 -0
  46. package/src/solid/forms/form-alert.tsx +19 -0
  47. package/src/solid/forms/index.ts +32 -0
  48. package/src/solid/mutation/index.ts +5 -0
  49. package/src/solid/mutation/use-app-mutation.ts +171 -0
  50. package/src/solid/route-boundary/boundaries.tsx +104 -0
  51. package/src/solid/route-boundary/index.ts +1 -0
  52. package/src/solid/settings/index.ts +1 -0
  53. package/src/solid/settings/setting-list.tsx +185 -0
  54. package/src/solid/styles.css +2 -0
  55. package/src/solid/tables/columns.tsx +40 -0
  56. package/src/solid/tables/data-table.tsx +448 -0
  57. package/src/solid/tables/filter-row.tsx +161 -0
  58. package/src/solid/tables/index.ts +4 -0
  59. package/src/solid/tables/pagination.tsx +78 -0
  60. package/src/styles.css +12 -0
  61. package/src/tables/columns.tsx +39 -0
  62. package/src/tables/data-table.tsx +617 -0
  63. package/src/tables/filter-row.tsx +260 -0
  64. package/src/tables/index.ts +3 -0
  65. package/src/tables/pagination.tsx +93 -0
  66. package/src/tables/utils.ts +5 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pherus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,77 @@
1
- # Temporary Holding Version
1
+ # @passui/tanstack
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional TanStack Form, Query, Table and Router integrations for Passui.
4
+ One package supports native React and native SolidJS through separate
5
+ entry points. Shared helpers have no UI runtime dependency.
6
+
7
+ ## SolidJS
8
+
9
+ ```bash
10
+ bunx @passui/cli@latest init --framework solid --integration tanstack
11
+ # Manual alternative
12
+ bun add @passui/solid @passui/tanstack solid-js tailwindcss @tanstack/solid-form @tanstack/solid-query @tanstack/solid-router @tanstack/solid-table
13
+ ```
14
+
15
+ ```css
16
+ @import "@passui/tanstack/solid/styles.css";
17
+ ```
18
+
19
+ ```ts
20
+ import { createAppForm } from "@passui/tanstack/solid/forms"
21
+ import { createAppMutation } from "@passui/tanstack/solid/mutation"
22
+ import { DataTable, selectColumn } from "@passui/tanstack/solid/tables"
23
+ import { ComposeViewport } from "@passui/tanstack/solid/document"
24
+ import { AuthShell } from "@passui/tanstack/solid/auth-shell"
25
+ import { SettingList } from "@passui/tanstack/solid/settings"
26
+ import { DefaultBoundary, DefaultLoader, NotFound } from "@passui/tanstack/solid/route-boundary"
27
+ ```
28
+
29
+ Solid form and mutation options are accessors: `createAppForm(() => ({
30
+ defaultValues, onSubmit }))` and `createAppMutation(() => ({ mutationFn }))`.
31
+ `useAppForm` and `useAppMutation` aliases are also exported. Field contexts
32
+ return an accessor; use `field().state.value`. Bound fields include input,
33
+ checkbox, textarea, switch, radioCard, multiselect, avatar and otp.
34
+ Mount Solid QueryClientProvider around mutation consumers.
35
+
36
+ Use SolidJS 1.9.17+ and compile this package's TSX through Solid. In Vite 8,
37
+ exclude `@passui/solid` and `@passui/tanstack` from `optimizeDeps`, include
38
+ `solid` in `resolve.conditions`, and put both packages plus
39
+ `/@tanstack\/solid-/` in `ssr.noExternal`. SSR conditions should include
40
+ `solid`, `module`, `node` and `development|production`. This compiles the
41
+ Solid framework source for the right server runtime. See the complete
42
+ config in `@passui/solid`'s README or use the generated starter.
43
+
44
+ ## React
45
+
46
+ ```bash
47
+ bunx @passui/cli@latest init --framework react --integration tanstack
48
+ ```
49
+
50
+ ```css
51
+ @import "@passui/tanstack/react/styles.css";
52
+ ```
53
+
54
+ React exports use `/react/forms`, `/react/form-fields`, `/react/mutation`,
55
+ `/react/tables`, `/react/document`, `/react/auth-shell`, `/react/settings`
56
+ and `/react/route-boundary`. Existing unprefixed paths, such as `/forms`,
57
+ remain React defaults. Existing `/styles.css` also remains available.
58
+
59
+ Starting at 0.2.0, framework dependencies are optional peers rather than
60
+ mandatory React dependencies. The CLI installs the appropriate peers
61
+ while preserving existing versions. Manual React setups must install the
62
+ React TanStack adapters they use; `/document` also imports TanStack React
63
+ devtools and their Query and Router panels. See package.json for supported
64
+ peer ranges. Solid consumers do not need React packages.
65
+
66
+ ## Shared core
67
+
68
+ `@passui/tanstack/core` exports framework independent table helpers and
69
+ `shouldRestoreOptimisticSnapshot`. Both mutation adapters preserve newer
70
+ concurrent cache writes when an older optimistic request fails.
71
+
72
+ The UI packages remain independent of this optional integration. Put
73
+ framework Scripts in ComposeViewport.Window's `after` slot, outside main.
74
+ Credentials stay outside this repository. Releases use the repository's
75
+ `publish.yml` workflow and the `npm-publish` environment with npm OIDC.
76
+
77
+ MIT.
package/package.json CHANGED
@@ -1,6 +1,166 @@
1
1
  {
2
- "name": "@passui/tanstack",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@passui/tanstack",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/phe-rus/passui.git",
9
+ "directory": "packages/tanstack"
10
+ },
11
+ "homepage": "https://passui.pherus.org/docs/installation",
12
+ "publishConfig": {
13
+ "registry": "https://registry.npmjs.org",
14
+ "access": "public"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "publish:check": "bun pm pack --dry-run",
25
+ "build": "tsc --noEmit"
26
+ },
27
+ "dependencies": {
28
+ "@hugeicons/core-free-icons": "^4.3.5"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^19.3.0",
32
+ "react-dom": "^19.3.0",
33
+ "@tanstack/react-query": "^5.104.0",
34
+ "tailwindcss": "^4.3.3",
35
+ "@hugeicons/react": "^1.1.10",
36
+ "@tanstack/react-devtools": "^0.10.13",
37
+ "@tanstack/react-form": "^1.33.5",
38
+ "@tanstack/react-query-devtools": "^5.104.0",
39
+ "@tanstack/react-router": "^1.170.39",
40
+ "@tanstack/react-router-devtools": "^1.167.2",
41
+ "@tanstack/react-table": "^9.2.4",
42
+ "motion": "^13.4.4",
43
+ "@passui/react": "^0.1.15",
44
+ "@passui/solid": "^0.1.0",
45
+ "solid-js": "^1.9.17",
46
+ "@tanstack/solid-form": "^1.33.5",
47
+ "@tanstack/solid-query": "^5.104.5",
48
+ "@tanstack/solid-router": "^1.170.43",
49
+ "@tanstack/solid-table": "^9.3.1"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^26.6.3",
53
+ "@types/react": "^19.3.0",
54
+ "@types/react-dom": "^19.3.0",
55
+ "tailwindcss": "^4.3.3",
56
+ "typescript": "^7.0.2",
57
+ "vitest": "5.0.5",
58
+ "vite": "8.3.5",
59
+ "@hugeicons/react": "^1.1.10",
60
+ "@tanstack/react-devtools": "^0.10.13",
61
+ "@tanstack/react-form": "^1.33.5",
62
+ "@tanstack/react-query-devtools": "^5.104.0",
63
+ "@tanstack/react-router": "^1.170.39",
64
+ "@tanstack/react-router-devtools": "^1.167.2",
65
+ "@tanstack/react-table": "^9.2.4",
66
+ "motion": "^13.4.4",
67
+ "@passui/react": "^0.1.15",
68
+ "@passui/solid": "^0.1.0",
69
+ "solid-js": "1.9.17",
70
+ "@tanstack/solid-form": "1.33.5",
71
+ "@tanstack/solid-query": "5.104.5",
72
+ "@tanstack/solid-router": "1.170.43",
73
+ "@tanstack/solid-table": "9.3.1",
74
+ "vite-plugin-solid": "2.11.14",
75
+ "react": "^19.3.0",
76
+ "react-dom": "^19.3.0",
77
+ "@tanstack/react-query": "^5.104.0"
78
+ },
79
+ "exports": {
80
+ "./forms": "./src/forms/index.ts",
81
+ "./form-fields": "./src/form-fields/index.ts",
82
+ "./tables": "./src/tables/index.ts",
83
+ "./document": "./src/document/index.ts",
84
+ "./auth-shell": "./src/auth-shell/index.ts",
85
+ "./settings": "./src/settings/index.ts",
86
+ "./mutation": "./src/mutation/index.ts",
87
+ "./route-boundary": "./src/route-boundary/index.ts",
88
+ "./styles.css": "./src/styles.css",
89
+ "./react/forms": "./src/forms/index.ts",
90
+ "./solid/forms": "./src/solid/forms/index.ts",
91
+ "./react/form-fields": "./src/form-fields/index.ts",
92
+ "./solid/form-fields": "./src/solid/form-fields/index.ts",
93
+ "./react/tables": "./src/tables/index.ts",
94
+ "./solid/tables": "./src/solid/tables/index.ts",
95
+ "./react/document": "./src/document/index.ts",
96
+ "./solid/document": "./src/solid/document/index.ts",
97
+ "./react/auth-shell": "./src/auth-shell/index.ts",
98
+ "./solid/auth-shell": "./src/solid/auth-shell/index.ts",
99
+ "./react/settings": "./src/settings/index.ts",
100
+ "./solid/settings": "./src/solid/settings/index.ts",
101
+ "./react/mutation": "./src/mutation/index.ts",
102
+ "./solid/mutation": "./src/solid/mutation/index.ts",
103
+ "./react/route-boundary": "./src/route-boundary/index.ts",
104
+ "./solid/route-boundary": "./src/solid/route-boundary/index.ts",
105
+ "./react/styles.css": "./src/styles.css",
106
+ "./solid/styles.css": "./src/solid/styles.css",
107
+ "./core": "./src/shared/index.ts"
108
+ },
109
+ "description": "TanStack form, table and router integrations for Passui.",
110
+ "peerDependenciesMeta": {
111
+ "react": {
112
+ "optional": true
113
+ },
114
+ "react-dom": {
115
+ "optional": true
116
+ },
117
+ "@tanstack/react-query": {
118
+ "optional": true
119
+ },
120
+ "@hugeicons/react": {
121
+ "optional": true
122
+ },
123
+ "@tanstack/react-devtools": {
124
+ "optional": true
125
+ },
126
+ "@tanstack/react-form": {
127
+ "optional": true
128
+ },
129
+ "@tanstack/react-query-devtools": {
130
+ "optional": true
131
+ },
132
+ "@tanstack/react-router": {
133
+ "optional": true
134
+ },
135
+ "@tanstack/react-router-devtools": {
136
+ "optional": true
137
+ },
138
+ "@tanstack/react-table": {
139
+ "optional": true
140
+ },
141
+ "motion": {
142
+ "optional": true
143
+ },
144
+ "@passui/react": {
145
+ "optional": true
146
+ },
147
+ "@passui/solid": {
148
+ "optional": true
149
+ },
150
+ "solid-js": {
151
+ "optional": true
152
+ },
153
+ "@tanstack/solid-form": {
154
+ "optional": true
155
+ },
156
+ "@tanstack/solid-query": {
157
+ "optional": true
158
+ },
159
+ "@tanstack/solid-router": {
160
+ "optional": true
161
+ },
162
+ "@tanstack/solid-table": {
163
+ "optional": true
164
+ }
165
+ }
166
+ }
@@ -0,0 +1,26 @@
1
+ import { Outlet, useLocation } from "@tanstack/react-router"
2
+ import type { ReactNode } from "react"
3
+
4
+ /**
5
+ * The frame for every page reached before or outside an app (sign in, create
6
+ * account, recovery, consent): no card, a soft light behind the page, the
7
+ * brand on top, content sliding in as you move through the flow. CSS
8
+ * animations only, so the page is never hidden waiting on JavaScript.
9
+ */
10
+ export function AuthShell({ brand }: { brand: ReactNode }) {
11
+ const { pathname } = useLocation()
12
+
13
+ return (
14
+ <section className="relative isolate flex min-h-dvh flex-col items-center justify-center px-4 py-12">
15
+ <div className="flex w-full max-w-[26rem] flex-col items-start gap-6">
16
+ {brand}
17
+ <div
18
+ key={pathname}
19
+ className="w-full motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-right-4 motion-safe:duration-500 motion-safe:ease-out"
20
+ >
21
+ <Outlet />
22
+ </div>
23
+ </div>
24
+ </section>
25
+ )
26
+ }
@@ -0,0 +1 @@
1
+ export * from "./auth-shell"
@@ -0,0 +1,96 @@
1
+ import { cn } from "@passui/react/cn"
2
+ import { TanStackDevtools } from "@tanstack/react-devtools"
3
+ import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools"
4
+ import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools"
5
+ import type {
6
+ ComponentPropsWithoutRef,
7
+ PropsWithChildren,
8
+ ReactNode,
9
+ } from "react"
10
+
11
+ /** Extra props (such as `data-theme`) land on `<html>` itself. */
12
+ type ComposeViewportProps = PropsWithChildren<
13
+ ComponentPropsWithoutRef<"html">
14
+ >
15
+
16
+ type WindowProps = ComponentPropsWithoutRef<"body"> & {
17
+ /**
18
+ * Rendered as direct `<body>` children, after `<main>`, not inside it.
19
+ * `<Scripts />` (and devtools) belong here — TanStack Router's own docs
20
+ * say `<Scripts />` "should be placed near the end of the document
21
+ * body", not nested inside the app's content wrapper.
22
+ */
23
+ after?: ReactNode
24
+ }
25
+
26
+ export function ComposeViewport({
27
+ children,
28
+ lang = "en",
29
+ className,
30
+ ...props
31
+ }: ComposeViewportProps) {
32
+ return (
33
+ <html
34
+ lang={lang}
35
+ className={cn("antialiased blur-none", className)}
36
+ suppressHydrationWarning
37
+ {...props}
38
+ >
39
+ {children}
40
+ </html>
41
+ )
42
+ }
43
+
44
+ function Window({
45
+ className,
46
+ children,
47
+ after,
48
+ ...props
49
+ }: WindowProps) {
50
+ return (
51
+ <body
52
+ className={cn(
53
+ "fixed h-svh w-full min-w-full bg-background",
54
+ "overflow-x-hidden selection:bg-olive-500/15",
55
+ "typeset wrap-anywhere duration-200",
56
+ "flex flex-col",
57
+ className
58
+ )}
59
+ {...props}
60
+ >
61
+ <main
62
+ className={cn(
63
+ "flex flex-col flex-1 min-h-svh overflow-auto",
64
+ "no-scrollbar"
65
+ )}
66
+ >
67
+ {children}
68
+ </main>
69
+ {after}
70
+ </body>
71
+ )
72
+ }
73
+
74
+ function Devtools() {
75
+ return (
76
+ <TanStackDevtools
77
+ config={{
78
+ triggerMode: "floating",
79
+ position: "top-right",
80
+ }}
81
+ plugins={[
82
+ {
83
+ name: "TanStack Query",
84
+ render: <ReactQueryDevtoolsPanel />,
85
+ },
86
+ {
87
+ name: "Tanstack Router",
88
+ render: <TanStackRouterDevtoolsPanel />,
89
+ },
90
+ ]}
91
+ />
92
+ )
93
+ }
94
+
95
+ ComposeViewport.Window = Window
96
+ ComposeViewport.Devtools = Devtools
@@ -0,0 +1 @@
1
+ export * from "./compose-viewport"
@@ -0,0 +1,192 @@
1
+ import {
2
+ TextField,
3
+ type TextFieldProps,
4
+ } from "@passui/react/text-field"
5
+ import { TextEditor } from "@passui/react/text-editor"
6
+ import { Toggle } from "@passui/react/toggle"
7
+ import { useFieldContext } from "../forms/contexts"
8
+ import {
9
+ createContext,
10
+ useContext,
11
+ type ComponentProps,
12
+ type ReactNode,
13
+ } from "react"
14
+
15
+ export const PeachFieldLabels = createContext<
16
+ { show: string; hide: string } | undefined
17
+ >(undefined)
18
+
19
+ export function FieldInput(
20
+ props: Omit<
21
+ TextFieldProps,
22
+ "value" | "onChange" | "onBlur" | "name"
23
+ >
24
+ ) {
25
+ const field = useFieldContext<string>()
26
+ const revealLabels = useContext(PeachFieldLabels)
27
+ return (
28
+ <TextField
29
+ revealLabels={revealLabels}
30
+ {...props}
31
+ name={field.name}
32
+ value={field.state.value}
33
+ onChange={(event) =>
34
+ field.handleChange(event.target.value)
35
+ }
36
+ onBlur={field.handleBlur}
37
+ errors={
38
+ field.state.meta.isTouched
39
+ ? field.state.meta.errors.flatMap(
40
+ (error) =>
41
+ error?.message
42
+ ? [error.message]
43
+ : []
44
+ )
45
+ : []
46
+ }
47
+ />
48
+ )
49
+ }
50
+
51
+ export function FieldCheckbox({ label }: { label: string }) {
52
+ const field = useFieldContext<boolean>()
53
+ return (
54
+ <Toggle
55
+ style="checkbox"
56
+ label={label}
57
+ checked={field.state.value}
58
+ onChange={(checked) => {
59
+ field.handleChange(checked)
60
+ field.handleBlur()
61
+ }}
62
+ />
63
+ )
64
+ }
65
+
66
+ export function FieldSwitch({
67
+ label,
68
+ description,
69
+ disabled,
70
+ }: {
71
+ label: string
72
+ description?: string
73
+ disabled?: boolean
74
+ }) {
75
+ const field = useFieldContext<boolean>()
76
+ return (
77
+ <div className="flex items-center justify-between gap-4">
78
+ <div className="text-subheadline">
79
+ {label}
80
+ {description && (
81
+ <p className="text-footnote text-label-secondary">
82
+ {description}
83
+ </p>
84
+ )}
85
+ </div>
86
+ <Toggle
87
+ label={label}
88
+ checked={field.state.value}
89
+ disabled={disabled}
90
+ onChange={(checked) => {
91
+ field.handleChange(checked)
92
+ field.handleBlur()
93
+ }}
94
+ />
95
+ </div>
96
+ )
97
+ }
98
+
99
+ export function FieldTextarea({
100
+ label,
101
+ icon,
102
+ ...props
103
+ }: ComponentProps<"textarea"> & {
104
+ label: string
105
+ icon?: ReactNode
106
+ }) {
107
+ const field = useFieldContext<string>()
108
+ const errors = field.state.meta.isTouched
109
+ ? field.state.meta.errors.flatMap((error) =>
110
+ error?.message ? [error.message] : []
111
+ )
112
+ : []
113
+ return (
114
+ <div className="flex flex-col gap-2">
115
+ <label
116
+ htmlFor={field.name}
117
+ className="text-subheadline font-semibold"
118
+ >
119
+ {icon}
120
+ {label}
121
+ </label>
122
+ <TextEditor
123
+ {...props}
124
+ id={field.name}
125
+ name={field.name}
126
+ aria-invalid={errors.length > 0}
127
+ aria-describedby={
128
+ errors.length
129
+ ? `${field.name}-errors`
130
+ : undefined
131
+ }
132
+ value={field.state.value}
133
+ onBlur={field.handleBlur}
134
+ onChange={(event) =>
135
+ field.handleChange(event.target.value)
136
+ }
137
+ />
138
+ {errors.length > 0 && (
139
+ <p
140
+ id={`${field.name}-errors`}
141
+ role="alert"
142
+ className="text-footnote text-danger"
143
+ >
144
+ {Array.from(new Set(errors)).join(". ")}
145
+ </p>
146
+ )}
147
+ </div>
148
+ )
149
+ }
150
+
151
+ export function FieldOtp({
152
+ label,
153
+ maxLength = 6,
154
+ onComplete,
155
+ }: {
156
+ label: string
157
+ maxLength?: number
158
+ onComplete?: (value: string) => void
159
+ }) {
160
+ const field = useFieldContext<string>()
161
+ return (
162
+ <TextField
163
+ label={label}
164
+ name={field.name}
165
+ value={field.state.value}
166
+ inputMode="numeric"
167
+ autoComplete="one-time-code"
168
+ pattern="[0-9]*"
169
+ maxLength={maxLength}
170
+ autoFocus
171
+ onBlur={field.handleBlur}
172
+ onChange={(event) => {
173
+ const code = event.target.value
174
+ .replace(/\D/g, "")
175
+ .slice(0, maxLength)
176
+ field.handleChange(code)
177
+ if (code.length === maxLength)
178
+ onComplete?.(code)
179
+ }}
180
+ errors={
181
+ field.state.meta.isTouched
182
+ ? field.state.meta.errors.flatMap(
183
+ (error) =>
184
+ error?.message
185
+ ? [error.message]
186
+ : []
187
+ )
188
+ : []
189
+ }
190
+ />
191
+ )
192
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../forms/index"
2
+ export { PeachFieldLabels } from "./fields"