@semcore/data-table 2.0.0 → 2.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/src/index.d.ts DELETED
@@ -1,99 +0,0 @@
1
- import React from 'react';
2
- import { PropGetterFn } from '@semcore/core';
3
- import { IBoxProps, IFlexProps } from '@semcore/flex-box';
4
-
5
- /* utils type */
6
- type CProps<Props, Ctx = {}, UCProps = {}> = Props & {
7
- children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;
8
- };
9
- type ReturnEl = React.ReactElement | null;
10
- /* utils type */
11
-
12
- type ChildRenderFn<Props> = Props & {
13
- children?: (props: Props, column: DataTableData, index: number) => { [key: string]: unknown };
14
- };
15
-
16
- export type DataTableData = { [key: string]: unknown };
17
- export type DataTableSort = [string, 'desc' | 'asc'];
18
- export type DataTableTheme = 'muted' | 'info' | 'success' | 'warning' | 'danger';
19
- export type DataTableUse = 'primary' | 'secondary';
20
- export type DataTableRow = DataTableCell[];
21
- export type DataTableCell = {
22
- /** Name of column */
23
- name: string;
24
- /** Data of column */
25
- data: React.ReactNode;
26
- [key: string]: unknown;
27
- };
28
-
29
- export interface IDataTableProps extends IBoxProps {
30
- /** Theme for table
31
- * @default primary
32
- * */
33
- use?: DataTableUse;
34
- /** Data for table */
35
- data?: DataTableData[];
36
- /** Active sort object */
37
- sort?: DataTableSort;
38
- /** Handler call when will request change sort */
39
- onSortChange?: (sort: DataTableSort, e?: React.SyntheticEvent) => void;
40
- }
41
-
42
- export interface IDataTableHeadProps extends IBoxProps {
43
- /** Sticky header table
44
- * @deprecated
45
- * */
46
- sticky?: boolean;
47
-
48
- /** Hidden header */
49
- hidden?: boolean;
50
- }
51
-
52
- export interface IDataTableColumnProps extends IFlexProps {
53
- /** Unique name column */
54
- name?: string;
55
- /** Enable sort for column also if you pass string you can set default sort */
56
- sortable?: boolean | 'desc' | 'asc';
57
- /** Enable resize for column
58
- * @ignore */
59
- resizable?: boolean;
60
- /** Fixed column on the left/right */
61
- fixed?: 'left' | 'right';
62
- }
63
-
64
- export interface IDataTableBodyProps extends IBoxProps {
65
- /** Rows table */
66
- rows?: DataTableRow[];
67
- }
68
-
69
- export interface IDataTableRowProps extends IBoxProps {
70
- /** Theme for row */
71
- theme?: DataTableTheme;
72
- /** Displays row as active/hover */
73
- active?: boolean;
74
- }
75
-
76
- export interface IDataTableCellProps extends IFlexProps {
77
- /** Unique name column or columns separated by / */
78
- name: string;
79
- /** Theme for cell */
80
- theme?: DataTableTheme;
81
- }
82
-
83
- interface IDataTableCtx {
84
- getHeadProps: PropGetterFn;
85
- getBodyProps: PropGetterFn;
86
- }
87
-
88
- declare const ROW_GROUP: unique symbol;
89
-
90
- declare const DataTable: (<T>(props: CProps<IDataTableProps & T, IDataTableCtx>) => ReturnEl) & {
91
- Head: <T>(props: IDataTableHeadProps & T) => ReturnEl;
92
- Body: <T>(props: IDataTableBodyProps & T) => ReturnEl;
93
- Column: <T>(props: IDataTableColumnProps & T) => ReturnEl;
94
- Cell: <T>(props: ChildRenderFn<IDataTableCellProps & T>) => ReturnEl;
95
- Row: <T>(props: ChildRenderFn<IDataTableRowProps & T>) => ReturnEl;
96
- };
97
-
98
- export { ROW_GROUP };
99
- export default DataTable;
package/src/utils.js DELETED
@@ -1,54 +0,0 @@
1
- export function getScrollOffsetValue(columns) {
2
- return columns.reduce(
3
- (acc, c) => {
4
- if (c.fixed === 'left') {
5
- acc[0] += c.width;
6
- }
7
- if (c.fixed === 'right') {
8
- acc[1] += c.width;
9
- }
10
- return acc;
11
- },
12
- [0, 0],
13
- );
14
- }
15
-
16
- export function flattenColumns(columns) {
17
- return columns.reduce((acc, c) => {
18
- let columns = [c];
19
- if (c.columns) {
20
- columns = flattenColumns(c.columns);
21
- }
22
- acc = acc.concat(columns);
23
- return acc;
24
- }, []);
25
- }
26
-
27
- export function getFixedStyle(column, columns) {
28
- const side = column.fixed;
29
- if (!side) return [undefined, undefined];
30
- const names = column.name.split('/');
31
- const nameSideMap = {
32
- left: names[0],
33
- right: names[names.length - 1],
34
- };
35
- const name = nameSideMap[side];
36
- const index = columns.findIndex((c) => c.name === name);
37
-
38
- if (index === -1) return [undefined, undefined];
39
-
40
- const startIndexSideMap = {
41
- left: 0,
42
- right: index,
43
- };
44
- const endIndexSideMap = {
45
- left: index,
46
- right: columns.length - 1,
47
- };
48
- const columnsFixed = columns.slice(startIndexSideMap[side], endIndexSideMap[side]);
49
-
50
- if (columnsFixed.length < 1) return [side, 0];
51
-
52
- const vars = columnsFixed.map((c) => `var(--${c.name}_width)`);
53
- return [side, vars.length === 1 ? vars[0] : `calc(${vars.join(' + ')})`];
54
- }