@canvas-components/react-list-table 0.2.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/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/index.cjs +2915 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +85 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +2913 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 canvas-components contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @canvas-components/react-list-table
|
|
2
|
+
|
|
3
|
+
`@canvas-components/react-list-table` 是 `@canvas-components/list-table` 的 React 适配层,负责把原生 Canvas 表格接入 React 应用,并提供更接近业务开发习惯的组件化入口。
|
|
4
|
+
|
|
5
|
+
## 功能作用
|
|
6
|
+
|
|
7
|
+
- 提供 `ReactListTable` 组件
|
|
8
|
+
- 内置工具栏、分页层、编辑层、tooltip、图片预览
|
|
9
|
+
- 暴露 `ref` 方法,方便外部校验和滚动定位
|
|
10
|
+
- 保持底层大数据性能和纯原生渲染能力
|
|
11
|
+
|
|
12
|
+
## 安装方法
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @canvas-components/react-list-table @canvas-components/list-table react@^16.8 react-dom@^16.8
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
最低依赖版本:
|
|
19
|
+
|
|
20
|
+
- `react >= 16.8.0`
|
|
21
|
+
- `react-dom >= 16.8.0`
|
|
22
|
+
- `Node.js >= 18.12.0`
|
|
23
|
+
- `pnpm >= 9.0.0`
|
|
24
|
+
|
|
25
|
+
## 使用方法
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { useMemo, useRef } from "react";
|
|
29
|
+
import {
|
|
30
|
+
ReactListTable,
|
|
31
|
+
type ReactListTableRef,
|
|
32
|
+
} from "@canvas-components/react-list-table";
|
|
33
|
+
|
|
34
|
+
interface UserRow {
|
|
35
|
+
id: number;
|
|
36
|
+
name: string;
|
|
37
|
+
age: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function DemoTable() {
|
|
41
|
+
const tableRef = useRef<ReactListTableRef<UserRow> | null>(null);
|
|
42
|
+
|
|
43
|
+
const columns = useMemo(
|
|
44
|
+
() => [
|
|
45
|
+
{ key: "name", title: "姓名", dataIndex: "name", width: 180 },
|
|
46
|
+
{ key: "age", title: "年龄", dataIndex: "age", width: 120, align: "right" as const },
|
|
47
|
+
],
|
|
48
|
+
[],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ReactListTable<UserRow>
|
|
53
|
+
ref={tableRef}
|
|
54
|
+
rowKey="id"
|
|
55
|
+
height={480}
|
|
56
|
+
columns={columns}
|
|
57
|
+
dataSource={[
|
|
58
|
+
{ id: 1, name: "张三", age: 28 },
|
|
59
|
+
{ id: 2, name: "李四", age: 31 },
|
|
60
|
+
]}
|
|
61
|
+
toolbar={{ showRefresh: true, showExport: true }}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 属性说明
|
|
68
|
+
|
|
69
|
+
### `ReactListTableProps`
|
|
70
|
+
|
|
71
|
+
`ReactListTableProps` 继承自 `ListTableOptions`,并额外补充 React 宿主相关能力。
|
|
72
|
+
|
|
73
|
+
| 属性 | 类型 | 说明 |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| `width` | `number \| string` | 表格宽度 |
|
|
76
|
+
| `height` | `number \| string` | 表格高度 |
|
|
77
|
+
| `emptyText` | `string` | 空状态文案 |
|
|
78
|
+
| `scroll` | `ReactListTableScrollConfig` | React 风格滚动尺寸配置 |
|
|
79
|
+
| `locale` | `ReactListTableLocale` | 本地化文案 |
|
|
80
|
+
| `onChange` | `ListTableQueryChange<RecordType>` | 查询状态变更回调 |
|
|
81
|
+
| `className` | `string` | 根节点类名 |
|
|
82
|
+
| `style` | `CSSProperties` | 根节点样式 |
|
|
83
|
+
| `title` | `ReactNode` | 标题栏左侧内容 |
|
|
84
|
+
| `toolbar` | `false \| ReactListTableToolbarOptions` | 工具栏配置,传 `false` 隐藏 |
|
|
85
|
+
|
|
86
|
+
其余如 `columns`、`dataSource`、`rowSelection`、`expandable`、`pagination`、`rowDrag`、`draggable`、`resizable` 等属性与 `@canvas-components/list-table` 保持一致。
|
|
87
|
+
|
|
88
|
+
### `ReactListTableToolbarOptions`
|
|
89
|
+
|
|
90
|
+
| 属性 | 类型 | 说明 |
|
|
91
|
+
| --- | --- | --- |
|
|
92
|
+
| `showRefresh` | `boolean` | 是否显示刷新按钮 |
|
|
93
|
+
| `showFullscreen` | `boolean` | 是否显示全屏按钮 |
|
|
94
|
+
| `showDensity` | `boolean` | 是否显示密度切换 |
|
|
95
|
+
| `showColumnSetting` | `boolean` | 是否显示列设置 |
|
|
96
|
+
| `columnSettingWidth` | `number \| string` | 列设置面板宽度 |
|
|
97
|
+
| `showExport` | `boolean` | 是否显示导出按钮 |
|
|
98
|
+
| `onRefresh` | `() => void` | 点击刷新回调 |
|
|
99
|
+
| `onExport` | `() => void` | 自定义导出回调 |
|
|
100
|
+
| `getFullscreenNode` | `() => HTMLElement \| null` | 自定义全屏节点 |
|
|
101
|
+
| `extra` | `ReactNode` | 工具栏右侧额外内容 |
|
|
102
|
+
|
|
103
|
+
## 方法说明
|
|
104
|
+
|
|
105
|
+
### `ReactListTableRef`
|
|
106
|
+
|
|
107
|
+
| 方法 | 签名 | 说明 |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `validate` | `() => Promise<RecordType[]>` | 触发表格校验 |
|
|
110
|
+
| `scrollTo` | `(options) => void` | 滚动到指定行 |
|
|
111
|
+
| `getDebugSnapshot` | `() => ListTableDebugSnapshot \| null` | 获取调试快照 |
|
|
112
|
+
|
|
113
|
+
## 类型别名
|
|
114
|
+
|
|
115
|
+
| 类型 | 说明 |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `ReactListTableTableProps<RecordType>` | `ReactListTableProps<RecordType>` 的别名 |
|
|
118
|
+
| `ReactListTableColumnType<RecordType>` | 单列类型别名 |
|
|
119
|
+
| `ReactListTableColumnsType<RecordType>` | 列数组类型别名 |
|
|
120
|
+
| `ReactListTableRowSelection<RecordType>` | 行选择类型别名 |
|
|
121
|
+
| `ReactListTablePagination` | 分页类型别名 |
|
|
122
|
+
| `ReactListTableQuery<RecordType>` | 查询类型别名 |
|
|
123
|
+
|
|
124
|
+
## 推荐场景
|
|
125
|
+
|
|
126
|
+
- React 后台管理表格
|
|
127
|
+
- 大数据量只读 / 可编辑表格
|
|
128
|
+
- 需要原生性能但又希望保留 React 组件用法的场景
|