@a2v2ai/uikit 0.0.30 → 0.0.31
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/DataTable/DataTable.d.ts +17 -3
- package/DataTable/DataTable.js +33 -2
- package/Pagination/Pagination.d.ts +35 -0
- package/Pagination/Pagination.js +37 -0
- package/index.d.ts +2 -1
- package/index.js +1 -0
- package/package.json +1 -1
package/DataTable/DataTable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
interface DataTableColumn<T> {
|
|
3
3
|
key: string;
|
|
4
4
|
title: string;
|
|
5
5
|
titleRender?: () => ReactNode;
|
|
@@ -8,14 +8,28 @@ export interface DataTableColumn<T> {
|
|
|
8
8
|
render?: (value: unknown, record: T, index: number) => ReactNode;
|
|
9
9
|
className?: string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
interface DataTablePagination {
|
|
12
|
+
current: number;
|
|
13
|
+
pageSize: number;
|
|
14
|
+
total: number;
|
|
15
|
+
onChange: (page: number) => void;
|
|
16
|
+
}
|
|
17
|
+
interface DataTableScroll {
|
|
18
|
+
y?: number | string;
|
|
19
|
+
}
|
|
20
|
+
interface DataTableProps<T extends object> {
|
|
12
21
|
columns: DataTableColumn<T>[];
|
|
13
22
|
dataSource: T[];
|
|
14
23
|
rowKey: keyof T | ((record: T) => string);
|
|
15
24
|
className?: string;
|
|
25
|
+
pagination?: DataTablePagination;
|
|
26
|
+
scroll?: DataTableScroll;
|
|
27
|
+
loading?: boolean;
|
|
28
|
+
loadingRows?: number;
|
|
16
29
|
}
|
|
17
30
|
declare const DataTable: {
|
|
18
|
-
<T extends object>({ columns, dataSource, rowKey, className, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
<T extends object>({ columns, dataSource, rowKey, className, pagination, scroll, loading, loadingRows, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
19
32
|
displayName: string;
|
|
20
33
|
};
|
|
21
34
|
export { DataTable };
|
|
35
|
+
export type { DataTableColumn, DataTableProps, DataTablePagination, DataTableScroll };
|
package/DataTable/DataTable.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../Table/Table";
|
|
3
|
-
|
|
3
|
+
import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "../Pagination/Pagination";
|
|
4
|
+
import { Skeleton } from "../Skeleton/Skeleton";
|
|
5
|
+
const getPageNumbers = (current, totalPages) => {
|
|
6
|
+
const pages = [];
|
|
7
|
+
if (totalPages <= 7) {
|
|
8
|
+
for (let i = 1; i <= totalPages; i++) {
|
|
9
|
+
pages.push(i);
|
|
10
|
+
}
|
|
11
|
+
return pages;
|
|
12
|
+
}
|
|
13
|
+
// Always show first page
|
|
14
|
+
pages.push(1);
|
|
15
|
+
if (current <= 3) {
|
|
16
|
+
// Near the start
|
|
17
|
+
pages.push(2, 3, 4, "ellipsis", totalPages);
|
|
18
|
+
}
|
|
19
|
+
else if (current >= totalPages - 2) {
|
|
20
|
+
// Near the end
|
|
21
|
+
pages.push("ellipsis", totalPages - 3, totalPages - 2, totalPages - 1, totalPages);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// In the middle
|
|
25
|
+
pages.push("ellipsis", current - 1, current, current + 1, "ellipsis", totalPages);
|
|
26
|
+
}
|
|
27
|
+
return pages;
|
|
28
|
+
};
|
|
29
|
+
const DataTable = ({ columns, dataSource, rowKey, className, pagination, scroll, loading, loadingRows = 5, }) => {
|
|
4
30
|
const getRowKey = (record) => {
|
|
5
31
|
if (typeof rowKey === "function") {
|
|
6
32
|
return rowKey(record);
|
|
@@ -14,7 +40,12 @@ const DataTable = ({ columns, dataSource, rowKey, className, }) => {
|
|
|
14
40
|
}
|
|
15
41
|
return value;
|
|
16
42
|
};
|
|
17
|
-
|
|
43
|
+
const totalPages = pagination ? Math.ceil(pagination.total / pagination.pageSize) : 0;
|
|
44
|
+
const pageNumbers = pagination ? getPageNumbers(pagination.current, totalPages) : [];
|
|
45
|
+
const tableContent = (_jsxs(Table, { className: className, children: [_jsx(TableHeader, { className: scroll?.y ? "sticky top-0 z-10" : undefined, children: _jsx(TableRow, { children: columns.map((column) => (_jsx(TableHead, { className: column.className, style: { width: column.width }, children: column.titleRender ? column.titleRender() : column.title }, column.key))) }) }), _jsx(TableBody, { children: loading
|
|
46
|
+
? Array.from({ length: loadingRows }).map((_, rowIndex) => (_jsx(TableRow, { children: columns.map((column) => (_jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-full" }) }, column.key))) }, `skeleton-${rowIndex}`)))
|
|
47
|
+
: dataSource.map((record, index) => (_jsx(TableRow, { children: columns.map((column) => (_jsx(TableCell, { children: getCellValue(record, column, index) }, column.key))) }, getRowKey(record)))) })] }));
|
|
48
|
+
return (_jsxs("div", { className: "w-full", children: [scroll?.y ? (_jsx("div", { className: "relative w-full overflow-auto", style: { maxHeight: scroll.y }, children: tableContent })) : (tableContent), pagination && totalPages > 1 && (_jsx("div", { className: "mt-4", children: _jsx(Pagination, { children: _jsxs(PaginationContent, { children: [_jsx(PaginationItem, { children: _jsx(PaginationPrevious, { disabled: pagination.current === 1, onClick: () => pagination.onChange(pagination.current - 1) }) }), pageNumbers.map((page, index) => (_jsx(PaginationItem, { children: page === "ellipsis" ? (_jsx(PaginationEllipsis, {})) : (_jsx(PaginationLink, { isActive: page === pagination.current, onClick: () => pagination.onChange(page), children: page })) }, index))), _jsx(PaginationItem, { children: _jsx(PaginationNext, { disabled: pagination.current === totalPages, onClick: () => pagination.onChange(pagination.current + 1) }) })] }) }) }))] }));
|
|
18
49
|
};
|
|
19
50
|
DataTable.displayName = "DataTable";
|
|
20
51
|
export { DataTable };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare function Pagination({ className, ...props }: React.ComponentProps<"nav">): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare namespace Pagination {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
declare function PaginationContent({ className, ...props }: React.ComponentProps<"ul">): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare namespace PaginationContent {
|
|
8
|
+
var displayName: string;
|
|
9
|
+
}
|
|
10
|
+
declare function PaginationItem({ ...props }: React.ComponentProps<"li">): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare namespace PaginationItem {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
type PaginationLinkProps = {
|
|
15
|
+
isActive?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
} & React.ComponentProps<"button">;
|
|
18
|
+
declare function PaginationLink({ className, isActive, disabled, ...props }: PaginationLinkProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
declare namespace PaginationLink {
|
|
20
|
+
var displayName: string;
|
|
21
|
+
}
|
|
22
|
+
declare function PaginationPrevious({ className, ...props }: React.ComponentProps<typeof PaginationLink>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
declare namespace PaginationPrevious {
|
|
24
|
+
var displayName: string;
|
|
25
|
+
}
|
|
26
|
+
declare function PaginationNext({ className, ...props }: React.ComponentProps<typeof PaginationLink>): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
declare namespace PaginationNext {
|
|
28
|
+
var displayName: string;
|
|
29
|
+
}
|
|
30
|
+
declare function PaginationEllipsis({ className, ...props }: React.ComponentProps<"span">): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
declare namespace PaginationEllipsis {
|
|
32
|
+
var displayName: string;
|
|
33
|
+
}
|
|
34
|
+
export { Pagination, PaginationContent, PaginationLink, PaginationItem, PaginationPrevious, PaginationNext, PaginationEllipsis, };
|
|
35
|
+
export type { PaginationLinkProps };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/utils";
|
|
5
|
+
import { buttonVariants } from "../Button/Button";
|
|
6
|
+
function Pagination({ className, ...props }) {
|
|
7
|
+
return (_jsx("nav", { role: "navigation", "aria-label": "pagination", className: cn("mx-auto flex w-full justify-center", className), ...props }));
|
|
8
|
+
}
|
|
9
|
+
Pagination.displayName = "Pagination";
|
|
10
|
+
function PaginationContent({ className, ...props }) {
|
|
11
|
+
return (_jsx("ul", { className: cn("flex flex-row items-center gap-1", className), ...props }));
|
|
12
|
+
}
|
|
13
|
+
PaginationContent.displayName = "PaginationContent";
|
|
14
|
+
function PaginationItem({ ...props }) {
|
|
15
|
+
return _jsx("li", { ...props });
|
|
16
|
+
}
|
|
17
|
+
PaginationItem.displayName = "PaginationItem";
|
|
18
|
+
function PaginationLink({ className, isActive, disabled, ...props }) {
|
|
19
|
+
return (_jsx("button", { type: "button", "aria-current": isActive ? "page" : undefined, disabled: disabled, className: cn(buttonVariants({
|
|
20
|
+
variant: isActive ? "outline" : "ghost",
|
|
21
|
+
size: "small",
|
|
22
|
+
}), "size-9", disabled && "pointer-events-none opacity-50", className), ...props }));
|
|
23
|
+
}
|
|
24
|
+
PaginationLink.displayName = "PaginationLink";
|
|
25
|
+
function PaginationPrevious({ className, ...props }) {
|
|
26
|
+
return (_jsxs(PaginationLink, { "aria-label": "Go to previous page", className: cn("gap-1 pl-2.5 pr-4 w-auto", className), ...props, children: [_jsx(ChevronLeft, { className: "size-4" }), _jsx("span", { className: "hidden sm:block", children: "Previous" })] }));
|
|
27
|
+
}
|
|
28
|
+
PaginationPrevious.displayName = "PaginationPrevious";
|
|
29
|
+
function PaginationNext({ className, ...props }) {
|
|
30
|
+
return (_jsxs(PaginationLink, { "aria-label": "Go to next page", className: cn("gap-1 pl-4 pr-2.5 w-auto", className), ...props, children: [_jsx("span", { className: "hidden sm:block", children: "Next" }), _jsx(ChevronRight, { className: "size-4" })] }));
|
|
31
|
+
}
|
|
32
|
+
PaginationNext.displayName = "PaginationNext";
|
|
33
|
+
function PaginationEllipsis({ className, ...props }) {
|
|
34
|
+
return (_jsxs("span", { "aria-hidden": true, className: cn("flex size-9 items-center justify-center", className), ...props, children: [_jsx(MoreHorizontal, { className: "size-4" }), _jsx("span", { className: "sr-only", children: "More pages" })] }));
|
|
35
|
+
}
|
|
36
|
+
PaginationEllipsis.displayName = "PaginationEllipsis";
|
|
37
|
+
export { Pagination, PaginationContent, PaginationLink, PaginationItem, PaginationPrevious, PaginationNext, PaginationEllipsis, };
|
package/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator, inputOTPVaria
|
|
|
20
20
|
export { Label, labelVariants, type LabelProps } from "./Label/Label";
|
|
21
21
|
export { Loader, loaderVariants, type LoaderProps, type LoaderSize, type LoaderColor } from "./Loader/Loader";
|
|
22
22
|
export { Menubar, MenubarPortal, MenubarMenu, MenubarTrigger, MenubarContent, MenubarGroup, MenubarSeparator, MenubarLabel, MenubarItem, MenubarShortcut, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarSub, MenubarSubTrigger, MenubarSubContent, } from "./Menubar/Menubar";
|
|
23
|
+
export { Pagination, PaginationContent, PaginationLink, PaginationItem, PaginationPrevious, PaginationNext, PaginationEllipsis, type PaginationLinkProps, } from "./Pagination/Pagination";
|
|
23
24
|
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from "./Popover/Popover";
|
|
24
25
|
export { Progress, progressVariants, progressIndicatorVariants, type ProgressProps, type ProgressSize, type ProgressVariant } from "./Progress/Progress";
|
|
25
26
|
export { RadioGroup, RadioGroupItem, radioGroupItemVariants, type RadioGroupItemProps, type RadioGroupItemSize } from "./RadioGroup/RadioGroup";
|
|
@@ -32,7 +33,7 @@ export { Slider, type SliderProps } from "./Slider/Slider";
|
|
|
32
33
|
export { Spinner, spinnerVariants, type SpinnerProps, type SpinnerSize, type SpinnerVariant } from "./Spinner/Spinner";
|
|
33
34
|
export { Switch, switchVariants, type SwitchProps, type SwitchSize } from "./Switch/Switch";
|
|
34
35
|
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, } from "./Table/Table";
|
|
35
|
-
export { DataTable, type DataTableColumn, type DataTableProps } from "./DataTable/DataTable";
|
|
36
|
+
export { DataTable, type DataTableColumn, type DataTableProps, type DataTablePagination, type DataTableScroll } from "./DataTable/DataTable";
|
|
36
37
|
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants, type TabsListProps, type TabsListVariant } from "./Tabs/Tabs";
|
|
37
38
|
export { Textarea, textareaVariants, type TextareaProps, type TextareaVariant, type TextareaResize } from "./Textarea/Textarea";
|
|
38
39
|
export { Toaster, toast, type ToastProps, type ToastTheme } from "./Toast/Toast";
|
package/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator, inputOTPVaria
|
|
|
22
22
|
export { Label, labelVariants } from "./Label/Label";
|
|
23
23
|
export { Loader, loaderVariants } from "./Loader/Loader";
|
|
24
24
|
export { Menubar, MenubarPortal, MenubarMenu, MenubarTrigger, MenubarContent, MenubarGroup, MenubarSeparator, MenubarLabel, MenubarItem, MenubarShortcut, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarSub, MenubarSubTrigger, MenubarSubContent, } from "./Menubar/Menubar";
|
|
25
|
+
export { Pagination, PaginationContent, PaginationLink, PaginationItem, PaginationPrevious, PaginationNext, PaginationEllipsis, } from "./Pagination/Pagination";
|
|
25
26
|
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from "./Popover/Popover";
|
|
26
27
|
export { Progress, progressVariants, progressIndicatorVariants } from "./Progress/Progress";
|
|
27
28
|
export { RadioGroup, RadioGroupItem, radioGroupItemVariants } from "./RadioGroup/RadioGroup";
|