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] Allow customization of icons #29336

Merged
merged 5 commits into from Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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-docs/pagination-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"default": "'standard'"
},
"component": { "type": { "name": "elementType" } },
"components": {
"type": {
"name": "shape",
"description": "{ first?: elementType, last?: elementType, next?: elementType, previous?: elementType }"
},
"default": "{\n first: FirstPageIcon,\n last: LastPageIcon,\n next: NavigateNextIcon,\n previous: NavigateBeforeIcon,\n}"
},
"disabled": { "type": { "name": "bool" } },
"page": { "type": { "name": "node" } },
"selected": { "type": { "name": "bool" } },
Expand Down
22 changes: 22 additions & 0 deletions docs/src/pages/components/pagination/CustomIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Pagination from '@mui/material/Pagination';
import PaginationItem from '@mui/material/PaginationItem';
import Stack from '@mui/material/Stack';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';

export default function CustomIcons() {
return (
<Stack spacing={2}>
<Pagination
count={10}
renderItem={(item) => (
<PaginationItem
components={{ previous: ArrowBackIcon, next: ArrowForwardIcon }}
{...item}
/>
)}
/>
</Stack>
);
}
22 changes: 22 additions & 0 deletions docs/src/pages/components/pagination/CustomIcons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Pagination from '@mui/material/Pagination';
import PaginationItem from '@mui/material/PaginationItem';
import Stack from '@mui/material/Stack';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';

export default function CustomIcons() {
return (
<Stack spacing={2}>
<Pagination
count={10}
renderItem={(item) => (
<PaginationItem
components={{ previous: ArrowBackIcon, next: ArrowForwardIcon }}
{...item}
/>
)}
/>
</Stack>
);
}
9 changes: 9 additions & 0 deletions docs/src/pages/components/pagination/CustomIcons.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Pagination
count={10}
renderItem={(item) => (
<PaginationItem
components={{ previous: ArrowBackIcon, next: ArrowForwardIcon }}
{...item}
/>
)}
/>
6 changes: 6 additions & 0 deletions docs/src/pages/components/pagination/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ You can optionally enable first-page and last-page buttons, or disable the previ

{{"demo": "pages/components/pagination/PaginationButtons.js"}}

## Custom icons

It's possible to customize the control icons.

{{"demo": "pages/components/pagination/CustomIcons.js"}}

## Pagination ranges

You can specify how many digits to display either side of current page with the `siblingRange` prop, and adjacent to the start and end page number with the `boundaryRange` prop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"color": "The active color.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"components": "The components used for first, last, next &amp; previous item type",
"disabled": "If <code>true</code>, the component is disabled.",
"page": "The current page number.",
"selected": "If <code>true</code> the pagination item is selected.",
Expand Down
15 changes: 15 additions & 0 deletions packages/mui-material/src/PaginationItem/PaginationItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ export interface PaginationItemTypeMap<P = {}, D extends React.ElementType = 'di
'standard' | 'primary' | 'secondary',
PaginationItemPropsColorOverrides
>;
/**
* The components used for first, last, next & previous item type
* @default {
* first: FirstPageIcon,
* last: LastPageIcon,
* next: NavigateNextIcon,
* previous: NavigateBeforeIcon,
* }
*/
components?: {
first?: React.ElementType;
last?: React.ElementType;
next?: React.ElementType;
previous?: React.ElementType;
};
/**
* If `true`, the component is disabled.
* @default false
Expand Down
37 changes: 29 additions & 8 deletions packages/mui-material/src/PaginationItem/PaginationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ const PaginationItem = React.forwardRef(function PaginationItem(inProps, ref) {
className,
color = 'standard',
component,
components = {
first: FirstPageIcon,
last: LastPageIcon,
next: NavigateNextIcon,
previous: NavigateBeforeIcon,
},
disabled = false,
page,
selected = false,
Expand Down Expand Up @@ -271,16 +277,16 @@ const PaginationItem = React.forwardRef(function PaginationItem(inProps, ref) {
const normalizedIcons =
theme.direction === 'rtl'
? {
previous: NavigateNextIcon,
next: NavigateBeforeIcon,
last: FirstPageIcon,
first: LastPageIcon,
previous: components.next || NavigateNextIcon,
next: components.previous || NavigateBeforeIcon,
last: components.first || FirstPageIcon,
first: components.last || LastPageIcon,
}
: {
previous: NavigateBeforeIcon,
next: NavigateNextIcon,
first: FirstPageIcon,
last: LastPageIcon,
previous: components.previous || NavigateBeforeIcon,
next: components.next || NavigateNextIcon,
first: components.first || FirstPageIcon,
last: components.last || LastPageIcon,
};

const Icon = normalizedIcons[type];
Expand Down Expand Up @@ -340,6 +346,21 @@ PaginationItem.propTypes /* remove-proptypes */ = {
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The components used for first, last, next & previous item type
* @default {
* first: FirstPageIcon,
* last: LastPageIcon,
* next: NavigateNextIcon,
* previous: NavigateBeforeIcon,
* }
*/
components: PropTypes.shape({
first: PropTypes.elementType,
last: PropTypes.elementType,
next: PropTypes.elementType,
previous: PropTypes.elementType,
}),
/**
* If `true`, the component is disabled.
* @default false
Expand Down