shadcn-ui-react 0.5.3 → 0.6.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/README.md +74 -26
- package/dist/index.cjs +296 -119
- package/dist/index.d.cts +146 -9
- package/dist/index.d.ts +146 -9
- package/dist/index.js +300 -121
- package/dist/style.css +535 -21
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -361,65 +361,113 @@ export default function UserAuthForm() {
|
|
|
361
361
|
### 📊 DataTable
|
|
362
362
|
|
|
363
363
|
```tsx
|
|
364
|
-
import React, { useState } from "react";
|
|
364
|
+
import React, { useMemo, useState } from "react";
|
|
365
|
+
import type { ColumnDef } from "@tanstack/react-table";
|
|
365
366
|
import { DataTable } from "shadcn-ui-react";
|
|
366
|
-
import { ColumnDef } from "@tanstack/react-table";
|
|
367
367
|
|
|
368
368
|
type User = {
|
|
369
369
|
id: number;
|
|
370
370
|
name: string;
|
|
371
371
|
email: string;
|
|
372
|
+
role: "Admin" | "Editor" | "Viewer";
|
|
372
373
|
};
|
|
373
374
|
|
|
374
375
|
const columns: ColumnDef<User, any>[] = [
|
|
375
376
|
{ accessorKey: "id", header: "ID" },
|
|
376
|
-
{
|
|
377
|
+
{
|
|
378
|
+
accessorKey: "name",
|
|
379
|
+
header: "Name",
|
|
380
|
+
cell: ({ row }) => (
|
|
381
|
+
<div className="flex items-center gap-2">
|
|
382
|
+
<div className="h-2 w-2 rounded-full bg-primary" />
|
|
383
|
+
<span className="font-medium">{row.original.name}</span>
|
|
384
|
+
</div>
|
|
385
|
+
),
|
|
386
|
+
},
|
|
377
387
|
{ accessorKey: "email", header: "Email" },
|
|
388
|
+
{
|
|
389
|
+
accessorKey: "role",
|
|
390
|
+
header: "Role",
|
|
391
|
+
cell: ({ row }) => (
|
|
392
|
+
<span className="inline-flex items-center rounded-full border px-2 py-0.5 text-xs">
|
|
393
|
+
{row.original.role}
|
|
394
|
+
</span>
|
|
395
|
+
),
|
|
396
|
+
},
|
|
378
397
|
];
|
|
379
398
|
|
|
380
399
|
const data: User[] = [
|
|
381
|
-
{ id: 1, name: "John Doe", email: "john@example.com" },
|
|
382
|
-
{ id: 2, name: "Jane Smith", email: "jane@example.com" },
|
|
383
|
-
{ id: 3, name: "Sam Johnson", email: "sam@example.com" },
|
|
384
|
-
{ id: 4, name: "Alice Brown", email: "alice@example.com" },
|
|
385
|
-
{ id: 5, name: "Bob White", email: "bob@example.com" },
|
|
386
|
-
{ id: 6, name: "Charlie Black", email: "charlie@example.com" },
|
|
387
|
-
{ id: 7, name: "Diana Green", email: "diana@example.com" },
|
|
388
|
-
{ id: 8, name: "Eve Blue", email: "eve@example.com" },
|
|
389
|
-
{ id: 9, name: "Frank Yellow", email: "frank@example.com" },
|
|
390
|
-
{ id: 10, name: "Grace Red", email: "grace@example.com" },
|
|
400
|
+
{ id: 1, name: "John Doe", email: "john@example.com", role: "Admin" },
|
|
401
|
+
{ id: 2, name: "Jane Smith", email: "jane@example.com", role: "Editor" },
|
|
402
|
+
{ id: 3, name: "Sam Johnson", email: "sam@example.com", role: "Viewer" },
|
|
403
|
+
{ id: 4, name: "Alice Brown", email: "alice@example.com", role: "Editor" },
|
|
404
|
+
{ id: 5, name: "Bob White", email: "bob@example.com", role: "Viewer" },
|
|
405
|
+
{ id: 6, name: "Charlie Black", email: "charlie@example.com", role: "Admin" },
|
|
406
|
+
{ id: 7, name: "Diana Green", email: "diana@example.com", role: "Viewer" },
|
|
407
|
+
{ id: 8, name: "Eve Blue", email: "eve@example.com", role: "Editor" },
|
|
408
|
+
{ id: 9, name: "Frank Yellow", email: "frank@example.com", role: "Viewer" },
|
|
409
|
+
{ id: 10, name: "Grace Red", email: "grace@example.com", role: "Admin" },
|
|
391
410
|
];
|
|
392
411
|
|
|
393
412
|
const Example = () => {
|
|
394
413
|
const [page, setPage] = useState(1);
|
|
395
414
|
const [perPage, setPerPage] = useState(5);
|
|
396
415
|
|
|
397
|
-
const
|
|
416
|
+
const pageCount = useMemo(() => Math.ceil(data.length / perPage), [perPage]);
|
|
398
417
|
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
418
|
+
const paginatedData = useMemo(() => {
|
|
419
|
+
const start = (page - 1) * perPage;
|
|
420
|
+
const end = page * perPage;
|
|
421
|
+
return data.slice(start, end);
|
|
422
|
+
}, [page, perPage]);
|
|
405
423
|
|
|
406
424
|
return (
|
|
407
|
-
<div>
|
|
408
|
-
<
|
|
425
|
+
<div className="space-y-4">
|
|
426
|
+
<div className="space-y-1">
|
|
427
|
+
<h1 className="text-xl font-bold">DataTable v2</h1>
|
|
428
|
+
<p className="text-sm text-muted-foreground">
|
|
429
|
+
Manual pagination + templates + sticky header + accent
|
|
430
|
+
</p>
|
|
431
|
+
</div>
|
|
409
432
|
|
|
410
433
|
<DataTable
|
|
411
434
|
columns={columns}
|
|
412
435
|
data={paginatedData}
|
|
413
|
-
pageCount={
|
|
436
|
+
pageCount={pageCount}
|
|
414
437
|
page={page}
|
|
415
438
|
perPage={perPage}
|
|
416
|
-
onPageChange={
|
|
417
|
-
onPageSizeChange={
|
|
439
|
+
onPageChange={setPage}
|
|
440
|
+
onPageSizeChange={(size) => {
|
|
441
|
+
setPerPage(size);
|
|
442
|
+
setPage(1);
|
|
443
|
+
}}
|
|
444
|
+
totalRows={data.length}
|
|
445
|
+
isRowsSelected={false}
|
|
418
446
|
rowPerPageLabel="Rows per page"
|
|
419
447
|
pageLabel="Page"
|
|
420
448
|
ofLabel="of"
|
|
421
449
|
rowsSelectedLabel="rows selected"
|
|
422
|
-
emptyData={<div>No data available</div>}
|
|
450
|
+
emptyData={<div className="py-10 text-center">No data available</div>}
|
|
451
|
+
|
|
452
|
+
// ✨ NEW (v0.6.6)
|
|
453
|
+
template="neo" // neo | glass | compact | minimal | clean | elevated | grid | cards
|
|
454
|
+
accent="primary" // primary | emerald | indigo | rose | amber | zinc
|
|
455
|
+
stickyHeader={true}
|
|
456
|
+
headerScroll={false}
|
|
457
|
+
animate={true}
|
|
458
|
+
heightClassName="h-[420px]" // Important: Define the height for the ScrollArea to work.
|
|
459
|
+
|
|
460
|
+
onClick={(row) => {
|
|
461
|
+
// demo: click in row
|
|
462
|
+
console.log("Row clicked:", row);
|
|
463
|
+
}}
|
|
464
|
+
|
|
465
|
+
// optional
|
|
466
|
+
classNames={{
|
|
467
|
+
// root: "border-primary/20",
|
|
468
|
+
// th: "text-[10px]",
|
|
469
|
+
// td: "py-2",
|
|
470
|
+
}}
|
|
423
471
|
/>
|
|
424
472
|
</div>
|
|
425
473
|
);
|