| 1 | "use client"; |
| 2 | |
| 3 | import { Columns3 } from "lucide-react"; |
| 4 | |
| 5 | import { getColumnSizeLabel } from "@/components/notebook/presentation/editor/lib"; |
| 6 | import { ToolbarGroup } from "@/components/plate/ui/toolbar"; |
| 7 | import { Slider } from "@/components/ui/slider"; |
| 8 | import { |
| 9 | Tooltip, |
| 10 | TooltipContent, |
| 11 | TooltipTrigger, |
| 12 | } from "@/components/ui/tooltip"; |
| 13 | import { useToolbarContext } from "./ToolbarContext"; |
| 14 | |
| 15 | export function ColumnSizeSlider() { |
| 16 | const { |
| 17 | supportsColumnSizeControl, |
| 18 | currentColumnSize, |
| 19 | columnSizeOptions, |
| 20 | handleNodePropertyUpdate, |
| 21 | } = useToolbarContext(); |
| 22 | |
| 23 | if (!supportsColumnSizeControl) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | return ( |
| 28 | <ToolbarGroup className="flex"> |
| 29 | <Tooltip> |
| 30 | <TooltipTrigger asChild> |
| 31 | <div className="flex items-center gap-2 px-2"> |
| 32 | <Columns3 className="size-4 text-muted-foreground" /> |
| 33 | <Slider |
| 34 | value={[ |
| 35 | columnSizeOptions.indexOf(currentColumnSize) !== -1 |
| 36 | ? columnSizeOptions.indexOf(currentColumnSize) |
| 37 | : 1, |
| 38 | ]} |
| 39 | onValueChange={(values) => { |
| 40 | const value = values[0]; |
| 41 | if ( |
| 42 | typeof value === "number" && |
| 43 | value >= 0 && |
| 44 | value < columnSizeOptions.length |
| 45 | ) { |
| 46 | const newColumnSize = columnSizeOptions[value]; |
| 47 | if (newColumnSize) { |
| 48 | handleNodePropertyUpdate("columnSize", newColumnSize); |
| 49 | } |
| 50 | } |
| 51 | }} |
| 52 | max={columnSizeOptions.length - 1} |
| 53 | step={1} |
| 54 | className="w-20 [data-slider-thumb]:size-3!" |
| 55 | /> |
| 56 | </div> |
| 57 | </TooltipTrigger> |
| 58 | |
| 59 | <TooltipContent> |
| 60 | <p>Column Size ({getColumnSizeLabel(currentColumnSize)})</p> |
| 61 | </TooltipContent> |
| 62 | </Tooltip> |
| 63 | </ToolbarGroup> |
| 64 | ); |
| 65 | } |
| 66 |