-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(PPDSC-2839): pagination support for custom components #707
Conversation
You can preview these changes on: |
<nav | ||
aria-label="pagination" | ||
class="emotion-1" | ||
data-testid="pagination-container" | ||
> | ||
<a | ||
aria-current="page" | ||
aria-label="current page, page 3" | ||
class="emotion-2" | ||
data-testid="pagination-item" | ||
href="https://paginationitem.test" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="emotion-3 emotion-4" | ||
fill="currentColor" | ||
focusable="false" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M0 0h24v24H0z" | ||
fill="none" | ||
/> | ||
<path | ||
d="M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4V7zm-1-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" | ||
/> | ||
</svg> | ||
</a> | ||
</ul> | ||
</nav> | ||
<ul | ||
class="emotion-2" | ||
> | ||
<a | ||
aria-current="page" | ||
aria-label="current page, page 3" | ||
class="emotion-3" | ||
data-testid="pagination-item" | ||
href="https://paginationitem.test" | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOt sure what's the use case here, but this HTML output seems wrong, a
can't be direct child of a UL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pushed (it was just a flawed test fixture, not an implementation bug)
inputRef.current?.blur(); | ||
}; | ||
|
||
const ariaId = getSSRId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with useReactKeys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pushed
<label | ||
id={inputLabelId} | ||
htmlFor={inputId} | ||
aria-hidden | ||
style={{display: 'none'}} | ||
> | ||
Enter page between 1 and {lastPage} | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use <ScreenReaderOnly as="label">
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pushed
@@ -1,4 +1,5 @@ | |||
import React from 'react'; | |||
import React, {useRef} from 'react'; | |||
import {useTheme} from '@emotion/react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be import from newskit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pushed
itemButton?: Override<ButtonOrButtonLinkProps & PaginationItemProps>; | ||
itemDescription?: Override<TextBlockProps & PaginationItemDescriptionProps>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between those 2? they seem the same to me.
I can do itemButton: (props) => <TextBlock>{props.pageNumber}</TextBlock>
basically, we have 2 ways to replace pagination items.
Can we simplified the API, seems to many options and overrides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a separate itemDescription render prop makes the API simpler for the cases such when the user wants to appends text after the default item Button. Otherwise they would need to manually repeat a lot of code, that is usually hidden behind the scenes, eg
itemButton: (props) => (
<GridLayout
columns="auto auto"
rows="1fr"
autoFlow="row"
alignItems="center"
columnGap="space010"
>
<PaginationButton {...props />
<TextBlock>{props.pageNumber}</TextBlock>
</GridLayout>
)
<PaginationPrevItem /> | ||
<PaginationNextItem /> | ||
</Pagination> | ||
</StorybookCase> | ||
<StorybookCase title="Next and previous labels"> | ||
<Pagination {...defaultProps} aria-label="next and previous labels"> | ||
<Pagination {...uncontrolledProps} aria-label="next and previous labels"> | ||
<PaginationPrevItem overrides={{width: 'auto'}}> | ||
Previous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you pass children shoun't it replace the icon as well ?
I wound expect to pass their own icon as children here instead of having to use overrides={{icon: fn}}. IMO we should have only 1 way to changing the children via the overrides or via passing childrne but not combination of both.
If people want to add label they can do it via overrides={icon: ()<> previous</>}} or something like this, in that way they might want to go only with labels or change positions of the icon and label.
itemButton: () => null, | ||
itemDescription: ({ | ||
pageNumber, | ||
lastPage, | ||
...textBlockStyles | ||
}) => ( | ||
<TextBlock {...textBlockStyles}> | ||
Page {pageNumber} of {lastPage} | ||
</TextBlock> | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using PaginationItems here does makes whole composability useless, isn't it?
To me the idea of composability is to be able to put / replace any content with you own
<Pagianation>
<PaginationFirstItem />
<PaginationPrevItem />
<PaginationListItem> Page 1 of 10 </PaginationListItem>
//or
<li>Page 1 of 10</li>
// or
<li><Form><Select /></Form></li>
<PaginationNextItem />
<PaginationLastItem />
</Pagination>
If we add render methonds ( which overrides are ) and allow people to render what-ever they want via our componetns, do we really need composable Pagination?
PPDSC-2839
There are new stories for Pagination input and selection custom components.
They are called "Variations in input": http://ncu-newskit-docs-pr.s3-website-eu-west-1.amazonaws.com/ppdsc-2839-custom-pagination/storybook/?path=/docs/components-pagination--story-variations-in-input
and "Variations in selection": http://ncu-newskit-docs-pr.s3-website-eu-west-1.amazonaws.com/ppdsc-2839-custom-pagination/storybook/?path=/docs/components-pagination--story-variations-in-selection
Some refactoring and fixing of iteration 1 code was required.
This should now satisfy all possible use cases.
DON'T look at the Documentation Site URL on this ticket. The one on #712 is the most up-to-date.
I have done:
I have tested manually:
Before:
After:
Who should review this PR:
How to test: