@umituz/web-design-system 4.6.2 → 4.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-design-system",
3
- "version": "4.6.2",
3
+ "version": "4.6.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Web Design System - Tailwind v4 authored, precompiled CSS shipped. Atomic Design components (Atoms, Molecules, Organisms, Templates) for React applications.",
@@ -198,7 +198,7 @@ describe('DataTable', () => {
198
198
  expect(cellsBefore.join()).toContain('bravo');
199
199
  fireEvent.click(screen.getByRole('columnheader', { name: /name/i }));
200
200
  const firstDataRow = screen.getAllByRole('row')[1];
201
- expect(firstDataRow.textContent).toContain('alpha');
201
+ expect(firstDataRow?.textContent).toContain('alpha');
202
202
  });
203
203
 
204
204
  it('controlled sort delegates to onSortChange', () => {
@@ -704,6 +704,28 @@ describe('accessia supersets', () => {
704
704
  expect(screen.getAllByRole('row')[1]?.textContent).toContain('alpha');
705
705
  });
706
706
 
707
+ it('DataTable cell-only column works without accessor and honors controlled null sort', () => {
708
+ interface Local {
709
+ id: string;
710
+ name: string;
711
+ }
712
+ const { container } = render(
713
+ <DataTable<Local>
714
+ data={[
715
+ { id: 'cn-b', name: 'cn-bravo' },
716
+ { id: 'cn-a', name: 'cn-alpha' },
717
+ ]}
718
+ sortable
719
+ sort={null}
720
+ onSortChange={() => {}}
721
+ columns={[{ id: 'name', header: 'Name', cell: (r) => <em>{r.name}</em> }]}
722
+ />,
723
+ );
724
+ const firstCell = container.querySelector('tbody td');
725
+ expect(firstCell?.textContent).toContain('cn-bravo');
726
+ expect(firstCell?.innerHTML).toContain('<em>');
727
+ });
728
+
707
729
  it('Progress info tone paints the fill info', () => {
708
730
  render(<Progress value={60} tone="info" aria-label="load" />);
709
731
  expect(screen.getByRole('progressbar', { name: 'load' }).querySelector('div')?.className).toContain('bg-info');
@@ -33,8 +33,10 @@ const nameTones = [
33
33
  const initialsOf = (name: string): string => {
34
34
  const parts = name.trim().split(/\s+/).filter(Boolean);
35
35
  if (parts.length === 0) return '';
36
- if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
37
- return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
36
+ const first = parts[0] ?? '';
37
+ const last = parts[parts.length - 1] ?? '';
38
+ if (parts.length === 1) return first.slice(0, 2).toUpperCase();
39
+ return (first.charAt(0) + last.charAt(0)).toUpperCase();
38
40
  };
39
41
 
40
42
  const toneIndexOf = (name: string): number => {
@@ -42,7 +42,8 @@ export interface SortState {
42
42
  export interface Column<T> {
43
43
  id: string;
44
44
  header: ReactNode;
45
- accessor: keyof T | ((row: T) => ReactNode);
45
+ /** Data source; optional when the column renders through `cell` only. */
46
+ accessor?: keyof T | ((row: T) => ReactNode);
46
47
  cell?: (row: T) => ReactNode;
47
48
  sortValue?: (row: T) => string | number;
48
49
  sortable?: boolean;
@@ -66,8 +67,8 @@ export interface DataTableProps<T> extends BaseProps {
66
67
  caption?: string;
67
68
  size?: MediumSizes;
68
69
  sortable?: boolean;
69
- sort?: SortState;
70
- initialSort?: SortState;
70
+ sort?: SortState | null;
71
+ initialSort?: SortState | null;
71
72
  onSortChange?: (id: string) => void;
72
73
  rowKey?: (row: T) => string;
73
74
  selectedId?: string;
@@ -114,6 +115,7 @@ const hideBelowStyles: Record<ColumnHideBelow, string> = {
114
115
 
115
116
  function displayValue<T>(column: Column<T>, row: T): ReactNode {
116
117
  if (column.cell) return column.cell(row);
118
+ if (column.accessor === undefined) return null;
117
119
  return typeof column.accessor === 'function'
118
120
  ? column.accessor(row)
119
121
  : (row[column.accessor] as ReactNode);
@@ -121,6 +123,7 @@ function displayValue<T>(column: Column<T>, row: T): ReactNode {
121
123
 
122
124
  function sortValueOf<T>(column: Column<T>, row: T): string | number | null {
123
125
  if (column.sortValue) return column.sortValue(row);
126
+ if (column.accessor === undefined) return null;
124
127
  const value =
125
128
  typeof column.accessor === 'function' ? column.accessor(row) : row[column.accessor];
126
129
  if (typeof value === 'number') return value;
@@ -252,7 +255,7 @@ export function DataTable<T>({
252
255
  const [internalSort, setInternalSort] = useState<SortState | null>(initialSort ?? null);
253
256
  const [currentPage, setCurrentPage] = useState(1);
254
257
 
255
- const activeSort = sort ?? internalSort;
258
+ const activeSort = sort !== undefined ? sort : internalSort;
256
259
  const controlled = sort !== undefined;
257
260
 
258
261
  const handleSort = (id: string) => {