From e0dfb55c5457aec489fc084c4567e791b4c65eb1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 26 Mar 2025 00:37:41 +0000 Subject: 3/25 까지의 대표님 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/data-table/data-table-pin-left.tsx | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 components/data-table/data-table-pin-left.tsx (limited to 'components/data-table/data-table-pin-left.tsx') diff --git a/components/data-table/data-table-pin-left.tsx b/components/data-table/data-table-pin-left.tsx new file mode 100644 index 00000000..81e83564 --- /dev/null +++ b/components/data-table/data-table-pin-left.tsx @@ -0,0 +1,95 @@ +"use client" + +import * as React from "react" +import { type Table } from "@tanstack/react-table" +import { Check, ChevronsUpDown, MoveLeft } from "lucide-react" + +import { cn, toSentenceCase } from "@/lib/utils" +import { Button } from "@/components/ui/button" +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "@/components/ui/command" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" + +/** + * “Pin Left” Popover. Lists columns that can be pinned. + * If pinned===‘left’ → checked, if pinned!==‘left’ → unchecked. + * Toggling check => pin(‘left’) or pin(false). + */ +export function PinLeftButton({ table }: { table: Table }) { + const [open, setOpen] = React.useState(false) + const triggerRef = React.useRef(null) + + return ( + + + + + + triggerRef.current?.focus()} + > + + + + No columns found. + + {table + .getAllLeafColumns() + .filter((col) => col.getCanPin?.()) + .map((column) => { + const pinned = column.getIsPinned?.() // 'left'|'right'|false + // => pinned === 'left' => checked + return ( + { + // if currently pinned===left => unpin + // else => pin left + column.pin?.(pinned === "left" ? false : "left") + }} + > + + {toSentenceCase(column.id)} + + {/* Check if pinned===‘left’ */} + + + ) + })} + + + + + + ) +} \ No newline at end of file -- cgit v1.2.3