"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { ButtonGroup } from "@suphark/ui/components/ui/button-group"; import { cn } from "@suphark/ui/lib/utils"; import { MinusIcon, PlusIcon } from "lucide-react"; export interface ZoomControlsProps { /** ระดับซูม (1 = 100%) */ value: number; onValueChange: (value: number) => void; /** ค่าเริ่มต้น 0.25 */ min?: number; /** ค่าเริ่มต้น 4 */ max?: number; /** ก้าวต่อการกด (ปัดให้ลงก้าว) — ค่าเริ่มต้น 0.25 */ step?: number; /** ค่าที่ปุ่ม % รีเซ็ตกลับ — ค่าเริ่มต้น 1 */ resetValue?: number; size?: "sm" | "default"; disabled?: boolean; className?: string; } /** ปัดค่าให้ลงก้าว แล้วจำกัดในช่วง (กันทศนิยมสะสม 0.30000000000000004) */ export function clampZoom(value: number, min: number, max: number, step: number): number { const snapped = Math.round(value / step) * step; return Math.min(max, Math.max(min, Number(snapped.toFixed(4)))); } /** * ปุ่มซูมพรีวิว − / 100% / + — ปุ่มกลางแสดงระดับปัจจุบัน กดแล้วรีเซ็ต · ถึงขอบ min/max ปุ่มนั้นปิด * ใช้กับพรีวิวเอกสาร/แม่แบบ/ผืนผ้าใบที่แอปวาดเอง (รูปใช้ `Lightbox` ซึ่งซูมได้ในตัว) * * const [zoom, setZoom] = useState(1); * *
…
*/ export function ZoomControls({ value, onValueChange, min = 0.25, max = 4, step = 0.25, resetValue = 1, size = "sm", disabled, className, }: ZoomControlsProps) { const t = useUiText().zoom; const percent = `${Math.round(value * 100)}%`; const go = (next: number) => onValueChange(clampZoom(next, min, max, step)); const iconSize = size === "sm" ? "icon-sm" : "icon"; return ( ); }