Skip to content

Commit

Permalink
Add new TableFoot component
Browse files Browse the repository at this point in the history
  • Loading branch information
lyzadanger committed Feb 16, 2023
1 parent 144f354 commit b53a578
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/components/data/TableFoot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import classnames from 'classnames';
import type { JSX } from 'preact';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import TableSectionContext from './TableSectionContext';
import type { TableSection } from './TableSectionContext';

type HTMLAttributes = JSX.HTMLAttributes<HTMLTableSectionElement>;

export type TableFootProps = PresentationalProps & HTMLAttributes;

/**
* Render a table footer section
*/
const TableFootNext = function TableFoot({
children,
classes,
elementRef,

...htmlAttributes
}: TableFootProps) {
const sectionContext: TableSection = {
section: 'foot',
};

return (
<TableSectionContext.Provider value={sectionContext}>
<tfoot
{...htmlAttributes}
data-component="TableFoot"
ref={downcastRef(elementRef)}
className={classnames(
// This tfoot element will take up available extra vertical space when
// a Table has sparse data. This prevents <TableRow>s from stretching
// vertically to fill extra space.
'h-full',
classes
)}
>
{children}
</tfoot>
</TableSectionContext.Provider>
);
};

export default TableFootNext;
1 change: 1 addition & 0 deletions src/components/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { default as ScrollBox } from './ScrollBox';
export { default as Table } from './Table';
export { default as TableBody } from './TableBody';
export { default as TableCell } from './TableCell';
export { default as TableFoot } from './TableFoot';
export { default as TableHead } from './TableHead';
export { default as TableRow } from './TableRow';
export { default as Thumbnail } from './Thumbnail';
26 changes: 26 additions & 0 deletions src/components/data/test/TableFoot-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableFoot from '../TableFoot';

describe('TableFoot', () => {
// Content function for shared presentational test does not wrap with context
// This is to ensure the component functions as expected without context
const contentFn = (Component, props = {}) => {
return mount(
<table>
<Component {...props}>
<tr>
<td>Cell content</td>
</tr>
</Component>
</table>
);
};

testPresentationalComponent(TableFoot, {
createContent: contentFn,
elementSelector: '[data-component="TableFoot"]',
});
});
1 change: 1 addition & 0 deletions src/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
Table,
TableBody,
TableCell,
TableFoot,
TableHead,
TableRow,
Thumbnail,
Expand Down

0 comments on commit b53a578

Please sign in to comment.