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

[Pagination] Add new component #18449

Closed
webuxmotion opened this issue Nov 19, 2019 · 10 comments · Fixed by #19049
Closed

[Pagination] Add new component #18449

webuxmotion opened this issue Nov 19, 2019 · 10 comments · Fixed by #19049
Labels
component: pagination This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@webuxmotion
Copy link

webuxmotion commented Nov 19, 2019

We need the new Pagination component like this https://react.semantic-ui.com/addons/pagination/

@oliviertassinari oliviertassinari changed the title We need the new Pagination component like this https://react.semantic-ui.com/addons/pagination/ [Pagination] Add new component Nov 19, 2019
@oliviertassinari oliviertassinari added the new feature New feature or request label Nov 19, 2019
@oliviertassinari
Copy link
Member

@iRyanBell
Copy link

How about something like this? https://github.com/vim-labs/materialui-pagination-component

@oliviertassinari
Copy link
Member

@iRyanBell Thanks for sharing. We will need to provide a built-in solution in Material-UI in the near future. I hope we can deliver it by Q1 2020. Would you be interested in this effort? I can guide you into this. I would need to run a benchmark in order to better understand how we can move forward. It would likely require a new effort, taking the good parts from everybody, your project included.

@iRyanBell
Copy link

@oliviertassinari Count me in.

@oliviertassinari
Copy link
Member

@iRyanBell Awesome, I will try to quick that off tomorrow.

@TrejGun
Copy link
Contributor

TrejGun commented Nov 24, 2019

in case you are interested. this lib is used by react-bootsrap

https://github.com/ultimate-pagination/react-ultimate-pagination

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 24, 2019

Benchmark

I have used the following sources to benchmark:

Proposal

I would recommend the following:

  1. I would propose this API
Pagination.propTypes = {
  /**
   * If `true`, all links  will be disabled.
   */
  disabled: PropTypes.bool,
  /**
   * The size.
   *
   * default 'medium'
   */
  size: PropTypes.oneOf(['small', 'medium']),
  /**
   * The active color.
   */
  color: PropTypes.oneOf(['primary', 'secondary']),
  /**
   * Callback fired when the page is changed.
   *
   * @param {object} event The event source of the callback.
   * @param {number} page The page selected.
   */
  onChange: PropTypes.func,
  /**
   * The zero-based index of the current page.
   */
  page: PropTypes.number.isRequired,
  /**
   * The total number of pages.
   */
  count: PropTypes.number.isRequired,
  /**
   * Number of always visible pages at the beginning and end.
   */
  boundaryRange: PropTypes.number,
  /**
   * Number of always visible pages before and after the current one.
   */
  siblingRange: PropTypes.number,
  /**
   * If `true`, show the first page item.
   */
  displayFirstItem: PropTypes.bool,
  /**
   * Render the item.
   *
   * @param {object} params
   * @returns {ReactNode}
   */
  renderItem: PropTypes.func,
  /**
   * Text label for the first page item.
   *
   * default First page
   */
  firstItemText: PropTypes.string,
  /**
   * Text label for the next page item.
   *
   * default Next page
   */
  nextItemText: PropTypes.string,
  /**
   * Text label for the next page item.
   *
   * default Last page
   */
  lastItemText: PropTypes.string,
  /**
   * Text label for the next page item.
   *
   * default Previous page
   */
  previousItemText: PropTypes.string,
  /**
   * If `true`, hide the next page item.
   */
  hideNextItem: PropTypes.bool,
  /**
   * If `true`, hide the previous page item.
   */
  hidePreviousItem: PropTypes.bool,
  /**
   * If `true`, show the last page item.
   */
  displayLastItem: PropTypes.bool,
};
  1. We translate the xText props.
  2. Add integration demo with react-router.
  3. Not to use the Paper component.
  4. Render links, not buttons.
  5. We might want to expose a PaginationItem component so people can compose it in the renderItem prop.
  6. What about we only expose one style of the pagination?
  7. Mentioning TablePagination in the documentation
  8. Remove references to "material-ui-flat-pagination" from the documentation
  9. Explore responsive support, e.g. Pagination is not responsive by default twbs/bootstrap#23504.

References

  1. https://atlaskit.atlassian.com/packages/core/pagination#/about
    Capture d’écran 2019-11-24 à 23 35 30
  2. https://github.com/vim-labs/materialui-pagination-component
    Capture d’écran 2019-11-24 à 23 37 18
  3. https://dribbble.com/shots/6726286-DailyUI085-Pagination
    Capture d’écran 2019-11-24 à 23 40 30

@iRyanBell
Copy link

iRyanBell commented Nov 25, 2019

I'm surprised to see so few other examples using a select box for page selection. I found this to be very intuitive and the fastest way to move between specific pages.
Pagination with select box from materialui-pagination-component

Personally, disabled buttons with "..." feels a bit unnecessary, but it is a very common design trend. On Bing.com, they only use the ellipsis on the left edge.
Bing.com results

@oliviertassinari
Copy link
Member

I share the same observation. I have seen one select based pagination (baseui). An input field seems more frequent. For instance https://www.shutterstock.com/fr/search/tree.

On Bing.com, they only use the ellipsis on the left edge.

Actually, I think that bondaryPageRange=0 should lead to no ellipses.

@oliviertassinari oliviertassinari added the component: pagination This is the name of the generic UI component, not the React module! label Nov 25, 2019
@oliviertassinari
Copy link
Member

I had another thought, what if we expose the Pagination DOM structure. Something like this (1)?

import React from 'react';
import { Link } from '@material-ui/core';
import { Link as RouterLink } from 'react-router-dom';
import { usePagination, Pagination, PaginationItem } from '@material-ui/lab';

// The use of React.forwardRef will no longer be required for react-router-dom v6.
// See https://github.com/ReactTraining/react-router/issues/6056
const Link1 = React.forwardRef<HTMLAnchorElement, RouterLinkProps>((props, ref) => (
  <RouterLink innerRef={ref} {...props} />
));

function MyPagination() {
  const items = usePagination({
    page: 2,
    count: 10,
  });

  return (
    <Pagination>
      {items.map(item =>
        <PaginationItem
          to={`/cars${item.page === 1 ? '' : `?page=${item.page}`}`}
          component={Link1}
          {...item}
        />
      )}
    </Pagination>
  )
}

Instead of (2)

import React from 'react';
import { Link } from '@material-ui/core';
import { Link as RouterLink } from 'react-router-dom';
import { Pagination, PaginationItem } from '@material-ui/lab';

// The use of React.forwardRef will no longer be required for react-router-dom v6.
// See https://github.com/ReactTraining/react-router/issues/6056
const Link1 = React.forwardRef<HTMLAnchorElement, RouterLinkProps>((props, ref) => (
  <RouterLink innerRef={ref} {...props} />
));

function MyPagination() {
  return (
    <Pagination
      page={2}
      count={10}
      renderItem={(item => (
        <PaginationItem
          to={`/cars${item.page === 1 ? '' : `?page=${item.page}`}`}
          component={Link1}
          {...item}
        />
      )}
    />
  )
}

But maybe we can support both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pagination This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants