feat: Add builit-in formatter, and ability to pass custom children#17
Open
drake-nathan wants to merge 1 commit intothijssmudde:mainfrom
Open
feat: Add builit-in formatter, and ability to pass custom children#17drake-nathan wants to merge 1 commit intothijssmudde:mainfrom
drake-nathan wants to merge 1 commit intothijssmudde:mainfrom
Conversation
❌ Deploy Preview for react-headless-pagination failed.
|
drake-nathan
commented
Feb 17, 2025
|
|
||
| type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & { | ||
| as?: React.ReactElement; | ||
| children?: string | React.ReactNode; |
Author
There was a problem hiding this comment.
Both of these props are already inherited from ButtonHTMLAttributes, and string is already included in ReactNode.
drake-nathan
commented
Feb 17, 2025
| ); | ||
|
|
||
| describe("Pagination", () => { | ||
| const mockFormat = jest.fn((number) => { |
Author
There was a problem hiding this comment.
We need to mock this, otherwise the test would fail in any locale outside the US.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.formatterprop that can accept a function to replace the default formatter.childrento accept aReactNodeOR a function that takes the page numbers and returns aReactNodegetPageContent()function that uses the internal page and default formatter by default, but is overridden bychildren.Please let me know what you think about these changes. I'm happy to adjust the implementation as needed.