import React from 'react' import { __, _x, sprintf } from '@wordpress/i18n' import { buildUrl } from '../../../utils/urls' import { Button } from '../Button' import type { ReactNode } from 'react' interface NavigationButtonProps { icon: ReactNode newPage: number className?: string disabled?: boolean helperText?: string setCurrentPage: (page: number) => void pageSearchParam?: string } const NavigationButton: React.FC = ({ icon, newPage, disabled, className, helperText, setCurrentPage, pageSearchParam }) => pageSearchParam ? <> { event.preventDefault() setCurrentPage(newPage) }} > {helperText} {icon} {'\n'} : interface NavigationButtonsProps { currentPage: number disabled?: boolean pageSearchParam?: string setCurrentPage: (page: number) => void } const BackwardNavigationButtons: React.FC = ({ currentPage, ...buttonProps }) => 1 === currentPage ? <> {'\n'} {'\n'} : <> «} newPage={1} className="first-page" /* translators: Hidden accessibility text. */ helperText={__('First page', 'code-snippets')} {...buttonProps} />{'\n'} ‹} newPage={Math.max(1, currentPage - 1)} className="prev-page" /* translators: Hidden accessibility text. */ helperText={__('Previous page', 'code-snippets')} {...buttonProps} />{'\n'} interface ForwardNavigationButtonsProps extends NavigationButtonsProps { totalPages: number } const ForwardNavigationButtons: React.FC = ({ currentPage, totalPages, ...buttonProps }) => totalPages === currentPage ? <> {'\n'} : <> ›} newPage={Math.min(totalPages, currentPage + 1)} className="next-page" /* translators: Hidden accessibility text. */ helperText={__('Next page', 'code-snippets')} {...buttonProps} />{'\n'} »} newPage={totalPages} className="last-page" /* translators: Hidden accessibility text. */ helperText={__('Last page', 'code-snippets')} {...buttonProps} />{'\n'} interface PagingInputProps { which: 'top' | 'bottom' totalPages: number inputName?: string disabled?: boolean inputValue: number setInputValue: (value: number) => void confirmInputValue: VoidFunction } const PagingInput: React.FC = ({ which, disabled, inputName, inputValue, totalPages, setInputValue, confirmInputValue }) => { const value = Number(event.target.value) if (value) { setInputValue(value) } }} /> interface CurrentPageProps extends PagingInputProps { currentPage: number } const CurrentPage: React.FC = ({ which, totalPages, currentPage, ...inputProps }) => 'bottom' === which ? <> {/* translators: Hidden accessibility text. */} {__('Current Page', 'code-snippets')} {/* translators: 1: Current page. 2: Total pages. */ sprintf(_x('%1$s of %2$s', 'paging', 'code-snippets'), currentPage, totalPages)} : {/* translators: Mid-sentence: current page number of total pages. */} {` ${__('of', 'code-snippets')} `} {totalPages} export interface TablePaginationNavigationProps { which: 'top' | 'bottom' inputValue: number totalPages: number currentPage: number disabled?: boolean setInputValue: (value: number) => void setCurrentPage: (page: number) => void pageSearchParam?: string } export const TablePaginationNavigation: React.FC = ({ which, disabled, totalPages, inputValue, currentPage, setCurrentPage, setInputValue, pageSearchParam }) => ( setCurrentPage(inputValue)} />{'\n'} )