import { useState } from "react" import { Button } from "../Button/Button.tsx" import { Checkbox } from "../Checkbox/Checkbox.tsx" import { Popover } from "../Popover/Popover.tsx" import { ReorderList } from "../ReorderList/ReorderList.tsx" export type TableColumnChoice = { key: string label: string isVisible: boolean isRequired?: boolean } export type TableColumnsProps = { columns: readonly TableColumnChoice[] onChange: (columns: TableColumnChoice[]) => void label?: string } /** Column visibility and ordering, with keyboard moves as the primary path. */ export const TableColumns = ({ columns, onChange, label = "Columns", }: TableColumnsProps) => { const [isVisible, setIsVisible] = useState(false) return ( setIsVisible(false)} trigger={ } > { const next = [...columns] const [column] = next.splice(from, 1) next.splice(to, 0, column) onChange(next) }} renderItem={({ item, isFirst, isLast, moveBy }) => (
onChange( columns.map((column) => column.key === item.key ? { ...column, isVisible: isChecked } : column, ), ) } />
)} />
) }