@fakeoai/ui 0.0.8 → 0.0.9

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.
@@ -1,6 +1,7 @@
1
1
  import { TableProps } from "antd";
2
2
  import React from "react";
3
3
  import { UseQueryResult } from "@tanstack/react-query";
4
+ import { ExpandableConfig } from "antd/es/table/interface";
4
5
  import { IPage } from "../types";
5
6
  export interface TableAction<T> {
6
7
  label?: string;
@@ -25,7 +26,7 @@ export declare function getTableInstance<T>({ columns, expandable, actions, butt
25
26
  columns: TableProps<T>["columns"];
26
27
  actions?: TableAction<T>[] | TableActionFunc<T>;
27
28
  buttons?: React.ReactNode;
28
- expandable?: NonNullable<TableProps<T>["expandable"]>;
29
+ expandable?: ExpandableConfig<T>["expandedRowRender"];
29
30
  rowSelection?: TableProps<T>["rowSelection"];
30
31
  children?: React.ReactNode;
31
32
  api: (params: any) => UseQueryResult<IPage<T>, Error>;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Table as AntdTable } from "antd";
3
3
  import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, } from "@heroui/react";
4
4
  import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
5
- import { EllipsisVertical } from "lucide-react";
5
+ import { EllipsisVertical, RotateCw } from "lucide-react";
6
6
  import { Pagination } from "./pagination";
7
7
  import { Loading } from "./loading";
8
8
  import { cn } from "..";
@@ -106,11 +106,19 @@ export function getTableInstance({ columns, expandable, actions = [], buttons, a
106
106
  columnWidth: 50,
107
107
  fixed: false,
108
108
  }, rowSelection);
109
- const { data, isFetching } = api(params);
109
+ const { data, isFetching, refetch } = api(params);
110
110
  const onPageChange = useCallback((offset, limit) => {
111
111
  setOffset(offset);
112
112
  setLimit(limit);
113
113
  }, []);
114
+ const expandableProps = useMemo(() => expandable &&
115
+ {
116
+ columnWidth: 50,
117
+ columnTitle: (_jsx("div", { className: "flex items-center justify-center", children: _jsx(RotateCw, { className: "w-4 h-4 cursor-pointer", onClick: () => refetch() }) })),
118
+ fixed: "left",
119
+ expandRowByClick: true,
120
+ expandedRowRender: expandable,
121
+ }, [expandable]);
114
122
  const onTableChange = useCallback((_, filter, sorter) => {
115
123
  if (Object.entries(filter).some(([k, v]) => !Object.keys(filters).includes(k) || v !== filters[k])) {
116
124
  setFilters(filter);
@@ -139,7 +147,7 @@ export function getTableInstance({ columns, expandable, actions = [], buttons, a
139
147
  onChange: onPageChange,
140
148
  current: o,
141
149
  pageSize: l,
142
- }, children: children, expandable: expandable, rowSelection: rowSelectionProps, actions: actions, onChange: onTableChange, rowKey: "id" })), [
150
+ }, children: children, expandable: expandableProps, rowSelection: rowSelectionProps, actions: actions, onChange: onTableChange, rowKey: "id" })), [
143
151
  isFetching,
144
152
  columns,
145
153
  data,
@@ -151,5 +159,6 @@ export function getTableInstance({ columns, expandable, actions = [], buttons, a
151
159
  rowSelection,
152
160
  className,
153
161
  children,
162
+ expandableProps,
154
163
  ]);
155
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fakeoai/ui",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Reusable UI components and common table logic extracted from tokens2.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",