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(Table): rework render props (#21)
- Loading branch information
Showing
40 changed files
with
494 additions
and
446 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,21 +1,29 @@ | ||
import React from 'react'; | ||
|
||
import type {Cell as CellProperties} from '@tanstack/react-table'; | ||
import type {Cell as CellType} from '@tanstack/react-table'; | ||
import {flexRender} from '@tanstack/react-table'; | ||
|
||
import {getCellClassModes} from '../../utils/getCellClassModes'; | ||
import {getCellStyles} from '../../utils/getCellStyles'; | ||
import {getCellClassModes, getCellStyles} from '../../utils'; | ||
import {b} from '../Table/Table.classname'; | ||
|
||
export interface CellProps<TData> { | ||
cell: CellProperties<TData, unknown>; | ||
className?: string; | ||
export interface CellProps<TData> extends React.TdHTMLAttributes<HTMLTableCellElement> { | ||
cell?: CellType<TData, unknown>; | ||
} | ||
|
||
export const Cell = <TData,>({cell, className}: CellProps<TData>) => { | ||
export const Cell = <TData,>({ | ||
cell, | ||
children, | ||
className, | ||
style, | ||
...restProps | ||
}: CellProps<TData>) => { | ||
return ( | ||
<td className={b('cell', getCellClassModes(cell), className)} style={getCellStyles(cell)}> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
<td | ||
className={b('cell', getCellClassModes(cell), className)} | ||
style={getCellStyles(cell, style)} | ||
{...restProps} | ||
> | ||
{cell ? flexRender(cell.column.columnDef.cell, cell.getContext()) : children} | ||
</td> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {block} from '../../utils'; | ||
|
||
export const b = block('group-header'); |
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,40 @@ | ||
@use '../variables'; | ||
|
||
$block: '.#{variables.$ns}group-header'; | ||
|
||
#{$block} { | ||
position: sticky; | ||
inset-inline-start: 0; | ||
margin: 0; | ||
|
||
&__button { | ||
appearance: none; | ||
|
||
display: flex; | ||
gap: 8px; | ||
padding: 0; | ||
width: 100%; | ||
|
||
border: none; | ||
outline: none; | ||
background: inherit; | ||
cursor: pointer; | ||
} | ||
|
||
&__icon { | ||
display: inline-block; | ||
vertical-align: middle; | ||
transform: rotate(-90deg); | ||
transition: transform 0.1s ease-out; | ||
|
||
&_expanded { | ||
transform: rotate(0); | ||
} | ||
} | ||
|
||
&__content { | ||
display: inline-flex; | ||
gap: 4px; | ||
font-weight: 500; | ||
} | ||
} |
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,37 @@ | ||
import React from 'react'; | ||
|
||
import type {Row} from '@tanstack/react-table'; | ||
|
||
import {b} from './GroupHeader.classname'; | ||
|
||
import './GroupHeader.scss'; | ||
|
||
export interface GroupHeaderProps<TData> { | ||
className?: string; | ||
getGroupTitle?: (row: Row<TData>) => React.ReactNode; | ||
row: Row<TData>; | ||
} | ||
|
||
export const GroupHeader = <TData,>({className, getGroupTitle, row}: GroupHeaderProps<TData>) => { | ||
return ( | ||
<h2 className={b(null, className)}> | ||
<button className={b('button')} onClick={row.getToggleExpandedHandler()}> | ||
<svg | ||
className={b('icon', {expanded: row.getIsExpanded()})} | ||
viewBox="0 0 16 16" | ||
width="16" | ||
height="16" | ||
> | ||
<path | ||
d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
<span className={b('content')}> | ||
<span className={b('title')}>{getGroupTitle?.(row) ?? row.id}</span> | ||
<span className={b('total')}>{row.subRows.length}</span> | ||
</span> | ||
</button> | ||
</h2> | ||
); | ||
}; |
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 @@ | ||
export * from './GroupHeader'; |
Oops, something went wrong.