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] Introduce new component #19049

Merged
merged 66 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
2ada4e2
[Pagination] Add new component
mbrookes Dec 31, 2019
dddd56c
Update docs/src/pages/components/pagination/pagination.md
Dec 31, 2019
0669be2
Remove demo labels
mbrookes Dec 31, 2019
b9b7124
Buttons demo
mbrookes Jan 1, 2020
e40a027
proptypes
mbrookes Jan 1, 2020
5f02673
Pass through props uneeded by usePagination
mbrookes Jan 1, 2020
599d8ef
Less prominent outlined-disabled
mbrookes Jan 1, 2020
4ddcac9
Remove querystring support
mbrookes Jan 1, 2020
6298757
Make PaginationItem public
mbrookes Jan 1, 2020
27578c8
no href
mbrookes Jan 9, 2020
9861e24
Add support for boundaryRange prop
mbrookes Jan 10, 2020
ed0e6ec
refactor usePaginiation
mbrookes Jan 10, 2020
d5aa97e
Fix buttons after refactor
mbrookes Jan 11, 2020
e845016
misc cleanup
mbrookes Jan 12, 2020
7f68de1
uncontrolled
mbrookes Jan 12, 2020
0a8aa86
fix demo function names
mbrookes Jan 12, 2020
32e6617
Router integration
mbrookes Jan 13, 2020
40bc049
fix feedback
mbrookes Jan 16, 2020
2b9a0b2
Use useControlled
mbrookes Jan 17, 2020
75bb396
remove itemProps abstraction
mbrookes Jan 17, 2020
545f266
simplify paginationItem rendering
mbrookes Jan 17, 2020
00d1d04
Change paginationRange demo order
mbrookes Jan 17, 2020
1bb5913
Support defaultPage
mbrookes Jan 17, 2020
c1f6550
Add tests for usePagination
mbrookes Jan 18, 2020
ac3d8d0
Remove incomplete typescript demos
mbrookes Jan 18, 2020
47891cc
Update API docs
mbrookes Jan 18, 2020
10cf379
Don't mandate index.d.ts
mbrookes Jan 18, 2020
df33709
prettier
mbrookes Jan 18, 2020
ef36248
fix demos
mbrookes Jan 18, 2020
35ed356
Font sizes, size spacing, disabled ellipis
mbrookes Jan 19, 2020
11050e8
Icon sizes
mbrookes Jan 19, 2020
df0fd3b
Internalize the icons
mbrookes Jan 19, 2020
4f476e8
Use unique key to fix rerender when ellipses change
mbrookes Jan 19, 2020
438546b
reorder link demo props
mbrookes Jan 19, 2020
9268a5e
no transition, disable ripple
mbrookes Jan 19, 2020
9f9f9b3
Revert "no transition, disable ripple"
mbrookes Jan 20, 2020
aacf707
Use timer to delay click event
mbrookes Jan 20, 2020
727bac9
update roadmap, fix PaginationItem PropTypes
mbrookes Jan 21, 2020
8de9629
fix previous / next disabled state
mbrookes Jan 23, 2020
0496ebb
Fix usePagination tests after 4f476e8
mbrookes Jan 23, 2020
3a1ee2d
Base test structure
mbrookes Jan 23, 2020
6c6d01b
Mark icons as internal component
mbrookes Jan 23, 2020
e0c9d04
lint
mbrookes Jan 24, 2020
cea79e3
tests
mbrookes Jan 27, 2020
4e757bc
docs:api
mbrookes Jan 30, 2020
758ff8c
tests
mbrookes Feb 1, 2020
2aa8ad4
Merge branch 'master' into pagination
mbrookes Feb 2, 2020
7812f14
yarn
mbrookes Feb 2, 2020
55257da
docs:api - not sure how this got lost
mbrookes Feb 2, 2020
7d873e4
fix roadmap
mbrookes Feb 2, 2020
ce34619
Correct the spelling "correction" :)
mbrookes Feb 2, 2020
30c7bef
Remove component prop
mbrookes Feb 2, 2020
319c582
boundaryRange -> boundaryCount
mbrookes Feb 2, 2020
9465a53
siblingRange -> siblingCount
mbrookes Feb 2, 2020
91e396e
stub types
mbrookes Feb 2, 2020
471ea3a
expect > assert
mbrookes Feb 2, 2020
c46cb32
use theme colors
mbrookes Feb 3, 2020
52531d2
Merge branch 'master' into pagination
mbrookes Feb 3, 2020
aa70802
yarn.lock
mbrookes Feb 3, 2020
c085b2c
Use theme colors continued
mbrookes Feb 4, 2020
3f0aaec
Add comment with source of range function
mbrookes Feb 4, 2020
8d69349
Update packages/material-ui-lab/src/Pagination/Pagination.js
Feb 4, 2020
3d83a66
rename ariaLabel to defaultAriaLabel & fix comment
mbrookes Feb 4, 2020
6263722
docs:api & prettier
mbrookes Feb 4, 2020
f55cfea
Use for
mbrookes Feb 4, 2020
5d968aa
Add words to router integration section
mbrookes Feb 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/pages/api/pagination-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import markdown from './pagination-item.md';

