@svgrid/ui 2.6.1 → 3.0.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.
- package/index.mjs +6 -4
- package/package.json +2 -2
- package/recipes/data/data-table.svelte +109 -0
- package/recipes/registry.json +1723 -1695
package/index.mjs
CHANGED
|
@@ -395,7 +395,7 @@ async function cmdAdd(registry, tokens, args) {
|
|
|
395
395
|
` ${color('dim', 'Start an app:')} ${color('cyan', 'npm create @svgrid@latest')} ${color('dim', '(then run add inside it)')}\n`,
|
|
396
396
|
)
|
|
397
397
|
} else {
|
|
398
|
-
stdout.write(` ${color('dim', 'Use it:')} import { ${exportName(first
|
|
398
|
+
stdout.write(` ${color('dim', 'Use it:')} import { ${exportName(first)} } from '@svgrid/grid'\n`)
|
|
399
399
|
// "See it" - skip when we already wrote preview routes just above.
|
|
400
400
|
if (!(args.preview && isSvelteKit(projectRoot))) {
|
|
401
401
|
stdout.write(` ${color('dim', 'See it:')} ${color('cyan', `npx @svgrid/ui try ${ids}`)} ${color('dim', '(opens in your browser)')}\n`)
|
|
@@ -546,9 +546,11 @@ ${sections.join('\n')}
|
|
|
546
546
|
}
|
|
547
547
|
|
|
548
548
|
/** Component export name from its id (calendar -> SvCalendar, time-picker ->
|
|
549
|
-
* SvTimePicker).
|
|
550
|
-
|
|
551
|
-
|
|
549
|
+
* SvTimePicker). A registry item can override it with `export` when the id and
|
|
550
|
+
* the component name diverge (data-table -> SvGrid). */
|
|
551
|
+
function exportName(item) {
|
|
552
|
+
if (item.export) return item.export
|
|
553
|
+
return 'Sv' + item.id.split('-').map((s) => s[0].toUpperCase() + s.slice(1)).join('')
|
|
552
554
|
}
|
|
553
555
|
|
|
554
556
|
function relFromCwd(cwd, p) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "commercial",
|
|
5
5
|
"url": "https://svgrid.com/pricing"
|
|
6
6
|
},
|
|
7
|
-
"version": "
|
|
7
|
+
"version": "3.0.0",
|
|
8
8
|
"description": "Add and preview SvGrid UI components in one command: npx @svgrid/ui try calendar",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"svelte": "^5.55.5",
|
|
42
42
|
"svelte-check": "^4.4.6",
|
|
43
43
|
"typescript": "6.0.3",
|
|
44
|
-
"@svgrid/grid": "
|
|
44
|
+
"@svgrid/grid": "3.0.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test:types": "svelte-check --tsconfig ./tsconfig.json"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// SvGrid - a sortable, filterable, paginated data table with row selection.
|
|
3
|
+
// Your copy, edit freely. Docs: https://svgrid.com/docs/getting-started/
|
|
4
|
+
//
|
|
5
|
+
// Everything below is declared, not wired. There is no sort handler, no
|
|
6
|
+
// filter state, no page-index variable and no {#each} - the grid owns them.
|
|
7
|
+
// Column visibility lives in the header column menu ("Choose columns").
|
|
8
|
+
import {
|
|
9
|
+
SvGrid,
|
|
10
|
+
tableFeatures,
|
|
11
|
+
rowSortingFeature,
|
|
12
|
+
columnFilteringFeature,
|
|
13
|
+
rowPaginationFeature,
|
|
14
|
+
rowSelectionFeature,
|
|
15
|
+
renderSnippet,
|
|
16
|
+
type ColumnDef,
|
|
17
|
+
} from '@svgrid/grid'
|
|
18
|
+
// Match your design system. Swap for tailwind / material / fluent, or drop
|
|
19
|
+
// the import and set the --sg-* custom properties yourself.
|
|
20
|
+
import '@svgrid/grid/themes/shadcn.css'
|
|
21
|
+
|
|
22
|
+
type Payment = {
|
|
23
|
+
id: string
|
|
24
|
+
status: 'pending' | 'processing' | 'success' | 'failed'
|
|
25
|
+
email: string
|
|
26
|
+
amount: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Register only the features this table uses - the rest is tree-shaken out.
|
|
30
|
+
const features = tableFeatures({
|
|
31
|
+
rowSortingFeature,
|
|
32
|
+
columnFilteringFeature,
|
|
33
|
+
rowPaginationFeature,
|
|
34
|
+
rowSelectionFeature,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const data: Payment[] = [
|
|
38
|
+
{ id: 'm5gr84i9', status: 'success', email: 'ken99@example.com', amount: 316 },
|
|
39
|
+
{ id: '3u1reuv4', status: 'success', email: 'abe45@example.com', amount: 242 },
|
|
40
|
+
{ id: 'derv1ws0', status: 'processing', email: 'monserrat44@example.com', amount: 837 },
|
|
41
|
+
{ id: '5kma53ae', status: 'success', email: 'silas22@example.com', amount: 874 },
|
|
42
|
+
{ id: 'bhqecj4p', status: 'failed', email: 'carmella@example.com', amount: 721 },
|
|
43
|
+
{ id: 'p9x2llqz', status: 'pending', email: 'noor@example.com', amount: 158 },
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const columns: ColumnDef<typeof features, Payment>[] = [
|
|
47
|
+
{ field: 'status', header: 'Status', width: 130, cell: (ctx) => renderSnippet(StatusCell, { row: ctx.row.original }) },
|
|
48
|
+
{ field: 'email', header: 'Email' },
|
|
49
|
+
{ field: 'amount', header: 'Amount', width: 140, format: { type: 'currency', currency: 'USD' } },
|
|
50
|
+
// Starts hidden but stays listed in "Choose columns" for the user to re-enable.
|
|
51
|
+
{ field: 'id', header: 'Payment ID', width: 140, visible: false },
|
|
52
|
+
{ id: 'actions', header: '', width: 60, sortable: false, filterable: false, cell: (ctx) => renderSnippet(RowActions, { row: ctx.row.original }) },
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
const copyId = (id: string) => navigator.clipboard?.writeText(id)
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
{#snippet StatusCell(props: { row: Payment })}
|
|
59
|
+
<span class="dt-status" data-status={props.row.status}>{props.row.status}</span>
|
|
60
|
+
{/snippet}
|
|
61
|
+
|
|
62
|
+
{#snippet RowActions(props: { row: Payment })}
|
|
63
|
+
<button class="dt-actions" title="Copy payment ID" onclick={() => copyId(props.row.id)}>
|
|
64
|
+
⋮
|
|
65
|
+
</button>
|
|
66
|
+
{/snippet}
|
|
67
|
+
|
|
68
|
+
<SvGrid
|
|
69
|
+
{data}
|
|
70
|
+
{columns}
|
|
71
|
+
{features}
|
|
72
|
+
sortable
|
|
73
|
+
filterable
|
|
74
|
+
showGlobalFilter
|
|
75
|
+
showRowSelection
|
|
76
|
+
pageable
|
|
77
|
+
showPagination
|
|
78
|
+
pageSize={5}
|
|
79
|
+
fitColumns
|
|
80
|
+
enableRowSummaries={false}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
<style>
|
|
84
|
+
.dt-status {
|
|
85
|
+
display: inline-flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
border: 1px solid var(--sg-border, #e4e4e7);
|
|
88
|
+
border-radius: 9999px;
|
|
89
|
+
padding: 0 0.5rem;
|
|
90
|
+
font-size: 0.75rem;
|
|
91
|
+
line-height: 1.25rem;
|
|
92
|
+
text-transform: capitalize;
|
|
93
|
+
}
|
|
94
|
+
.dt-status[data-status='success'] { color: #15803d; border-color: #86efac; }
|
|
95
|
+
.dt-status[data-status='failed'] { color: #b91c1c; border-color: #fca5a5; }
|
|
96
|
+
.dt-status[data-status='processing'] { color: #a16207; border-color: #fde047; }
|
|
97
|
+
|
|
98
|
+
.dt-actions {
|
|
99
|
+
background: none;
|
|
100
|
+
border: 0;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
color: inherit;
|
|
103
|
+
font-size: 1rem;
|
|
104
|
+
line-height: 1;
|
|
105
|
+
padding: 0.25rem 0.5rem;
|
|
106
|
+
border-radius: 0.375rem;
|
|
107
|
+
}
|
|
108
|
+
.dt-actions:hover { background: var(--sg-row-hover-bg, rgba(0, 0, 0, 0.05)); }
|
|
109
|
+
</style>
|