Skip to content

Commit

Permalink
feat: add overrides for filter and sorter #154
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuechlin committed May 25, 2023
1 parent 83055cd commit 1222fa4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ColumnFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ColumnFilterProps {
color: string;
}

export const ColumnFilter = function ColumnFilter({ column, className, color, filterFn }: ColumnFilterProps) {
export const DefaultColumnFilter = function ColumnFilter({ column, className, color, filterFn }: ColumnFilterProps) {
const [state, setState] = useSetState({ open: false, value: null as unknown });

const handleOpen = () =>
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ColumnSorterProps {
color: string;
}

export const ColumnSorter = ({ column, className, color }: ColumnSorterProps) => {
export const DefaultColumnSorter = ({ column, className, color }: ColumnSorterProps) => {
const sorted = column.getIsSorted();
return (
<ActionIcon
Expand Down
18 changes: 15 additions & 3 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
} from '@tanstack/react-table';
import { useVirtualizer } from '@tanstack/react-virtual';
import { Fragment, RefCallback, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
import { ColumnFilter } from './ColumnFilter';
import { ColumnSorter } from './ColumnSorter';
import { DefaultColumnFilter } from './ColumnFilter';
import { DefaultColumnSorter } from './ColumnSorter';
import useStyles from './DataGrid.styles';
import { GlobalFilter, globalFilterFn } from './GlobalFilter';
import { DEFAULT_INITIAL_SIZE, Pagination as DefaultPagination } from './Pagination';
Expand Down Expand Up @@ -96,7 +96,17 @@ export function DataGrid<TData extends RowData>({
empty,
locale,
// component overrides
components: { headerWrapper, headerRow, headerCell, bodyWrapper, bodyRow, bodyCell, pagination } = {},
components: {
headerWrapper,
headerRow,
headerCell,
bodyWrapper,
bodyRow,
bodyCell,
pagination,
columnFilter,
columnSorter,
} = {},
// table option ovverides
options,
// rest
Expand All @@ -109,6 +119,8 @@ export function DataGrid<TData extends RowData>({
const BodyRow = bodyRow ?? DefaultBodyRow;
const BodyCell = bodyCell ?? DefaultBodyCell;
const Pagination = pagination ?? DefaultPagination;
const ColumnFilter = columnFilter ?? DefaultColumnFilter;
const ColumnSorter = columnSorter ?? DefaultColumnSorter;
const { classes, theme, cx } = useStyles(
{
height,
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
TableState,
} from '@tanstack/react-table';
import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ReactElement, ReactNode, Ref } from 'react';
import { ColumnFilterProps } from './ColumnFilter';
import { ColumnSorterProps } from './ColumnSorter';
import useStyles from './DataGrid.styles';
import { PaginationProps } from './Pagination';
import {
Expand Down Expand Up @@ -229,4 +231,6 @@ export type DataGridComponents<TData> = {
bodyRow: ComponentType<DataGridBodyRowProps<TData>>;
bodyCell: ComponentType<DataGridBodyCellProps<TData>>;
pagination: ComponentType<PaginationProps<TData>>;
columnFilter: ComponentType<ColumnFilterProps>;
columnSorter: ComponentType<ColumnSorterProps>;
};

0 comments on commit 1222fa4

Please sign in to comment.