@passui/tanstack 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +52 -2
- package/package.json +65 -5
- package/src/auth-shell/auth-shell.tsx +26 -0
- package/src/auth-shell/index.ts +1 -0
- package/src/document/compose-viewport.tsx +96 -0
- package/src/document/index.ts +1 -0
- package/src/form-fields/fields.tsx +192 -0
- package/src/form-fields/index.ts +2 -0
- package/src/form-fields/selection.tsx +149 -0
- package/src/form-fields/submit.tsx +40 -0
- package/src/forms/contexts.ts +8 -0
- package/src/forms/elements/form-alert.tsx +30 -0
- package/src/forms/elements/submit.tsx +1 -0
- package/src/forms/fields/avatar-picker.tsx +399 -0
- package/src/forms/fields/avatar.tsx +299 -0
- package/src/forms/fields/checkbox.tsx +1 -0
- package/src/forms/fields/index.ts +32 -0
- package/src/forms/fields/input.tsx +1 -0
- package/src/forms/fields/multiselect.tsx +1 -0
- package/src/forms/fields/otp.tsx +1 -0
- package/src/forms/fields/radio-card.tsx +1 -0
- package/src/forms/fields/switch.tsx +1 -0
- package/src/forms/fields/textarea.tsx +1 -0
- package/src/forms/index.ts +30 -0
- package/src/mutation/index.ts +1 -0
- package/src/mutation/use-app-mutation.ts +160 -0
- package/src/route-boundary/default-boundary.tsx +61 -0
- package/src/route-boundary/default-loader.tsx +19 -0
- package/src/route-boundary/index.ts +3 -0
- package/src/route-boundary/not-founder.tsx +50 -0
- package/src/settings/index.ts +1 -0
- package/src/settings/setting-list.tsx +252 -0
- package/src/styles.css +12 -0
- package/src/tables/columns.tsx +39 -0
- package/src/tables/data-table.tsx +617 -0
- package/src/tables/filter-row.tsx +260 -0
- package/src/tables/index.ts +3 -0
- package/src/tables/pagination.tsx +93 -0
- package/src/tables/utils.ts +35 -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,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Passui TanStack integrations
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional TanStack Form, Table and Router integrations for Passui's native
|
|
4
|
+
React controls. Passui itself works without this package.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
bun add @passui/react @passui/tanstack @tanstack/react-query
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Use React 19 and Tailwind CSS 4. Import this stylesheet once; it includes
|
|
13
|
+
Passui's styles:
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
@import "@passui/tanstack/styles.css";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Import an integration from its own entry point:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { useAppForm } from "@passui/tanstack/forms"
|
|
23
|
+
import { useAppMutation } from "@passui/tanstack/mutation"
|
|
24
|
+
import { ComposeViewport } from "@passui/tanstack/document"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The package exports TypeScript and TSX source. Your app's bundler must
|
|
28
|
+
process those files and its stylesheet through Tailwind CSS 4. Query
|
|
29
|
+
integrations use your app's QueryClientProvider.
|
|
30
|
+
|
|
31
|
+
## Publishing
|
|
32
|
+
|
|
33
|
+
From the Pherus checkout:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bun run typecheck
|
|
37
|
+
bun run test
|
|
38
|
+
bun run publish:check
|
|
39
|
+
bun publish
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Publish the matching Passui version first. Bun resolves the local
|
|
43
|
+
`workspace:^` dependency to a public version range when packing. Login
|
|
44
|
+
with an npm account that can publish under `@passui`. Credentials stay in
|
|
45
|
+
your user npm configuration.
|
|
46
|
+
|
|
47
|
+
The Passui repository's `publish.yml` GitHub Actions workflow uses
|
|
48
|
+
the `npm-publish` environment and npm OIDC authentication. Its trusted
|
|
49
|
+
publisher must reference `phe-rus/passui`.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@passui/tanstack",
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
+
"@hugeicons/react": "^1.1.10",
|
|
30
|
+
"@tanstack/react-devtools": "^0.10.13",
|
|
31
|
+
"@tanstack/react-form": "^1.33.5",
|
|
32
|
+
"@tanstack/react-query-devtools": "^5.104.0",
|
|
33
|
+
"@tanstack/react-router": "^1.170.39",
|
|
34
|
+
"@tanstack/react-router-devtools": "^1.167.2",
|
|
35
|
+
"@tanstack/react-table": "^9.2.4",
|
|
36
|
+
"motion": "^13.4.4",
|
|
37
|
+
"@passui/react": "^0.1.14"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^19.3.0",
|
|
41
|
+
"react-dom": "^19.3.0",
|
|
42
|
+
"@tanstack/react-query": "^5.104.0",
|
|
43
|
+
"tailwindcss": "^4.3.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^26.6.3",
|
|
47
|
+
"@types/react": "^19.3.0",
|
|
48
|
+
"@types/react-dom": "^19.3.0",
|
|
49
|
+
"tailwindcss": "^4.3.3",
|
|
50
|
+
"typescript": "^7.0.2",
|
|
51
|
+
"vitest": "5.0.5",
|
|
52
|
+
"vite": "8.3.5"
|
|
53
|
+
},
|
|
54
|
+
"exports": {
|
|
55
|
+
"./forms": "./src/forms/index.ts",
|
|
56
|
+
"./form-fields": "./src/form-fields/index.ts",
|
|
57
|
+
"./tables": "./src/tables/index.ts",
|
|
58
|
+
"./document": "./src/document/index.ts",
|
|
59
|
+
"./auth-shell": "./src/auth-shell/index.ts",
|
|
60
|
+
"./settings": "./src/settings/index.ts",
|
|
61
|
+
"./mutation": "./src/mutation/index.ts",
|
|
62
|
+
"./route-boundary": "./src/route-boundary/index.ts",
|
|
63
|
+
"./styles.css": "./src/styles.css"
|
|
64
|
+
},
|
|
65
|
+
"description": "TanStack form, table and router integrations for Passui."
|
|
66
|
+
}
|
|
@@ -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,149 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
import { cn } from "@passui/react/cn"
|
|
3
|
+
import { Toggle } from "@passui/react/toggle"
|
|
4
|
+
import { useFieldContext } from "../forms/contexts"
|
|
5
|
+
|
|
6
|
+
type Option = {
|
|
7
|
+
label: string
|
|
8
|
+
value: string
|
|
9
|
+
description?: string
|
|
10
|
+
icon?: ReactNode
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function FieldRadioCard({
|
|
15
|
+
label,
|
|
16
|
+
description,
|
|
17
|
+
options,
|
|
18
|
+
disabled,
|
|
19
|
+
columns = 1,
|
|
20
|
+
}: {
|
|
21
|
+
label: string
|
|
22
|
+
description?: string
|
|
23
|
+
options: Option[]
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
columns?: 1 | 2
|
|
26
|
+
}) {
|
|
27
|
+
const field = useFieldContext<string>()
|
|
28
|
+
return (
|
|
29
|
+
<fieldset
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
className="flex flex-col gap-2"
|
|
32
|
+
>
|
|
33
|
+
<legend className="text-subheadline font-semibold">
|
|
34
|
+
{label}
|
|
35
|
+
</legend>
|
|
36
|
+
{description && (
|
|
37
|
+
<p className="text-footnote text-label-secondary">
|
|
38
|
+
{description}
|
|
39
|
+
</p>
|
|
40
|
+
)}
|
|
41
|
+
<div
|
|
42
|
+
className={cn(
|
|
43
|
+
"grid gap-2",
|
|
44
|
+
columns === 2 && "md:grid-cols-2"
|
|
45
|
+
)}
|
|
46
|
+
>
|
|
47
|
+
{options.map((option) => (
|
|
48
|
+
<label
|
|
49
|
+
key={option.value}
|
|
50
|
+
className={cn(
|
|
51
|
+
"flex items-start gap-3 rounded-xl border p-3",
|
|
52
|
+
field.state.value === option.value
|
|
53
|
+
? "border-accent-text bg-accent/10"
|
|
54
|
+
: "border-separator bg-elevated",
|
|
55
|
+
(disabled || option.disabled) &&
|
|
56
|
+
"opacity-40"
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
<input
|
|
60
|
+
type="radio"
|
|
61
|
+
name={field.name}
|
|
62
|
+
value={option.value}
|
|
63
|
+
checked={
|
|
64
|
+
field.state.value ===
|
|
65
|
+
option.value
|
|
66
|
+
}
|
|
67
|
+
disabled={option.disabled}
|
|
68
|
+
onBlur={field.handleBlur}
|
|
69
|
+
onChange={() =>
|
|
70
|
+
field.handleChange(
|
|
71
|
+
option.value
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
className="mt-1 accent-accent-text"
|
|
75
|
+
/>
|
|
76
|
+
{option.icon}
|
|
77
|
+
<span className="text-subheadline">
|
|
78
|
+
{option.label}
|
|
79
|
+
{option.description && (
|
|
80
|
+
<span className="block text-footnote text-label-secondary">
|
|
81
|
+
{option.description}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</span>
|
|
85
|
+
</label>
|
|
86
|
+
))}
|
|
87
|
+
</div>
|
|
88
|
+
</fieldset>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function FieldMultiselect({
|
|
93
|
+
label,
|
|
94
|
+
description,
|
|
95
|
+
options,
|
|
96
|
+
}: {
|
|
97
|
+
label: string
|
|
98
|
+
description?: string
|
|
99
|
+
options: Option[]
|
|
100
|
+
}) {
|
|
101
|
+
const field = useFieldContext<string[]>()
|
|
102
|
+
return (
|
|
103
|
+
<fieldset className="flex flex-col gap-3">
|
|
104
|
+
<legend className="text-subheadline font-semibold">
|
|
105
|
+
{label}
|
|
106
|
+
</legend>
|
|
107
|
+
{description && (
|
|
108
|
+
<p className="text-footnote text-label-secondary">
|
|
109
|
+
{description}
|
|
110
|
+
</p>
|
|
111
|
+
)}
|
|
112
|
+
{options.map((option) => (
|
|
113
|
+
<div key={option.value}>
|
|
114
|
+
<Toggle
|
|
115
|
+
style="checkbox"
|
|
116
|
+
label={option.label}
|
|
117
|
+
disabled={option.disabled}
|
|
118
|
+
checked={field.state.value.includes(
|
|
119
|
+
option.value
|
|
120
|
+
)}
|
|
121
|
+
onChange={(checked) => {
|
|
122
|
+
field.handleChange(
|
|
123
|
+
checked
|
|
124
|
+
? Array.from(
|
|
125
|
+
new Set([
|
|
126
|
+
...field.state
|
|
127
|
+
.value,
|
|
128
|
+
option.value,
|
|
129
|
+
])
|
|
130
|
+
)
|
|
131
|
+
: field.state.value.filter(
|
|
132
|
+
(value) =>
|
|
133
|
+
value !==
|
|
134
|
+
option.value
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
field.handleBlur()
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
{option.description && (
|
|
141
|
+
<p className="pl-8 text-footnote text-label-secondary">
|
|
142
|
+
{option.description}
|
|
143
|
+
</p>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
))}
|
|
147
|
+
</fieldset>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Button } from "@passui/react/button"
|
|
2
|
+
import { useFormContext } from "../forms/contexts"
|
|
3
|
+
|
|
4
|
+
export function Submit({ label }: { label: string }) {
|
|
5
|
+
const form = useFormContext()
|
|
6
|
+
return (
|
|
7
|
+
<form.Subscribe
|
|
8
|
+
selector={(state) => [
|
|
9
|
+
state.isSubmitting,
|
|
10
|
+
state.canSubmit,
|
|
11
|
+
state.isDirty,
|
|
12
|
+
state.isTouched,
|
|
13
|
+
]}
|
|
14
|
+
>
|
|
15
|
+
{([pending, valid, dirty, touched]) => (
|
|
16
|
+
<Button
|
|
17
|
+
type="submit"
|
|
18
|
+
variant="default"
|
|
19
|
+
size="default"
|
|
20
|
+
aria-busy={pending}
|
|
21
|
+
disabled={
|
|
22
|
+
pending ||
|
|
23
|
+
!valid ||
|
|
24
|
+
!dirty ||
|
|
25
|
+
!touched
|
|
26
|
+
}
|
|
27
|
+
className="w-full"
|
|
28
|
+
>
|
|
29
|
+
{pending && (
|
|
30
|
+
<span
|
|
31
|
+
aria-hidden
|
|
32
|
+
className="size-4 animate-spin rounded-full border-2 border-current border-r-transparent"
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
{label}
|
|
36
|
+
</Button>
|
|
37
|
+
)}
|
|
38
|
+
</form.Subscribe>
|
|
39
|
+
)
|
|
40
|
+
}
|