@sio-group/ui-datatable 0.1.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/CHANGELOG.md +16 -0
- package/README.md +429 -0
- package/dist/index.cjs +647 -0
- package/dist/index.d.cts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +620 -0
- package/dist/styles/index.css +154 -0
- package/dist/styles/index.css.map +1 -0
- package/package.json +44 -0
- package/src/assets/scss/index.scss +170 -0
- package/src/assets/scss/tokens/_color.scss +19 -0
- package/src/assets/scss/tokens/_datatable.scss +10 -0
- package/src/components/ActionCell.tsx +88 -0
- package/src/components/DataTable.tsx +85 -0
- package/src/components/DataTableBody.tsx +34 -0
- package/src/components/DataTableControls.tsx +35 -0
- package/src/components/DataTableHeader.tsx +59 -0
- package/src/components/DefaultSortIcon.tsx +13 -0
- package/src/components/TableCell.tsx +17 -0
- package/src/components/cell-types/BooleanCell.tsx +29 -0
- package/src/components/cell-types/DateCell.tsx +28 -0
- package/src/components/cell-types/EmptyCell.tsx +3 -0
- package/src/components/cell-types/InlineInputCell.tsx +129 -0
- package/src/hooks/useDataTable.ts +113 -0
- package/src/index.ts +14 -0
- package/src/types/action-cell-props.d.ts +9 -0
- package/src/types/action-menu.d.ts +15 -0
- package/src/types/column.d.ts +10 -0
- package/src/types/data-table-body-props.d.ts +16 -0
- package/src/types/data-table-header-props.d.ts +11 -0
- package/src/types/data-table-props.d.ts +32 -0
- package/src/types/entity.d.ts +4 -0
- package/src/types/form-field.d.ts +8 -0
- package/src/types/index.ts +11 -0
- package/src/types/pagination-meta.d.ts +7 -0
- package/src/types/sort-state.d.ts +6 -0
- package/src/types/table-cell-props.d.ts +9 -0
- package/src/types/use-data-table-props.d.ts +14 -0
- package/src/types/use-data-table-return.d.ts +14 -0
- package/src/utils/is-pill-value.ts +7 -0
- package/src/utils/render-object.tsx +18 -0
- package/src/utils/render-value.tsx +89 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +8 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {Column, FormField} from "../types";
|
|
2
|
+
import {EmptyCell} from "../components/cell-types/EmptyCell";
|
|
3
|
+
import {BooleanCell} from "../components/cell-types/BooleanCell";
|
|
4
|
+
import {Link, Pill} from "@sio-group/ui-core";
|
|
5
|
+
import {renderObject} from "./render-object";
|
|
6
|
+
import {DateCell} from "../components/cell-types/DateCell";
|
|
7
|
+
import {isPillValue} from "./is-pill-value";
|
|
8
|
+
import {InlineInputCell} from "../components/cell-types/InlineInputCell";
|
|
9
|
+
|
|
10
|
+
interface RenderValueProps <T extends { id: string | number }> {
|
|
11
|
+
value: T[keyof T];
|
|
12
|
+
column: Column<T>;
|
|
13
|
+
item: T;
|
|
14
|
+
formFields?: FormField[];
|
|
15
|
+
updateData?: (id: (string | number), values: Partial<T>) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const renderValue = <T extends { id: string | number }> ({value, column, item, formFields, updateData}: RenderValueProps<T>) => {
|
|
19
|
+
const formatKey: string | undefined = typeof column.format === 'object' ? column.format.key : undefined;
|
|
20
|
+
|
|
21
|
+
const formField: FormField | undefined = formFields?.find((f: FormField): boolean => f.name === column.name);
|
|
22
|
+
if (formField) {
|
|
23
|
+
return (
|
|
24
|
+
<InlineInputCell
|
|
25
|
+
column={column}
|
|
26
|
+
value={value}
|
|
27
|
+
item={item}
|
|
28
|
+
formField={formField}
|
|
29
|
+
updateData={updateData}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (value === null || value === undefined) return <EmptyCell />;
|
|
35
|
+
if (Array.isArray(value) && !value.length) return <EmptyCell />;
|
|
36
|
+
|
|
37
|
+
if (column.format === "boolean" || column.format === "button") {
|
|
38
|
+
return (
|
|
39
|
+
<BooleanCell
|
|
40
|
+
column={column}
|
|
41
|
+
value={value}
|
|
42
|
+
item={item}
|
|
43
|
+
updateData={updateData}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (column.format === "datetime" || column.format === "date") {
|
|
49
|
+
return (
|
|
50
|
+
<DateCell
|
|
51
|
+
column={column}
|
|
52
|
+
value={value}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (column.format === "pill" && isPillValue(value)) {
|
|
58
|
+
return <Pill status={value.status} label={value.label} />;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (column.format === "email") {
|
|
62
|
+
return <Link to={`mailto:${value}`}>{String(value)}</Link>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
{(value as Array<Record<string, unknown> | string>).map((x, i) => (
|
|
69
|
+
<div key={i}>
|
|
70
|
+
{typeof x === 'object' && x !== null
|
|
71
|
+
? formatKey
|
|
72
|
+
? String((x as Record<string, unknown>)[formatKey] ?? '')
|
|
73
|
+
: renderObject(x)
|
|
74
|
+
: String(x)
|
|
75
|
+
}
|
|
76
|
+
</div>
|
|
77
|
+
))}
|
|
78
|
+
</>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof value === 'object') {
|
|
83
|
+
return formatKey
|
|
84
|
+
? String((value as Record<string, unknown>)[formatKey] ?? '')
|
|
85
|
+
: renderObject(value as Record<string, unknown>);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return String(value)
|
|
89
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"composite": false,
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"jsxImportSource": "react"
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
11
|
+
"exclude": ["dist", "node_modules"],
|
|
12
|
+
"references": [
|
|
13
|
+
{ "path": "../ui-core" },
|
|
14
|
+
{ "path": "../ui-pagination" },
|
|
15
|
+
{ "path": "../ui-modal" },
|
|
16
|
+
]
|
|
17
|
+
}
|
package/tsup.config.ts
ADDED