import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import { RiArrowLeftLine, RiArrowRightLine } from '@remixicon/react' import { useDebounceFn } from 'ahooks' import { Pagination } from './pagination' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import cn from '@/utils/classnames' type Props = { className?: string current: number onChange: (cur: number) => void total: number limit?: number onLimitChange?: (limit: number) => void } const CustomizedPagination: FC = ({ className, current, onChange, total, limit = 10, onLimitChange, }) => { const { t } = useTranslation() const totalPages = Math.ceil(total / limit) const inputRef = React.useRef(null) const [showInput, setShowInput] = React.useState(false) const [inputValue, setInputValue] = React.useState(current + 1) const [showPerPageTip, setShowPerPageTip] = React.useState(false) const { run: handlePaging } = useDebounceFn((value: string) => { if (parseInt(value) > totalPages) { setInputValue(totalPages) onChange(totalPages - 1) setShowInput(false) return } if (parseInt(value) < 1) { setInputValue(1) onChange(0) setShowInput(false) return } onChange(parseInt(value) - 1) setInputValue(parseInt(value)) setShowInput(false) }, { wait: 500 }) const handleInputChange = (e: React.ChangeEvent) => { const value = e.target.value if (!value) return setInputValue('') if (isNaN(parseInt(value))) return setInputValue('') setInputValue(parseInt(value)) handlePaging(value) } return (
} disabled={current === 0} > {!showInput && (
setShowInput(true)} >
{current + 1}
/
{totalPages}
)} {showInput && ( setShowInput(false)} /> )} } disabled={current === totalPages - 1} >
{onLimitChange && (
{showPerPageTip ? t('common.pagination.perPage') : ''}
setShowPerPageTip(true)} onMouseLeave={() => setShowPerPageTip(false)} >
onLimitChange?.(10)} >10
onLimitChange?.(25)} >25
onLimitChange?.(50)} >50
)}
) } export default CustomizedPagination