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.
feat(BaseTable): additional properties for classNames and attributes …
…customization (#36)
- Loading branch information
Showing
33 changed files
with
331 additions
and
322 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
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
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 |
---|---|---|
@@ -1,35 +1,49 @@ | ||
import React from 'react'; | ||
|
||
import type {HeaderGroup} from '@tanstack/react-table'; | ||
import type {Header, HeaderGroup} from '@tanstack/react-table'; | ||
|
||
import {shouldRenderFooterCell} from '../../utils'; | ||
import type {BaseFooterCellProps} from '../BaseFooterCell'; | ||
import {BaseFooterCell} from '../BaseFooterCell'; | ||
import {b} from '../BaseTable/BaseTable.classname'; | ||
|
||
export interface BaseFooterRowProps<TData, TValue> | ||
extends React.TdHTMLAttributes<HTMLTableRowElement> { | ||
cellClassName: BaseFooterCellProps<TData, TValue>['className']; | ||
className?: string; | ||
export interface BaseFooterRowProps<TData, TValue = unknown> | ||
extends Omit<React.HTMLAttributes<HTMLTableRowElement>, 'className'> { | ||
footerGroup: HeaderGroup<TData>; | ||
attributes?: | ||
| React.HTMLAttributes<HTMLTableRowElement> | ||
| ((footerGroup: HeaderGroup<TData>) => React.HTMLAttributes<HTMLTableRowElement>); | ||
cellAttributes?: BaseFooterCellProps<TData, TValue>['attributes']; | ||
cellClassName?: BaseFooterCellProps<TData, TValue>['className']; | ||
className?: string | ((footerGroup: HeaderGroup<TData>) => string); | ||
} | ||
|
||
export const BaseFooterRow = <TData, TValue>({ | ||
cellClassName, | ||
className, | ||
export const BaseFooterRow = <TData, TValue = unknown>({ | ||
footerGroup, | ||
attributes: attributesProp, | ||
cellAttributes, | ||
cellClassName, | ||
className: classNameProp, | ||
...restProps | ||
}: BaseFooterRowProps<TData, TValue>) => { | ||
const isEmptyRow = footerGroup.headers.every((header) => !header.column.columnDef.footer); | ||
const attributes = | ||
typeof attributesProp === 'function' ? attributesProp(footerGroup) : attributesProp; | ||
|
||
if (isEmptyRow) { | ||
return null; | ||
} | ||
const className = | ||
typeof classNameProp === 'function' ? classNameProp(footerGroup) : classNameProp; | ||
|
||
return ( | ||
<tr className={b('footer-row', className)} {...restProps}> | ||
{footerGroup.headers.map((header) => ( | ||
<BaseFooterCell key={header.column.id} className={cellClassName} header={header} /> | ||
))} | ||
<tr className={b('footer-row', className)} {...restProps} {...attributes}> | ||
{footerGroup.headers.map((header) => | ||
shouldRenderFooterCell(header) ? ( | ||
<BaseFooterCell | ||
key={header.column.id} | ||
header={header as Header<TData, TValue>} | ||
attributes={cellAttributes} | ||
className={cellClassName} | ||
/> | ||
) : null, | ||
)} | ||
</tr> | ||
); | ||
}; |
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
Oops, something went wrong.