Skip to content

Commit

Permalink
feat(table): create table footer component (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek authored Jan 23, 2023
1 parent f7f6318 commit aee7d22
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 6 deletions.
94 changes: 93 additions & 1 deletion docs/patterns/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Table,
TableBody,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
Expand Down Expand Up @@ -362,6 +363,97 @@ const SortableTable = () => {
)
}`}
</Code>
<h3>Border variant Table with TableFooter</h3>
<Table variant="border">
<TableHead>
<TableRow>
<TableHeader scope="col">First Name</TableHeader>
<TableHeader scope="col">Last Name</TableHeader>
<TableHeader scope="col">Email</TableHeader>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Frank</TableCell>
<TableCell>Zappa</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Duane</TableCell>
<TableCell>Allman</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Yamandu</TableCell>
<TableCell>Costa</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Jimmy</TableCell>
<TableCell>Herring</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
</TableBody>
<TableFooter>
<TableRow>
<TableCell>This is a table footer.</TableCell>
<TableCell>It can be used to provide additional</TableCell>
<TableCell>information about the table.</TableCell>
</TableRow>
</TableFooter>
</Table>
<Code role="region" tabIndex="0">
{`import React from 'react';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@deque/cauldron-react';
const TableBorder = () => (
<Table variant="border">
<TableHead>
<TableRow>
<TableHeader scope="col">First Name</TableHeader>
<TableHeader scope="col">Last Name</TableHeader>
<TableHeader scope="col">Email</TableHeader>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Frank</TableCell>
<TableCell>Zappa</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Duane</TableCell>
<TableCell>Allman</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Yamandu</TableCell>
<TableCell>Costa</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
<TableRow>
<TableCell>Jimmy</TableCell>
<TableCell>Herring</TableCell>
<TableCell>[email protected]</TableCell>
</TableRow>
</TableBody>
<TableFooter>
<TableRow>
<TableCell>This is a table footer.</TableCell>
<TableCell>It can be used to provide additional</TableCell>
<TableCell>information about the table.</TableCell>
</TableRow>
</TableFooter>
</Table>
)`}
</Code>

<div className="Demo-props">
<h2>Props</h2>
Expand Down Expand Up @@ -417,7 +509,7 @@ const SortableTable = () => {
className
}}
/>
<h3>TableHead, TableBody, TableRow, and TableCell</h3>
<h3>TableHead, TableBody, TableFooter, TableRow, and TableCell</h3>
<PropDocs
docs={{
children,
Expand Down
23 changes: 20 additions & 3 deletions packages/react/__tests__/src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Table, {
TableCell,
TableHead,
TableHeader,
TableRow
TableRow,
TableFooter
} from '../../../../src/components/Table';
import axe from '../../../axe';

Expand All @@ -31,6 +32,14 @@ const renderDefaultTable = () =>
<TableCell className="my-table-cell">2</TableCell>
</TableRow>
</TableBody>
<TableFooter className="my-table-footer" data-foo="true">
<TableRow className="my-table-row">
<TableCell className="my-table-cell" data-foo="true">
foo
</TableCell>
<TableCell className="my-table-cell">bar</TableCell>
</TableRow>
</TableFooter>
</Table>
);

Expand All @@ -42,14 +51,16 @@ describe('Table components', () => {
const tableHeader = table.find('TableHeader').at(0);
const tableBody = table.find('TableBody');
const tableCell = table.find('TableCell').at(0);
const tableFooter = table.find('TableFooter').at(0);

const tableItems = [
table,
tableHead,
tableRow,
tableHeader,
tableBody,
tableCell
tableCell,
tableFooter
];

tableItems.forEach(wrapper => {
Expand All @@ -64,13 +75,15 @@ describe('Table components', () => {
const tableHeader = table.find('TableHeader').at(0);
const tableBody = table.find('TableBody');
const tableCell = table.find('TableCell').at(0);
const tableFooter = table.find('TableFooter').at(0);

expect(table.is('.my-table')).toBe(true);
expect(tableHead.is('.my-table-head')).toBe(true);
expect(tableRow.is('.my-table-row')).toBe(true);
expect(tableHeader.is('.my-table-header')).toBe(true);
expect(tableBody.is('.my-table-body')).toBe(true);
expect(tableCell.is('.my-table-cell')).toBe(true);
expect(tableFooter.is('.my-table-footer')).toBe(true);
});

test('passes arbitrary props through', () => {
Expand All @@ -80,14 +93,16 @@ describe('Table components', () => {
const tableHeader = table.find('TableHeader').at(0);
const tableBody = table.find('TableBody');
const tableCell = table.find('TableCell').at(0);
const tableFooter = table.find('TableFooter').at(0);

const tableItems = [
table,
tableHead,
tableRow,
tableHeader,
tableBody,
tableCell
tableCell,
tableFooter
];

tableItems.forEach(wrapper => {
Expand All @@ -104,12 +119,14 @@ describe('Table components', () => {
const head = shallow(<TableHead>a</TableHead>);
const header = shallow(<TableHeader>a</TableHeader>);
const row = shallow(<TableRow>a</TableRow>);
const footer = shallow(<TableFooter>a</TableFooter>);

expect(table.is('table')).toBe(true);
expect(body.is('tbody')).toBe(true);
expect(cell.is('td')).toBe(true);
expect(head.is('thead')).toBe(true);
expect(header.is('th')).toBe(true);
expect(footer.is('tfoot')).toBe(true);
expect(row.is('tr')).toBe(true);
});

Expand Down
21 changes: 21 additions & 0 deletions packages/react/src/components/Table/TableFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { HTMLAttributes } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

const TableFooter = ({
children,
className,
...other
}: HTMLAttributes<HTMLTableSectionElement>) => (
<tfoot className={classNames('TableFooter', className)} {...other}>
{children}
</tfoot>
);

TableFooter.displayName = 'TableFooter';
TableFooter.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string
};

export default TableFooter;
1 change: 1 addition & 0 deletions packages/react/src/components/Table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as TableCell } from './TableCell';
export { default as TableHead } from './TableHead';
export { default as TableHeader } from './TableHeader';
export { default as TableRow } from './TableRow';
export { default as TableFooter } from './TableFooter';
3 changes: 2 additions & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export {
TableCell,
TableHead,
TableHeader,
TableRow
TableRow,
TableFooter
} from './components/Table';
export { default as Tabs, Tab, TabPanel } from './components/Tabs';
export {
Expand Down
11 changes: 10 additions & 1 deletion packages/styles/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
}

.TableCell,
.TableHeader {
.TableHeader,
.TableFooter {
padding: var(--table-space) var(--space-smallest);
}

Expand All @@ -103,12 +104,20 @@

.Table--border,
.Table--border .TableHeader,
.Table--border .TableFooter,
.Table--border .TableCell {
border: 1px solid var(--gray-40);
}

.cauldron--theme-dark .Table--border,
.cauldron--theme-dark .Table--border .TableHeader,
.cauldron--theme-dark .Table--border .TableFooter,
.cauldron--theme-dark .Table--border .TableCell {
border-color: var(--stroke-dark);
}

.TableFooter .TableCell {
background: var(--table-header-background-color);
font-weight: var(--font-weight-medium);
color: var(--table-header-text-color);
}

0 comments on commit aee7d22

Please sign in to comment.