From 5b3d96c7eb0300a7314ec22f66d0296de955a673 Mon Sep 17 00:00:00 2001 From: Saimon8420 Date: Mon, 30 Dec 2024 13:36:14 +0600 Subject: [PATCH] rnd panel fixed for mobile devices --- src/components/Canvas.jsx | 19 +-- src/components/CanvasCapture.jsx | 31 ++-- src/components/CanvasSetting.jsx | 204 +++++++++++++----------- src/components/EditPanel.jsx | 34 ++-- src/components/Layouts/RndComponent.jsx | 28 ++++ src/components/ObjectPanel.jsx | 79 ++++++--- src/components/ui/scroll-area.jsx | 6 +- 7 files changed, 233 insertions(+), 168 deletions(-) create mode 100644 src/components/Layouts/RndComponent.jsx diff --git a/src/components/Canvas.jsx b/src/components/Canvas.jsx index acd5529..d4bf066 100644 --- a/src/components/Canvas.jsx +++ b/src/components/Canvas.jsx @@ -1,7 +1,6 @@ import { useEffect, useCallback, useContext } from 'react'; import CanvasContext from './Context/canvasContext/CanvasContext'; import ActiveObjectContext from './Context/activeObject/ObjectContext'; -import { Rnd } from 'react-rnd'; import OpenContext from './Context/openContext/OpenContext'; import CanvasSetting from './CanvasSetting'; import { EditPanel } from './EditPanel'; @@ -79,21 +78,9 @@ const Canvas = () => { return (
- {openSetting && ( - - - - )} + {openSetting && + + } { openPanel && diff --git a/src/components/CanvasCapture.jsx b/src/components/CanvasCapture.jsx index b98f7c2..56167e5 100644 --- a/src/components/CanvasCapture.jsx +++ b/src/components/CanvasCapture.jsx @@ -5,9 +5,9 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle } from './ui/card'; -import { Rnd } from 'react-rnd'; import { X } from 'lucide-react'; import { Separator } from './ui/separator'; +import RndComponent from './Layouts/RndComponent'; const resolutions = [ { value: '720p', label: 'HD (1280x720)', width: 1280, height: 720 }, @@ -73,28 +73,33 @@ const CanvasCapture = () => { }; }; + const rndValue = { + valueX: 0, + valueY: 20, + width: 250, + height: 150, + minWidth: 250, + maxWidth: 300, + minHeight: 150, + maxHeight: 300, + bound: "parent" + } + return ( <> {captureOpen && ( - +
- Capture Panel
-
+
- - + )} ); diff --git a/src/components/CanvasSetting.jsx b/src/components/CanvasSetting.jsx index 6f0cefe..6fec611 100644 --- a/src/components/CanvasSetting.jsx +++ b/src/components/CanvasSetting.jsx @@ -10,6 +10,8 @@ import { Input } from './ui/input'; import { Slider } from './ui/slider'; import { fabric } from 'fabric'; import OpenContext from './Context/openContext/OpenContext'; +import { ScrollArea } from './ui/scroll-area'; +import RndComponent from './Layouts/RndComponent'; const CanvasSetting = () => { const { canvas } = useContext(CanvasContext); @@ -155,104 +157,120 @@ const CanvasSetting = () => { } }; + const rndValue = { + valueX: 0, + valueY: 20, + width: 250, + height: 0, + minWidth: 250, + maxWidth: 300, + minHeight: 0, + maxHeight: 400, + bound: "parent" + } + return ( - - Canvas Setting - -
- - - -
-
- -
- - - -
-
- -
- -
- - - -
-
- - - -
- - { - const newOpacity = value[0]; // Extract slider value - adjustBackgroundOpacity(newOpacity); // Adjust Fabric.js background opacity - }} - /> -
-
- + + + Canvas Setting + +
-
-
- - { - if (canvasSettings?.width > parseInt(e.target.value)) { - handleChange('width', parseInt(e.target.value, 10)); - } - }} - /> -
+ -
- - { - if (canvasSettings?.height > parseInt(e.target.value)) { - handleChange('height', parseInt(e.target.value, 10)); - } - }} - /> +
+
+ +
+ + + +
+
+ +
+ +
+ + + +
+
+ + + +
+ + { + const newOpacity = value[0]; // Extract slider value + adjustBackgroundOpacity(newOpacity); // Adjust Fabric.js background opacity + }} + /> +
+
+ + + +
+
+ + { + if (canvasSettings?.width > parseInt(e.target.value)) { + handleChange('width', parseInt(e.target.value, 10)); + } + }} + /> +
+ +
+ + { + if (canvasSettings?.height > parseInt(e.target.value)) { + handleChange('height', parseInt(e.target.value, 10)); + } + }} + /> +
+
-
-
-
+ + +
) } diff --git a/src/components/EditPanel.jsx b/src/components/EditPanel.jsx index a782b4d..6980052 100644 --- a/src/components/EditPanel.jsx +++ b/src/components/EditPanel.jsx @@ -1,4 +1,3 @@ -import { Rnd } from 'react-rnd'; import { useCallback, useContext, useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; import { Button } from './ui/button'; @@ -10,6 +9,7 @@ import OpenContext from './Context/openContext/OpenContext'; import CanvasContext from './Context/canvasContext/CanvasContext'; import ActiveObjectContext from './Context/activeObject/ObjectContext'; import { fabric } from 'fabric'; +import RndComponent from './Layouts/RndComponent'; export function EditPanel() { const [isCollapsed, setIsCollapsed] = useState(false); @@ -189,31 +189,31 @@ export function EditPanel() { } }; + const rndValue = { + valueX: 0, + valueY: 20, + width: 250, + height: 0, + minWidth: 250, + maxWidth: 300, + minHeight: 0, + maxHeight: 0, + bound: "parent" + } + return ( - +
- + Edit Panel
setIsCollapsed(!open)}> - @@ -373,7 +373,7 @@ export function EditPanel() {
-
+ ) } diff --git a/src/components/Layouts/RndComponent.jsx b/src/components/Layouts/RndComponent.jsx new file mode 100644 index 0000000..4e7f609 --- /dev/null +++ b/src/components/Layouts/RndComponent.jsx @@ -0,0 +1,28 @@ +import { Rnd } from 'react-rnd'; + +const RndComponent = ({ children, value }) => { + + const { valueX, valueY, width, height, minWidth, maxWidth, minHeight, maxHeight, bound } = value; + + return ( + + + {children} + + ) +} + +export default RndComponent \ No newline at end of file diff --git a/src/components/ObjectPanel.jsx b/src/components/ObjectPanel.jsx index a9cbefe..19f0e39 100644 --- a/src/components/ObjectPanel.jsx +++ b/src/components/ObjectPanel.jsx @@ -1,10 +1,9 @@ import { Button } from './ui/button' -import { Card, CardContent, CardHeader, CardTitle } from './ui/card' +import { Card, CardHeader, CardTitle } from './ui/card' import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible' import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs' import { useContext, useState } from 'react' import { PencilRuler, Shapes, Store, Upload, ChevronDown, ChevronUp, X } from 'lucide-react'; -import { Rnd } from 'react-rnd'; import OpenContext from './Context/openContext/OpenContext'; import AllIconsPage from './EachComponent/Icons/AllIcons' import { Separator } from './ui/separator' @@ -12,34 +11,35 @@ import { ScrollArea } from './ui/scroll-area' import AddShapes from './Layouts/AddShapes' import UploadImage from './EachComponent/UploadImage' import CustomizeShape from './EachComponent/CustomizeShape' +import RndComponent from './Layouts/RndComponent' const ObjectPanel = () => { const [isCollapsed, setIsCollapsed] = useState(false); const { tabValue, setTabValue, setOpenObjectPanel } = useContext(OpenContext); + + const rndValue = { + valueX: 0, + valueY: 20, + width: 250, + height: 0, + minWidth: 250, + maxWidth: 300, + minHeight: 0, + maxHeight: 400, + bound: "parent" + } + return ( - +
- + Object Panel
- setIsCollapsed(!open)}> + setIsCollapsed(!open)}>