export default function Page() {
return <MarkdownDocs markdown={markdown} />;
}
75 changes: 75 additions & 0 deletions docs/pages/api/pagination-item.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
filename: /packages/material-ui-lab/src/PaginationItem/PaginationItem.js
---

<!--- This documentation is automatically generated, do not try to edit it. -->

# PaginationItem API

<p class="description">The API documentation of the PaginationItem React component. Learn more about the props and the CSS customization points.</p>

## Import

```js
import PaginationItem from '@material-ui/lab/PaginationItem';
// or
import { PaginationItem } from '@material-ui/lab';
```

You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/).



## Props

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">color</span> | <span class="prop-type">'standard'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'standard'</span> | The active color. |
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | | The component used for the root node. Either a string to use a DOM element or a component. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the item will be disabled. |
| <span class="prop-name">getAriaLabel</span> | <span class="prop-type">func</span> | <span class="prop-default">function defaultGetAriaLabel(type, page, selected) { if (type === 'page') { return `${selected ? '' : 'go to '}page ${page}`; } return `Go to ${type} page`;}</span> | Accepts a function which returns a string value that provides a user-friendly name for the current page.<br><br>**Signature:**<br>`function(type?: string, page: number, selected: bool) => string`<br>*type:* The link or button type to format ('page' | 'first' | 'last' | 'next' | 'previous').<br>*page:* The page number to format.<br>*selected:* If true, the current page is selected. |
| <span class="prop-name">onClick</span> | <span class="prop-type">func</span> | | Callback fired when the page is changed.<br><br>**Signature:**<br>`function(event: object, page: number) => void`<br>*event:* The event source of the callback.<br>*page:* The page selected. |
| <span class="prop-name">page</span> | <span class="prop-type">number</span> | | The current page number. |
| <span class="prop-name">selected</span> | <span class="prop-type">bool</span> | | If `true` the pagination item is selected. |
| <span class="prop-name">shape</span> | <span class="prop-type">'round'<br>&#124;&nbsp;'rounded'</span> | <span class="prop-default">'round'</span> | The shape of the pagination item. |
| <span class="prop-name">size</span> | <span class="prop-type">'small'<br>&#124;&nbsp;'medium'<br>&#124;&nbsp;'large'</span> | <span class="prop-default">'medium'</span> | The size of the pagination item. |
| <span class="prop-name">type</span> | <span class="prop-type">'page'<br>&#124;&nbsp;'first'<br>&#124;&nbsp;'last'<br>&#124;&nbsp;'next'<br>&#124;&nbsp;'previous'<br>&#124;&nbsp;'start-ellipsis'<br>&#124;&nbsp;'end-ellipsis'</span> | <span class="prop-default">'page'</span> | |
| <span class="prop-name">variant</span> | <span class="prop-type">'text'<br>&#124;&nbsp;'outlined'</span> | | |

The `ref` is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

## CSS

- Style sheet name: `PaginationItem`.
- Style sheet details:

| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.root-44</span> | Styles applied to the root element.
| <span class="prop-name">outlined</span> | <span class="prop-name">.outlined-45</span> | Styles applied to the button element if `outlined="true"`.
| <span class="prop-name">textPrimary</span> | <span class="prop-name">.textPrimary-46</span> | Styles applied to the button element if `variant="text"` and `color="primary"`.
| <span class="prop-name">textSecondary</span> | <span class="prop-name">.textSecondary-47</span> | Styles applied to the button element if `variant="text"` and `color="secondary"`.
| <span class="prop-name">outlinedPrimary</span> | <span class="prop-name">.outlinedPrimary-48</span> | Styles applied to the button element if `variant="outlined"` and `color="primary"`.
| <span class="prop-name">outlinedSecondary</span> | <span class="prop-name">.outlinedSecondary-49</span> | Styles applied to the button element if `variant="outlined"` and `color="secondary"`.
| <span class="prop-name">rounded</span> | <span class="prop-name">.rounded-50</span> | Styles applied to the button element if `rounded="true"`.
| <span class="prop-name">ellipsis</span> | <span class="prop-name">.ellipsis-51</span> | Styles applied to the ellipsis element.
| <span class="prop-name">icon</span> | <span class="prop-name">.icon-52</span> | Styles applied to the icon element.
| <span class="prop-name">sizeSmall</span> | <span class="prop-name">.sizeSmall-53</span> | Pseudo-class applied to the root element if `size="small"`.
| <span class="prop-name">sizeLarge</span> | <span class="prop-name">.sizeLarge-54</span> | Pseudo-class applied to the root element if `size="large"`.
| <span class="prop-name">disabled</span> | <span class="prop-name">.disabled-55</span> | Pseudo-class applied to the root element if `disabled={true}`.
| <span class="prop-name">selected</span> | <span class="prop-name">.selected-56</span> | Pseudo-class applied to the root element if `selected={true}`.

