@snack-uikit/table 0.6.5-preview-85c5f47b.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/LICENSE +201 -0
  3. package/README.md +165 -0
  4. package/dist/components/Table/Table.d.ts +104 -0
  5. package/dist/components/Table/Table.js +125 -0
  6. package/dist/components/Table/constants.d.ts +3 -0
  7. package/dist/components/Table/constants.js +14 -0
  8. package/dist/components/Table/hooks.d.ts +19 -0
  9. package/dist/components/Table/hooks.js +37 -0
  10. package/dist/components/Table/index.d.ts +1 -0
  11. package/dist/components/Table/index.js +1 -0
  12. package/dist/components/Table/styles.module.css +46 -0
  13. package/dist/components/TableEmptyState/TableEmptyState.d.ts +8 -0
  14. package/dist/components/TableEmptyState/TableEmptyState.js +8 -0
  15. package/dist/components/TableEmptyState/index.d.ts +1 -0
  16. package/dist/components/TableEmptyState/index.js +1 -0
  17. package/dist/components/TableEmptyState/styles.module.css +15 -0
  18. package/dist/components/TablePagination/TablePagination.d.ts +8 -0
  19. package/dist/components/TablePagination/TablePagination.js +19 -0
  20. package/dist/components/TablePagination/index.d.ts +1 -0
  21. package/dist/components/TablePagination/index.js +1 -0
  22. package/dist/components/TablePagination/styles.module.css +11 -0
  23. package/dist/components/index.d.ts +1 -0
  24. package/dist/components/index.js +1 -0
  25. package/dist/constants.d.ts +28 -0
  26. package/dist/constants.js +31 -0
  27. package/dist/exportTable.d.ts +9 -0
  28. package/dist/exportTable.js +51 -0
  29. package/dist/helperComponents/Cells/BodyCell/BodyCell.d.ts +7 -0
  30. package/dist/helperComponents/Cells/BodyCell/BodyCell.js +24 -0
  31. package/dist/helperComponents/Cells/BodyCell/index.d.ts +1 -0
  32. package/dist/helperComponents/Cells/BodyCell/index.js +1 -0
  33. package/dist/helperComponents/Cells/BodyCell/styles.module.css +12 -0
  34. package/dist/helperComponents/Cells/Cell.d.ts +9 -0
  35. package/dist/helperComponents/Cells/Cell.js +20 -0
  36. package/dist/helperComponents/Cells/HeaderCell/HeaderCell.d.ts +7 -0
  37. package/dist/helperComponents/Cells/HeaderCell/HeaderCell.js +17 -0
  38. package/dist/helperComponents/Cells/HeaderCell/helpers.d.ts +2 -0
  39. package/dist/helperComponents/Cells/HeaderCell/helpers.js +12 -0
  40. package/dist/helperComponents/Cells/HeaderCell/index.d.ts +1 -0
  41. package/dist/helperComponents/Cells/HeaderCell/index.js +1 -0
  42. package/dist/helperComponents/Cells/HeaderCell/styles.module.css +53 -0
  43. package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.d.ts +22 -0
  44. package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.js +36 -0
  45. package/dist/helperComponents/Cells/RowActionsCell/index.d.ts +1 -0
  46. package/dist/helperComponents/Cells/RowActionsCell/index.js +1 -0
  47. package/dist/helperComponents/Cells/RowActionsCell/styles.module.css +34 -0
  48. package/dist/helperComponents/Cells/SelectionCell/SelectionCell.d.ts +2 -0
  49. package/dist/helperComponents/Cells/SelectionCell/SelectionCell.js +45 -0
  50. package/dist/helperComponents/Cells/SelectionCell/index.d.ts +1 -0
  51. package/dist/helperComponents/Cells/SelectionCell/index.js +1 -0
  52. package/dist/helperComponents/Cells/SelectionCell/styles.module.css +13 -0
  53. package/dist/helperComponents/Cells/StatusCell/StatusCell.d.ts +27 -0
  54. package/dist/helperComponents/Cells/StatusCell/StatusCell.js +43 -0
  55. package/dist/helperComponents/Cells/StatusCell/constants.d.ts +13 -0
  56. package/dist/helperComponents/Cells/StatusCell/constants.js +14 -0
  57. package/dist/helperComponents/Cells/StatusCell/index.d.ts +1 -0
  58. package/dist/helperComponents/Cells/StatusCell/index.js +1 -0
  59. package/dist/helperComponents/Cells/StatusCell/styles.module.css +96 -0
  60. package/dist/helperComponents/Cells/index.d.ts +5 -0
  61. package/dist/helperComponents/Cells/index.js +5 -0
  62. package/dist/helperComponents/Cells/styles.module.css +13 -0
  63. package/dist/helperComponents/ExportButton/ExportButton.d.ts +10 -0
  64. package/dist/helperComponents/ExportButton/ExportButton.js +27 -0
  65. package/dist/helperComponents/ExportButton/index.d.ts +1 -0
  66. package/dist/helperComponents/ExportButton/index.js +1 -0
  67. package/dist/helperComponents/Rows/BodyRow.d.ts +15 -0
  68. package/dist/helperComponents/Rows/BodyRow.js +25 -0
  69. package/dist/helperComponents/Rows/HeaderRow.d.ts +1 -0
  70. package/dist/helperComponents/Rows/HeaderRow.js +11 -0
  71. package/dist/helperComponents/Rows/PinnedCells.d.ts +8 -0
  72. package/dist/helperComponents/Rows/PinnedCells.js +6 -0
  73. package/dist/helperComponents/Rows/Row.d.ts +10 -0
  74. package/dist/helperComponents/Rows/Row.js +18 -0
  75. package/dist/helperComponents/Rows/index.d.ts +2 -0
  76. package/dist/helperComponents/Rows/index.js +2 -0
  77. package/dist/helperComponents/Rows/styles.module.css +87 -0
  78. package/dist/helperComponents/contexts.d.ts +14 -0
  79. package/dist/helperComponents/contexts.js +14 -0
  80. package/dist/helperComponents/helpers.d.ts +2 -0
  81. package/dist/helperComponents/helpers.js +9 -0
  82. package/dist/helperComponents/hooks.d.ts +28 -0
  83. package/dist/helperComponents/hooks.js +67 -0
  84. package/dist/helperComponents/index.d.ts +7 -0
  85. package/dist/helperComponents/index.js +7 -0
  86. package/dist/helperComponents/types.d.ts +7 -0
  87. package/dist/helperComponents/types.js +1 -0
  88. package/dist/index.d.ts +3 -0
  89. package/dist/index.js +3 -0
  90. package/dist/types.d.ts +38 -0
  91. package/dist/types.js +1 -0
  92. package/dist/utils.d.ts +2 -0
  93. package/dist/utils.js +9 -0
  94. package/package.json +55 -0
  95. package/src/components/Table/Table.tsx +385 -0
  96. package/src/components/Table/constants.ts +18 -0
  97. package/src/components/Table/hooks.tsx +68 -0
  98. package/src/components/Table/index.ts +1 -0
  99. package/src/components/Table/styles.module.scss +55 -0
  100. package/src/components/TableEmptyState/TableEmptyState.tsx +25 -0
  101. package/src/components/TableEmptyState/index.ts +1 -0
  102. package/src/components/TableEmptyState/styles.module.scss +18 -0
  103. package/src/components/TablePagination/TablePagination.tsx +70 -0
  104. package/src/components/TablePagination/index.ts +1 -0
  105. package/src/components/TablePagination/styles.module.scss +13 -0
  106. package/src/components/index.ts +1 -0
  107. package/src/constants.ts +31 -0
  108. package/src/exportTable.ts +82 -0
  109. package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +32 -0
  110. package/src/helperComponents/Cells/BodyCell/index.ts +1 -0
  111. package/src/helperComponents/Cells/BodyCell/styles.module.scss +15 -0
  112. package/src/helperComponents/Cells/Cell.tsx +21 -0
  113. package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +53 -0
  114. package/src/helperComponents/Cells/HeaderCell/helpers.tsx +14 -0
  115. package/src/helperComponents/Cells/HeaderCell/index.ts +1 -0
  116. package/src/helperComponents/Cells/HeaderCell/styles.module.scss +74 -0
  117. package/src/helperComponents/Cells/RowActionsCell/RowActionsCell.tsx +118 -0
  118. package/src/helperComponents/Cells/RowActionsCell/index.ts +1 -0
  119. package/src/helperComponents/Cells/RowActionsCell/styles.module.scss +44 -0
  120. package/src/helperComponents/Cells/SelectionCell/SelectionCell.tsx +54 -0
  121. package/src/helperComponents/Cells/SelectionCell/index.ts +1 -0
  122. package/src/helperComponents/Cells/SelectionCell/styles.module.scss +18 -0
  123. package/src/helperComponents/Cells/StatusCell/StatusCell.tsx +108 -0
  124. package/src/helperComponents/Cells/StatusCell/constants.ts +14 -0
  125. package/src/helperComponents/Cells/StatusCell/index.ts +1 -0
  126. package/src/helperComponents/Cells/StatusCell/styles.module.scss +95 -0
  127. package/src/helperComponents/Cells/index.ts +5 -0
  128. package/src/helperComponents/Cells/styles.module.scss +13 -0
  129. package/src/helperComponents/ExportButton/ExportButton.tsx +70 -0
  130. package/src/helperComponents/ExportButton/index.ts +1 -0
  131. package/src/helperComponents/Rows/BodyRow.tsx +78 -0
  132. package/src/helperComponents/Rows/HeaderRow.tsx +36 -0
  133. package/src/helperComponents/Rows/PinnedCells.tsx +17 -0
  134. package/src/helperComponents/Rows/Row.tsx +20 -0
  135. package/src/helperComponents/Rows/index.ts +2 -0
  136. package/src/helperComponents/Rows/styles.module.scss +127 -0
  137. package/src/helperComponents/contexts.ts +29 -0
  138. package/src/helperComponents/helpers.ts +13 -0
  139. package/src/helperComponents/hooks.ts +84 -0
  140. package/src/helperComponents/index.ts +7 -0
  141. package/src/helperComponents/types.ts +13 -0
  142. package/src/index.ts +3 -0
  143. package/src/types.ts +80 -0
  144. package/src/utils.ts +13 -0
