@meta-1/design 0.0.195 → 0.0.197
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/package.json
CHANGED
|
@@ -50,7 +50,6 @@ export type DataTableColumn<TData> = ColumnDef<TData, unknown> & {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export interface DataTableProps<TData> {
|
|
53
|
-
autoHidePagination?: boolean;
|
|
54
53
|
inCard?: boolean;
|
|
55
54
|
columns: DataTableColumn<TData>[];
|
|
56
55
|
data: TData[];
|
|
@@ -173,7 +172,6 @@ export function DataTable<TData>(props: DataTableProps<TData>) {
|
|
|
173
172
|
load,
|
|
174
173
|
cellHandles,
|
|
175
174
|
showHeader = true,
|
|
176
|
-
autoHidePagination = true,
|
|
177
175
|
inCard = false,
|
|
178
176
|
maxHeight,
|
|
179
177
|
} = props;
|
|
@@ -360,11 +358,8 @@ export function DataTable<TData>(props: DataTableProps<TData>) {
|
|
|
360
358
|
const showToolbar = useMemo(() => filter || showVisibilityControl, [filter, showVisibilityControl]);
|
|
361
359
|
|
|
362
360
|
const showPagination = useMemo(() => {
|
|
363
|
-
if (autoHidePagination) {
|
|
364
|
-
return pagination && (pagination as PaginationProps).total > (pagination as PaginationProps).pageSize;
|
|
365
|
-
}
|
|
366
361
|
return pagination;
|
|
367
|
-
}, [pagination
|
|
362
|
+
}, [pagination]);
|
|
368
363
|
|
|
369
364
|
// 渲染表头的通用函数
|
|
370
365
|
const renderTableHeader = () => {
|
|
@@ -468,54 +463,56 @@ export function DataTable<TData>(props: DataTableProps<TData>) {
|
|
|
468
463
|
};
|
|
469
464
|
|
|
470
465
|
return (
|
|
471
|
-
|
|
472
|
-
{
|
|
473
|
-
<div
|
|
474
|
-
|
|
475
|
-
"border-0 border-secondary border-b border-solid pb-2",
|
|
476
|
-
"flex items-end",
|
|
477
|
-
filter ? "justify-between" : "justify-end",
|
|
478
|
-
)}
|
|
479
|
-
>
|
|
480
|
-
{filter ? <Filters {...filter} load={load} loading={loading} /> : null}
|
|
481
|
-
{showVisibilityControl ? (
|
|
482
|
-
<Dropdown align="end" asChild={true} items={columnSettings}>
|
|
483
|
-
<Action className="!p-0 h-9 w-9">
|
|
484
|
-
<LayoutIcon className="h-[18px] w-[18px]" />
|
|
485
|
-
</Action>
|
|
486
|
-
</Dropdown>
|
|
487
|
-
) : null}
|
|
488
|
-
</div>
|
|
489
|
-
) : null}
|
|
490
|
-
<div className={cn("relative")}>
|
|
491
|
-
{maxHeight ? (
|
|
492
|
-
// 有高度限制时:直接渲染 table 元素,避免 Table 组件自带的 overflow-x-auto 包裹层
|
|
493
|
-
<div className={cn("overflow-x-auto", !mounted && "invisible")}>
|
|
466
|
+
<div className={cn("relative")}>
|
|
467
|
+
<div className={"flex flex-col gap-md"}>
|
|
468
|
+
<div>
|
|
469
|
+
{showToolbar ? (
|
|
494
470
|
<div
|
|
495
|
-
className=
|
|
496
|
-
|
|
471
|
+
className={cn(
|
|
472
|
+
"border-0 border-secondary border-b border-solid pb-2",
|
|
473
|
+
"flex items-end",
|
|
474
|
+
filter ? "justify-between" : "justify-end",
|
|
475
|
+
)}
|
|
497
476
|
>
|
|
498
|
-
<
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
477
|
+
{filter ? <Filters {...filter} load={load} loading={loading} /> : null}
|
|
478
|
+
{showVisibilityControl ? (
|
|
479
|
+
<Dropdown align="end" asChild={true} items={columnSettings}>
|
|
480
|
+
<Action className="!p-0 h-9 w-9">
|
|
481
|
+
<LayoutIcon className="h-[18px] w-[18px]" />
|
|
482
|
+
</Action>
|
|
483
|
+
</Dropdown>
|
|
484
|
+
) : null}
|
|
485
|
+
</div>
|
|
486
|
+
) : null}
|
|
487
|
+
{maxHeight ? (
|
|
488
|
+
// 有高度限制时:直接渲染 table 元素,避免 Table 组件自带的 overflow-x-auto 包裹层
|
|
489
|
+
<div className={cn("overflow-x-auto", !mounted && "invisible")}>
|
|
490
|
+
<div
|
|
491
|
+
className="overflow-y-auto"
|
|
492
|
+
style={{ maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight }}
|
|
504
493
|
>
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
494
|
+
<table
|
|
495
|
+
className={classNames(
|
|
496
|
+
"data-table data-table-sticky-header w-full caption-bottom text-sm",
|
|
497
|
+
inCard ? "in-card" : null,
|
|
498
|
+
)}
|
|
499
|
+
data-slot="table"
|
|
500
|
+
>
|
|
501
|
+
{renderTableHeader()}
|
|
502
|
+
{renderTableBody()}
|
|
503
|
+
</table>
|
|
504
|
+
</div>
|
|
508
505
|
</div>
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
506
|
+
) : (
|
|
507
|
+
// 无高度限制时,使用原有布局
|
|
508
|
+
<Table className={classNames("data-table", inCard ? "in-card" : null, !mounted && "invisible")}>
|
|
509
|
+
{renderTableHeader()}
|
|
510
|
+
{renderTableBody()}
|
|
511
|
+
</Table>
|
|
512
|
+
)}
|
|
513
|
+
</div>
|
|
517
514
|
{showPagination ? (
|
|
518
|
-
<div className={cn(
|
|
515
|
+
<div className={cn(!mounted && "invisible")}>
|
|
519
516
|
<Pagination
|
|
520
517
|
{...(pagination as PaginationProps)}
|
|
521
518
|
onChange={(page: number) => {
|
|
@@ -527,12 +524,12 @@ export function DataTable<TData>(props: DataTableProps<TData>) {
|
|
|
527
524
|
/>
|
|
528
525
|
</div>
|
|
529
526
|
) : null}
|
|
530
|
-
{loading || !mounted ? (
|
|
531
|
-
<div className="dark:!bg-black/5 absolute top-0 right-0 bottom-0 left-0 z-50 flex items-center justify-center bg-white/50">
|
|
532
|
-
<Spin />
|
|
533
|
-
</div>
|
|
534
|
-
) : null}
|
|
535
527
|
</div>
|
|
536
|
-
|
|
528
|
+
{loading || !mounted ? (
|
|
529
|
+
<div className="dark:!bg-black/5 absolute top-0 right-0 bottom-0 left-0 z-50 flex items-center justify-center bg-white/50">
|
|
530
|
+
<Spin />
|
|
531
|
+
</div>
|
|
532
|
+
) : null}
|
|
533
|
+
</div>
|
|
537
534
|
);
|
|
538
535
|
}
|