import ActiveObjectContext from '@/components/Context/activeObject/ObjectContext'; import CanvasContext from '@/components/Context/canvasContext/CanvasContext'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Slider } from '@/components/ui/slider'; import { useContext, useEffect, useState } from 'react'; import { ArrowUp, ArrowDown, ArrowLeft, ArrowRight, ChevronUp, ChevronDown } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import CollapsibleComponent from './CollapsibleComponent'; const PositionCustomization = () => { const { canvas } = useContext(CanvasContext) const { activeObject } = useContext(ActiveObjectContext) const [objectPosition, setObjectPosition] = useState({ left: 50, top: 50 }) const [isOpen, setIsOpen] = useState(true); useEffect(() => { if (activeObject) { setObjectPosition({ left: Math.round(activeObject.left || 0), top: Math.round(activeObject.top || 0), }) } }, [activeObject]) const updateObjectPosition = (key, value) => { const updatedPosition = { ...objectPosition, [key]: value } setObjectPosition(updatedPosition) if (canvas && activeObject) { activeObject.set(updatedPosition) canvas.renderAll() } } const handleInputChange = (key, value) => { const numValue = parseInt(value, 10) if (!isNaN(numValue)) { updateObjectPosition(key, numValue) } } const handleSliderChange = (key, value) => { updateObjectPosition(key, value[0]) } const adjustPosition = (key, delta) => { const newValue = objectPosition[key] + delta updateObjectPosition(key, newValue) } const content = () => { return ( Left handleInputChange('left', e.target.value)} className="w-20" /> handleSliderChange('left', value)} className="flex-grow" /> Top handleInputChange('top', e.target.value)} className="w-20" /> handleSliderChange('top', value)} className="flex-grow" /> adjustPosition('top', -1)} aria-label="Move up" variant="outline" size="icon" className="w-full h-full" > adjustPosition('left', -1)} aria-label="Move left" variant="outline" size="icon" className="w-full h-full" > adjustPosition('left', 1)} aria-label="Move right" variant="outline" size="icon" className="w-full h-full" > adjustPosition('top', 1)} aria-label="Move down" variant="outline" size="icon" className="w-full h-full" > ) } return ( {content()} ) } export default PositionCustomization