Skip to content

Commit

Permalink
Closes #321. Add className prop to wrap with styled-components & all
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurV committed Oct 26, 2021
1 parent f42f49c commit 6e3706f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## To be released

- A new prop `renderOnZeroPageCount` has been added. It allows to define what to display when `pageCount` is zero. By default, it lets the main pagination boxes be displayed (Previous / Next). To display nothing, just provides `renderOnZeroPageCount={null}`. (see: https://github.com/AdeleD/react-paginate/pull/377)
- A new prop `className` has been added, which is an alias to `containerClassName` and is usefull for integration with CSS-in-JS frameworks like styled-components. (see: https://github.com/AdeleD/react-paginate/issues/321)

## >= 7.1.3

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ You can also check this **[CodePen demo](https://codepen.io/monsieurv/pen/yLoMxY
| `forcePage` | `Number` | To override selected page with parent prop. Use this if you want to control the page from your app state. |
| `disableInitialCallback` | `boolean` | Disable `onPageChange` callback with initial page. Default: `false` |
| `containerClassName` | `String` | The classname of the pagination container. |
| `className` | `String` | Same as `containerClassName`. For use with [styled-components](https://styled-components.com/) & other CSS-in-JS. |
| `pageClassName` | `String` | The classname on tag `li` of each page element. |
| `pageLinkClassName` | `String` | The classname on tag `a` of each page element. |
| `pageLabelBuilder` | `Function` | Function to set the text on page links. Defaults to `(page) => page` |
Expand Down
23 changes: 22 additions & 1 deletion __tests__/PaginationBoxView-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,28 @@ describe('Test custom props', () => {
describe('containerClassName', () => {
it('should use the containerClassName prop when defined', () => {
const pagination = ReactTestUtils.renderIntoDocument(
<PaginationBoxView containerClassName={'my-pagination'} />
<PaginationBoxView containerClassName="my-pagination" />
);
expect(ReactDOM.findDOMNode(pagination).className).toEqual(
'my-pagination'
);
});

it('should use the className prop when defined', () => {
const pagination = ReactTestUtils.renderIntoDocument(
<PaginationBoxView className="my-pagination" />
);
expect(ReactDOM.findDOMNode(pagination).className).toEqual(
'my-pagination'
);
});

it('should use the className prop in priority from containerClassName', () => {
const pagination = ReactTestUtils.renderIntoDocument(
<PaginationBoxView
className="my-pagination"
containerClassName="another"
/>
);
expect(ReactDOM.findDOMNode(pagination).className).toEqual(
'my-pagination'
Expand Down
4 changes: 3 additions & 1 deletion react_components/PaginationBoxView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class PaginationBoxView extends Component {
forcePage: PropTypes.number,
disableInitialCallback: PropTypes.bool,
containerClassName: PropTypes.string,
className: PropTypes.string,
pageClassName: PropTypes.string,
pageLinkClassName: PropTypes.string,
pageLabelBuilder: PropTypes.func,
Expand Down Expand Up @@ -346,6 +347,7 @@ export default class PaginationBoxView extends Component {
const {
disabledClassName,
pageCount,
className,
containerClassName,
previousLabel,
previousClassName,
Expand All @@ -371,7 +373,7 @@ export default class PaginationBoxView extends Component {
const nextAriaDisabled = selected === pageCount - 1 ? 'true' : 'false';

return (
<ul className={containerClassName}>
<ul className={className || containerClassName}>
<li className={previousClasses}>
<a
className={previousLinkClassName}
Expand Down

0 comments on commit 6e3706f

Please sign in to comment.