react-headless-pagination
react-headless-pagination copied to clipboard
feat: Add builit-in formatter, and ability to pass custom children
Description
My company, Paylocity, is using this lib to build our Pagination component. We have many instances where we need page numbers in the thousands, and we want those localized and formatted properly. This PR adds that functionality, as well as the ability to pass custom children to the Page Button.
Changes Made
- Create a default formatter with
Intl.NumberFormat()to format page numbers based on locale. Note that we do not want to explicitly define a locale, we want to inherit the user's runtime locale. - Add a
formatterprop that can accept a function to replace the default formatter. - Change
childrento accept aReactNodeOR a function that takes the page numbers and returns aReactNode - Put all this together in a
getPageContent()function that uses the internal page and default formatter by default, but is overridden bychildren. - Add tests and Stories to verify changes.
- Consolidate some types.
Please let me know what you think about these changes. I'm happy to adjust the implementation as needed.
Deploy Preview for react-headless-pagination failed.
| Name | Link |
|---|---|
| Latest commit | 03724cf4faaef18036cd2510b1ab9f28c20b0524 |
| Latest deploy log | https://app.netlify.com/sites/react-headless-pagination/deploys/67b3b21665a8bc000850c011 |