@passui/tanstack 0.2.7 → 0.3.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 (139) hide show
  1. package/dist/{types/src/auth-shell → auth-shell}/auth-shell.d.ts +3 -3
  2. package/dist/auth-shell/auth-shell.js +17 -0
  3. package/dist/auth-shell.d.ts +2 -0
  4. package/dist/auth-shell.js +1 -0
  5. package/dist/core.d.ts +3 -0
  6. package/dist/core.js +3 -0
  7. package/dist/{types/src/document → document}/compose-viewport.d.ts +11 -11
  8. package/dist/document/compose-viewport.js +43 -0
  9. package/dist/document.d.ts +2 -0
  10. package/dist/document.js +1 -0
  11. package/dist/form-fields/fields.d.ts +30 -0
  12. package/dist/form-fields/fields.js +160 -0
  13. package/dist/form-fields/selection.d.ts +21 -0
  14. package/dist/form-fields/selection.js +73 -0
  15. package/dist/form-fields/submit.d.ts +3 -0
  16. package/dist/form-fields/submit.js +26 -0
  17. package/dist/form-fields.d.ts +7 -0
  18. package/dist/form-fields.js +7 -0
  19. package/dist/forms/contexts.js +4 -0
  20. package/dist/{types/src/forms → forms}/elements/form-alert.d.ts +4 -4
  21. package/dist/forms/elements/form-alert.js +19 -0
  22. package/dist/forms/fields/avatar-picker.d.ts +10 -0
  23. package/dist/forms/fields/avatar-picker.js +228 -0
  24. package/dist/forms/fields/avatar.d.ts +30 -0
  25. package/dist/forms/fields/avatar.js +188 -0
  26. package/dist/forms/fields/checkbox.d.ts +2 -0
  27. package/dist/forms/fields/index.d.ts +21 -0
  28. package/dist/forms/fields/index.js +15 -0
  29. package/dist/forms/fields/input.d.ts +2 -0
  30. package/dist/forms/fields/multiselect.d.ts +2 -0
  31. package/dist/forms/fields/otp.d.ts +2 -0
  32. package/dist/forms/fields/radio-card.d.ts +2 -0
  33. package/dist/forms/fields/switch.d.ts +2 -0
  34. package/dist/forms/fields/textarea.d.ts +2 -0
  35. package/dist/forms.d.ts +45 -0
  36. package/dist/forms.js +16 -0
  37. package/dist/mutation/use-app-mutation.d.ts +23 -0
  38. package/dist/mutation/use-app-mutation.js +41 -0
  39. package/dist/mutation.d.ts +3 -0
  40. package/dist/mutation.js +3 -0
  41. package/dist/route-boundary/default-boundary.d.ts +2 -0
  42. package/dist/route-boundary/default-boundary.js +40 -0
  43. package/dist/route-boundary/default-loader.d.ts +6 -0
  44. package/dist/route-boundary/default-loader.js +17 -0
  45. package/dist/{types/src/route-boundary → route-boundary}/not-founder.d.ts +2 -2
  46. package/dist/route-boundary/not-founder.js +44 -0
  47. package/dist/route-boundary.d.ts +4 -0
  48. package/dist/route-boundary.js +4 -0
  49. package/dist/settings/setting-list.d.ts +51 -0
  50. package/dist/settings/setting-list.js +122 -0
  51. package/dist/settings.d.ts +2 -0
  52. package/dist/settings.js +1 -0
  53. package/dist/{types/src/shared → shared}/optimistic.d.ts +2 -2
  54. package/dist/shared/optimistic.js +16 -0
  55. package/dist/{types/src/shared → shared}/table.d.ts +7 -7
  56. package/dist/shared/table.js +12 -0
  57. package/dist/tables/columns.d.ts +3 -0
  58. package/dist/tables/columns.js +21 -0
  59. package/dist/tables/data-table.d.ts +76 -0
  60. package/dist/tables/data-table.js +307 -0
  61. package/dist/tables/filter-row.js +137 -0
  62. package/dist/tables/pagination.d.ts +8 -0
  63. package/dist/tables/pagination.js +86 -0
  64. package/dist/tables.d.ts +4 -0
  65. package/dist/tables.js +4 -0
  66. package/package.json +129 -128
  67. package/src/styles.css +1 -0
  68. package/dist/types/src/auth-shell/index.d.ts +0 -1
  69. package/dist/types/src/document/index.d.ts +0 -1
  70. package/dist/types/src/form-fields/fields.d.ts +0 -24
  71. package/dist/types/src/form-fields/index.d.ts +0 -2
  72. package/dist/types/src/form-fields/selection.d.ts +0 -21
  73. package/dist/types/src/form-fields/submit.d.ts +0 -3
  74. package/dist/types/src/forms/contexts.d.ts +0 -1
  75. package/dist/types/src/forms/elements/submit.d.ts +0 -1
  76. package/dist/types/src/forms/fields/avatar-picker.d.ts +0 -30
  77. package/dist/types/src/forms/fields/avatar.d.ts +0 -30
  78. package/dist/types/src/forms/fields/checkbox.d.ts +0 -1
  79. package/dist/types/src/forms/fields/index.d.ts +0 -21
  80. package/dist/types/src/forms/fields/input.d.ts +0 -1
  81. package/dist/types/src/forms/fields/multiselect.d.ts +0 -1
  82. package/dist/types/src/forms/fields/otp.d.ts +0 -1
  83. package/dist/types/src/forms/fields/radio-card.d.ts +0 -1
  84. package/dist/types/src/forms/fields/switch.d.ts +0 -1
  85. package/dist/types/src/forms/fields/textarea.d.ts +0 -1
  86. package/dist/types/src/forms/index.d.ts +0 -41
  87. package/dist/types/src/mutation/index.d.ts +0 -1
  88. package/dist/types/src/mutation/use-app-mutation.d.ts +0 -22
  89. package/dist/types/src/route-boundary/default-boundary.d.ts +0 -2
  90. package/dist/types/src/route-boundary/default-loader.d.ts +0 -6
  91. package/dist/types/src/route-boundary/index.d.ts +0 -3
  92. package/dist/types/src/settings/index.d.ts +0 -1
  93. package/dist/types/src/settings/setting-list.d.ts +0 -51
  94. package/dist/types/src/shared/index.d.ts +0 -2
  95. package/dist/types/src/tables/columns.d.ts +0 -3
  96. package/dist/types/src/tables/data-table.d.ts +0 -76
  97. package/dist/types/src/tables/filter-row.d.ts +0 -9
  98. package/dist/types/src/tables/index.d.ts +0 -3
  99. package/dist/types/src/tables/pagination.d.ts +0 -8
  100. package/dist/types/src/tables/utils.d.ts +0 -1
  101. package/src/auth-shell/auth-shell.tsx +0 -16
  102. package/src/auth-shell/index.ts +0 -1
  103. package/src/document/compose-viewport.tsx +0 -80
  104. package/src/document/index.ts +0 -1
  105. package/src/form-fields/fields.tsx +0 -147
  106. package/src/form-fields/index.ts +0 -2
  107. package/src/form-fields/selection.tsx +0 -109
  108. package/src/form-fields/submit.tsx +0 -35
  109. package/src/forms/contexts.ts +0 -4
  110. package/src/forms/elements/form-alert.tsx +0 -21
  111. package/src/forms/elements/submit.tsx +0 -1
  112. package/src/forms/fields/avatar-picker.tsx +0 -319
  113. package/src/forms/fields/avatar.tsx +0 -269
  114. package/src/forms/fields/checkbox.tsx +0 -1
  115. package/src/forms/fields/index.ts +0 -29
  116. package/src/forms/fields/input.tsx +0 -1
  117. package/src/forms/fields/multiselect.tsx +0 -1
  118. package/src/forms/fields/otp.tsx +0 -1
  119. package/src/forms/fields/radio-card.tsx +0 -1
  120. package/src/forms/fields/switch.tsx +0 -1
  121. package/src/forms/fields/textarea.tsx +0 -1
  122. package/src/forms/index.ts +0 -26
  123. package/src/mutation/index.ts +0 -1
  124. package/src/mutation/use-app-mutation.ts +0 -100
  125. package/src/route-boundary/default-boundary.tsx +0 -46
  126. package/src/route-boundary/default-loader.tsx +0 -23
  127. package/src/route-boundary/index.ts +0 -3
  128. package/src/route-boundary/not-founder.tsx +0 -39
  129. package/src/settings/index.ts +0 -1
  130. package/src/settings/setting-list.tsx +0 -223
  131. package/src/shared/index.ts +0 -2
  132. package/src/shared/optimistic.ts +0 -19
  133. package/src/shared/table.ts +0 -12
  134. package/src/tables/columns.tsx +0 -30
  135. package/src/tables/data-table.tsx +0 -524
  136. package/src/tables/filter-row.tsx +0 -196
  137. package/src/tables/index.ts +0 -3
  138. package/src/tables/pagination.tsx +0 -85
  139. package/src/tables/utils.ts +0 -5
@@ -1,319 +0,0 @@
1
- import { Camera01Icon, Delete02Icon, Image01Icon, TextFontIcon } from "@hugeicons/core-free-icons"
2
- import { HugeiconsIcon } from "@hugeicons/react"
3
- import { useEffect, useRef, useState } from "react"
4
- import type { ReactNode } from "react"
5
- import {
6
- ProfileImage,
7
- ProfileImageFallback,
8
- ProfileImageContent,
9
- } from "@passui/react/profile-image"
10
- import { Button } from "@passui/react/button"
11
- import { Sheet } from "@passui/react/sheet"
12
- import { createPortal } from "react-dom"
13
- import { cn } from "@passui/react/cn"
14
- import { Ambient } from "@passui/react/ambient"
15
-
16
- export type AvatarPickerLabels = {
17
- photo: string
18
- photoDescription: string
19
- choosePhoto: string
20
- takePhoto: string
21
- capture: string
22
- monogram: string
23
- removePhoto: string
24
- cancel: string
25
- }
26
-
27
- type AvatarPickerProps = {
28
- open: boolean
29
- onOpenChange: (open: boolean) => void
30
- label: string
31
- image?: string
32
- clearable: boolean
33
- labels: AvatarPickerLabels
34
- onChooseFile: () => void
35
- /** A captured frame, still to be framed in Move and Scale. */
36
- onCapture: (file: File) => void
37
- /** A finished image that needs no framing, like a monogram. */
38
- onChoose: (file: File) => void
39
- onRemove: () => void
40
- }
41
-
42
- type CameraViewProps = {
43
- labels: AvatarPickerLabels
44
- onCapture: (file: File) => void
45
- onCancel: () => void
46
- }
47
-
48
- type OptionProps = {
49
- icon: typeof Image01Icon
50
- tone?: "default" | "destructive"
51
- onClick: () => void
52
- children: ReactNode
53
- }
54
-
55
- // Apple's contact monogram gradients
56
- const MONOGRAM_GRADIENTS = [
57
- ["#A1A1A6", "#6E6E73"],
58
- ["#FF9F0A", "#FF6A00"],
59
- ["#FF6482", "#FF2D55"],
60
- ["#BF5AF2", "#8944E3"],
61
- ["#64D2FF", "#0A84FF"],
62
- ["#34C759", "#0FA958"],
63
- ] as const
64
-
65
- function initialsOf(label: string) {
66
- const parts = label.trim().split(/\s+/).filter(Boolean)
67
- const letters = parts.length > 1 ? [parts[0], parts[parts.length - 1]] : parts
68
- return letters.map((part) => part[0]?.toUpperCase() ?? "").join("") || "?"
69
- }
70
-
71
- async function toFile(canvas: HTMLCanvasElement, name: string, type: string) {
72
- const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, type, 0.92))
73
- if (!blob) throw new Error("Could not export the image")
74
- return new File([blob], name, { type })
75
- }
76
-
77
- async function renderMonogram(initials: string, [from, to]: readonly [string, string]) {
78
- const size = 512
79
- const canvas = document.createElement("canvas")
80
- canvas.width = size
81
- canvas.height = size
82
- const context = canvas.getContext("2d")
83
- if (!context) throw new Error("Canvas is not available")
84
- const gradient = context.createLinearGradient(0, 0, 0, size)
85
- gradient.addColorStop(0, from)
86
- gradient.addColorStop(1, to)
87
- context.fillStyle = gradient
88
- context.fillRect(0, 0, size, size)
89
- context.fillStyle = "#fff"
90
- context.textAlign = "center"
91
- context.textBaseline = "middle"
92
- context.font = `600 ${initials.length > 1 ? 196 : 232}px -apple-system, "SF Pro Rounded", "SF Pro Display", system-ui, sans-serif`
93
- context.fillText(initials, size / 2, size / 2 + 12)
94
- return toFile(canvas, "monogram.png", "image/png")
95
- }
96
-
97
- function Option({ icon, tone = "default", onClick, children }: OptionProps) {
98
- return (
99
- <button
100
- type="button"
101
- onClick={onClick}
102
- className={cn(
103
- "flex w-full items-center gap-3 px-4 py-3 text-left text-subheadline transition-colors",
104
- "hover:bg-foreground/[0.04] focus-visible:bg-foreground/[0.06] focus-visible:outline-none",
105
- tone === "destructive" && "text-destructive"
106
- )}
107
- >
108
- <HugeiconsIcon icon={icon} className="size-4.5 shrink-0 opacity-80" />
109
- {children}
110
- </button>
111
- )
112
- }
113
-
114
- /** The live selfie view: the frame under a circle, an iOS shutter below. */
115
- function CameraView({ labels, onCapture, onCancel }: CameraViewProps) {
116
- const videoRef = useRef<HTMLVideoElement>(null)
117
- const [failed, setFailed] = useState(false)
118
-
119
- useEffect(() => {
120
- let stream: MediaStream | null = null
121
- navigator.mediaDevices
122
- .getUserMedia({
123
- video: {
124
- facingMode: "user",
125
- width: 1280,
126
- height: 1280,
127
- },
128
- })
129
- .then((media) => {
130
- stream = media
131
- if (videoRef.current) videoRef.current.srcObject = media
132
- })
133
- .catch(() => setFailed(true))
134
- return () => {
135
- for (const track of stream?.getTracks() ?? []) track.stop()
136
- }
137
- }, [])
138
-
139
- async function capture() {
140
- const video = videoRef.current
141
- if (!video?.videoWidth) return
142
- const canvas = document.createElement("canvas")
143
- canvas.width = video.videoWidth
144
- canvas.height = video.videoHeight
145
- const context = canvas.getContext("2d")
146
- if (!context) return
147
- // the preview is mirrored like a mirror; keep the photo matching it
148
- context.translate(canvas.width, 0)
149
- context.scale(-1, 1)
150
- context.drawImage(video, 0, 0)
151
- onCapture(await toFile(canvas, "photo.jpg", "image/jpeg"))
152
- }
153
-
154
- return (
155
- <div className="flex flex-col items-center gap-5 bg-neutral-950 px-5 pt-8 pb-6">
156
- <div className="relative size-64 overflow-hidden rounded-full ring-1 ring-white/20">
157
- {failed ? (
158
- <div className="flex size-full items-center justify-center p-8 text-center text-caption text-white/70">
159
- {labels.takePhoto}
160
- </div>
161
- ) : (
162
- <video
163
- ref={videoRef}
164
- autoPlay
165
- playsInline
166
- muted
167
- className="size-full -scale-x-100 object-cover"
168
- />
169
- )}
170
- </div>
171
- <div className="grid w-full grid-cols-3 items-center">
172
- <Button
173
- type="button"
174
- variant="ghost"
175
- size="sm"
176
- className="justify-self-start text-white hover:bg-white/10 hover:text-white"
177
- onClick={onCancel}
178
- >
179
- {labels.cancel}
180
- </Button>
181
- <button
182
- type="button"
183
- aria-label={labels.capture}
184
- disabled={failed}
185
- onClick={() => void capture()}
186
- className="size-16 justify-self-center rounded-full border-4 border-white p-1 transition-transform active:scale-95 disabled:opacity-40"
187
- >
188
- <span className="block size-full rounded-full bg-white" />
189
- </button>
190
- </div>
191
- </div>
192
- )
193
- }
194
-
195
- /**
196
- * The photo sheet Apple shows for a contact photo: the current photo lit by
197
- * its own colors, then the ways to change it.
198
- */
199
- export function AvatarPicker({
200
- open,
201
- onOpenChange,
202
- label,
203
- image,
204
- clearable,
205
- labels,
206
- onChooseFile,
207
- onCapture,
208
- onChoose,
209
- onRemove,
210
- }: AvatarPickerProps) {
211
- const [mode, setMode] = useState<"menu" | "camera">("menu")
212
- const [monogramOpen, setMonogramOpen] = useState(false)
213
- const [canUseCamera, setCanUseCamera] = useState(false)
214
- const initials = initialsOf(label)
215
-
216
- useEffect(() => {
217
- setCanUseCamera(Boolean(navigator.mediaDevices?.getUserMedia))
218
- }, [])
219
-
220
- useEffect(() => {
221
- if (!open) {
222
- setMode("menu")
223
- setMonogramOpen(false)
224
- }
225
- }, [open])
226
-
227
- if (typeof document === "undefined") return null
228
- return createPortal(
229
- <Sheet
230
- open={open}
231
- onClose={() => onOpenChange(false)}
232
- label={mode === "camera" ? labels.takePhoto : labels.photo}
233
- className="gap-0 overflow-hidden rounded-3xl p-0 sm:max-w-[22rem]"
234
- >
235
- {mode === "camera" ? (
236
- <>
237
- <h2 className="sr-only">{labels.takePhoto}</h2>
238
- <CameraView
239
- labels={labels}
240
- onCapture={onCapture}
241
- onCancel={() => setMode("menu")}
242
- />
243
- </>
244
- ) : (
245
- <>
246
- <Ambient
247
- src={image}
248
- className="flex flex-col items-center gap-3 px-5 pt-8 pb-6 text-center"
249
- >
250
- <ProfileImage className="size-28 shadow-[0_12px_32px_-12px_rgb(0_0_0/0.45)] ring-1 ring-white/50">
251
- <ProfileImageContent src={image} alt={label} />
252
- <ProfileImageFallback className="text-title">
253
- {initials}
254
- </ProfileImageFallback>
255
- </ProfileImage>
256
- <div className="flex flex-col gap-0.5">
257
- <h2>{labels.photo}</h2>
258
- <p>{labels.photoDescription}</p>
259
- </div>
260
- </Ambient>
261
-
262
- <div className="m-3 flex flex-col divide-y divide-border/40 overflow-hidden rounded-2xl border border-border/35 bg-card shadow-xs">
263
- <Option icon={Image01Icon} onClick={onChooseFile}>
264
- {labels.choosePhoto}
265
- </Option>
266
- {canUseCamera && (
267
- <Option icon={Camera01Icon} onClick={() => setMode("camera")}>
268
- {labels.takePhoto}
269
- </Option>
270
- )}
271
- <Option
272
- icon={TextFontIcon}
273
- onClick={() => setMonogramOpen((current) => !current)}
274
- >
275
- {labels.monogram}
276
- </Option>
277
- {monogramOpen && (
278
- <div className="flex items-center justify-between gap-2 px-4 py-3">
279
- {MONOGRAM_GRADIENTS.map((gradient) => (
280
- <button
281
- key={gradient[0]}
282
- type="button"
283
- aria-label={`${labels.monogram} ${gradient[0]}`}
284
- onClick={() =>
285
- void renderMonogram(initials, gradient).then(onChoose)
286
- }
287
- className="flex size-10 items-center justify-center rounded-full text-subheadline font-semibold text-white shadow-xs ring-1 ring-black/5 transition-transform hover:scale-105 active:scale-95"
288
- style={{
289
- backgroundImage: `linear-gradient(${gradient[0]}, ${gradient[1]})`,
290
- }}
291
- >
292
- {initials}
293
- </button>
294
- ))}
295
- </div>
296
- )}
297
- {clearable && image && (
298
- <Option icon={Delete02Icon} tone="destructive" onClick={onRemove}>
299
- {labels.removePhoto}
300
- </Option>
301
- )}
302
- </div>
303
-
304
- <div className="px-3 pb-3">
305
- <Button
306
- type="button"
307
- variant="secondary"
308
- className="w-full rounded-2xl"
309
- onClick={() => onOpenChange(false)}
310
- >
311
- {labels.cancel}
312
- </Button>
313
- </div>
314
- </>
315
- )}
316
- </Sheet>,
317
- document.body
318
- )
319
- }
@@ -1,269 +0,0 @@
1
- import {
2
- ProfileImage,
3
- ProfileImageFallback,
4
- ProfileImageContent,
5
- } from "@passui/react/profile-image"
6
- import { HugeiconsIcon } from "@hugeicons/react"
7
- import { Delete02Icon } from "@hugeicons/core-free-icons"
8
- import { Button } from "@passui/react/button"
9
- import { useFieldContext } from "../contexts"
10
- import { useEffect, useRef, useState } from "react"
11
- import type { DragEvent, ReactNode } from "react"
12
- import { cn } from "@passui/react/cn"
13
- import { Ambient } from "@passui/react/ambient"
14
- import { AvatarPicker } from "./avatar-picker"
15
- import type { AvatarPickerLabels } from "./avatar-picker"
16
-
17
- // A field's value has three real states, not two: `null` (untouched, keep
18
- // whatever's already there), a `File` (a new one was picked), and `false`
19
- // (explicitly cleared, distinct from untouched — only reachable when
20
- // `clearable` is on). The submitting form reads this to decide whether to
21
- // upload a new file, send an explicit clear, or omit the field entirely.
22
- export type FieldAvatarValue = File | null | false
23
-
24
- export type FieldAvatarLabels = AvatarPickerLabels & {
25
- edit: string
26
- remove: string
27
- /** Shown under a picked photo until it's kept or dropped. */
28
- confirmHint: string
29
- save: string
30
- }
31
-
32
- type FieldAvatarProps = {
33
- /** Compact identity row for account settings. */
34
- compact?: boolean
35
- existingImage?: string | null
36
- label: string
37
- accept?: string
38
- /** Offer removing the image once there is one. Off by default: a
39
- * personal avatar usually just gets replaced, not cleared to nothing. */
40
- clearable?: boolean
41
- /** Sit the photo in a surface lit by its own colors, with this under it. */
42
- caption?: ReactNode
43
- /** For a translated UI; English otherwise. */
44
- labels?: Partial<FieldAvatarLabels>
45
- }
46
-
47
- const DEFAULT_LABELS: FieldAvatarLabels = {
48
- edit: "Edit",
49
- remove: "Remove",
50
- confirmHint: "Press Enter to use this photo, Esc to cancel",
51
- save: "Use photo",
52
- cancel: "Cancel",
53
- photo: "Photo",
54
- photoDescription: "Choose how you appear.",
55
- choosePhoto: "Choose Photo…",
56
- takePhoto: "Take Photo",
57
- capture: "Take photo",
58
- monogram: "Monogram",
59
- removePhoto: "Remove Photo",
60
- }
61
-
62
- const imageFrom = (files: FileList | null | undefined) =>
63
- [...(files ?? [])].find((file) => file.type.startsWith("image/")) ?? null
64
-
65
- /**
66
- * A photo you click to replace: a small menu (choose, take, monogram), then
67
- * the new image shows in place and Enter keeps it (Esc drops it); no cropping dialog.
68
- */
69
- export function FieldAvatar({
70
- compact = false,
71
- existingImage,
72
- label,
73
- accept = "image/png,image/webp,image/jpeg,image/svg+xml",
74
- clearable = false,
75
- caption,
76
- labels,
77
- }: FieldAvatarProps) {
78
- const text = { ...DEFAULT_LABELS, ...labels }
79
- const field = useFieldContext<FieldAvatarValue>()
80
- const fileInputRef = useRef<HTMLInputElement>(null)
81
- const [pending, setPending] = useState<File | null>(null)
82
- const [sheetOpen, setSheetOpen] = useState(false)
83
- const [dragOver, setDragOver] = useState(false)
84
- const [preview, setPreview] = useState<string | null>(null)
85
- const isCleared = field.state.value === false
86
- const shown = pending ?? field.state.value
87
-
88
- useEffect(() => {
89
- if (!(shown instanceof File)) {
90
- setPreview(null)
91
- return
92
- }
93
- const url = URL.createObjectURL(shown)
94
- setPreview(url)
95
- return () => URL.revokeObjectURL(url)
96
- }, [shown])
97
-
98
- // while a picked photo waits, Enter keeps it and Escape drops it
99
- useEffect(() => {
100
- if (!pending) return
101
- const onKey = (event: KeyboardEvent) => {
102
- if (event.key === "Enter") {
103
- event.preventDefault()
104
- keep()
105
- }
106
- if (event.key === "Escape") setPending(null)
107
- }
108
- window.addEventListener("keydown", onKey)
109
- return () => window.removeEventListener("keydown", onKey)
110
- })
111
-
112
- function keep() {
113
- if (!pending) return
114
- field.handleChange(pending)
115
- setPending(null)
116
- }
117
-
118
- const currentImage = isCleared ? undefined : (preview ?? existingImage ?? undefined)
119
- const canClear = clearable && !pending && !isCleared && Boolean(currentImage)
120
-
121
- function onDrop(event: DragEvent<HTMLButtonElement>) {
122
- event.preventDefault()
123
- setDragOver(false)
124
- const file = imageFrom(event.dataTransfer.files)
125
- if (file) setPending(file)
126
- }
127
-
128
- const photo = (
129
- <div className="flex w-fit flex-col items-center gap-3">
130
- <button
131
- type="button"
132
- onClick={() => setSheetOpen(true)}
133
- onDragOver={(event) => {
134
- event.preventDefault()
135
- setDragOver(true)
136
- }}
137
- onDragLeave={() => setDragOver(false)}
138
- onDrop={onDrop}
139
- onPaste={(event) => {
140
- const file = imageFrom(event.clipboardData.files)
141
- if (file) setPending(file)
142
- }}
143
- className={cn(
144
- "group relative rounded-full outline-none",
145
- "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
146
- )}
147
- aria-label={`${text.edit} ${label}`}
148
- >
149
- <ProfileImage
150
- className={cn(
151
- "relative ring-1 ring-white/40",
152
- compact ? "size-16!" : "size-43!",
153
- caption && !compact && "shadow-[0_16px_40px_-16px_rgb(0_0_0/0.5)]",
154
- "transition-transform duration-300 ease-out group-hover:scale-[1.02] group-active:scale-[0.98]",
155
- (dragOver || pending) && "scale-[1.04]"
156
- )}
157
- >
158
- <ProfileImageContent
159
- src={currentImage}
160
- alt={label}
161
- className="object-cover transition-[filter] duration-300 group-hover:brightness-90"
162
- />
163
- <ProfileImageFallback className={compact ? "text-title3" : "text-large-title"}>
164
- {(label.charAt(0) || "?").toUpperCase()}
165
- </ProfileImageFallback>
166
- </ProfileImage>
167
- {/* the frosted "Edit" capsule sitting on the photo's lower edge */}
168
- {!pending && (
169
- <span
170
- className={cn(
171
- "absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full px-3 py-1",
172
- "bg-black/35 text-caption font-medium text-white backdrop-blur-md",
173
- "opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-focus-visible:opacity-100",
174
- dragOver && "opacity-100"
175
- )}
176
- >
177
- {text.edit}
178
- </span>
179
- )}
180
- </button>
181
- {pending && (
182
- <div className="flex flex-col items-center gap-2 animate-in fade-in-0 slide-in-from-top-1 duration-300">
183
- <p className="text-muted-foreground">{text.confirmHint}</p>
184
- <div className="flex items-center gap-1">
185
- <Button
186
- type="button"
187
- variant="ghost"
188
- size="sm"
189
- onClick={() => setPending(null)}
190
- >
191
- {text.cancel}
192
- </Button>
193
- <Button variant="default" type="button" size="sm" onClick={keep}>
194
- {text.save}
195
- </Button>
196
- </div>
197
- </div>
198
- )}
199
- {canClear && !caption && (
200
- <Button
201
- type="button"
202
- variant="ghost"
203
- size="sm"
204
- className="text-muted-foreground"
205
- onClick={() => field.handleChange(false)}
206
- >
207
- <HugeiconsIcon icon={Delete02Icon} />
208
- {text.remove}
209
- </Button>
210
- )}
211
- </div>
212
- )
213
-
214
- return (
215
- <>
216
- {compact ? (
217
- <div className="flex min-w-0 flex-wrap items-center gap-4">
218
- {photo}
219
- {!pending && caption}
220
- </div>
221
- ) : caption ? (
222
- <Ambient
223
- src={currentImage}
224
- className="flex w-full flex-col items-center gap-4 pt-6 pb-2 text-center"
225
- >
226
- {photo}
227
- {!pending && caption}
228
- </Ambient>
229
- ) : (
230
- photo
231
- )}
232
- <input
233
- ref={fileInputRef}
234
- type="file"
235
- accept={accept}
236
- className="hidden"
237
- onChange={(e) => {
238
- const file = e.target.files?.[0]
239
- e.target.value = ""
240
- if (file) setPending(file)
241
- }}
242
- />
243
- <AvatarPicker
244
- open={sheetOpen}
245
- onOpenChange={setSheetOpen}
246
- label={label}
247
- image={currentImage}
248
- clearable={clearable}
249
- labels={text}
250
- onChooseFile={() => {
251
- setSheetOpen(false)
252
- fileInputRef.current?.click()
253
- }}
254
- onCapture={(file) => {
255
- setSheetOpen(false)
256
- setPending(file)
257
- }}
258
- onChoose={(file) => {
259
- setSheetOpen(false)
260
- field.handleChange(file)
261
- }}
262
- onRemove={() => {
263
- setSheetOpen(false)
264
- field.handleChange(false)
265
- }}
266
- />
267
- </>
268
- )
269
- }
@@ -1 +0,0 @@
1
- export { FieldCheckbox } from "../../form-fields/fields"
@@ -1,29 +0,0 @@
1
- import {
2
- FieldInput,
3
- FieldCheckbox,
4
- FieldTextarea,
5
- FieldSwitch,
6
- FieldOtp,
7
- } from "../../form-fields/fields"
8
- import { FieldRadioCard, FieldMultiselect } from "../../form-fields/selection"
9
- import { FieldAvatar } from "./avatar"
10
-
11
- export const fields = {
12
- input: FieldInput,
13
- checkbox: FieldCheckbox,
14
- textarea: FieldTextarea,
15
- switch: FieldSwitch,
16
- radioCard: FieldRadioCard,
17
- multiselect: FieldMultiselect,
18
- avatar: FieldAvatar,
19
- otp: FieldOtp,
20
- }
21
-
22
- export * from "./input"
23
- export * from "./checkbox"
24
- export * from "./textarea"
25
- export * from "./switch"
26
- export * from "./radio-card"
27
- export * from "./multiselect"
28
- export * from "./avatar"
29
- export * from "./otp"
@@ -1 +0,0 @@
1
- export { FieldInput } from "../../form-fields/fields"
@@ -1 +0,0 @@
1
- export { FieldMultiselect } from "../../form-fields/selection"
@@ -1 +0,0 @@
1
- export { FieldOtp } from "../../form-fields/fields"
@@ -1 +0,0 @@
1
- export { FieldRadioCard } from "../../form-fields/selection"
@@ -1 +0,0 @@
1
- export { FieldSwitch } from "../../form-fields/fields"
@@ -1 +0,0 @@
1
- export { FieldTextarea } from "../../form-fields/fields"
@@ -1,26 +0,0 @@
1
- import { createFormHook, useSelector, useStore } from "@tanstack/react-form"
2
- import { fieldContext, formContext } from "./contexts"
3
- import { Submit } from "./elements/submit"
4
- import { fields } from "./fields/index"
5
-
6
- export const { useAppForm, withForm } = createFormHook({
7
- fieldComponents: {
8
- ...fields,
9
- },
10
- formComponents: {
11
- submit: Submit,
12
- },
13
- fieldContext,
14
- formContext,
15
- })
16
-
17
- // for reading another field's live value from within a form — e.g. a
18
- // radioCard whose options depend on what's currently selected elsewhere in
19
- // the same form — without subscribing the whole component to every field
20
- export { useSelector, useStore }
21
-
22
- // field prop/value types (e.g. FieldAvatarValue), for a caller that needs to
23
- // type a value it hands to a field before the form itself is submitted
24
- export * from "./fields/index"
25
-
26
- export { FormAlert } from "./elements/form-alert"
@@ -1 +0,0 @@
1
- export * from "./use-app-mutation"