import { composeEventHandlers } from "@kobalte/utils"; import { type Component, type JSX, type ValidComponent, splitProps, } from "solid-js"; import * as Button from "../button"; import type { ElementOf, PolymorphicProps } from "../polymorphic"; import { usePaginationContext } from "./pagination-context"; export interface PaginationItemOptions { /** The page number of this item. (1-indexed) */ page: number; } export interface PaginationItemCommonProps< T extends HTMLElement = HTMLElement, > { onClick: JSX.EventHandlerUnion; } export interface PaginationItemRenderProps extends PaginationItemCommonProps, Button.ButtonRootRenderProps { "aria-current": "page" | undefined; "data-current": "" | undefined; } export type PaginationItemProps< T extends ValidComponent | HTMLElement = HTMLElement, > = PaginationItemOptions & Partial>>; export function PaginationItem( props: PolymorphicProps>, ) { const context = usePaginationContext(); const [local, others] = splitProps(props as PaginationItemProps, [ "page", "onClick", ]); const isCurrent = () => { return context.page() === local.page; }; const onClick: JSX.EventHandlerUnion = () => { context.setPage(local.page); }; return (
  • > > aria-current={isCurrent() ? "page" : undefined} data-current={isCurrent() ? "" : undefined} onClick={composeEventHandlers([local.onClick, onClick])} {...others} />
  • ); }