From a26e9e75914cd5503ae831830f5954f0438b0796 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 3 Mar 2020 18:23:37 +0100 Subject: [PATCH] [Pagination] Leverage `@default` over default values --- .../src/Pagination/Pagination.js | 30 ++++++++++++------- .../src/Pagination/usePagination.js | 1 + 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/material-ui-lab/src/Pagination/Pagination.js b/packages/material-ui-lab/src/Pagination/Pagination.js index a54ce6f2604412..4f589f1346946a 100644 --- a/packages/material-ui-lab/src/Pagination/Pagination.js +++ b/packages/material-ui-lab/src/Pagination/Pagination.js @@ -27,29 +27,27 @@ function defaultGetAriaLabel(type, page, selected) { } const Pagination = React.forwardRef(function Pagination(props, ref) { - /* eslint-disable no-unused-vars */ const { - boundaryCount = 1, + boundaryCount, children, classes, className, color = 'standard', - count = 1, - defaultPage = 1, - disabled = false, + count, + defaultPage, + disabled, getItemAriaLabel: getAriaLabel = defaultGetAriaLabel, - hideNextButton = false, - hidePrevButton = false, + hideNextButton, + hidePrevButton, renderItem = item => , shape = 'round', - showFirstButton = false, - showLastButton = false, - siblingCount = 1, + showFirstButton, + showLastButton, + siblingCount, size = 'medium', variant = 'text', ...other } = props; - /* eslint-enable no-unused-vars */ const { items } = usePagination({ ...props, componentName: 'Pagination' }); @@ -79,9 +77,11 @@ const Pagination = React.forwardRef(function Pagination(props, ref) { ); }); +// @default tags synced with default values from usePagination Pagination.propTypes = { /** * Number of always visible pages at the beginning and end. + * @default 1 */ boundaryCount: PropTypes.number, /** @@ -103,14 +103,17 @@ Pagination.propTypes = { color: PropTypes.oneOf(['default', 'primary', 'secondary']), /** * The total number of pages. + * @default 1 */ count: PropTypes.number, /** * The page selected by default when the component is uncontrolled. + * @default 1 */ defaultPage: PropTypes.number, /** * If `true`, all the pagination component will be disabled. + * @default false */ disabled: PropTypes.bool, /** @@ -126,10 +129,12 @@ Pagination.propTypes = { getItemAriaLabel: PropTypes.func, /** * If `true`, hide the next-page button. + * @default false */ hideNextButton: PropTypes.bool, /** * If `true`, hide the previous-page button. + * @default false */ hidePrevButton: PropTypes.bool, /** @@ -156,14 +161,17 @@ Pagination.propTypes = { shape: PropTypes.oneOf(['round', 'rounded']), /** * If `true`, show the first-page button. + * @default false */ showFirstButton: PropTypes.bool, /** * If `true`, show the last-page button. + * @default false */ showLastButton: PropTypes.bool, /** * Number of always visible pages before and after the current page. + * @default 1 */ siblingCount: PropTypes.number, /** diff --git a/packages/material-ui-lab/src/Pagination/usePagination.js b/packages/material-ui-lab/src/Pagination/usePagination.js index 556921fe1d763f..21aea2ce2e35db 100644 --- a/packages/material-ui-lab/src/Pagination/usePagination.js +++ b/packages/material-ui-lab/src/Pagination/usePagination.js @@ -1,6 +1,7 @@ import { useControlled } from '@material-ui/core/utils'; export default function usePagination(props = {}) { + // keep default values in sync with @defaul tags in Pagination.propTypes const { boundaryCount: boundaryCountProp = 1, componentName = 'usePagination',