Skip to content

Commit

Permalink
feat: add ability to pass custom class to table header (EightfoldAI#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ychhabra-eightfold authored Jul 11, 2022
1 parent a7c341e commit e8133e3
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/__snapshots__/storybook.test.js.snap
Git LFS file not shown
2 changes: 2 additions & 0 deletions src/components/Table/Internal/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function Header<RecordType>({
columns,
flattenColumns,
onHeaderRow,
classNames,
}: HeaderProps<RecordType>): React.ReactElement {
const { getComponent } = useContext(TableContext);
const rows: CellType<RecordType>[][] = useMemo(
Expand All @@ -97,6 +98,7 @@ function Header<RecordType>({
{rows.map((row, rowIndex) => {
const rowNode = (
<HeaderRow
classNames={classNames}
key={rowIndex}
flattenColumns={flattenColumns}
cells={row}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Table/Internal/Header/Header.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export interface RowProps<RecordType> {
cellComponent: CustomizeComponent;
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
index: number;
classNames?: string;
}

export interface HeaderProps<RecordType> {
columns: ColumnsType<RecordType>;
flattenColumns: readonly ColumnType<RecordType>[];
stickyOffsets: StickyOffsets;
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
classNames?: string;
}
3 changes: 3 additions & 0 deletions src/components/Table/Internal/Header/HeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RowProps } from './Header.types';
import TableContext from '../Context/TableContext';
import { getCellFixedInfo } from '../Utilities/fixUtil';
import { getColumnsKey } from '../Utilities/valueUtil';
import { mergeClasses } from '../../../../shared/utilities';

function HeaderRow<RecordType>({
cells,
Expand All @@ -14,6 +15,7 @@ function HeaderRow<RecordType>({
cellComponent: CellComponent,
onHeaderRow,
index,
classNames,
}: RowProps<RecordType>) {
const { direction } = useContext(TableContext);

Expand Down Expand Up @@ -47,6 +49,7 @@ function HeaderRow<RecordType>({
return (
<Cell
{...cell}
classNames={mergeClasses([cell.classNames, classNames])}
ellipsis={column.ellipsis}
align={column.align}
component={CellComponent}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Table/Internal/OcTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function OcTable<RecordType extends DefaultRecordType>(
onHeaderRow,
transformColumns,
sticky,
headerClassName,
} = props;

const mergedData = data || EMPTY_DATA;
Expand Down Expand Up @@ -484,6 +485,7 @@ function OcTable<RecordType extends DefaultRecordType>(
onHeaderRow,
fixHeader,
scroll,
classNames: headerClassName,
};

// Empty
Expand Down Expand Up @@ -599,7 +601,10 @@ function OcTable<RecordType extends DefaultRecordType>(
>
{(fixedHolderPassProps) => (
<>
<Header {...fixedHolderPassProps} />
<Header
{...fixedHolderPassProps}
classNames={headerClassName}
/>
{fixFooter === 'top' && (
<Footer {...fixedHolderPassProps}>
{summaryNode}
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/Internal/OcTable.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export interface OcTableProps<RecordType = unknown> {
onRow?: GetComponentProps<RecordType>;
onHeaderRow?: GetComponentProps<readonly ColumnType<RecordType>[]>;
emptyText?: React.ReactNode | (() => React.ReactNode);
headerClassName?: string;

direction?: string;

Expand Down
1 change: 1 addition & 0 deletions src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ export const Virtual_List: FC = () => {

const tableArgs: Object = {
alternateRowColor: true,
headerClassName: 'my-header',
bordered: true,
classNames: 'my-table-class',
id: 'myTableId',
Expand Down

0 comments on commit e8133e3

Please sign in to comment.