@@ -0,0 +1,28 @@
1
+ export declare enum ColumnPinPosition {
2
+ Left = "left",
3
+ Right = "right"
4
+ }
5
+ export declare enum ColumnAlign {
6
+ Left = "left",
7
+ Right = "right"
8
+ }
9
+ export declare const TEST_IDS: {
10
+ headerSortIndicator: string;
11
+ headerRow: string;
12
+ headerCell: string;
13
+ bodyRow: string;
14
+ bodyCell: string;
15
+ pinnedCells: string;
16
+ rowSelect: string;
17
+ rowActions: {
18
+ droplistTrigger: string;
19
+ droplist: string;
20
+ option: string;
21
+ };
22
+ statusIndicator: string;
23
+ statusLabel: string;
24
+ };
25
+ export declare enum SortFn {
26
+ DateTime = "datetime",
27
+ AlphaNumeric = "alphanumeric"
28
+ }
@@ -0,0 +1,31 @@
1
+ export var ColumnPinPosition;
2
+ (function (ColumnPinPosition) {
3
+ ColumnPinPosition["Left"] = "left";
4
+ ColumnPinPosition["Right"] = "right";
5
+ })(ColumnPinPosition || (ColumnPinPosition = {}));
6
+ export var ColumnAlign;
7
+ (function (ColumnAlign) {
8
+ ColumnAlign["Left"] = "left";
9
+ ColumnAlign["Right"] = "right";
10
+ })(ColumnAlign || (ColumnAlign = {}));
11
+ export const TEST_IDS = {
12
+ headerSortIndicator: 'table__header__sort-indicator',
13
+ headerRow: 'table__header-row',
14
+ headerCell: 'table__header-cell',
15
+ bodyRow: 'table__body-row',
16
+ bodyCell: 'table__body-cell',
17
+ pinnedCells: 'table__pinned-cells',
18
+ rowSelect: 'table__row-select',
19
+ rowActions: {
20
+ droplistTrigger: 'table__body-row__droplistTrigger',
21
+ droplist: 'table__body-row__actions-droplist',
22
+ option: 'table__body-row__action-option',
23
+ },
24
+ statusIndicator: 'table__status-indicator',
25
+ statusLabel: 'table__status-label',
26
+ };
27
+ export var SortFn;
28
+ (function (SortFn) {
29
+ SortFn["DateTime"] = "datetime";
30
+ SortFn["AlphaNumeric"] = "alphanumeric";
31
+ })(SortFn || (SortFn = {}));
@@ -0,0 +1,9 @@
1
+ import { ColumnDefinition } from './types';
2
+ type ExportTableData<TData> = {
3
+ data: TData[];
4
+ columnDefinitions: ColumnDefinition<TData>[];
5
+ fileName?: string;
6
+ };
7
+ export declare function exportToCSV<TData extends object>({ columnDefinitions, fileName, data, }: ExportTableData<TData>): string;
8
+ export declare function exportToXLSX<TData extends object>({ columnDefinitions, fileName, data, }: ExportTableData<TData>): import("xlsx").WorkSheet;
9
+ export {};
@@ -0,0 +1,51 @@
1
+ import { utils as xlsxUtils, writeFileXLSX } from 'xlsx';
2
+ function getColumnAccessorKey(column) {
3
+ if ('accessorKey' in column && column.accessorKey) {
4
+ return String(column.accessorKey);
5
+ }
6
+ }
7
+ function getFilteredColumnsIds(columnDefinitions) {
8
+ return columnDefinitions
9
+ .filter(column => { var _a; return getColumnAccessorKey(column) && !((_a = column.meta) === null || _a === void 0 ? void 0 : _a.skipOnExport); })
10
+ .map(column => getColumnAccessorKey(column));
11
+ }
12
+ function getXlsxFormatTable({ data, columnDefinitions, }) {
13
+ const filteredIds = getFilteredColumnsIds(columnDefinitions);
14
+ return data.map((line) => {
15
+ const lineRecord = line;
16
+ const result = [];
17
+ filteredIds.forEach(key => {
18
+ if (!key) {
19
+ result.push('');
20
+ return;
21
+ }
22
+ result.push(lineRecord[key]);
23
+ });
24
+ return result;
25
+ });
26
+ }
27
+ export function exportToCSV({ columnDefinitions, fileName = 'Table', data, }) {
28
+ const xlsxData = getXlsxFormatTable({ data, columnDefinitions });
29
+ const filteredIds = getFilteredColumnsIds(columnDefinitions);
30
+ const table = [filteredIds, ...xlsxData];
31
+ const csv = table.map(line => line.map(el => `"${el}"`).join(',')).join('\n');
32
+ const blob = new Blob([csv], { type: 'text/csv' });
33
+ const url = window.URL.createObjectURL(blob);
34
+ const tempLink = Object.assign(document.createElement('a'), {
35
+ target: '_blank',
36
+ href: url,
37
+ download: fileName,
38
+ });
39
+ tempLink.click();
40
+ tempLink.remove();
41
+ return csv;
42
+ }
43
+ export function exportToXLSX({ columnDefinitions, fileName = 'Table', data, }) {
44
+ const xlsxData = getXlsxFormatTable({ data, columnDefinitions });
45
+ const filteredIds = getFilteredColumnsIds(columnDefinitions);
46
+ const workbook = xlsxUtils.book_new();
47
+ const worksheet = xlsxUtils.aoa_to_sheet([filteredIds, ...xlsxData]);
48
+ xlsxUtils.book_append_sheet(workbook, worksheet);
49
+ writeFileXLSX(workbook, `${fileName}.xlsx`);
50
+ return worksheet;
51
+ }
@@ -0,0 +1,7 @@
1
+ import { Cell as TableCell } from '@tanstack/react-table';
2
+ import { CellProps } from '../Cell';
3
+ type BodyCellProps<TData> = Omit<CellProps, 'style' | 'children'> & {
4
+ cell: TableCell<TData, unknown>;
5
+ };
6
+ export declare function BodyCell<TData>({ cell, className, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { flexRender } from '@tanstack/react-table';
14
+ import cn from 'classnames';
15
+ import { TEST_IDS } from '../../../constants';
16
+ import { useCellSizes } from '../../hooks';
17
+ import { Cell } from '../Cell';
18
+ import styles from './styles.module.css';
19
+ export function BodyCell(_a) {
20
+ var { cell, className } = _a, props = __rest(_a, ["cell", "className"]);
21
+ const columnDef = cell.column.columnDef;
22
+ const style = useCellSizes(cell);
23
+ return (_jsx(Cell, Object.assign({}, props, { style: style, className: cn(styles.tableBodyCell, className, columnDef.cellClassName), "data-align": columnDef.align, "data-no-padding": columnDef.noBodyCellPadding || undefined, "data-column-id": cell.column.id, "data-test-id": TEST_IDS.bodyCell }, { children: flexRender(columnDef.cell, cell.getContext()) })));
24
+ }
@@ -0,0 +1 @@
1
+ export * from './BodyCell';
@@ -0,0 +1 @@
1
+ export * from './BodyCell';
@@ -0,0 +1,12 @@
1
+ .tableBodyCell{
2
+ gap:var(--space-table-cell-gap, 4px);
3
+ padding-left:var(--space-table-cell-padding, 8px);
4
+ padding-right:var(--space-table-cell-padding, 8px);
5
+ color:var(--sys-neutral-text-main, #333333);
6
+ }
7
+ .tableBodyCell[data-align=right]{
8
+ justify-content:flex-end;
9
+ }
10
+ .tableBodyCell[data-no-padding]{
11
+ padding:0;
12
+ }
@@ -0,0 +1,9 @@
1
+ import { CSSProperties, MouseEventHandler, ReactNode } from 'react';
2
+ import { DataAttributes } from '../types';
3
+ export type CellProps = {
4
+ children: ReactNode;
5
+ onClick?: MouseEventHandler;
6
+ className?: string;
7
+ style?: CSSProperties;
8
+ } & DataAttributes;
9
+ export declare function Cell({ onClick, className, style, children, ...attributes }: CellProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import cn from 'classnames';
14
+ import styles from './styles.module.css';
15
+ export function Cell(_a) {
16
+ var { onClick, className, style, children } = _a, attributes = __rest(_a, ["onClick", "className", "style", "children"]);
17
+ return (
18
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
19
+ _jsx("div", Object.assign({ role: 'cell', onClick: onClick, className: cn(styles.tableCell, className), style: style }, attributes, { children: children })));
20
+ }
@@ -0,0 +1,7 @@
1
+ import { Header } from '@tanstack/react-table';
2
+ import { CellProps } from '../Cell';
3
+ type HeaderCellProps<TData> = Omit<CellProps, 'align' | 'children' | 'onClick' | 'style'> & {
4
+ header: Header<TData, unknown>;
5
+ };
6
+ export declare function HeaderCell<TData>({ header, className }: HeaderCellProps<TData>): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { flexRender } from '@tanstack/react-table';
3
+ import cn from 'classnames';
4
+ import { TruncateString } from '@snack-uikit/truncate-string';
5
+ import { TEST_IDS } from '../../../constants';
6
+ import { useCellSizes } from '../../hooks';
7
+ import { Cell } from '../Cell';
8
+ import { getSortingIcon } from './helpers';
9
+ import styles from './styles.module.css';
10
+ export function HeaderCell({ header, className }) {
11
+ const isSortable = header.column.getCanSort();
12
+ const sortDirection = isSortable && (header.column.getIsSorted() || undefined);
13
+ const sortIcon = getSortingIcon(sortDirection);
14
+ const columnDef = header.column.columnDef;
15
+ const style = useCellSizes(header);
16
+ return (_jsxs(Cell, Object.assign({ style: style, onClick: header.column.getToggleSortingHandler(), "data-sortable": isSortable || undefined, "data-no-padding": columnDef.noHeaderCellPadding || undefined, "data-no-offset": columnDef.noHeaderCellBorderOffset || undefined, "data-test-id": TEST_IDS.headerCell, className: cn(styles.tableHeaderCell, className, columnDef.headerClassName) }, { children: [columnDef.header && (_jsx("div", Object.assign({ className: styles.tableHeaderCellName }, { children: _jsx(TruncateString, { text: flexRender(columnDef.header, header.getContext()) }) }))), Boolean(sortIcon) && (_jsx("div", Object.assign({ className: styles.tableHeaderSortIcon, "data-sort-direction": sortDirection, "data-test-id": TEST_IDS.headerSortIndicator }, { children: sortIcon })))] })));
17
+ }
@@ -0,0 +1,2 @@
1
+ import { SortDirection } from '@tanstack/react-table';
2
+ export declare function getSortingIcon(sort?: SortDirection | false): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ArrowDownSVG, ArrowUpSVG } from '@snack-uikit/icons';
3
+ export function getSortingIcon(sort) {
4
+ switch (sort) {
5
+ case 'asc':
6
+ return _jsx(ArrowUpSVG, { size: 16 });
7
+ case 'desc':
8
+ return _jsx(ArrowDownSVG, { size: 16 });
9
+ default:
10
+ return null;
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export * from './HeaderCell';
@@ -0,0 +1 @@
1
+ export * from './HeaderCell';
@@ -0,0 +1,53 @@
1
+ .tableHeaderCell{
2
+ padding:var(--space-table-cell-padding, 8px);
3
+ position:relative;
4
+ display:flex;
5
+ align-items:center;
6
+ box-sizing:border-box;
7
+ width:100%;
8
+ background-color:inherit;
9
+ }
10
+ .tableHeaderCell::after{
11
+ pointer-events:none;
12
+ content:"";
13
+ position:absolute;
14
+ bottom:0;
15
+ left:50%;
16
+ transform:translateX(-50%);
17
+ width:calc(100% - var(--space-table-head-separator-padding, 8px) * 2);
18
+ height:1px;
19
+ background-color:var(--sys-neutral-decor-default, #dedede);
20
+ }
21
+ .tableHeaderCell[data-sortable]{
22
+ cursor:pointer;
23
+ }
24
+ .tableHeaderCell[data-no-offset]::after{
25
+ left:0;
26
+ transform:none;
27
+ width:calc(100% - var(--space-table-head-separator-padding, 8px));
28
+ }
29
+ .tableHeaderCell[data-no-padding]{
30
+ padding:0;
31
+ }
32
+ .tableHeaderCell[data-no-padding]::after{
33
+ width:100%;
34
+ }
35
+
36
+ .tableHeaderCellName{
37
+ height:var(--size-table-head-name-layout, 24px);
38
+ display:inline-flex;
39
+ align-items:center;
40
+ box-sizing:border-box;
41
+ min-width:0;
42
+ color:var(--sys-neutral-text-light, #898989);
43
+ }
44
+
45
+ .tableHeaderSortIcon{
46
+ display:flex;
47
+ box-sizing:border-box;
48
+ color:var(--sys-neutral-text-light, #898989);
49
+ }
50
+ .tableHeaderSortIcon svg{
51
+ width:var(--dimension-2m, 16px) !important;
52
+ height:var(--dimension-2m, 16px) !important;
53
+ }
@@ -0,0 +1,22 @@
1
+ import { CellContext } from '@tanstack/react-table';
2
+ import { MouseEvent } from 'react';
3
+ import { ItemSingleProps } from '@snack-uikit/droplist';
4
+ import { ColumnDefinition } from '../../../types';
5
+ export type RowActionInfo<TData> = {
6
+ rowId: string;
7
+ data: TData;
8
+ itemId?: string;
9
+ };
10
+ export type RowActionProps<TData> = Pick<ItemSingleProps, 'option' | 'disabled' | 'icon' | 'description' | 'caption' | 'tagLabel'> & {
11
+ id?: string;
12
+ onClick(row: RowActionInfo<TData>, e: MouseEvent<HTMLButtonElement>): void;
13
+ };
14
+ export type ActionsGenerator<TData> = (cell: CellContext<TData, unknown>) => RowActionProps<TData>[];
15
+ export type RowActionsColumnDefProps<TData> = {
16
+ /** Действия для строки */
17
+ actionsGenerator: ActionsGenerator<TData>;
18
+ /** Закрепление колонки справа в таблице */
19
+ pinned?: boolean;
20
+ };
21
+ /** Вспомогательная функция для создания ячейки с дополнительными действиями у строки */
22
+ export declare function getRowActionsColumnDef<TData>({ actionsGenerator, pinned, }: RowActionsColumnDefProps<TData>): ColumnDefinition<TData>;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { ButtonFunction } from '@snack-uikit/button';
4
+ import { Droplist } from '@snack-uikit/droplist';
5
+ import { MoreSVG } from '@snack-uikit/icons';
6
+ import { ColumnPinPosition, TEST_IDS } from '../../../constants';
7
+ import { useRowContext } from '../../contexts';
8
+ import styles from './styles.module.css';
9
+ function RowActionsCell({ row, actions }) {
10
+ const { droplistOpened, setDroplistOpen } = useRowContext();
11
+ const { triggerElementRef, handleDroplistFocusLeave, handleDroplistItemKeyDown, handleTriggerKeyDown, handleDroplistItemClick, firstElementRefCallback, } = Droplist.useKeyboardNavigation({ setDroplistOpen });
12
+ const handleItemClick = (item) => (e) => {
13
+ item.onClick({ rowId: row.id, itemId: item.id, data: row.original }, e);
14
+ };
15
+ const disabled = !row.getCanSelect();
16
+ const stopPropagationClick = (e) => {
17
+ e.stopPropagation();
18
+ };
19
+ return (
20
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
21
+ _jsx("div", Object.assign({ onClick: stopPropagationClick, className: styles.rowActionsCellWrap, "data-open": droplistOpened || undefined }, { children: !disabled && Boolean(actions.length) && (_jsx(Droplist, Object.assign({ open: droplistOpened, onOpenChange: setDroplistOpen, placement: Droplist.placements.BottomEnd, firstElementRefCallback: firstElementRefCallback, onFocusLeave: handleDroplistFocusLeave, triggerElement: _jsx("span", { children: _jsx(ButtonFunction, { icon: _jsx(MoreSVG, { size: 24 }), "data-test-id": TEST_IDS.rowActions.droplistTrigger, onKeyDown: handleTriggerKeyDown, ref: triggerElementRef }) }), triggerClassName: styles.rowActionsCellTrigger, size: Droplist.sizes.S, "data-test-id": TEST_IDS.rowActions.droplist }, { children: actions.map(item => (_createElement(Droplist.ItemSingle, Object.assign({}, item, { key: `${row.id}-${item.id || item.option}`, onClick: e => handleDroplistItemClick(e, handleItemClick(item)), "data-test-id": TEST_IDS.rowActions.option, onKeyDown: handleDroplistItemKeyDown })))) }))) })));
22
+ }
23
+ /** Вспомогательная функция для создания ячейки с дополнительными действиями у строки */
24
+ export function getRowActionsColumnDef({ actionsGenerator, pinned, }) {
25
+ return {
26
+ id: 'rowActions',
27
+ pinned: pinned ? ColumnPinPosition.Right : undefined,
28
+ size: 40,
29
+ meta: {
30
+ skipOnExport: true,
31
+ },
32
+ noBodyCellPadding: true,
33
+ cellClassName: styles.rowActionsCell,
34
+ cell: cell => _jsx(RowActionsCell, { row: cell.row, actions: actionsGenerator(cell) }),
35
+ };
36
+ }
@@ -0,0 +1 @@
1
+ export * from './RowActionsCell';
@@ -0,0 +1 @@
1
+ export * from './RowActionsCell';
@@ -0,0 +1,34 @@
1
+ .rowActionsCell{
2
+ position:relative;
3
+ border-color:inherit;
4
+ }
5
+ .rowActionsCell::after{
6
+ pointer-events:none;
7
+ content:"";
8
+ position:absolute;
9
+ top:calc(0px - var(--border-width-table, 1px));
10
+ bottom:calc(0px - var(--border-width-table, 1px));
11
+ left:0;
12
+ box-sizing:border-box;
13
+ width:100%;
14
+ border-left:var(--border-width-table, 1px) solid;
15
+ border-color:inherit;
16
+ }
17
+
18
+ .rowActionsCellWrap{
19
+ box-sizing:border-box;
20
+ width:100%;
21
+ height:100%;
22
+ }
23
+
24
+ .rowActionsCellTrigger{
25
+ padding-left:var(--space-table-cell-action-padding, 4px);
26
+ padding-right:var(--space-table-cell-action-padding, 4px);
27
+ cursor:pointer;
28
+ display:flex;
29
+ align-items:center;
30
+ justify-content:center;
31
+ box-sizing:border-box;
32
+ width:100%;
33
+ height:100%;
34
+ }
@@ -0,0 +1,2 @@
1
+ import { ColumnDefinition } from '../../../types';
2
+ export declare function getSelectionCellColumnDef<TData>(): ColumnDefinition<TData>;
@@ -0,0 +1,45 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Checkbox, Radio } from '@snack-uikit/toggles';
14
+ import { ColumnPinPosition, TEST_IDS } from '../../../constants';
15
+ import styles from './styles.module.css';
16
+ function SelectionCell(_a) {
17
+ var { isMulti, onChange } = _a, props = __rest(_a, ["isMulti", "onChange"]);
18
+ const handleCellClick = (e) => {
19
+ e.stopPropagation();
20
+ onChange(props.checked);
21
+ };
22
+ return (
23
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
24
+ _jsx("div", Object.assign({ onClick: handleCellClick, className: styles.selectionCell, "data-test-id": TEST_IDS.rowSelect }, { children: isMulti ? _jsx(Checkbox, Object.assign({}, props, { size: Checkbox.sizes.S })) : _jsx(Radio, Object.assign({}, props, { size: Radio.sizes.S })) })));
25
+ }
26
+ export function getSelectionCellColumnDef() {
27
+ return {
28
+ id: 'selectionCell',
29
+ pinned: ColumnPinPosition.Left,
30
+ noBodyCellPadding: true,
31
+ size: 40,
32
+ headerClassName: styles.selectionCellHeader,
33
+ cell: ({ row, table }) => {
34
+ const disabled = !row.getCanSelect();
35
+ if (disabled)
36
+ return null;
37
+ const { enableMultiRowSelection } = table.options;
38
+ const isMulti = typeof enableMultiRowSelection === 'boolean' ? enableMultiRowSelection : true;
39
+ return (_jsx(SelectionCell, { isMulti: isMulti, checked: row.getIsSelected(), onChange: row.getToggleSelectedHandler() }));
40
+ },
41
+ meta: {
42
+ skipOnExport: true,
43
+ },
44
+ };
45
+ }
@@ -0,0 +1 @@
1
+ export * from './SelectionCell';
@@ -0,0 +1 @@
1
+ export * from './SelectionCell';
@@ -0,0 +1,13 @@
1
+ .selectionCell{
2
+ width:var(--size-table-line-height, 40px);
3
+ cursor:pointer;
4
+ display:flex;
5
+ align-items:center;
6
+ justify-content:center;
7
+ box-sizing:border-box;
8
+ height:100%;
9
+ }
10
+
11
+ .selectionCellHeader{
12
+ padding:0;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { ColumnDefinition } from '../../../types';
2
+ import { StatusAppearance } from './constants';
3
+ export { StatusAppearance };
4
+ type BaseStatusColumnDef = {
5
+ /** Имя ключа соответствующее полю в data */
6
+ accessorKey: string;
7
+ /** Маппинг значений статуса на цвета */
8
+ mapStatusToAppearance(value: string | number): StatusAppearance;
9
+ /** Включение/выключение сортировки */
10
+ enableSorting?: boolean;
11
+ };
12
+ type StatusColumnDef = BaseStatusColumnDef & {
13
+ renderDescription?: never;
14
+ size?: never;
15
+ header?: never;
16
+ };
17
+ type StatusColumnDefWithDescription<TData> = BaseStatusColumnDef & {
18
+ /** Функция для отрисовки текста, если не передана, то будет отрисован только индикатор статуса */
19
+ renderDescription(cellValue: string): string;
20
+ /** Размер ячейки */
21
+ size: number;
22
+ /** Заголовок колонки */
23
+ header?: ColumnDefinition<TData>['header'];
24
+ };
25
+ export type StatusColumnDefinitionProps<TData> = StatusColumnDef | StatusColumnDefWithDescription<TData>;
26
+ /** Вспомогательная функция для создания ячейки со статусом */
27
+ export declare function getStatusColumnDef<TData>({ header, accessorKey, mapStatusToAppearance, renderDescription, size, enableSorting, }: StatusColumnDefinitionProps<TData>): ColumnDefinition<TData>;
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TruncateString } from '@snack-uikit/truncate-string';
3
+ import { Typography } from '@snack-uikit/typography';
4
+ import { ColumnPinPosition, TEST_IDS } from '../../../constants';
5
+ import { MIN_STATUS_CELL_SIZE, StatusAppearance } from './constants';
6
+ import styles from './styles.module.css';
7
+ export { StatusAppearance };
8
+ function StatusCell({ appearance, label }) {
9
+ const isLoading = appearance === StatusAppearance.Loading;
10
+ return (_jsxs("div", Object.assign({ className: styles.statusCell, "data-no-label": !label || undefined }, { children: [_jsx("div", { "data-appearance": isLoading ? undefined : appearance, className: styles.statusCellIndicator, "data-loading": isLoading || undefined, "data-test-id": TEST_IDS.statusIndicator }), label && (_jsx("div", Object.assign({ className: styles.statusCellLabel, "data-test-id": TEST_IDS.statusLabel }, { children: _jsx(Typography.LightLabelS, { children: _jsx(TruncateString, { text: label }) }) })))] })));
11
+ }
12
+ /** Вспомогательная функция для создания ячейки со статусом */
13
+ export function getStatusColumnDef({ header, accessorKey, mapStatusToAppearance, renderDescription, size, enableSorting, }) {
14
+ const hasDescription = Boolean(renderDescription);
15
+ return {
16
+ id: 'snack_predefined_statusColumn',
17
+ pinned: ColumnPinPosition.Left,
18
+ noBodyCellPadding: true,
19
+ noHeaderCellPadding: !hasDescription,
20
+ noHeaderCellBorderOffset: hasDescription,
21
+ size: hasDescription ? size : MIN_STATUS_CELL_SIZE,
22
+ minSize: MIN_STATUS_CELL_SIZE,
23
+ meta: {
24
+ skipOnExport: true,
25
+ },
26
+ accessorKey,
27
+ enableSorting,
28
+ header: hasDescription ? header : undefined,
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ accessorFn: (row) => renderDescription && Object.hasOwn(row, accessorKey)
31
+ ? renderDescription(row[accessorKey])
32
+ : undefined,
33
+ cell: cell => {
34
+ const value = typeof cell.row.original === 'object' && Object.hasOwn(cell.row.original, accessorKey)
35
+ ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
+ // @ts-ignore
37
+ cell.row.original[accessorKey]
38
+ : cell.getValue();
39
+ const appearance = mapStatusToAppearance(value);
40
+ return _jsx(StatusCell, { appearance: appearance, label: renderDescription ? renderDescription(value) : undefined });
41
+ },
42
+ };
43
+ }
@@ -0,0 +1,13 @@
1
+ export declare enum StatusAppearance {
2
+ Primary = "primary",
3
+ Neutral = "neutral",
4
+ Red = "red",
5
+ Orange = "orange",
6
+ Yellow = "yellow",
7
+ Green = "green",
8
+ Blue = "blue",
9
+ Violet = "violet",
10
+ Pink = "pink",
11
+ Loading = "loading"
12
+ }
13
+ export declare const MIN_STATUS_CELL_SIZE = 16;
@@ -0,0 +1,14 @@
1
+ export var StatusAppearance;
2
+ (function (StatusAppearance) {
3
+ StatusAppearance["Primary"] = "primary";
4
+ StatusAppearance["Neutral"] = "neutral";
5
+ StatusAppearance["Red"] = "red";
6
+ StatusAppearance["Orange"] = "orange";
7
+ StatusAppearance["Yellow"] = "yellow";
8
+ StatusAppearance["Green"] = "green";
9
+ StatusAppearance["Blue"] = "blue";
10
+ StatusAppearance["Violet"] = "violet";
11
+ StatusAppearance["Pink"] = "pink";
12
+ StatusAppearance["Loading"] = "loading";
13
+ })(StatusAppearance || (StatusAppearance = {}));
14
+ export const MIN_STATUS_CELL_SIZE = 16;
@@ -0,0 +1 @@
1
+ export * from './StatusCell';
@@ -0,0 +1 @@
1
+ export * from './StatusCell';