import classNames from 'classnames'; import { cloneElement, ComponentPropsWithRef, isValidElement } from 'react'; import { polymorphic } from '../Helper/Polymorphic'; import { ComponentTheme } from './Button'; export interface PaginationProps extends ComponentPropsWithRef<'ul'> { theme?: ComponentTheme; size?: 'sm' | 'lg'; } export const Pagination = polymorphic( ({ as: Root = 'ul', theme, size, className, ...props }) => ( ) ); Pagination.displayName = 'Pagination'; type PageState = Partial>; export type PageItemProps = ComponentPropsWithRef<'li'> & PageState; export const PageItem = polymorphic( ({ as: Root = 'li', active, disabled, className, children, ...props }) => { const child = isValidElement(children) && children.type === PageLink ? cloneElement(children, { active: children.props.active ?? active, disabled: children.props.disabled ?? disabled }) : children; return ( {child} ); } ); PageItem.displayName = 'PageItem'; export type PageLinkProps = ComponentPropsWithRef<'a'> & PageState; export const PageLink = polymorphic( ({ as: RootAs, active, disabled, className, href, tabIndex, onClick, 'aria-current': current, ...props }) => { const Root = RootAs ?? (href === undefined ? 'span' : 'a'); return ( ); } ); PageLink.displayName = 'PageLink'; export const PageText = polymorphic>( ({ as: Root = 'span', className, ...props }) => ( ) ); PageText.displayName = 'PageText';