import { Checkbox, DropdownMenu, SvgUse } from "@ivtui/base"
import clsx from "clsx"
import type * as React from "react"
import type { JSX } from "react"
import { useEffect, useRef } from "react"
function Table({ className, ...props }: React.ComponentProps<"table">): JSX.Element {
return (
)
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">): JSX.Element {
return (
)
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">): JSX.Element {
return (
)
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">): JSX.Element {
return (
tr]:last:border-b-0", className)}
{...props}
/>
)
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">): JSX.Element {
return (
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">): JSX.Element {
return (
)
}
function TableCell({ className, ...props }: React.ComponentProps<"td">): JSX.Element {
return (
)
}
function TableCaption({ className, ...props }: React.ComponentProps<"caption">): JSX.Element {
return (
)
}
function SortableHeader({
children,
isSorted,
isSortedDesc,
onSort,
onHide,
className,
...props
}: {
children: React.ReactNode
isSorted: boolean
isSortedDesc: boolean
onSort?: (direction: "asc" | "desc") => void
onHide?: () => void
className?: string
} & React.ComponentProps<"th">): JSX.Element {
const handleSort = (direction: "asc" | "desc") => {
onSort?.(direction)
}
const renderSortIcon = () => {
if (isSorted) {
if (isSortedDesc) {
return
}
return
}
return
}
return (
{children}
e.stopPropagation()}
>
{renderSortIcon()}
Toggle sort
handleSort("asc")}>
Asc
handleSort("desc")}>
Desc
Hide
)
}
// Custom checkbox component that supports indeterminate state
function TableCheckbox({
indeterminate = false,
...props
}: React.ComponentProps & { indeterminate?: boolean }): JSX.Element {
const ref = useRef(null)
useEffect(() => {
if (ref.current) {
// Cast to HTMLInputElement to access the indeterminate property
;(ref.current as unknown as HTMLInputElement).indeterminate = indeterminate
}
}, [indeterminate])
return
}
export {
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
SortableHeader,
TableCheckbox,
}