import { Button } from "@/src/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuCheckboxItem, } from "@/src/components/ui/dropdown-menu"; import useLocalStorage from "@/src/components/useLocalStorage"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { Rows3, Rows2, Rows4 } from "lucide-react"; const heightOptions = [ { id: "s", label: "Small", icon: }, { id: "m", label: "Medium", icon: }, { id: "l", label: "Large", icon: }, ] as const; const defaultHeights: Record = { s: "h-7", // after removing the container around IO, we want the row height a bit more than 6 m: "h-24", l: "h-64", }; export type RowHeight = (typeof heightOptions)[number]["id"]; export type CustomHeights = Record; export const getRowHeightTailwindClass = ( rowHeight?: RowHeight, customHeights?: CustomHeights, ) => { if (!rowHeight) return undefined; return customHeights?.[rowHeight] || defaultHeights[rowHeight]; }; export function useRowHeightLocalStorage( tableName: string, defaultValue: RowHeight, ) { const [rowHeight, setRowHeight, clearRowHeight] = useLocalStorage( `${tableName}Height`, defaultValue, ); return [rowHeight, setRowHeight, clearRowHeight] as const; } export const DataTableRowHeightSwitch = ({ rowHeight, setRowHeight, }: { rowHeight: RowHeight; setRowHeight: (e: RowHeight) => void; }) => { const capture = usePostHogClientCapture(); return ( Row height {heightOptions.map(({ id, label }) => ( { // Prevent closing the dropdown menu to allow the user to adjust their selection e.preventDefault(); capture("table:row_height_switch_select", { rowHeight: id, }); setRowHeight(id); }} > {label} ))} ); };