Skip to content
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

Merged
merged 19 commits into from
Mar 20, 2023

Conversation

JohnTParsons
Copy link
Collaborator

@JohnTParsons JohnTParsons commented Mar 14, 2023

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:

  • Written unit tests against changes
  • Written functional tests against the component and/or NewsKit site
  • Updated relevant documentation

I have tested manually:

  • The feature's functionality is working as expected on Chrome, Firefox, Safari and Edge
  • The screen reader reads and flows through the elements as expected.
  • There are no new errors in the browser console coming from this PR.
  • When visual test is not added, it renders correctly on different browsers and mobile viewports (Safari, Firefox, small mobile viewport, tablet)
  • The Playground feature is working as expected

Before:

After:

Who should review this PR:

How to test:

@github-actions github-actions bot added the feature This change contains a new feature label Mar 14, 2023
@pp-serviceaccount
Copy link
Collaborator

@JohnTParsons JohnTParsons marked this pull request as ready for review March 16, 2023 15:50
@JohnTParsons JohnTParsons requested a review from a team as a code owner March 16, 2023 15:50
@JohnTParsons JohnTParsons added ready for review Please assist in getting this reviewed and removed Requires design review labels Mar 17, 2023
src/__tests__/__snapshots__/index.test.ts.snap Outdated Show resolved Hide resolved
Comment on lines 6939 to 6953
<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"
>
Copy link
Contributor

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

Copy link
Collaborator Author

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)

src/pagination/components/item/pagination-item.tsx Outdated Show resolved Hide resolved
inputRef.current?.blur();
};

const ariaId = getSSRId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with useReactKeys

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change pushed

Comment on lines 245 to 252
<label
id={inputLabelId}
htmlFor={inputId}
aria-hidden
style={{display: 'none'}}
>
Enter page between 1 and {lastPage}
</label>
Copy link
Contributor

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?

Copy link
Collaborator Author

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';
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change pushed

Comment on lines 98 to +99
itemButton?: Override<ButtonOrButtonLinkProps & PaginationItemProps>;
itemDescription?: Override<TextBlockProps & PaginationItemDescriptionProps>;
Copy link
Contributor

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.

Copy link
Collaborator Author

@JohnTParsons JohnTParsons Mar 17, 2023

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>
)

src/pagination/defaults.ts Outdated Show resolved Hide resolved
mstuartf
mstuartf previously approved these changes Mar 17, 2023
<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
Copy link
Contributor

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.

Comment on lines +408 to +417
itemButton: () => null,
itemDescription: ({
pageNumber,
lastPage,
...textBlockStyles
}) => (
<TextBlock {...textBlockStyles}>
Page {pageNumber} of {lastPage}
</TextBlock>
),
Copy link
Contributor

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?

@JohnTParsons JohnTParsons merged commit f101abc into main Mar 20, 2023
@JohnTParsons JohnTParsons deleted the feat/PPDSC-2839-custom-pagination branch March 20, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This change contains a new feature ready for review Please assist in getting this reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants