@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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/package.json +65 -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 +160 -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/styles.css +12 -0
  35. package/src/tables/columns.tsx +39 -0
  36. package/src/tables/data-table.tsx +617 -0
  37. package/src/tables/filter-row.tsx +260 -0
  38. package/src/tables/index.ts +3 -0
  39. package/src/tables/pagination.tsx +93 -0
  40. package/src/tables/utils.ts +35 -0
@@ -0,0 +1,252 @@
1
+ import {
2
+ IconButton,
3
+ type IconButtonSize,
4
+ } from "@passui/react/icon-button"
5
+ import {
6
+ ArrowRight01Icon,
7
+ Copy01Icon,
8
+ Tick02Icon,
9
+ } from "@hugeicons/core-free-icons"
10
+ import { HugeiconsIcon } from "@hugeicons/react"
11
+ import { cn } from "@passui/react/cn"
12
+ import { Link } from "@tanstack/react-router"
13
+ import type { LinkProps } from "@tanstack/react-router"
14
+ import type { ReactNode } from "react"
15
+ import { useState } from "react"
16
+
17
+ type SettingListProps = {
18
+ id?: string
19
+ /** h3 when the list sits inside an Area that already has the h2. */
20
+ as?: "h2" | "h3"
21
+ /** A Glyph beside the heading; rows themselves stay plain. */
22
+ icon?: ReactNode
23
+ title?: string
24
+ description?: string
25
+ /** Right of the heading: an Add button, or a Coming soon badge. */
26
+ action?: ReactNode
27
+ /** "tile": the rounded, lifted card of the account app's overview. */
28
+ variant?: "inset" | "tile"
29
+ children: ReactNode
30
+ className?: string
31
+ }
32
+
33
+ type RowProps = {
34
+ icon?: ReactNode
35
+ title: ReactNode
36
+ description?: ReactNode
37
+ /** The current value, muted on the right, like "On" or an email. */
38
+ value?: ReactNode
39
+ trailing?: ReactNode
40
+ to?: LinkProps["to"]
41
+ params?: LinkProps["params"]
42
+ hash?: string
43
+ onClick?: () => void
44
+ /** Show the chevron without a destination, for a preview row. */
45
+ chevron?: boolean
46
+ tone?: "default" | "destructive"
47
+ }
48
+
49
+ /**
50
+ * A titled group of settings in one inset card, hairlines between rows
51
+ * (even rows wrapped in a Preview), a soft highlight under the one you point at.
52
+ */
53
+ export function SettingList({
54
+ id,
55
+ as: Heading = "h2",
56
+ icon,
57
+ title,
58
+ description,
59
+ action,
60
+ variant = "inset",
61
+ children,
62
+ className,
63
+ }: SettingListProps) {
64
+ const lines = cn(
65
+ "[&>*+*]:border-t [&>*+*]:border-border/40",
66
+ "[&_.setting-row+.setting-row]:border-t [&_.setting-row+.setting-row]:border-border/40"
67
+ )
68
+
69
+ // the account app's tile: the heading lives inside the card, on a tinted band
70
+ if (variant === "tile")
71
+ return (
72
+ <section
73
+ id={id}
74
+ className={cn(
75
+ "flex scroll-mt-24 flex-col overflow-hidden rounded-3xl border border-separator/70 bg-elevated shadow-sm",
76
+ className
77
+ )}
78
+ >
79
+ {title && (
80
+ <div className="flex items-center gap-3 border-b border-separator/60 px-4 py-4 sm:px-5 [&>span:first-child]:size-9 [&>span:first-child_.glyph]:size-4">
81
+ {icon}
82
+ <div className="flex min-w-0 flex-1 flex-col">
83
+ <Heading className="text-base">
84
+ {title}
85
+ </Heading>
86
+ {description && (
87
+ <p className="text-[13px] text-muted-foreground">
88
+ {description}
89
+ </p>
90
+ )}
91
+ </div>
92
+ {action}
93
+ </div>
94
+ )}
95
+ <div
96
+ className={cn(
97
+ "flex flex-col py-1 [&_.setting-row]:min-h-16 [&_.setting-row]:px-4 sm:[&_.setting-row]:px-5 [&_.setting-row_h3]:text-subheadline [&_.setting-row_p]:text-footnote",
98
+ lines
99
+ )}
100
+ >
101
+ {children}
102
+ </div>
103
+ </section>
104
+ )
105
+
106
+ return (
107
+ <section
108
+ id={id}
109
+ className={cn(
110
+ "flex scroll-mt-20 flex-col gap-3",
111
+ "[&>div:last-child]:rounded-2xl [&>div:last-child]:shadow-xs",
112
+ "[&>div:first-child_h2]:text-subheadline [&>div:first-child_h2]:font-semibold",
113
+ "[&>div:first-child_p]:text-footnote [&>div:first-child_p]:text-label-secondary",
114
+ "[&_.setting-row]:min-h-16 [&_.setting-row]:px-4 [&_.setting-row]:py-3",
115
+ "[&_.setting-row_h3]:whitespace-normal [&_.setting-row_h3]:wrap-anywhere [&_.setting-row_h3]:text-subheadline",
116
+ "[&_.setting-row_p]:wrap-anywhere [&_.setting-row_p]:text-footnote [&_.setting-row_p]:text-label-secondary",
117
+ "[&_.setting-row>span]:whitespace-normal [&_.setting-row>span]:wrap-anywhere",
118
+ className
119
+ )}
120
+ >
121
+ {title && (
122
+ <div className="flex flex-wrap items-start justify-between gap-3">
123
+ <div className="flex min-w-0 flex-1 items-start gap-3">
124
+ {icon}
125
+ <div className="min-w-0 wrap-anywhere">
126
+ <Heading>{title}</Heading>
127
+ {description && (
128
+ <p className="text-sm">
129
+ {description}
130
+ </p>
131
+ )}
132
+ </div>
133
+ </div>
134
+ {action}
135
+ </div>
136
+ )}
137
+ <div
138
+ className={cn(
139
+ "flex flex-col overflow-hidden rounded-xl border border-border/35 bg-card shadow-xs",
140
+ lines
141
+ )}
142
+ >
143
+ {children}
144
+ </div>
145
+ </section>
146
+ )
147
+ }
148
+
149
+ function Row({
150
+ icon,
151
+ title,
152
+ description,
153
+ value,
154
+ trailing,
155
+ to,
156
+ params,
157
+ hash,
158
+ onClick,
159
+ chevron,
160
+ tone = "default",
161
+ }: RowProps) {
162
+ const interactive = Boolean(to || onClick)
163
+ const className = cn(
164
+ "setting-row flex min-h-10 w-full items-center gap-3 px-3.5 py-1.5 text-left",
165
+ interactive &&
166
+ "cursor-pointer transition-colors hover:bg-foreground/[0.035] focus-visible:bg-foreground/[0.05] focus-visible:outline-none",
167
+ tone === "destructive" && "[&_h3]:text-destructive"
168
+ )
169
+ const body = (
170
+ <>
171
+ {icon}
172
+ <span className="flex min-w-0 flex-1 flex-col">
173
+ <h3 className="truncate text-sm">{title}</h3>
174
+ {description && (
175
+ <p className="text-xs">{description}</p>
176
+ )}
177
+ </span>
178
+ {value && (
179
+ <span className="max-w-[45%] truncate text-sm text-muted-foreground">
180
+ {value}
181
+ </span>
182
+ )}
183
+ {trailing}
184
+ {(chevron ?? interactive) && (
185
+ <HugeiconsIcon
186
+ icon={ArrowRight01Icon}
187
+ className="size-4 shrink-0 text-muted-foreground/60"
188
+ />
189
+ )}
190
+ </>
191
+ )
192
+
193
+ if (to) {
194
+ return (
195
+ <Link
196
+ to={to}
197
+ params={params}
198
+ hash={hash}
199
+ className={className}
200
+ >
201
+ {body}
202
+ </Link>
203
+ )
204
+ }
205
+ if (onClick) {
206
+ return (
207
+ <button
208
+ type="button"
209
+ onClick={onClick}
210
+ className={className}
211
+ >
212
+ {body}
213
+ </button>
214
+ )
215
+ }
216
+ return <div className={className}>{body}</div>
217
+ }
218
+
219
+ /** A row's trailing copy button; shows a tick for a moment after copying. */
220
+ function Copy({
221
+ value,
222
+ label = "Copy",
223
+ size = "icon-xs",
224
+ }: {
225
+ value: string
226
+ label?: string
227
+ /** Quiet and row-sized by default; any of Passui's icon sizes. */
228
+ size?: IconButtonSize
229
+ }) {
230
+ const [copied, setCopied] = useState(false)
231
+ return (
232
+ <IconButton
233
+ variant="ghost"
234
+ size={size}
235
+ label={label}
236
+ onClick={async (event) => {
237
+ event.stopPropagation()
238
+ await navigator.clipboard.writeText(value)
239
+ setCopied(true)
240
+ setTimeout(() => setCopied(false), 1500)
241
+ }}
242
+ >
243
+ <HugeiconsIcon
244
+ icon={copied ? Tick02Icon : Copy01Icon}
245
+ className="size-4"
246
+ />
247
+ </IconButton>
248
+ )
249
+ }
250
+
251
+ SettingList.Row = Row
252
+ SettingList.Copy = Copy
package/src/styles.css ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Passui with its TanStack integrations, in one import:
3
+ *
4
+ * @import "@passui/tanstack/styles.css";
5
+ *
6
+ * It brings in all of Passui's styles and registers this package's
7
+ * components; Tailwind finds the app's own files by itself.
8
+ */
9
+ @import "@passui/react/styles.css";
10
+
11
+ /* forms, tables and the document shell, from this file's place in the package */
12
+ @source "./";
@@ -0,0 +1,39 @@
1
+ import type { RowData } from "@tanstack/react-table"
2
+ import { Toggle } from "@passui/react/toggle"
3
+ import type { DataTableColumnDef } from "./data-table"
4
+
5
+ export function selectColumn<
6
+ TData extends RowData,
7
+ >(): DataTableColumnDef<TData> {
8
+ return {
9
+ id: "select",
10
+ enableColumnFilter: false,
11
+ enableGlobalFilter: false,
12
+ header: ({ table }) => (
13
+ <Toggle
14
+ style="checkbox"
15
+ labelHidden
16
+ checked={table.getIsAllPageRowsSelected()}
17
+ mixed={
18
+ table.getIsSomePageRowsSelected() &&
19
+ !table.getIsAllPageRowsSelected()
20
+ }
21
+ onChange={(checked) =>
22
+ table.toggleAllPageRowsSelected(checked)
23
+ }
24
+ label="Select all"
25
+ />
26
+ ),
27
+ cell: ({ row }) => (
28
+ <Toggle
29
+ style="checkbox"
30
+ labelHidden
31
+ checked={row.getIsSelected()}
32
+ onChange={(checked) =>
33
+ row.toggleSelected(checked)
34
+ }
35
+ label="Select row"
36
+ />
37
+ ),
38
+ }
39
+ }