@semcore/data-table 2.2.2 → 2.2.5

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.
@@ -149,8 +149,9 @@ SRow {
149
149
  }
150
150
 
151
151
  /* DEFAULT THEME */
152
- SRow[active] SCell:not([theme]),
153
- SRow:hover SCell:not([theme]) {
152
+ SRow[active] > SCell:not([theme]),
153
+ SRow:hover > SCell:not([theme]),
154
+ SRow SCell:hover + SGroupCell SCell:not([theme]) {
154
155
  background-color: #f6f7f7;
155
156
  }
156
157
 
@@ -159,9 +160,10 @@ SRow[theme='muted'] SCell:not([theme]) {
159
160
  background-color: #f2f3f4;
160
161
  }
161
162
 
162
- SRow:hover SCell[theme='muted'],
163
- SRow[theme='muted'][active] SCell:not([theme]),
164
- SRow[theme='muted']:hover SCell:not([theme]) {
163
+ SRow:hover > SCell[theme='muted'],
164
+ SRow[theme='muted'][active] > SCell:not([theme]),
165
+ SRow[theme='muted']:hover > SCell:not([theme]),
166
+ SRow[theme='muted'] SCell:hover + SGroupCell SCell:not([theme]) {
165
167
  background-color: #f6f7f7;
166
168
  }
167
169
 
@@ -170,9 +172,10 @@ SRow[theme='info'] SCell:not([theme]) {
170
172
  background-color: color-mod(var(--light-blue) blend(#fff 80%));
171
173
  }
172
174
 
173
- SRow:hover SCell[theme='info'],
174
- SRow[theme='info'][active] SCell:not([theme]),
175
- SRow[theme='info']:hover SCell:not([theme]) {
175
+ SRow:hover > SCell[theme='info'],
176
+ SRow[theme='info'][active] > SCell:not([theme]),
177
+ SRow[theme='info']:hover > SCell:not([theme]),
178
+ SRow[theme='info'] SCell:hover + SGroupCell SCell:not([theme]) {
176
179
  background-color: color-mod(var(--light-blue) blend(#fff 75%));
177
180
  }
178
181
 
@@ -181,9 +184,10 @@ SRow[theme='success'] SCell:not([theme]) {
181
184
  background-color: color-mod(var(--green) blend(#fff 85%));
182
185
  }
183
186
 
184
- SRow:hover SCell[theme='success'],
185
- SRow[theme='success'][active] SCell:not([theme]),
186
- SRow[theme='success']:hover SCell:not([theme]) {
187
+ SRow:hover > SCell[theme='success'],
188
+ SRow[theme='success'][active] > SCell:not([theme]),
189
+ SRow[theme='success']:hover > SCell:not([theme]),
190
+ SRow[theme='success'] SCell:hover + SGroupCell SCell:not([theme]) {
187
191
  background-color: color-mod(var(--green) blend(#fff 80%));
188
192
  }
189
193
 
@@ -192,9 +196,10 @@ SRow[theme='warning'] SCell:not([theme]) {
192
196
  background-color: color-mod(var(--light-orange) blend(#fff 85%));
193
197
  }
194
198
 
195
- SRow:hover SCell[theme='warning'],
196
- SRow[theme='warning'][active] SCell:not([theme]),
197
- SRow[theme='warning']:hover SCell:not([theme]) {
199
+ SRow:hover > SCell[theme='warning'],
200
+ SRow[theme='warning'][active] > SCell:not([theme]),
201
+ SRow[theme='warning']:hover > SCell:not([theme]),
202
+ SRow[theme='warning'] SCell:hover + SGroupCell SCell:not([theme]) {
198
203
  background-color: color-mod(var(--light-orange) blend(#fff 80%));
199
204
  }
200
205
 
@@ -203,9 +208,10 @@ SRow[theme='danger'] SCell:not([theme]) {
203
208
  background-color: color-mod(var(--red) blend(#fff 90%));
204
209
  }
205
210
 
206
- SRow:hover SCell[theme='danger'],
207
- SRow[theme='danger'][active] SCell:not([theme]),
208
- SRow[theme='danger']:hover SCell:not([theme]) {
211
+ SRow:hover > SCell[theme='danger'],
212
+ SRow[theme='danger'][active] > SCell:not([theme]),
213
+ SRow[theme='danger']:hover > SCell:not([theme]),
214
+ SRow[theme='danger'] SCell:hover + SGroupCell SCell:not([theme]) {
209
215
  background-color: color-mod(var(--red) blend(#fff 85%));
210
216
  }
211
217
 
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import { Component } from '@semcore/core';
3
+ import { RowData, Column, NestedCells, PropsLayer } from './types';
4
+ import ResizeObserver from 'resize-observer-polyfill';
5
+ import syncScroll from '@semcore/utils/lib/syncScroll';
6
+ declare type AsProps = {
7
+ rows: NestedCells[];
8
+ columns: Column[];
9
+ $scrollRef: ReturnType<ReturnType<typeof syncScroll>>;
10
+ onResize: ResizeObserverCallback;
11
+ rowPropsLayers: PropsLayer[];
12
+ use: 'primary' | 'secondary';
13
+ uniqueKey: string;
14
+ virtualScroll?: boolean | {
15
+ tollerance?: number;
16
+ rowHeight?: number;
17
+ };
18
+ };
19
+ declare type State = {
20
+ rowHeight: number | undefined;
21
+ scrollAreaHeight: undefined | number;
22
+ scrollOffset: number;
23
+ };
24
+ declare class Body extends Component<AsProps, State> {
25
+ state: State;
26
+ firstRowRef: React.RefObject<HTMLElement>;
27
+ firstRowResizeObserver: ResizeObserver | null;
28
+ getRowHeight: () => number | undefined;
29
+ renderCells(cells: NestedCells, rowData: RowData, index: number): React.ReactNode[];
30
+ renderRow(cells: NestedCells, { dataIndex, topOffset, nested }: {
31
+ dataIndex: number;
32
+ topOffset?: number;
33
+ nested: boolean;
34
+ }): React.ReactNode;
35
+ renderRows(rows: NestedCells[]): React.ReactNode[];
36
+ renderVirtualizedRows(rows: NestedCells[]): React.ReactNode[];
37
+ handleFirstRowResize: {
38
+ (...args: any[]): void;
39
+ cancel(): void;
40
+ };
41
+ handleScrollAreaResize: {
42
+ (...args: any[]): void;
43
+ cancel(): void;
44
+ };
45
+ handleScrollAreaScroll: (event: React.SyntheticEvent<HTMLElement>) => void;
46
+ setupRowSizeObserver: () => void;
47
+ componentWillUnmount(): void;
48
+ render(): React.ReactNode;
49
+ }
50
+ export default Body;
@@ -0,0 +1,100 @@
1
+ import React from 'react';
2
+ import { PropGetterFn } from '@semcore/core';
3
+ import { IBoxProps, IFlexProps } from '@semcore/flex-box';
4
+ declare const ROW_GROUP: unique symbol;
5
+ declare type CProps<Props, Ctx = {}, UCProps = {}> = Props & {
6
+ children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;
7
+ };
8
+ declare type ReturnEl = React.ReactElement | null;
9
+ declare type ChildRenderFn<Props> = Props & {
10
+ children?: (props: Props, column: DataTableData, index: number) => {
11
+ [key: string]: unknown;
12
+ };
13
+ };
14
+ export declare type DataTableData = {
15
+ [key: string]: unknown;
16
+ };
17
+ export declare type DataTableSort = [string, 'desc' | 'asc'];
18
+ export declare type DataTableTheme = 'muted' | 'info' | 'success' | 'warning' | 'danger';
19
+ export declare type DataTableUse = 'primary' | 'secondary';
20
+ export declare type DataTableRow = DataTableCell[];
21
+ export declare type DataTableCell = {
22
+ /** Name of column */
23
+ name: string;
24
+ /** Data of column */
25
+ data: React.ReactNode;
26
+ [key: string]: unknown;
27
+ };
28
+ export interface IDataTableProps extends IBoxProps {
29
+ /** Theme for table
30
+ * @default primary
31
+ * */
32
+ use?: DataTableUse;
33
+ /** Data for table */
34
+ data?: DataTableData[];
35
+ /** Active sort object */
36
+ sort?: DataTableSort;
37
+ /** Handler call when will request change sort */
38
+ onSortChange?: (sort: DataTableSort, e?: React.SyntheticEvent) => void;
39
+ /** Field name in one data entity that is unique accross all set of data
40
+ * @default id
41
+ */
42
+ uniqueKey?: string;
43
+ }
44
+ export interface IDataTableHeadProps extends IBoxProps {
45
+ /** Sticky header table
46
+ * @deprecated
47
+ * */
48
+ sticky?: boolean;
49
+ /** Hidden header */
50
+ hidden?: boolean;
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
+ export interface IDataTableBodyProps extends IBoxProps {
64
+ /** Rows table */
65
+ rows?: DataTableRow[];
66
+ /** When enabled, only visually acessable rows are rendered.
67
+ * `tollerance` property controls how many rows outside of viewport are render.
68
+ * `rowHeight` fixes the rows height if it known. If not provided, first row node height is measured.
69
+ * @default { tollerance: 2 }
70
+ */
71
+ virtualScroll?: boolean | {
72
+ tollerance?: number;
73
+ rowHeight?: number;
74
+ };
75
+ }
76
+ export interface IDataTableRowProps extends IBoxProps {
77
+ /** Theme for row */
78
+ theme?: DataTableTheme;
79
+ /** Displays row as active/hover */
80
+ active?: boolean;
81
+ }
82
+ export interface IDataTableCellProps extends IFlexProps {
83
+ /** Unique name column or columns separated by / */
84
+ name: string;
85
+ /** Theme for cell */
86
+ theme?: DataTableTheme;
87
+ }
88
+ interface IDataTableCtx {
89
+ getHeadProps: PropGetterFn;
90
+ getBodyProps: PropGetterFn;
91
+ }
92
+ declare const DefinitionTable: (<T>(props: CProps<IDataTableProps & T, IDataTableCtx, {}>) => ReturnEl) & {
93
+ Head: <T_1>(props: IDataTableHeadProps & T_1) => ReturnEl;
94
+ Body: <T_2>(props: IDataTableBodyProps & T_2) => ReturnEl;
95
+ Column: <T_3>(props: IDataTableColumnProps & T_3) => ReturnEl;
96
+ Cell: <T_4>(props: ChildRenderFn<IDataTableCellProps & T_4>) => ReturnEl;
97
+ Row: <T_5>(props: ChildRenderFn<IDataTableRowProps & T_5>) => ReturnEl;
98
+ };
99
+ export { ROW_GROUP };
100
+ export default DefinitionTable;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { Component } from '@semcore/core';
3
+ import type { Column } from './types';
4
+ import 'resize-observer-polyfill';
5
+ declare type AsProps = {
6
+ $onSortClick: (name: string, event: React.MouseEvent | React.KeyboardEvent) => void;
7
+ $scrollRef: (instance: unknown) => void;
8
+ use: 'primary' | 'secondary';
9
+ columnsChildren: Column[];
10
+ onResize: ResizeObserverCallback;
11
+ sticky: boolean;
12
+ ['data-ui-name']: string;
13
+ };
14
+ declare class Head extends Component<AsProps> {
15
+ columns: Column[];
16
+ static displayName: string;
17
+ bindHandlerSortClick: (name: string) => (event: React.MouseEvent) => void;
18
+ bindHandlerKeyDown: (name: string) => (event: React.KeyboardEvent) => void;
19
+ renderColumns(columns: Column[], width: number): React.ReactNode[];
20
+ renderColumn(column: Column, width: number): React.ReactNode;
21
+ render(): React.ReactNode;
22
+ }
23
+ export default Head;
@@ -0,0 +1,2 @@
1
+ export { default } from './DataTable';
2
+ export * from './DataTable';
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { ROW_GROUP } from './DataTable';
3
+ export declare type PseudoChildPropsGetter = (props: {
4
+ [propName: string]: unknown;
5
+ }, rowData: {
6
+ [columnName: string]: unknown;
7
+ }, index: number) => {
8
+ [propName: string]: unknown;
9
+ };
10
+ export declare type PropsLayer = {
11
+ childrenPropsGetter?: PseudoChildPropsGetter;
12
+ [propName: string]: unknown;
13
+ };
14
+ export declare type SortDirection = 'asc' | 'desc';
15
+ export declare type Column<Props extends {
16
+ [propName: string]: unknown;
17
+ } = {
18
+ [propName: string]: unknown;
19
+ }> = {
20
+ name: string;
21
+ active: boolean;
22
+ width: number;
23
+ fixed?: 'left' | 'right';
24
+ resizable?: boolean;
25
+ sortable?: boolean | SortDirection;
26
+ sortDirection: SortDirection;
27
+ cssVar: string | string[];
28
+ data?: unknown;
29
+ props: {
30
+ name: string;
31
+ } & Partial<{
32
+ onClick: (event: React.MouseEvent) => void;
33
+ onKeyDown: (event: React.KeyboardEvent) => void;
34
+ ref: React.RefObject<HTMLElement>;
35
+ style: React.CSSProperties;
36
+ fixed: 'left' | 'right';
37
+ children: React.ReactNode[];
38
+ resizable: boolean;
39
+ sortable: boolean | SortDirection;
40
+ sortDirection: SortDirection;
41
+ }> & Props;
42
+ columns: Column[];
43
+ };
44
+ export declare type Cell = Pick<Column, 'name' | 'cssVar' | 'fixed' | 'data'> & {
45
+ cellPropsLayers: PropsLayer[];
46
+ };
47
+ export declare type RowData<Data extends {
48
+ [columnName: string]: unknown;
49
+ } = {
50
+ [columnName: string]: unknown;
51
+ }> = Data & Partial<{
52
+ name: string;
53
+ [ROW_GROUP]: RowData[];
54
+ }>;
55
+ export declare type NestedCells = (Cell | NestedCells)[] & {
56
+ flatRowData?: RowData;
57
+ };
@@ -0,0 +1,6 @@
1
+ import type { Column } from './types';
2
+ export declare const getScrollOffsetValue: (columns: Column[]) => [leftOffset: number, rightOffset: number];
3
+ export declare const flattenColumns: (columns: Column[]) => Column<{
4
+ [propName: string]: unknown;
5
+ }>[];
6
+ export declare const getFixedStyle: (cell: Pick<Column, 'name' | 'fixed'>, columns: Column[]) => [side: "left" | "right", style: string | number] | [side: undefined, style: undefined];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/data-table",
3
3
  "description": "SEMRush DataTable Component",
4
- "version": "2.2.2",
4
+ "version": "2.2.5",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "author": "Roman Lysov <r.lysov@semrush.com>",
10
10
  "license": "MIT",
11
11
  "scripts": {
12
- "build": "build --source=js",
12
+ "build": "build --source=ts",
13
13
  "test": "jest"
14
14
  },
15
15
  "dependencies": {
package/src/Body.tsx CHANGED
@@ -55,7 +55,12 @@ class Body extends Component<AsProps, State> {
55
55
  const { styles, columns, use } = this.asProps;
56
56
  return cells.map((cell) => {
57
57
  if (Array.isArray(cell)) {
58
- return <div>{this.renderRows(cell as NestedCells[])}</div>;
58
+ const SGroupCell = 'div';
59
+ return sstyled(styles)(
60
+ <SGroupCell data-ui-name="group-cell">
61
+ {this.renderRows(cell as NestedCells[])}
62
+ </SGroupCell>,
63
+ );
59
64
  } else {
60
65
  const column = columns.find((c) => c.name === cell.name);
61
66
  const [name, value] = getFixedStyle(cell, columns);
package/src/Head.tsx CHANGED
@@ -8,7 +8,7 @@ import { callAllEventHandlers } from '@semcore/utils/lib/assignProps';
8
8
  import { flattenColumns, getFixedStyle, getScrollOffsetValue } from './utils';
9
9
  import type { Column } from './types';
10
10
  import logger from '@semcore/utils/lib/logger';
11
- import type ResizeObserverCallback from 'resize-observer-polyfill';
11
+ import 'resize-observer-polyfill';
12
12
 
13
13
  import scrollStyles from './style/scroll-area.shadow.css';
14
14
 
@@ -149,8 +149,9 @@ SRow {
149
149
  }
150
150
 
151
151
  /* DEFAULT THEME */
152
- SRow[active] SCell:not([theme]),
153
- SRow:hover SCell:not([theme]) {
152
+ SRow[active] > SCell:not([theme]),
153
+ SRow:hover > SCell:not([theme]),
154
+ SRow SCell:hover + SGroupCell SCell:not([theme]) {
154
155
  background-color: #f6f7f7;
155
156
  }
156
157
 
@@ -159,9 +160,10 @@ SRow[theme='muted'] SCell:not([theme]) {
159
160
  background-color: #f2f3f4;
160
161
  }
161
162
 
162
- SRow:hover SCell[theme='muted'],
163
- SRow[theme='muted'][active] SCell:not([theme]),
164
- SRow[theme='muted']:hover SCell:not([theme]) {
163
+ SRow:hover > SCell[theme='muted'],
164
+ SRow[theme='muted'][active] > SCell:not([theme]),
165
+ SRow[theme='muted']:hover > SCell:not([theme]),
166
+ SRow[theme='muted'] SCell:hover + SGroupCell SCell:not([theme]) {
165
167
  background-color: #f6f7f7;
166
168
  }
167
169
 
@@ -170,9 +172,10 @@ SRow[theme='info'] SCell:not([theme]) {
170
172
  background-color: color-mod(var(--light-blue) blend(#fff 80%));
171
173
  }
172
174
 
173
- SRow:hover SCell[theme='info'],
174
- SRow[theme='info'][active] SCell:not([theme]),
175
- SRow[theme='info']:hover SCell:not([theme]) {
175
+ SRow:hover > SCell[theme='info'],
176
+ SRow[theme='info'][active] > SCell:not([theme]),
177
+ SRow[theme='info']:hover > SCell:not([theme]),
178
+ SRow[theme='info'] SCell:hover + SGroupCell SCell:not([theme]) {
176
179
  background-color: color-mod(var(--light-blue) blend(#fff 75%));
177
180
  }
178
181
 
@@ -181,9 +184,10 @@ SRow[theme='success'] SCell:not([theme]) {
181
184
  background-color: color-mod(var(--green) blend(#fff 85%));
182
185
  }
183
186
 
184
- SRow:hover SCell[theme='success'],
185
- SRow[theme='success'][active] SCell:not([theme]),
186
- SRow[theme='success']:hover SCell:not([theme]) {
187
+ SRow:hover > SCell[theme='success'],
188
+ SRow[theme='success'][active] > SCell:not([theme]),
189
+ SRow[theme='success']:hover > SCell:not([theme]),
190
+ SRow[theme='success'] SCell:hover + SGroupCell SCell:not([theme]) {
187
191
  background-color: color-mod(var(--green) blend(#fff 80%));
188
192
  }
189
193
 
@@ -192,9 +196,10 @@ SRow[theme='warning'] SCell:not([theme]) {
192
196
  background-color: color-mod(var(--light-orange) blend(#fff 85%));
193
197
  }
194
198
 
195
- SRow:hover SCell[theme='warning'],
196
- SRow[theme='warning'][active] SCell:not([theme]),
197
- SRow[theme='warning']:hover SCell:not([theme]) {
199
+ SRow:hover > SCell[theme='warning'],
200
+ SRow[theme='warning'][active] > SCell:not([theme]),
201
+ SRow[theme='warning']:hover > SCell:not([theme]),
202
+ SRow[theme='warning'] SCell:hover + SGroupCell SCell:not([theme]) {
198
203
  background-color: color-mod(var(--light-orange) blend(#fff 80%));
199
204
  }
200
205
 
@@ -203,9 +208,10 @@ SRow[theme='danger'] SCell:not([theme]) {
203
208
  background-color: color-mod(var(--red) blend(#fff 90%));
204
209
  }
205
210
 
206
- SRow:hover SCell[theme='danger'],
207
- SRow[theme='danger'][active] SCell:not([theme]),
208
- SRow[theme='danger']:hover SCell:not([theme]) {
211
+ SRow:hover > SCell[theme='danger'],
212
+ SRow[theme='danger'][active] > SCell:not([theme]),
213
+ SRow[theme='danger']:hover > SCell:not([theme]),
214
+ SRow[theme='danger'] SCell:hover + SGroupCell SCell:not([theme]) {
209
215
  background-color: color-mod(var(--red) blend(#fff 85%));
210
216
  }
211
217