-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make TableFooter more composeable
Users can pass whatever components they want to be displayed in the footer Defaults to the current RowStatus component on the left and TablePagination on the right
- Loading branch information
Lael Birch
committed
Feb 17, 2021
1 parent
ed4fb38
commit 0d513a0
Showing
5 changed files
with
108 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import RowStatus from './RowStatus'; | ||
import TablePagination from './TablePagination'; | ||
|
||
const TableFooter = () => ( | ||
<div className="pgn__data-table-footer"> | ||
<RowStatus | ||
className="pgn__data-table-footer-row-status" | ||
/> | ||
<TablePagination /> | ||
const TableFooter = ({ className, children }) => ( | ||
<div className={classNames(className, 'pgn__data-table-footer')}> | ||
{children} | ||
</div> | ||
); | ||
|
||
TableFooter.defaultProps = { | ||
children: ( | ||
<> | ||
<TablePagination /> | ||
<RowStatus /> | ||
</> | ||
), | ||
className: null, | ||
}; | ||
|
||
TableFooter.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.node, | ||
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.node])), | ||
]), | ||
}; | ||
|
||
export default TableFooter; |
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,41 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import TableFooter from '../TableFooter'; | ||
import RowStatus from '../RowStatus'; | ||
import TablePagination from '../TablePagination'; | ||
import DataTableContext from '../DataTableContext'; | ||
|
||
const footerInstance = { | ||
previousPage: () => {}, | ||
nextPage: () => {}, | ||
canPreviousPage: true, | ||
canNextPage: true, | ||
state: { pageIndex: 1 }, | ||
pageCount: 3, | ||
itemCount: 30, | ||
}; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const TableFooterWrapper = ({ value = footerInstance, props = {}, children }) => ( | ||
<DataTableContext.Provider value={value}> | ||
<TableFooter {...props}>{children}</TableFooter> | ||
</DataTableContext.Provider> | ||
); | ||
|
||
describe('<TableFooter />', () => { | ||
it('Renders the default footer', () => { | ||
const wrapper = mount(<TableFooterWrapper />); | ||
expect(wrapper.find(RowStatus)).toHaveLength(1); | ||
expect(wrapper.find(TablePagination)).toHaveLength(1); | ||
}); | ||
it('accepts a class name', () => { | ||
const fakeClass = 'fancy-class'; | ||
const wrapper = mount(<TableFooterWrapper props={{ className: fakeClass }} />); | ||
expect(wrapper.find(TableFooter).props().className).toContain(fakeClass); | ||
}); | ||
it('renders a children', () => { | ||
const leftText = "I'm on the left"; | ||
const wrapper = mount(<TableFooterWrapper><div>{leftText}</div></TableFooterWrapper>); | ||
expect(wrapper.text()).toContain(leftText); | ||
}); | ||
}); |
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