-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add TableFooter component #9943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e215aab
cbb38cd
d7d8913
67186fd
a0e19e7
b92a840
23c1526
e34e20e
0e3e2aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export {TableView, TableHeader, TableBody, Row, Cell, Column, TableContext, EditableCell} from '../src/TableView'; | ||
| export {TableView, TableHeader, TableBody, Row, Cell, Column, TableContext, EditableCell, TableFooter} from '../src/TableView'; | ||
| export {Collection} from 'react-aria/Collection'; | ||
| export type {TableViewProps, TableHeaderProps, TableBodyProps, RowProps, CellProps, ColumnProps} from '../src/TableView'; | ||
| export type {TableViewProps, TableHeaderProps, TableBodyProps, RowProps, CellProps, ColumnProps, TableFooterProps} from '../src/TableView'; | ||
| export type {Selection, Key, SelectionMode, SortDescriptor, SortDirection} from '@react-types/shared'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { | |
| EditableCell, | ||
| Row, | ||
| TableBody, | ||
| TableFooter, | ||
| TableHeader, | ||
| TableView, | ||
| TableViewProps | ||
|
|
@@ -1887,3 +1888,44 @@ function NestedInlineEditExample(args) { | |
| export const TableWithNestedRowsAndInlineEditing: StoryObj<typeof TableView> = { | ||
| render: (args) => <NestedInlineEditExample {...args} /> | ||
| }; | ||
|
|
||
| const invoices = [ | ||
| {title: 'Website Design', status: 'Paid', paymentMethod: 'Credit Card', price: '$1,200'}, | ||
| {title: 'Logo Creation', status: 'Pending', paymentMethod: 'PayPal', price: '$350'}, | ||
| {title: 'SEO Optimization', status: 'Overdue', paymentMethod: 'Bank Transfer', price: '$800'}, | ||
| {title: 'Social Media Setup', status: 'Paid', paymentMethod: 'Debit Card', price: '$450'}, | ||
| {title: 'Content Writing', status: 'Pending', paymentMethod: 'Credit Card', price: '$600'}, | ||
| {title: 'App Development', status: 'Paid', paymentMethod: 'Wire Transfer', price: '$5,000'}, | ||
| {title: 'Maintenance Plan', status: 'Overdue', paymentMethod: 'PayPal', price: '$200'} | ||
| ]; | ||
|
|
||
| export const TableFooterExample: StoryObj<typeof TableView> = { | ||
| render: (args) => { | ||
| return ( | ||
| <TableView aria-label="Files" selectionMode="multiple" styles={style({width: 700})} {...args}> | ||
| <TableHeader> | ||
| <Column isRowHeader>Title</Column> | ||
| <Column>Status</Column> | ||
| <Column>Payment Method</Column> | ||
| <Column>Price</Column> | ||
| </TableHeader> | ||
| <TableBody items={invoices}> | ||
| {item => ( | ||
| <Row id={item.title}> | ||
| <Cell>{item.title}</Cell> | ||
| <Cell>{item.status}</Cell> | ||
| <Cell>{item.paymentMethod}</Cell> | ||
| <Cell>{item.price}</Cell> | ||
| </Row> | ||
| )} | ||
| </TableBody> | ||
| <TableFooter> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked and multiple footer rows appears to work, though row divider borders aren't a good contrast. I tried nesting rows in the footer as well in case someone wanted to use progressive disclosure for more complicated summaries, that also worked, though the expansion could end up in an odd spot, I made it the title column here.
I'm assuming these aren't officially supported, but nice to know they won't be much trouble to eventually support. Though it might be nice to be able to tell a TableBody/Footer if it is expandable so that the alignment doesn't end up like this if only one of them actually has expansion. I don't think we're doing anything right now that would prevent that in the future though. |
||
| <Row> | ||
| <Cell colSpan={3} align="end">Total:</Cell> | ||
| <Cell>{invoices.reduce((p, item) => p + Number(item.price.replace(/[$,]/g, '')), 0).toLocaleString('en-US', {style: 'currency', currency: 'USD', maximumFractionDigits: 0})}</Cell> | ||
| </Row> | ||
| </TableFooter> | ||
| </TableView> | ||
| ); | ||
| } | ||
| }; | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New feature: support for
disabledBehaviorat the individualRowlevel, not just at theTablelevel. This is so that the summary rows are not selectable but still focusable, regardless of thedisabledBehaviorof the rest of the table. Is this something we want to support?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess its fine, but feels a bit iffy to me to make it public api if it really is only used for the summary row case. Could we not just do a private prop or context or somethingto set this?