@girardmedia/bootspring 1.2.0 → 2.0.3
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/README.md +107 -14
- package/bin/bootspring.js +166 -27
- package/cli/agent.js +189 -17
- package/cli/analyze.js +499 -0
- package/cli/audit.js +557 -0
- package/cli/auth.js +495 -38
- package/cli/billing.js +302 -0
- package/cli/build.js +695 -0
- package/cli/business.js +109 -26
- package/cli/checkpoint-utils.js +168 -0
- package/cli/checkpoint.js +639 -0
- package/cli/cloud-sync.js +447 -0
- package/cli/content.js +198 -0
- package/cli/context.js +1 -1
- package/cli/deploy.js +543 -0
- package/cli/fundraise.js +112 -50
- package/cli/github-cmd.js +435 -0
- package/cli/health.js +477 -0
- package/cli/init.js +84 -13
- package/cli/legal.js +107 -95
- package/cli/log.js +2 -2
- package/cli/loop.js +976 -73
- package/cli/manager.js +711 -0
- package/cli/metrics.js +480 -0
- package/cli/monitor.js +812 -0
- package/cli/onboard.js +521 -0
- package/cli/orchestrator.js +12 -24
- package/cli/prd.js +594 -0
- package/cli/preseed-start.js +1483 -0
- package/cli/preseed.js +2302 -0
- package/cli/project.js +436 -0
- package/cli/quality.js +233 -0
- package/cli/security.js +913 -0
- package/cli/seed.js +1441 -5
- package/cli/skill.js +273 -211
- package/cli/suggest.js +989 -0
- package/cli/switch.js +453 -0
- package/cli/visualize.js +527 -0
- package/cli/watch.js +769 -0
- package/cli/workspace.js +607 -0
- package/core/analyze-workflow.js +1134 -0
- package/core/api-client.js +535 -22
- package/core/audit-workflow.js +1350 -0
- package/core/build-orchestrator.js +480 -0
- package/core/build-state.js +577 -0
- package/core/checkpoint-engine.js +408 -0
- package/core/config.js +1109 -26
- package/core/context-loader.js +21 -1
- package/core/deploy-workflow.js +836 -0
- package/core/entitlements.js +93 -22
- package/core/github-sync.js +610 -0
- package/core/index.js +8 -1
- package/core/ingest.js +1111 -0
- package/core/metrics-engine.js +768 -0
- package/core/onboard-workflow.js +1007 -0
- package/core/preseed-workflow.js +934 -0
- package/core/preseed.js +1617 -0
- package/core/project-context.js +325 -0
- package/core/project-state.js +694 -0
- package/core/r2-sync.js +583 -0
- package/core/scaffold.js +525 -7
- package/core/session.js +258 -0
- package/core/task-extractor.js +758 -0
- package/core/telemetry.js +28 -6
- package/core/tier-enforcement.js +737 -0
- package/core/utils.js +38 -14
- package/generators/questionnaire.js +15 -12
- package/generators/sections/ai.js +7 -7
- package/generators/sections/content.js +300 -0
- package/generators/sections/index.js +3 -0
- package/generators/sections/plugins.js +7 -6
- package/generators/templates/build-planning.template.js +596 -0
- package/generators/templates/content.template.js +819 -0
- package/generators/templates/index.js +2 -1
- package/hooks/git-autopilot.js +1250 -0
- package/hooks/index.js +9 -0
- package/intelligence/agent-collab.js +2057 -0
- package/intelligence/auto-suggest.js +634 -0
- package/intelligence/content-gen.js +1589 -0
- package/intelligence/cross-project.js +1647 -0
- package/intelligence/index.js +184 -0
- package/intelligence/learning/insights.json +517 -7
- package/intelligence/learning/pattern-learner.js +1008 -14
- package/intelligence/memory/decision-tracker.js +1431 -31
- package/intelligence/memory/decisions.jsonl +0 -0
- package/intelligence/orchestrator.js +2896 -1
- package/intelligence/prd.js +92 -1
- package/intelligence/recommendation-weights.json +14 -2
- package/intelligence/recommendations.js +463 -9
- package/intelligence/workflow-composer.js +1451 -0
- package/marketplace/index.d.ts +324 -0
- package/marketplace/index.js +1921 -0
- package/mcp/contracts/mcp-contract.v1.json +342 -4
- package/mcp/registry.js +680 -3
- package/mcp/response-formatter.js +23 -0
- package/mcp/tools/assist-tool.js +78 -4
- package/mcp/tools/autopilot-tool.js +408 -0
- package/mcp/tools/content-tool.js +571 -0
- package/mcp/tools/dashboard-tool.js +251 -5
- package/mcp/tools/mvp-tool.js +344 -0
- package/mcp/tools/plugin-tool.js +23 -1
- package/mcp/tools/prd-tool.js +579 -0
- package/mcp/tools/seed-tool.js +447 -0
- package/mcp/tools/skill-tool.js +43 -14
- package/mcp/tools/suggest-tool.js +147 -0
- package/package.json +15 -6
- package/agents/README.md +0 -93
- package/agents/ai-integration-expert/context.md +0 -386
- package/agents/api-expert/context.md +0 -416
- package/agents/architecture-expert/context.md +0 -454
- package/agents/auth-expert/context.md +0 -399
- package/agents/backend-expert/context.md +0 -483
- package/agents/business-strategy-expert/context.md +0 -180
- package/agents/code-review-expert/context.md +0 -365
- package/agents/competitive-analysis-expert/context.md +0 -239
- package/agents/data-modeling-expert/context.md +0 -352
- package/agents/database-expert/context.md +0 -250
- package/agents/devops-expert/context.md +0 -446
- package/agents/email-expert/context.md +0 -379
- package/agents/financial-expert/context.md +0 -213
- package/agents/frontend-expert/context.md +0 -364
- package/agents/fundraising-expert/context.md +0 -257
- package/agents/growth-expert/context.md +0 -249
- package/agents/index.js +0 -140
- package/agents/investor-relations-expert/context.md +0 -266
- package/agents/legal-expert/context.md +0 -284
- package/agents/marketing-expert/context.md +0 -236
- package/agents/monitoring-expert/context.md +0 -362
- package/agents/operations-expert/context.md +0 -279
- package/agents/partnerships-expert/context.md +0 -286
- package/agents/payment-expert/context.md +0 -340
- package/agents/performance-expert/context.md +0 -377
- package/agents/private-equity-expert/context.md +0 -246
- package/agents/railway-expert/context.md +0 -284
- package/agents/research-expert/context.md +0 -245
- package/agents/sales-expert/context.md +0 -241
- package/agents/security-expert/context.md +0 -343
- package/agents/testing-expert/context.md +0 -414
- package/agents/ui-ux-expert/context.md +0 -448
- package/agents/vercel-expert/context.md +0 -426
- package/skills/index.js +0 -787
- package/skills/patterns/README.md +0 -163
- package/skills/patterns/ai/agents.md +0 -281
- package/skills/patterns/ai/claude.md +0 -138
- package/skills/patterns/ai/embeddings.md +0 -150
- package/skills/patterns/ai/rag.md +0 -266
- package/skills/patterns/ai/streaming.md +0 -170
- package/skills/patterns/ai/structured-output.md +0 -162
- package/skills/patterns/ai/tools.md +0 -154
- package/skills/patterns/analytics/tracking.md +0 -220
- package/skills/patterns/api/errors.md +0 -296
- package/skills/patterns/api/graphql.md +0 -440
- package/skills/patterns/api/middleware.md +0 -279
- package/skills/patterns/api/openapi.md +0 -285
- package/skills/patterns/api/rate-limiting.md +0 -231
- package/skills/patterns/api/route-handler.md +0 -217
- package/skills/patterns/api/server-action.md +0 -249
- package/skills/patterns/api/versioning.md +0 -443
- package/skills/patterns/api/webhooks.md +0 -247
- package/skills/patterns/auth/clerk.md +0 -132
- package/skills/patterns/auth/mfa.md +0 -313
- package/skills/patterns/auth/nextauth.md +0 -140
- package/skills/patterns/auth/oauth.md +0 -237
- package/skills/patterns/auth/rbac.md +0 -152
- package/skills/patterns/auth/session-management.md +0 -367
- package/skills/patterns/auth/session.md +0 -120
- package/skills/patterns/database/audit.md +0 -177
- package/skills/patterns/database/migrations.md +0 -177
- package/skills/patterns/database/pagination.md +0 -230
- package/skills/patterns/database/pooling.md +0 -357
- package/skills/patterns/database/prisma.md +0 -180
- package/skills/patterns/database/relations.md +0 -187
- package/skills/patterns/database/seeding.md +0 -246
- package/skills/patterns/database/soft-delete.md +0 -153
- package/skills/patterns/database/transactions.md +0 -162
- package/skills/patterns/deployment/ci-cd.md +0 -231
- package/skills/patterns/deployment/docker.md +0 -188
- package/skills/patterns/deployment/monitoring.md +0 -387
- package/skills/patterns/deployment/vercel.md +0 -160
- package/skills/patterns/email/resend.md +0 -143
- package/skills/patterns/email/templates.md +0 -245
- package/skills/patterns/email/transactional.md +0 -503
- package/skills/patterns/email/verification.md +0 -176
- package/skills/patterns/files/download.md +0 -243
- package/skills/patterns/files/upload.md +0 -239
- package/skills/patterns/i18n/nextintl.md +0 -188
- package/skills/patterns/logging/structured.md +0 -292
- package/skills/patterns/notifications/email-queue.md +0 -248
- package/skills/patterns/notifications/push.md +0 -279
- package/skills/patterns/payments/checkout.md +0 -303
- package/skills/patterns/payments/invoices.md +0 -287
- package/skills/patterns/payments/portal.md +0 -245
- package/skills/patterns/payments/stripe.md +0 -272
- package/skills/patterns/payments/subscriptions.md +0 -300
- package/skills/patterns/payments/usage.md +0 -279
- package/skills/patterns/performance/caching.md +0 -276
- package/skills/patterns/performance/code-splitting.md +0 -233
- package/skills/patterns/performance/edge.md +0 -254
- package/skills/patterns/performance/isr.md +0 -266
- package/skills/patterns/performance/lazy-loading.md +0 -281
- package/skills/patterns/realtime/sse.md +0 -327
- package/skills/patterns/realtime/websockets.md +0 -336
- package/skills/patterns/search/filtering.md +0 -329
- package/skills/patterns/search/fulltext.md +0 -260
- package/skills/patterns/security/audit-logging.md +0 -444
- package/skills/patterns/security/csrf.md +0 -234
- package/skills/patterns/security/headers.md +0 -252
- package/skills/patterns/security/sanitization.md +0 -258
- package/skills/patterns/security/secrets.md +0 -261
- package/skills/patterns/security/validation.md +0 -268
- package/skills/patterns/security/xss.md +0 -229
- package/skills/patterns/seo/metadata.md +0 -252
- package/skills/patterns/state/context.md +0 -349
- package/skills/patterns/state/react-query.md +0 -313
- package/skills/patterns/state/url-state.md +0 -482
- package/skills/patterns/state/zustand.md +0 -262
- package/skills/patterns/testing/api.md +0 -259
- package/skills/patterns/testing/component.md +0 -233
- package/skills/patterns/testing/coverage.md +0 -207
- package/skills/patterns/testing/fixtures.md +0 -225
- package/skills/patterns/testing/integration.md +0 -436
- package/skills/patterns/testing/mocking.md +0 -177
- package/skills/patterns/testing/playwright.md +0 -162
- package/skills/patterns/testing/snapshot.md +0 -175
- package/skills/patterns/testing/vitest.md +0 -307
- package/skills/patterns/ui/accordions.md +0 -395
- package/skills/patterns/ui/cards.md +0 -299
- package/skills/patterns/ui/dropdowns.md +0 -476
- package/skills/patterns/ui/empty-states.md +0 -320
- package/skills/patterns/ui/forms.md +0 -405
- package/skills/patterns/ui/inputs.md +0 -319
- package/skills/patterns/ui/layouts.md +0 -282
- package/skills/patterns/ui/loading.md +0 -291
- package/skills/patterns/ui/modals.md +0 -338
- package/skills/patterns/ui/navigation.md +0 -374
- package/skills/patterns/ui/tables.md +0 -407
- package/skills/patterns/ui/toasts.md +0 -300
- package/skills/patterns/ui/tooltips.md +0 -396
- package/skills/patterns/utils/dates.md +0 -435
- package/skills/patterns/utils/errors.md +0 -451
- package/skills/patterns/utils/formatting.md +0 -345
- package/skills/patterns/utils/validation.md +0 -434
- package/templates/bootspring.config.js +0 -83
- package/templates/business/business-model-canvas.md +0 -246
- package/templates/business/business-plan.md +0 -266
- package/templates/business/competitive-analysis.md +0 -312
- package/templates/fundraising/data-room-checklist.md +0 -300
- package/templates/fundraising/investor-research.md +0 -243
- package/templates/fundraising/pitch-deck-outline.md +0 -253
- package/templates/legal/gdpr-checklist.md +0 -339
- package/templates/legal/privacy-policy.md +0 -285
- package/templates/legal/terms-of-service.md +0 -222
- package/templates/mcp.json +0 -9
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
# Data Table Patterns
|
|
2
|
-
|
|
3
|
-
Patterns for building data tables with TanStack Table.
|
|
4
|
-
|
|
5
|
-
## Basic Table
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
// components/tables/DataTable.tsx
|
|
9
|
-
'use client'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
useReactTable,
|
|
13
|
-
getCoreRowModel,
|
|
14
|
-
flexRender,
|
|
15
|
-
ColumnDef
|
|
16
|
-
} from '@tanstack/react-table'
|
|
17
|
-
|
|
18
|
-
interface Props<T> {
|
|
19
|
-
data: T[]
|
|
20
|
-
columns: ColumnDef<T>[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function DataTable<T>({ data, columns }: Props<T>) {
|
|
24
|
-
const table = useReactTable({
|
|
25
|
-
data,
|
|
26
|
-
columns,
|
|
27
|
-
getCoreRowModel: getCoreRowModel()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<table className="w-full border-collapse">
|
|
32
|
-
<thead>
|
|
33
|
-
{table.getHeaderGroups().map(headerGroup => (
|
|
34
|
-
<tr key={headerGroup.id}>
|
|
35
|
-
{headerGroup.headers.map(header => (
|
|
36
|
-
<th key={header.id} className="border-b p-2 text-left">
|
|
37
|
-
{flexRender(
|
|
38
|
-
header.column.columnDef.header,
|
|
39
|
-
header.getContext()
|
|
40
|
-
)}
|
|
41
|
-
</th>
|
|
42
|
-
))}
|
|
43
|
-
</tr>
|
|
44
|
-
))}
|
|
45
|
-
</thead>
|
|
46
|
-
<tbody>
|
|
47
|
-
{table.getRowModel().rows.map(row => (
|
|
48
|
-
<tr key={row.id} className="hover:bg-gray-50">
|
|
49
|
-
{row.getVisibleCells().map(cell => (
|
|
50
|
-
<td key={cell.id} className="border-b p-2">
|
|
51
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
52
|
-
</td>
|
|
53
|
-
))}
|
|
54
|
-
</tr>
|
|
55
|
-
))}
|
|
56
|
-
</tbody>
|
|
57
|
-
</table>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Usage
|
|
62
|
-
const columns: ColumnDef<User>[] = [
|
|
63
|
-
{ accessorKey: 'name', header: 'Name' },
|
|
64
|
-
{ accessorKey: 'email', header: 'Email' },
|
|
65
|
-
{
|
|
66
|
-
accessorKey: 'role',
|
|
67
|
-
header: 'Role',
|
|
68
|
-
cell: ({ getValue }) => (
|
|
69
|
-
<span className="rounded bg-gray-100 px-2 py-1">
|
|
70
|
-
{getValue() as string}
|
|
71
|
-
</span>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
<DataTable data={users} columns={columns} />
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Sortable Table
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
// components/tables/SortableTable.tsx
|
|
83
|
-
'use client'
|
|
84
|
-
|
|
85
|
-
import {
|
|
86
|
-
useReactTable,
|
|
87
|
-
getCoreRowModel,
|
|
88
|
-
getSortedRowModel,
|
|
89
|
-
SortingState,
|
|
90
|
-
flexRender,
|
|
91
|
-
ColumnDef
|
|
92
|
-
} from '@tanstack/react-table'
|
|
93
|
-
import { useState } from 'react'
|
|
94
|
-
import { ChevronUp, ChevronDown } from 'lucide-react'
|
|
95
|
-
|
|
96
|
-
export function SortableTable<T>({ data, columns }: Props<T>) {
|
|
97
|
-
const [sorting, setSorting] = useState<SortingState>([])
|
|
98
|
-
|
|
99
|
-
const table = useReactTable({
|
|
100
|
-
data,
|
|
101
|
-
columns,
|
|
102
|
-
state: { sorting },
|
|
103
|
-
onSortingChange: setSorting,
|
|
104
|
-
getCoreRowModel: getCoreRowModel(),
|
|
105
|
-
getSortedRowModel: getSortedRowModel()
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<table className="w-full">
|
|
110
|
-
<thead>
|
|
111
|
-
{table.getHeaderGroups().map(headerGroup => (
|
|
112
|
-
<tr key={headerGroup.id}>
|
|
113
|
-
{headerGroup.headers.map(header => (
|
|
114
|
-
<th
|
|
115
|
-
key={header.id}
|
|
116
|
-
className="cursor-pointer select-none p-2"
|
|
117
|
-
onClick={header.column.getToggleSortingHandler()}
|
|
118
|
-
>
|
|
119
|
-
<div className="flex items-center gap-1">
|
|
120
|
-
{flexRender(
|
|
121
|
-
header.column.columnDef.header,
|
|
122
|
-
header.getContext()
|
|
123
|
-
)}
|
|
124
|
-
{{
|
|
125
|
-
asc: <ChevronUp className="h-4 w-4" />,
|
|
126
|
-
desc: <ChevronDown className="h-4 w-4" />
|
|
127
|
-
}[header.column.getIsSorted() as string] ?? null}
|
|
128
|
-
</div>
|
|
129
|
-
</th>
|
|
130
|
-
))}
|
|
131
|
-
</tr>
|
|
132
|
-
))}
|
|
133
|
-
</thead>
|
|
134
|
-
{/* ... tbody same as basic */}
|
|
135
|
-
</table>
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Paginated Table
|
|
141
|
-
|
|
142
|
-
```tsx
|
|
143
|
-
// components/tables/PaginatedTable.tsx
|
|
144
|
-
'use client'
|
|
145
|
-
|
|
146
|
-
import {
|
|
147
|
-
useReactTable,
|
|
148
|
-
getCoreRowModel,
|
|
149
|
-
getPaginationRowModel,
|
|
150
|
-
PaginationState,
|
|
151
|
-
flexRender
|
|
152
|
-
} from '@tanstack/react-table'
|
|
153
|
-
import { useState } from 'react'
|
|
154
|
-
|
|
155
|
-
export function PaginatedTable<T>({ data, columns }: Props<T>) {
|
|
156
|
-
const [pagination, setPagination] = useState<PaginationState>({
|
|
157
|
-
pageIndex: 0,
|
|
158
|
-
pageSize: 10
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const table = useReactTable({
|
|
162
|
-
data,
|
|
163
|
-
columns,
|
|
164
|
-
state: { pagination },
|
|
165
|
-
onPaginationChange: setPagination,
|
|
166
|
-
getCoreRowModel: getCoreRowModel(),
|
|
167
|
-
getPaginationRowModel: getPaginationRowModel()
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<div>
|
|
172
|
-
<table className="w-full">
|
|
173
|
-
{/* ... thead and tbody */}
|
|
174
|
-
</table>
|
|
175
|
-
|
|
176
|
-
<div className="mt-4 flex items-center justify-between">
|
|
177
|
-
<div>
|
|
178
|
-
Page {table.getState().pagination.pageIndex + 1} of{' '}
|
|
179
|
-
{table.getPageCount()}
|
|
180
|
-
</div>
|
|
181
|
-
|
|
182
|
-
<div className="flex gap-2">
|
|
183
|
-
<button
|
|
184
|
-
onClick={() => table.previousPage()}
|
|
185
|
-
disabled={!table.getCanPreviousPage()}
|
|
186
|
-
>
|
|
187
|
-
Previous
|
|
188
|
-
</button>
|
|
189
|
-
<button
|
|
190
|
-
onClick={() => table.nextPage()}
|
|
191
|
-
disabled={!table.getCanNextPage()}
|
|
192
|
-
>
|
|
193
|
-
Next
|
|
194
|
-
</button>
|
|
195
|
-
</div>
|
|
196
|
-
|
|
197
|
-
<select
|
|
198
|
-
value={pagination.pageSize}
|
|
199
|
-
onChange={e => table.setPageSize(Number(e.target.value))}
|
|
200
|
-
>
|
|
201
|
-
{[10, 20, 50, 100].map(size => (
|
|
202
|
-
<option key={size} value={size}>
|
|
203
|
-
Show {size}
|
|
204
|
-
</option>
|
|
205
|
-
))}
|
|
206
|
-
</select>
|
|
207
|
-
</div>
|
|
208
|
-
</div>
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## Filterable Table
|
|
214
|
-
|
|
215
|
-
```tsx
|
|
216
|
-
// components/tables/FilterableTable.tsx
|
|
217
|
-
'use client'
|
|
218
|
-
|
|
219
|
-
import {
|
|
220
|
-
useReactTable,
|
|
221
|
-
getCoreRowModel,
|
|
222
|
-
getFilteredRowModel,
|
|
223
|
-
ColumnFiltersState,
|
|
224
|
-
flexRender
|
|
225
|
-
} from '@tanstack/react-table'
|
|
226
|
-
import { useState } from 'react'
|
|
227
|
-
|
|
228
|
-
export function FilterableTable<T>({ data, columns }: Props<T>) {
|
|
229
|
-
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([])
|
|
230
|
-
const [globalFilter, setGlobalFilter] = useState('')
|
|
231
|
-
|
|
232
|
-
const table = useReactTable({
|
|
233
|
-
data,
|
|
234
|
-
columns,
|
|
235
|
-
state: { columnFilters, globalFilter },
|
|
236
|
-
onColumnFiltersChange: setColumnFilters,
|
|
237
|
-
onGlobalFilterChange: setGlobalFilter,
|
|
238
|
-
getCoreRowModel: getCoreRowModel(),
|
|
239
|
-
getFilteredRowModel: getFilteredRowModel()
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
return (
|
|
243
|
-
<div>
|
|
244
|
-
{/* Global search */}
|
|
245
|
-
<input
|
|
246
|
-
type="text"
|
|
247
|
-
placeholder="Search all columns..."
|
|
248
|
-
value={globalFilter}
|
|
249
|
-
onChange={e => setGlobalFilter(e.target.value)}
|
|
250
|
-
className="mb-4 w-full rounded border p-2"
|
|
251
|
-
/>
|
|
252
|
-
|
|
253
|
-
<table className="w-full">
|
|
254
|
-
<thead>
|
|
255
|
-
{table.getHeaderGroups().map(headerGroup => (
|
|
256
|
-
<tr key={headerGroup.id}>
|
|
257
|
-
{headerGroup.headers.map(header => (
|
|
258
|
-
<th key={header.id} className="p-2">
|
|
259
|
-
{flexRender(
|
|
260
|
-
header.column.columnDef.header,
|
|
261
|
-
header.getContext()
|
|
262
|
-
)}
|
|
263
|
-
{header.column.getCanFilter() && (
|
|
264
|
-
<input
|
|
265
|
-
type="text"
|
|
266
|
-
value={(header.column.getFilterValue() ?? '') as string}
|
|
267
|
-
onChange={e => header.column.setFilterValue(e.target.value)}
|
|
268
|
-
placeholder="Filter..."
|
|
269
|
-
className="mt-1 w-full rounded border p-1 text-sm"
|
|
270
|
-
/>
|
|
271
|
-
)}
|
|
272
|
-
</th>
|
|
273
|
-
))}
|
|
274
|
-
</tr>
|
|
275
|
-
))}
|
|
276
|
-
</thead>
|
|
277
|
-
{/* ... tbody */}
|
|
278
|
-
</table>
|
|
279
|
-
</div>
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Selectable Table
|
|
285
|
-
|
|
286
|
-
```tsx
|
|
287
|
-
// components/tables/SelectableTable.tsx
|
|
288
|
-
'use client'
|
|
289
|
-
|
|
290
|
-
import {
|
|
291
|
-
useReactTable,
|
|
292
|
-
getCoreRowModel,
|
|
293
|
-
RowSelectionState,
|
|
294
|
-
flexRender,
|
|
295
|
-
ColumnDef
|
|
296
|
-
} from '@tanstack/react-table'
|
|
297
|
-
import { useState } from 'react'
|
|
298
|
-
|
|
299
|
-
export function SelectableTable<T>({ data, columns, onSelectionChange }: Props<T> & {
|
|
300
|
-
onSelectionChange?: (selected: T[]) => void
|
|
301
|
-
}) {
|
|
302
|
-
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
|
303
|
-
|
|
304
|
-
const selectionColumn: ColumnDef<T> = {
|
|
305
|
-
id: 'select',
|
|
306
|
-
header: ({ table }) => (
|
|
307
|
-
<input
|
|
308
|
-
type="checkbox"
|
|
309
|
-
checked={table.getIsAllRowsSelected()}
|
|
310
|
-
onChange={table.getToggleAllRowsSelectedHandler()}
|
|
311
|
-
/>
|
|
312
|
-
),
|
|
313
|
-
cell: ({ row }) => (
|
|
314
|
-
<input
|
|
315
|
-
type="checkbox"
|
|
316
|
-
checked={row.getIsSelected()}
|
|
317
|
-
onChange={row.getToggleSelectedHandler()}
|
|
318
|
-
/>
|
|
319
|
-
)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const table = useReactTable({
|
|
323
|
-
data,
|
|
324
|
-
columns: [selectionColumn, ...columns],
|
|
325
|
-
state: { rowSelection },
|
|
326
|
-
onRowSelectionChange: setRowSelection,
|
|
327
|
-
getCoreRowModel: getCoreRowModel()
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
// Notify parent of selection changes
|
|
331
|
-
const selectedRows = table.getSelectedRowModel().rows.map(r => r.original)
|
|
332
|
-
|
|
333
|
-
return (
|
|
334
|
-
<div>
|
|
335
|
-
<div className="mb-2 text-sm text-gray-500">
|
|
336
|
-
{selectedRows.length} of {data.length} selected
|
|
337
|
-
</div>
|
|
338
|
-
|
|
339
|
-
<table className="w-full">
|
|
340
|
-
{/* ... thead and tbody */}
|
|
341
|
-
</table>
|
|
342
|
-
|
|
343
|
-
{selectedRows.length > 0 && (
|
|
344
|
-
<div className="mt-4">
|
|
345
|
-
<button onClick={() => onSelectionChange?.(selectedRows)}>
|
|
346
|
-
Process Selected ({selectedRows.length})
|
|
347
|
-
</button>
|
|
348
|
-
</div>
|
|
349
|
-
)}
|
|
350
|
-
</div>
|
|
351
|
-
)
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## Server-Side Table
|
|
356
|
-
|
|
357
|
-
```tsx
|
|
358
|
-
// components/tables/ServerTable.tsx
|
|
359
|
-
'use client'
|
|
360
|
-
|
|
361
|
-
import { useQuery } from '@tanstack/react-query'
|
|
362
|
-
import { useState } from 'react'
|
|
363
|
-
|
|
364
|
-
interface TableParams {
|
|
365
|
-
page: number
|
|
366
|
-
pageSize: number
|
|
367
|
-
sortBy?: string
|
|
368
|
-
sortOrder?: 'asc' | 'desc'
|
|
369
|
-
filter?: string
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export function ServerTable() {
|
|
373
|
-
const [params, setParams] = useState<TableParams>({
|
|
374
|
-
page: 1,
|
|
375
|
-
pageSize: 10
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
const { data, isLoading } = useQuery({
|
|
379
|
-
queryKey: ['users', params],
|
|
380
|
-
queryFn: () => fetchUsers(params)
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
if (isLoading) return <TableSkeleton />
|
|
384
|
-
|
|
385
|
-
return (
|
|
386
|
-
<div>
|
|
387
|
-
<table>
|
|
388
|
-
{/* Render data.items */}
|
|
389
|
-
</table>
|
|
390
|
-
|
|
391
|
-
<Pagination
|
|
392
|
-
page={params.page}
|
|
393
|
-
pageSize={params.pageSize}
|
|
394
|
-
total={data.total}
|
|
395
|
-
onChange={(page) => setParams(p => ({ ...p, page }))}
|
|
396
|
-
/>
|
|
397
|
-
</div>
|
|
398
|
-
)
|
|
399
|
-
}
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
## When to Use
|
|
403
|
-
|
|
404
|
-
- Data display
|
|
405
|
-
- Admin panels
|
|
406
|
-
- Reports
|
|
407
|
-
- List views
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
# Toast Notification Patterns
|
|
2
|
-
|
|
3
|
-
Patterns for toast notifications with React Hot Toast and Sonner.
|
|
4
|
-
|
|
5
|
-
## React Hot Toast Setup
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
// components/providers/ToastProvider.tsx
|
|
9
|
-
import { Toaster } from 'react-hot-toast'
|
|
10
|
-
|
|
11
|
-
export function ToastProvider() {
|
|
12
|
-
return (
|
|
13
|
-
<Toaster
|
|
14
|
-
position="bottom-right"
|
|
15
|
-
toastOptions={{
|
|
16
|
-
duration: 4000,
|
|
17
|
-
style: {
|
|
18
|
-
background: '#333',
|
|
19
|
-
color: '#fff'
|
|
20
|
-
},
|
|
21
|
-
success: {
|
|
22
|
-
iconTheme: {
|
|
23
|
-
primary: '#10B981',
|
|
24
|
-
secondary: '#fff'
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
error: {
|
|
28
|
-
iconTheme: {
|
|
29
|
-
primary: '#EF4444',
|
|
30
|
-
secondary: '#fff'
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}}
|
|
34
|
-
/>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// app/layout.tsx
|
|
39
|
-
import { ToastProvider } from '@/components/providers/ToastProvider'
|
|
40
|
-
|
|
41
|
-
export default function RootLayout({ children }) {
|
|
42
|
-
return (
|
|
43
|
-
<html>
|
|
44
|
-
<body>
|
|
45
|
-
{children}
|
|
46
|
-
<ToastProvider />
|
|
47
|
-
</body>
|
|
48
|
-
</html>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Basic Toast Usage
|
|
54
|
-
|
|
55
|
-
```tsx
|
|
56
|
-
// components/UserActions.tsx
|
|
57
|
-
'use client'
|
|
58
|
-
|
|
59
|
-
import toast from 'react-hot-toast'
|
|
60
|
-
|
|
61
|
-
export function UserActions() {
|
|
62
|
-
async function handleSave() {
|
|
63
|
-
const result = await saveData()
|
|
64
|
-
|
|
65
|
-
if (result.success) {
|
|
66
|
-
toast.success('Changes saved successfully')
|
|
67
|
-
} else {
|
|
68
|
-
toast.error('Failed to save changes')
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function handleCopy() {
|
|
73
|
-
navigator.clipboard.writeText('text')
|
|
74
|
-
toast('Copied to clipboard', { icon: '📋' })
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<div>
|
|
79
|
-
<button onClick={handleSave}>Save</button>
|
|
80
|
-
<button onClick={handleCopy}>Copy</button>
|
|
81
|
-
</div>
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Promise Toast
|
|
87
|
-
|
|
88
|
-
```tsx
|
|
89
|
-
// Automatic loading/success/error states
|
|
90
|
-
async function handleSubmit() {
|
|
91
|
-
toast.promise(
|
|
92
|
-
submitForm(data),
|
|
93
|
-
{
|
|
94
|
-
loading: 'Saving...',
|
|
95
|
-
success: 'Successfully saved!',
|
|
96
|
-
error: (err) => `Error: ${err.message}`
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// With custom styling
|
|
102
|
-
toast.promise(
|
|
103
|
-
fetchData(),
|
|
104
|
-
{
|
|
105
|
-
loading: 'Loading data...',
|
|
106
|
-
success: (data) => `Loaded ${data.length} items`,
|
|
107
|
-
error: 'Failed to load'
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
style: { minWidth: '250px' },
|
|
111
|
-
success: { duration: 3000 },
|
|
112
|
-
error: { duration: 5000 }
|
|
113
|
-
}
|
|
114
|
-
)
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Custom Toast Component
|
|
118
|
-
|
|
119
|
-
```tsx
|
|
120
|
-
// components/ui/CustomToast.tsx
|
|
121
|
-
import toast from 'react-hot-toast'
|
|
122
|
-
import { X } from 'lucide-react'
|
|
123
|
-
|
|
124
|
-
interface Props {
|
|
125
|
-
title: string
|
|
126
|
-
message: string
|
|
127
|
-
action?: {
|
|
128
|
-
label: string
|
|
129
|
-
onClick: () => void
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function showCustomToast({ title, message, action }: Props) {
|
|
134
|
-
toast.custom((t) => (
|
|
135
|
-
<div
|
|
136
|
-
className={`${
|
|
137
|
-
t.visible ? 'animate-enter' : 'animate-leave'
|
|
138
|
-
} pointer-events-auto flex w-full max-w-md rounded-lg bg-white shadow-lg ring-1 ring-black/5`}
|
|
139
|
-
>
|
|
140
|
-
<div className="flex-1 p-4">
|
|
141
|
-
<p className="font-medium text-gray-900">{title}</p>
|
|
142
|
-
<p className="mt-1 text-sm text-gray-500">{message}</p>
|
|
143
|
-
{action && (
|
|
144
|
-
<button
|
|
145
|
-
onClick={() => {
|
|
146
|
-
action.onClick()
|
|
147
|
-
toast.dismiss(t.id)
|
|
148
|
-
}}
|
|
149
|
-
className="mt-2 text-sm font-medium text-blue-600 hover:text-blue-500"
|
|
150
|
-
>
|
|
151
|
-
{action.label}
|
|
152
|
-
</button>
|
|
153
|
-
)}
|
|
154
|
-
</div>
|
|
155
|
-
<div className="flex border-l">
|
|
156
|
-
<button
|
|
157
|
-
onClick={() => toast.dismiss(t.id)}
|
|
158
|
-
className="flex items-center justify-center p-4 hover:bg-gray-50"
|
|
159
|
-
>
|
|
160
|
-
<X className="h-5 w-5 text-gray-400" />
|
|
161
|
-
</button>
|
|
162
|
-
</div>
|
|
163
|
-
</div>
|
|
164
|
-
), { duration: 5000 })
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Usage
|
|
168
|
-
showCustomToast({
|
|
169
|
-
title: 'New message',
|
|
170
|
-
message: 'You have a new message from John',
|
|
171
|
-
action: {
|
|
172
|
-
label: 'View',
|
|
173
|
-
onClick: () => router.push('/messages')
|
|
174
|
-
}
|
|
175
|
-
})
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Sonner Setup
|
|
179
|
-
|
|
180
|
-
```tsx
|
|
181
|
-
// components/providers/SonnerProvider.tsx
|
|
182
|
-
import { Toaster } from 'sonner'
|
|
183
|
-
|
|
184
|
-
export function SonnerProvider() {
|
|
185
|
-
return (
|
|
186
|
-
<Toaster
|
|
187
|
-
position="bottom-right"
|
|
188
|
-
richColors
|
|
189
|
-
closeButton
|
|
190
|
-
expand={false}
|
|
191
|
-
toastOptions={{
|
|
192
|
-
classNames: {
|
|
193
|
-
toast: 'bg-background border-border',
|
|
194
|
-
title: 'text-foreground',
|
|
195
|
-
description: 'text-muted-foreground'
|
|
196
|
-
}
|
|
197
|
-
}}
|
|
198
|
-
/>
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## Sonner Usage
|
|
204
|
-
|
|
205
|
-
```tsx
|
|
206
|
-
// components/Actions.tsx
|
|
207
|
-
'use client'
|
|
208
|
-
|
|
209
|
-
import { toast } from 'sonner'
|
|
210
|
-
|
|
211
|
-
export function Actions() {
|
|
212
|
-
// Basic
|
|
213
|
-
function showInfo() {
|
|
214
|
-
toast('Event has been created')
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Variants
|
|
218
|
-
function showVariants() {
|
|
219
|
-
toast.success('Successfully saved')
|
|
220
|
-
toast.error('Something went wrong')
|
|
221
|
-
toast.warning('Please check your input')
|
|
222
|
-
toast.info('New update available')
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// With description
|
|
226
|
-
function showWithDescription() {
|
|
227
|
-
toast('Event created', {
|
|
228
|
-
description: 'Monday, January 3rd at 6:00pm'
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// With action
|
|
233
|
-
function showWithAction() {
|
|
234
|
-
toast('File deleted', {
|
|
235
|
-
action: {
|
|
236
|
-
label: 'Undo',
|
|
237
|
-
onClick: () => restoreFile()
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Promise
|
|
243
|
-
async function showPromise() {
|
|
244
|
-
toast.promise(saveChanges(), {
|
|
245
|
-
loading: 'Saving...',
|
|
246
|
-
success: 'Changes saved!',
|
|
247
|
-
error: 'Could not save'
|
|
248
|
-
})
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Custom duration
|
|
252
|
-
function showPersistent() {
|
|
253
|
-
toast('Important message', {
|
|
254
|
-
duration: Infinity, // Won't auto-dismiss
|
|
255
|
-
closeButton: true
|
|
256
|
-
})
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return <div>...</div>
|
|
260
|
-
}
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
## Toast Context Hook
|
|
264
|
-
|
|
265
|
-
```tsx
|
|
266
|
-
// hooks/useToast.ts
|
|
267
|
-
import toast from 'react-hot-toast'
|
|
268
|
-
|
|
269
|
-
export function useToast() {
|
|
270
|
-
return {
|
|
271
|
-
success: (message: string) => toast.success(message),
|
|
272
|
-
error: (message: string) => toast.error(message),
|
|
273
|
-
loading: (message: string) => toast.loading(message),
|
|
274
|
-
dismiss: (id?: string) => toast.dismiss(id),
|
|
275
|
-
promise: <T,>(
|
|
276
|
-
promise: Promise<T>,
|
|
277
|
-
messages: { loading: string; success: string; error: string }
|
|
278
|
-
) => toast.promise(promise, messages)
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Usage
|
|
283
|
-
const { success, error, promise } = useToast()
|
|
284
|
-
|
|
285
|
-
async function handleAction() {
|
|
286
|
-
try {
|
|
287
|
-
await doSomething()
|
|
288
|
-
success('Done!')
|
|
289
|
-
} catch (e) {
|
|
290
|
-
error('Failed!')
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
## When to Use
|
|
296
|
-
|
|
297
|
-
- Action feedback
|
|
298
|
-
- Form submissions
|
|
299
|
-
- Error notifications
|
|
300
|
-
- Status updates
|