diff --git a/components/pagination/MiniSelect.tsx b/components/pagination/MiniSelect.tsx index 4da99813ea..a1f65ff2bc 100644 --- a/components/pagination/MiniSelect.tsx +++ b/components/pagination/MiniSelect.tsx @@ -1,10 +1,12 @@ import * as React from 'react'; import Select from '../select'; -export default class MiniSelect extends React.Component { - static Option = Select.Option; - - render() { - return ; + +MiniSelect.Option = Select.Option; + +export default MiniSelect; diff --git a/components/pagination/Pagination.tsx b/components/pagination/Pagination.tsx index b046621544..eb800d5dd4 100644 --- a/components/pagination/Pagination.tsx +++ b/components/pagination/Pagination.tsx @@ -7,11 +7,11 @@ import RightOutlined from '@ant-design/icons/RightOutlined'; import DoubleLeftOutlined from '@ant-design/icons/DoubleLeftOutlined'; import DoubleRightOutlined from '@ant-design/icons/DoubleRightOutlined'; -import ResponsiveObserve from '../_util/responsiveObserve'; import MiniSelect from './MiniSelect'; import Select from '../select'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; -import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; +import { ConfigContext } from '../config-provider'; +import useBreakpoint from '../grid/hooks/useBreakpoint'; export interface PaginationProps { total?: number; @@ -53,28 +53,20 @@ export interface PaginationConfig extends PaginationProps { export type PaginationLocale = any; -export default class Pagination extends React.Component { - private token: string; +const Pagination: React.FC = ({ + prefixCls: customizePrefixCls, + selectPrefixCls: customizeSelectPrefixCls, + className, + size, + locale: customLocale, + ...restProps +}) => { + const { xs } = useBreakpoint(); - private inferredSmall: boolean = false; + const { getPrefixCls, direction } = React.useContext(ConfigContext); + const prefixCls = getPrefixCls('pagination', customizePrefixCls); - componentDidMount() { - this.token = ResponsiveObserve.subscribe(screens => { - const { xs } = screens; - const { size, responsive } = this.props; - const inferredSmall = !!(xs && !size && responsive); - if (this.inferredSmall !== inferredSmall) { - this.inferredSmall = inferredSmall; - this.forceUpdate(); - } - }); - } - - componentWillUnmount() { - ResponsiveObserve.unsubscribe(this.token); - } - - getIconsProps = (prefixCls: string, direction: 'ltr' | 'rtl' | undefined) => { + const getIconsProps = () => { let prevIcon = ( @@ -123,48 +115,33 @@ export default class Pagination extends React.Component { }; }; - renderPagination = (contextLocale: PaginationLocale) => { - const { - prefixCls: customizePrefixCls, - selectPrefixCls: customizeSelectPrefixCls, - className, - size, - locale: customLocale, - ...restProps - } = this.props; + const renderPagination = (contextLocale: PaginationLocale) => { const locale = { ...contextLocale, ...customLocale }; - const isSmall = size === 'small' || this.inferredSmall; - return ( - - {({ getPrefixCls, direction }: ConfigConsumerProps) => { - const prefixCls = getPrefixCls('pagination', customizePrefixCls); - const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls); - const extendedClassName = classNames(className, { - mini: isSmall, - [`${prefixCls}-rtl`]: direction === 'rtl', - }); + const isSmall = size === 'small' || !!(xs && !size && restProps.responsive); + const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls); + const extendedClassName = classNames(className, { + mini: isSmall, + [`${prefixCls}-rtl`]: direction === 'rtl', + }); - return ( - - ); - }} - + return ( + ); }; - render() { - return ( - - {this.renderPagination} - - ); - } -} + return ( + + {renderPagination} + + ); +}; + +export default Pagination; diff --git a/components/pagination/style/index.tsx b/components/pagination/style/index.tsx index 17626c8e42..701efcf638 100644 --- a/components/pagination/style/index.tsx +++ b/components/pagination/style/index.tsx @@ -2,4 +2,5 @@ import '../../style/index.less'; import './index.less'; // style dependencies +// deps-lint-skip: grid import '../../select/style';