Skip to content

Commit

Permalink
fix: allow passing metadata to the table columns
Browse files Browse the repository at this point in the history
  • Loading branch information
haideralsh committed May 8, 2024
1 parent fdbfb6b commit 8b1d736
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/Table/Table.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@ export interface CellInfoType {
row: RowType;
}

interface ColumnInfoType {
align?: ColumnAlignment;
label: string;
dataKey?: Key;
width?: string | number;
}

type ColumnAlignment = "left" | "right" | "center";

export type ColumnType = {
align?: ColumnAlignment;
label?: string;
cellFormatter?: (cell: CellInfoType) => React.ReactNode;
cellRenderer?: (cell: CellInfoType) => React.ReactNode;
headerRenderer?: (column: ColumnInfoType) => React.ReactNode;
headerFormatter?: (column: ColumnInfoType) => React.ReactNode;
headerRenderer?: (column: ColumnType) => React.ReactNode;
headerFormatter?: (column: ColumnType) => React.ReactNode;
width?: string | number;
metadata?: Record<string, unknown>;
} & ({ key: Key; dataKey?: never | undefined } | { dataKey: Key; key?: never | undefined });

export type Columns = ColumnType[];
Expand Down
3 changes: 2 additions & 1 deletion src/Table/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const renderHeaderCellContent = ({
label,
dataKey,
width,
}: ColumnType) => headerFormatter({ align, label, dataKey, width });
metadata,
}: ColumnType) => headerFormatter({ align, label, dataKey, width, metadata });

const TableHead = ({ columns, compact, sticky }: TableHeadProps) => {
const renderColumns = (allColumns: Columns) =>
Expand Down

0 comments on commit 8b1d736

Please sign in to comment.