@dbcdk/react-components 0.0.35 → 0.0.37

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.
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { TextWrap } from 'lucide-react';
3
+ import { isValidElement } from 'react';
3
4
  import { useMemo, useState } from 'react';
4
5
  import styles from './CodeBlock.module.css';
5
6
  import { Button } from '../button/Button';
@@ -15,12 +16,22 @@ const looksLikeStackFrame = (line) => {
15
16
  t.startsWith('↳') || // some tools
16
17
  /^at\s+\w/.test(t));
17
18
  };
19
+ function getTextContent(node) {
20
+ if (node == null || typeof node === 'boolean')
21
+ return '';
22
+ if (typeof node === 'string' || typeof node === 'number')
23
+ return String(node);
24
+ if (Array.isArray(node))
25
+ return node.map(getTextContent).join('');
26
+ if (isValidElement(node))
27
+ return getTextContent(node.props.children);
28
+ return '';
29
+ }
18
30
  export function CodeBlock({ code, children, copyButton, copyText, size = 'md', smart = true, wrap = true, }) {
19
- var _a;
20
31
  const text = typeof code === 'string' ? code : undefined;
21
- const copy = (_a = copyText !== null && copyText !== void 0 ? copyText : text) !== null && _a !== void 0 ? _a : '';
22
32
  const hasChildren = children !== undefined && children !== null;
23
33
  const [isWrapped, setIsWrapped] = useState(wrap);
34
+ const copy = useMemo(() => { var _a; return (_a = copyText !== null && copyText !== void 0 ? copyText : text) !== null && _a !== void 0 ? _a : getTextContent(children); }, [copyText, text, children]);
24
35
  const lines = useMemo(() => (smart && !hasChildren && typeof text === 'string' ? text.split('\n') : null), [smart, hasChildren, text]);
25
36
  return (_jsxs("div", { className: [
26
37
  styles.wrapper,
@@ -1,4 +1,4 @@
1
1
  import type { JSX } from 'react';
2
2
  import type { TableProps } from './Table.types';
3
- export declare function Table<T extends Record<string, any>>({ data, dataKey, columns, selectedRows, selectionMode, allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant, size, viewMode, striped, fillViewport, tableWidth, tableRootRef, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement, showFirstLast, pageSizeOptions, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }: TableProps<T>): JSX.Element;
3
+ export declare function Table<T extends Record<string, any>>({ data, dataKey, columns, selectedRows, selectionMode, allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant, size, viewMode, striped, fillViewport, tableWidth, tableRootRef, measuringLayout, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement, showFirstLast, pageSizeOptions, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }: TableProps<T>): JSX.Element;
4
4
  export type { ColumnItem } from './Table.types';
@@ -9,7 +9,7 @@ import { TableLoadingBody } from './components/TableLoadingBody';
9
9
  import { cx } from './table.classes';
10
10
  import styles from './Table.module.css';
11
11
  import { getVisibleColumns, SELECTION_COLUMN_PX } from './table.utils';
12
- export function Table({ data, dataKey, columns, selectedRows, selectionMode = 'single', allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant = 'primary', size = 'md', viewMode, striped, fillViewport = false, tableWidth, tableRootRef, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement = 'bottom', showFirstLast = false, pageSizeOptions, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }) {
12
+ export function Table({ data, dataKey, columns, selectedRows, selectionMode = 'single', allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant = 'primary', size = 'md', viewMode, striped, fillViewport = false, tableWidth, tableRootRef, measuringLayout = false, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement = 'bottom', showFirstLast = false, pageSizeOptions, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }) {
13
13
  const visibleColumns = useMemo(() => getVisibleColumns(columns), [columns]);
14
14
  const selectionInputName = useId();
15
15
  const hasSelection = Boolean(selectedRows && onRowSelect);
@@ -18,7 +18,7 @@ export function Table({ data, dataKey, columns, selectedRows, selectionMode = 's
18
18
  }, [onPageChange]);
19
19
  const bodyContent = loading && !data.length ? (_jsx(TableLoadingBody, { rows: take !== null && take !== void 0 ? take : 5, columns: visibleColumns, hasSelection: hasSelection })) : (_jsx(TableBody, { data: data, dataKey: dataKey, columns: visibleColumns, striped: striped, selectedRows: selectedRows, hasSelection: hasSelection, selectionMode: selectionMode, selectionInputName: selectionInputName, viewMode: viewMode, getRowSeverity: getRowSeverity, onRowClick: onRowClick, onRowMouseEnter: onRowMouseEnter, onRowSelect: onRowSelect }));
20
20
  const paginationEl = onPageChange && data.length > 0 ? (_jsx("div", { className: cx(styles.paginationSlot, paginationPlacement === 'top' && styles.paginationSlotTop), children: _jsx(Pagination, { itemsCount: totalItemsCount, take: take, skip: skip, onPageChange: handlePageChange, showFirstLast: showFirstLast, pageSizeOptions: pageSizeOptions }) })) : null;
21
- const tableClassName = cx(styles.tableRoot, styles[variant], styles[size], getRowSeverity && styles.severityTable);
21
+ const tableClassName = cx(styles.tableRoot, styles[variant], styles[size], measuringLayout && styles.measuringLayout, getRowSeverity && styles.severityTable);
22
22
  const tableShell = (_jsx("div", { ...rest, className: tableClassName, children: _jsx("div", { ref: tableRootRef, className: styles.tableScroll, children: !data.length && !loading ? (_jsx("div", { className: styles.emptyStateSlot, children: _jsx(TableEmptyState, { config: emptyConfig }) })) : (_jsxs("table", { className: styles.tableElement, "aria-rowcount": data.length, style: tableWidth != null ? { width: tableWidth } : undefined, children: [_jsxs("colgroup", { children: [hasSelection ? _jsx("col", { style: { width: SELECTION_COLUMN_PX } }) : null, visibleColumns.map(column => (_jsx("col", { style: column.width != null ? { width: column.width } : undefined }, column.id)))] }), _jsx(TableHeader, { columns: visibleColumns, hasSelection: hasSelection, selectionMode: selectionMode, allRowsSelected: allRowsSelected, onSelectAllRows: onSelectAllRows, sortById: sortById, sortDirection: sortDirection, onSortChange: onSortChange, headerExtras: headerExtras }), bodyContent] })) }) }));
23
23
  if (fillViewport) {
24
24
  return (_jsxs("div", { className: styles.fillViewportRoot, style: {
@@ -55,6 +55,10 @@
55
55
  max-inline-size: 100%;
56
56
  }
57
57
 
58
+ .measuringLayout {
59
+ visibility: hidden;
60
+ }
61
+
58
62
  .tableScroll {
59
63
  flex: 1 1 auto;
60
64
  min-block-size: 0;
@@ -157,7 +161,7 @@
157
161
 
158
162
  .headerCell.selectionCell,
159
163
  .cell.selectionCell {
160
- padding-inline: calc(var(--spacing-xxs) + 2px) var(--spacing-sm);
164
+ padding-inline: calc(var(--spacing-xxs) + 6px) var(--spacing-sm);
161
165
  cursor: pointer;
162
166
  overflow: visible;
163
167
  line-height: 0;
@@ -208,7 +212,7 @@
208
212
  cursor: pointer;
209
213
  }
210
214
 
211
- .clickableRow:hover > .cell {
215
+ .row:hover > .cell {
212
216
  background-color: var(--table-row-bg-hover);
213
217
  }
214
218
 
@@ -43,6 +43,7 @@ export type TableProps<T extends Record<string, any>> = Omit<HTMLAttributes<HTML
43
43
  fillViewport?: boolean;
44
44
  tableWidth?: number;
45
45
  tableRootRef?: Ref<HTMLDivElement>;
46
+ measuringLayout?: boolean;
46
47
  toolbar?: ReactNode;
47
48
  headerExtras?: (args: HeaderExtrasArgs<T>) => ReactNode;
48
49
  take?: number;
@@ -2,10 +2,8 @@ import { type ColumnDef, type SortingState } from '@tanstack/react-table';
2
2
  import * as React from 'react';
3
3
  import { TableProps, TableVariant } from './Table.types';
4
4
  import { ViewMode } from '../../hooks/useTableSettings';
5
- type Filterable<T> = Array<keyof T>;
6
- export type TanstackTableProps<T extends Record<string, any>> = Omit<TableProps<T>, 'columns' | 'onSortChange' | 'sortById' | 'sortDirection' | 'headerExtras' | 'gridTemplateColumns' | 'toolbar'> & {
5
+ export type TanstackTableProps<T extends Record<string, any>> = Omit<TableProps<T>, 'columns' | 'onSortChange' | 'sortById' | 'sortDirection' | 'headerExtras' | 'toolbar'> & {
7
6
  columns: ReadonlyArray<ColumnDef<T, any>>;
8
- filterable?: Filterable<T>;
9
7
  sorting?: SortingState;
10
8
  manualSorting?: boolean;
11
9
  onSortingChange?: (next: SortingState) => void;
@@ -15,4 +13,3 @@ export type TanstackTableProps<T extends Record<string, any>> = Omit<TableProps<
15
13
  visibleColumnIds?: string[];
16
14
  };
17
15
  export declare function TanstackTable<T extends Record<string, any>>(props: TanstackTableProps<T>): React.ReactNode;
18
- export {};
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useReactTable, getCoreRowModel, getSortedRowModel, getFilteredRowModel, } from '@tanstack/react-table';
3
+ import { useReactTable, getCoreRowModel, getSortedRowModel, } from '@tanstack/react-table';
4
4
  import * as React from 'react';
5
5
  import ColumnResizer from './components/column-resizer/ColumnResizer';
6
6
  import { Table } from './Table';
@@ -18,7 +18,6 @@ export function TanstackTable(props) {
18
18
  setUiSorting(controlledSorting);
19
19
  }, [isControlledSorting, controlledSorting, uiSorting]);
20
20
  const columnVisibility = React.useMemo(() => buildColumnVisibilityFromVisibleIds(columns, visibleColumnIds), [columns, visibleColumnIds]);
21
- const [columnFilters, setColumnFilters] = React.useState([]);
22
21
  const [columnSizing, setColumnSizing] = React.useState({});
23
22
  const containerRef = React.useRef(null);
24
23
  const [availableWidth, setAvailableWidth] = React.useState(undefined);
@@ -27,7 +26,6 @@ export function TanstackTable(props) {
27
26
  columns: columns,
28
27
  state: {
29
28
  sorting: uiSorting,
30
- columnFilters,
31
29
  columnSizing,
32
30
  columnVisibility,
33
31
  },
@@ -37,11 +35,9 @@ export function TanstackTable(props) {
37
35
  setUiSorting(next);
38
36
  onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(next);
39
37
  },
40
- onColumnFiltersChange: setColumnFilters,
41
38
  onColumnSizingChange: setColumnSizing,
42
39
  getCoreRowModel: getCoreRowModel(),
43
40
  getSortedRowModel: getSortedRowModel(),
44
- getFilteredRowModel: getFilteredRowModel(),
45
41
  manualSorting: manualSorting !== null && manualSorting !== void 0 ? manualSorting : false,
46
42
  enableColumnResizing: true,
47
43
  columnResizeMode: 'onChange',
@@ -79,6 +75,7 @@ export function TanstackTable(props) {
79
75
  availableWidth,
80
76
  });
81
77
  }, [table, selectedRows, onRowSelect, dataKey, columnSizing, availableWidth]);
78
+ const initialLayoutReady = availableWidth != null;
82
79
  const resolvedLayout = React.useMemo(() => {
83
80
  const next = {};
84
81
  table.getVisibleLeafColumns().forEach((column) => {
@@ -110,5 +107,5 @@ export function TanstackTable(props) {
110
107
  return null;
111
108
  return _jsx(ColumnResizer, { id: header.column.id, handler: handler });
112
109
  }, [table]);
113
- return (_jsx(Table, { ...tableProps, tableRootRef: containerRef, onSortChange: handleSortChange, dataKey: dataKey, data: visibleData, columns: columnItems, tableWidth: distributedLayout === null || distributedLayout === void 0 ? void 0 : distributedLayout.totalWidth, sortById: sortById, sortDirection: sortDirection, headerExtras: headerExtras, selectedRows: selectedRows, onRowSelect: onRowSelect }));
110
+ return (_jsx(Table, { ...tableProps, tableRootRef: containerRef, onSortChange: handleSortChange, dataKey: dataKey, data: visibleData, columns: columnItems, tableWidth: distributedLayout === null || distributedLayout === void 0 ? void 0 : distributedLayout.totalWidth, measuringLayout: !initialLayoutReady, sortById: sortById, sortDirection: sortDirection, headerExtras: headerExtras, selectedRows: selectedRows, onRowSelect: onRowSelect }));
114
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -56,7 +56,7 @@
56
56
  "changeset": "changeset",
57
57
  "version-packages": "changeset version",
58
58
  "typecheck": "tsc -p tsconfig.json --noEmit",
59
- "pack-it": "npm run build && npm pack",
59
+ "pack-it": "rimraf ./*.tgz && npm run build && npm pack",
60
60
  "postbuild": "cpy \"src/**/*.css\" dist --parents && cpy \"src/styles/styles.css\" dist && cpy \"src/styles/fonts/**/*\" dist/styles/fonts",
61
61
  "yalc:publish": "npm run build && yalc publish --push",
62
62
  "yalc:push": "npm run build && yalc push --scripts --changed",