react-headless-pagination icon indicating copy to clipboard operation
react-headless-pagination copied to clipboard

feat: Add builit-in formatter, and ability to pass custom children

Open drake-nathan opened this issue 1 year ago • 1 comments

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 formatter prop that can accept a function to replace the default formatter.
  • Change children to accept a ReactNode OR a function that takes the page numbers and returns a ReactNode
  • Put all this together in a getPageContent() function that uses the internal page and default formatter by default, but is overridden by children.
  • 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.

drake-nathan avatar Feb 17 '25 22:02 drake-nathan

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

netlify[bot] avatar Feb 17 '25 22:02 netlify[bot]