You can override the style of the component thanks to one of these customization points:

- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes).
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names).
- With a theme and an [`overrides` property](/customization/globals/#css).

If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/PaginationItem/PaginationItem.js) for more detail.

## Demos

- [Pagination](/components/pagination/)

7 changes: 7 additions & 0 deletions docs/pages/api/pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import markdown from './pagination.md';

export default function Page() {
return <MarkdownDocs markdown={markdown} />;
}
71 changes: 71 additions & 0 deletions docs/pages/api/pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
filename: /packages/material-ui-lab/src/Pagination/Pagination.js
---

<!--- This documentation is automatically generated, do not try to edit it. -->

# Pagination API

<p class="description">The API documentation of the Pagination React component. Learn more about the props and the CSS customization points.</p>

## Import

```js
import Pagination from '@material-ui/lab/Pagination';
// or
import { Pagination } from '@material-ui/lab';
```

You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/).



## Props

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">boundaryCount</span> | <span class="prop-type">number</span> | | Number of always visible pages at the beginning and end. |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | Pagination items. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'default'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'</span> | | The active color. |
| <span class="prop-name">count</span> | <span class="prop-type">number</span> | | The total number of pages. |
| <span class="prop-name">defaultPage</span> | <span class="prop-type">number</span> | | The page selected by default when the component is uncontrolled. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | | If `true`, all the pagination component will be disabled. |
| <span class="prop-name">getItemAriaLabel</span> | <span class="prop-type">func</span> | | Accepts a function which returns a string value that provides a user-friendly name for the current page.<br><br>**Signature:**<br>`function(type?: string, page: number, selected: bool) => string`<br>*type:* The link or button type to format ('page' | 'first' | 'last' | 'next' | 'previous').<br>*page:* The page number to format.<br>*selected:* If true, the current page is selected. |
| <span class="prop-name">hideNextButton</span> | <span class="prop-type">bool</span> | | If `true`, hide the next-page button. |
| <span class="prop-name">hidePrevButton</span> | <span class="prop-type">bool</span> | | If `true`, hide the previous-page button. |
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the page is changed.<br><br>**Signature:**<br>`function(event: object, page: number) => void`<br>*event:* The event source of the callback.<br>*page:* The page selected. |
| <span class="prop-name">page</span> | <span class="prop-type">number</span> | | The current page. |
| <span class="prop-name">renderItem</span> | <span class="prop-type">func</span> | | Render the item.<br><br>**Signature:**<br>`function(params: object) => ReactNode`<br>*params:* null |
| <span class="prop-name">shape</span> | <span class="prop-type">'round'<br>&#124;&nbsp;'rounded'</span> | | The shape of the pagination items. |
| <span class="prop-name">showFirstButton</span> | <span class="prop-type">bool</span> | | If `true`, show the first-page button. |
| <span class="prop-name">showLastButton</span> | <span class="prop-type">bool</span> | | If `true`, show the last-page button. |
| <span class="prop-name">siblingRange</span> | <span class="prop-type">number</span> | | Number of always visible pages before and after the current page. |
| <span class="prop-name">size</span> | <span class="prop-type">'small'<br>&#124;&nbsp;'medium'<br>&#124;&nbsp;'large'</span> | | The size of the pagination component. |
| <span class="prop-name">variant</span> | <span class="prop-type">'text'<br>&#124;&nbsp;'outlined'</span> | | The variant to use. |

The `ref` is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

## CSS

- Style sheet name: `MuiPagination`.
- Style sheet details:

| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiPagination-root</span> | Styles applied to the root element.

You can override the style of the component thanks to one of these customization points:

- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes).
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names).
- With a theme and an [`overrides` property](/customization/globals/#css).

If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/Pagination/Pagination.js) for more detail.

## Demos

- [Pagination](/components/pagination/)

14 changes: 14 additions & 0 deletions docs/pages/components/pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';

const req = require.context('docs/src/pages/components/pagination', false, /\.(md|js|tsx)$/);
const reqSource = require.context(
'!raw-loader!../../src/pages/components/pagination',
false,
/\.(js|tsx)$/,
);
const reqPrefix = 'pages/components/pagination';

