generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(BaseTable): pass getIsCustomRow, groupHeaderClassName and renderC…
…ustomRowContent into BaseRow (#66)
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/components/BaseTable/__stories__/stories/CustomRowStory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
|
||
import type {ColumnDef, Row} from '@tanstack/react-table'; | ||
|
||
import {useTable} from '../../../../hooks'; | ||
import type {BaseTableProps} from '../../BaseTable'; | ||
import {BaseTable} from '../../BaseTable'; | ||
import {data} from '../constants/data'; | ||
import type {Item} from '../types'; | ||
|
||
interface CustomItem { | ||
isCustom: boolean; | ||
} | ||
|
||
type ItemOrCustom = Item | CustomItem; | ||
|
||
const dataWithCustomRow: Array<ItemOrCustom> = [...data, {isCustom: true}]; | ||
|
||
const getIsCustomRow = (row: Row<ItemOrCustom>) => { | ||
return 'isCustom' in row.original && row.original.isCustom; | ||
}; | ||
|
||
const renderCustomRowContent: BaseTableProps<ItemOrCustom>['renderCustomRowContent'] = ({Cell}) => { | ||
return <Cell colSpan={2}>This is a custom row</Cell>; | ||
}; | ||
|
||
const columns: ColumnDef<ItemOrCustom>[] = [ | ||
{accessorKey: 'name', header: 'Name', size: 150}, | ||
{accessorKey: 'age', header: 'Age', size: 150}, | ||
]; | ||
|
||
export const CustomRowStory = () => { | ||
const table = useTable({ | ||
columns, | ||
data: dataWithCustomRow, | ||
}); | ||
|
||
return ( | ||
<BaseTable | ||
table={table} | ||
getIsCustomRow={getIsCustomRow} | ||
renderCustomRowContent={renderCustomRowContent} | ||
/> | ||
); | ||
}; |