@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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type SortDirection = 'asc' | 'desc';
|
|
5
|
+
|
|
6
|
+
interface SortState<T extends { id: string | number }> {
|
|
7
|
+
name: keyof T;
|
|
8
|
+
direction: SortDirection;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Column<T extends { id: number | string }> {
|
|
12
|
+
name: keyof T;
|
|
13
|
+
label: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
sort?: boolean;
|
|
17
|
+
format?: 'boolean' | 'button' | 'datetime' | 'date' | 'pill' | 'email' | { key: string };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Entity {
|
|
21
|
+
name: string;
|
|
22
|
+
label: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ActionMenuType = 'inline' | 'dropdown';
|
|
26
|
+
|
|
27
|
+
interface Action <T extends { id: string | number }> {
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
icon?: ReactNode;
|
|
31
|
+
onClick: (item: T) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ActionMenu <T extends { id: string | number }> {
|
|
35
|
+
type: ActionMenuType;
|
|
36
|
+
actions: Action<T>[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type FormFieldType = 'text' | 'radio' | 'select';
|
|
40
|
+
|
|
41
|
+
interface FormField {
|
|
42
|
+
name: string;
|
|
43
|
+
type: FormFieldType;
|
|
44
|
+
options?: { label: string; value: string }[] | string[];
|
|
45
|
+
required?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface PaginationMeta {
|
|
49
|
+
currentPage: number;
|
|
50
|
+
pageCount: number;
|
|
51
|
+
total: number;
|
|
52
|
+
from: number;
|
|
53
|
+
to: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface DataTableProps<T extends { id: string | number }> {
|
|
57
|
+
columns: Column<T>[],
|
|
58
|
+
data: T[],
|
|
59
|
+
pagination?: PaginationMeta,
|
|
60
|
+
onPaginate?: (page: number) => void,
|
|
61
|
+
onSearch?: (query: string) => void,
|
|
62
|
+
onSort?: (sort: SortState | null) => void,
|
|
63
|
+
searchValue?: string,
|
|
64
|
+
sortValue?: SortState | null,
|
|
65
|
+
clientPageSize?: number | null,
|
|
66
|
+
clientSearchKeys?: (keyof T)[],
|
|
67
|
+
entity?: Entity,
|
|
68
|
+
actionMenu?: ActionMenu<T>,
|
|
69
|
+
renderMenuIcon?: () => ReactNode,
|
|
70
|
+
onUpdate?: (id: string | number, values: Partial<T>) => void,
|
|
71
|
+
formFields?: FormField[],
|
|
72
|
+
renderSortIcon?: (direction: SortDirection, active: boolean) => ReactNode,
|
|
73
|
+
emptyMessage?: string,
|
|
74
|
+
striped?: boolean,
|
|
75
|
+
hover?: boolean,
|
|
76
|
+
style?: CSSProperties,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare const DataTable: <T extends {
|
|
80
|
+
id: string | number;
|
|
81
|
+
}>({ columns, entity, actionMenu, renderMenuIcon, onUpdate, formFields, renderSortIcon, emptyMessage, striped, hover, style, ...props }: DataTableProps<T>) => react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
export { type Action, type ActionMenu, type ActionMenuType, type Column, DataTable, type DataTableProps, type Entity, type FormField, type FormFieldType, type SortDirection, type SortState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type SortDirection = 'asc' | 'desc';
|
|
5
|
+
|
|
6
|
+
interface SortState<T extends { id: string | number }> {
|
|
7
|
+
name: keyof T;
|
|
8
|
+
direction: SortDirection;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Column<T extends { id: number | string }> {
|
|
12
|
+
name: keyof T;
|
|
13
|
+
label: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
sort?: boolean;
|
|
17
|
+
format?: 'boolean' | 'button' | 'datetime' | 'date' | 'pill' | 'email' | { key: string };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Entity {
|
|
21
|
+
name: string;
|
|
22
|
+
label: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ActionMenuType = 'inline' | 'dropdown';
|
|
26
|
+
|
|
27
|
+
interface Action <T extends { id: string | number }> {
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
icon?: ReactNode;
|
|
31
|
+
onClick: (item: T) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ActionMenu <T extends { id: string | number }> {
|
|
35
|
+
type: ActionMenuType;
|
|
36
|
+
actions: Action<T>[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type FormFieldType = 'text' | 'radio' | 'select';
|
|
40
|
+
|
|
41
|
+
interface FormField {
|
|
42
|
+
name: string;
|
|
43
|
+
type: FormFieldType;
|
|
44
|
+
options?: { label: string; value: string }[] | string[];
|
|
45
|
+
required?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface PaginationMeta {
|
|
49
|
+
currentPage: number;
|
|
50
|
+
pageCount: number;
|
|
51
|
+
total: number;
|
|
52
|
+
from: number;
|
|
53
|
+
to: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface DataTableProps<T extends { id: string | number }> {
|
|
57
|
+
columns: Column<T>[],
|
|
58
|
+
data: T[],
|
|
59
|
+
pagination?: PaginationMeta,
|
|
60
|
+
onPaginate?: (page: number) => void,
|
|
61
|
+
onSearch?: (query: string) => void,
|
|
62
|
+
onSort?: (sort: SortState | null) => void,
|
|
63
|
+
searchValue?: string,
|
|
64
|
+
sortValue?: SortState | null,
|
|
65
|
+
clientPageSize?: number | null,
|
|
66
|
+
clientSearchKeys?: (keyof T)[],
|
|
67
|
+
entity?: Entity,
|
|
68
|
+
actionMenu?: ActionMenu<T>,
|
|
69
|
+
renderMenuIcon?: () => ReactNode,
|
|
70
|
+
onUpdate?: (id: string | number, values: Partial<T>) => void,
|
|
71
|
+
formFields?: FormField[],
|
|
72
|
+
renderSortIcon?: (direction: SortDirection, active: boolean) => ReactNode,
|
|
73
|
+
emptyMessage?: string,
|
|
74
|
+
striped?: boolean,
|
|
75
|
+
hover?: boolean,
|
|
76
|
+
style?: CSSProperties,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare const DataTable: <T extends {
|
|
80
|
+
id: string | number;
|
|
81
|
+
}>({ columns, entity, actionMenu, renderMenuIcon, onUpdate, formFields, renderSortIcon, emptyMessage, striped, hover, style, ...props }: DataTableProps<T>) => react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
export { type Action, type ActionMenu, type ActionMenuType, type Column, DataTable, type DataTableProps, type Entity, type FormField, type FormFieldType, type SortDirection, type SortState };
|