export default function Page() {
return <MarkdownDocs req={req} reqSource={reqSource} reqPrefix={reqPrefix} />;
}
1 change: 1 addition & 0 deletions docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const pages = [
{ pathname: '/components/about-the-lab' },
{ pathname: '/components/alert' },
{ pathname: '/components/autocomplete' },
{ pathname: '/components/pagination' },
{ pathname: '/components/rating' },
{ pathname: '/components/skeleton' },
{ pathname: '/components/speed-dial' },
Expand Down
24 changes: 24 additions & 0 deletions docs/src/pages/components/pagination/BasicPagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
marginTop: theme.spacing(2),
},
},
}));

export default function BasicPagination() {
const classes = useStyles();

return (
<div className={classes.root}>
<Pagination count={10} />
<Pagination count={10} color="primary" />
<Pagination count={10} color="secondary" />
<Pagination count={10} disabled />
</div>
);
}
22 changes: 22 additions & 0 deletions docs/src/pages/components/pagination/PaginationButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
marginTop: theme.spacing(2),
},
},
}));

export default function PaginationButtons() {
const classes = useStyles();

return (
<div className={classes.root}>
<Pagination count={10} showFirstButton showLastButton />
<Pagination count={10} hidePrevButton hideNextButton />
</div>
);
}
25 changes: 25 additions & 0 deletions docs/src/pages/components/pagination/PaginationControlled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
marginTop: theme.spacing(2),
},
},
}));

export default function PaginationControlled() {
const classes = useStyles();
const [page, setPage] = React.useState(1);
const handleChange = (event, value) => setPage(value);

return (
<div className={classes.root}>
<Pagination count={10} page={page} onChange={handleChange} />
<Typography>Page: {page}</Typography>
</div>
);
}
22 changes: 22 additions & 0 deletions docs/src/pages/components/pagination/PaginationLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { MemoryRouter as Router } from 'react-router';
import { Link } from 'react-router-dom';
import Pagination from '@material-ui/lab/Pagination';
import PaginationItem from '@material-ui/lab/PaginationItem';

export default function PaginationLink() {
return (
<Router>
<Pagination
count={10}
renderItem={item => (
<PaginationItem
component={Link}
to={`/cars${item.page === 1 ? '' : `?page=${item.page}`}`}
{...item}
/>
)}
/>
</Router>
);
}
27 changes: 27 additions & 0 deletions docs/src/pages/components/pagination/PaginationLinkChildren.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { MemoryRouter as Router } from 'react-router';
import { Link } from 'react-router-dom';
import Pagination, { usePagination } from '@material-ui/lab/Pagination';
import PaginationItem from '@material-ui/lab/PaginationItem';

export default function PaginationLinkChildren() {
const { items } = usePagination({
count: 10,
});

return (
<Router>
<Pagination>
{items.map(item => (
<li key={item.type || item.page.toString()}>
<PaginationItem
component={Link}
to={`/cars${item.page === 1 ? '' : `?page=${item.page}`}`}
{...item}
/>
</li>
))}
</Pagination>
</Router>
);
}
24 changes: 24 additions & 0 deletions docs/src/pages/components/pagination/PaginationOutlined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
mbrookes marked this conversation as resolved.
Show resolved Hide resolved
marginTop: theme.spacing(2),
},
},
}));

export default function PaginationOutlined() {
const classes = useStyles();

return (
<div className={classes.root}>
<Pagination count={10} variant="outlined" />
<Pagination count={10} variant="outlined" color="primary" />
<Pagination count={10} variant="outlined" color="secondary" />
<Pagination count={10} variant="outlined" disabled />
</div>
);
}
24 changes: 24 additions & 0 deletions docs/src/pages/components/pagination/PaginationRanges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
marginTop: theme.spacing(2),
},
},
}));

export default function PaginationRanges() {
const classes = useStyles();

return (
<div className={classes.root}>
<Pagination count={11} defaultPage={6} siblingCount={0} />
<Pagination count={11} defaultPage={6} /> {/* Default ranges */}
<Pagination count={11} defaultPage={6} siblingCount={0} boundaryCount={2} />
<Pagination count={11} defaultPage={6} boundaryCount={2} />
</div>
);
}
22 changes: 22 additions & 0 deletions docs/src/pages/components/pagination/PaginationRounded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
marginTop: theme.spacing(2),
},
},
}));

export default function PaginationRounded() {
const classes = useStyles();

return (
<div className={classes.root}>
<Pagination count={10} shape="rounded" />
<Pagination count={10} variant="outlined" shape="rounded" />
</div>
);
}
Loading