diff --git a/src/pages/editor/components/EditorCanvas.tsx b/src/pages/editor/components/EditorCanvas.tsx index 5428b9d..8e41e85 100644 --- a/src/pages/editor/components/EditorCanvas.tsx +++ b/src/pages/editor/components/EditorCanvas.tsx @@ -17,6 +17,7 @@ import CellEditor from "@/components/CellEditor"; import ZoomControls from "./ZoomControls"; import EditorCanvasToolbar from "./EditorCanvasToolbar"; import { createScopedId } from "../store/editorStore.helpers"; +import { getKonvaGradientProps } from "../utils/gradient"; type EditorCanvasProps = { catalogSize?: string; @@ -46,9 +47,10 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { const currentPage = pages.find((page) => page.id === currentPageId); const bgColor = - currentPage?.backgroundType === 'color' + currentPage?.backgroundType === 'color' || currentPage?.backgroundType === 'gradient' ? currentPage.backgroundColor : '#ffffff'; + const bgGradient = currentPage?.backgroundGradient; const [bgImage] = useImage( currentPage?.backgroundType === 'image' @@ -331,6 +333,13 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { const scaledW = stageSize.width * finalScale; const scaledH = stageSize.height * finalScale; + const backgroundGradientProps = getKonvaGradientProps( + currentPage?.backgroundType === "gradient" ? "gradient" : "solid", + bgGradient, + stageSize.width, + stageSize.height, + "rect", + ); return (
@@ -394,6 +403,7 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { width={stageSize.width} height={stageSize.height} fill={bgColor} + {...backgroundGradientProps} listening={false} /> {currentPage?.backgroundType === 'image' && bgImage && ( diff --git a/src/pages/editor/components/SettingsPanel.tsx b/src/pages/editor/components/SettingsPanel.tsx index 9ea10a1..fd5a860 100644 --- a/src/pages/editor/components/SettingsPanel.tsx +++ b/src/pages/editor/components/SettingsPanel.tsx @@ -5,6 +5,7 @@ import type { DisplayStyle, BackgroundType } from '../store/editorStore' import UploadBoxDraggble from '@/components/UploadBoxDraggble' import { useSingleUpload } from '@/pages/uploader/hooks/useUploaderData' import ColorsImage from '@/assets/images/colors.png' +import ColorPicker from '@/components/ColorPicker' const PRESET_COLORS = [ '#a8edcf', @@ -23,6 +24,7 @@ const DISPLAY_STYLE_OPTIONS: { value: DisplayStyle; label: string }[] = [ const BACKGROUND_TYPE_OPTIONS: { value: BackgroundType; label: string }[] = [ { value: 'color', label: 'رنگ' }, + { value: 'gradient', label: 'گرادیانت' }, { value: 'image', label: 'تصویر' }, ] @@ -39,6 +41,11 @@ const SettingsPanel = () => { const currentPage = pages.find((page) => page.id === currentPageId) const backgroundType = currentPage?.backgroundType ?? 'color' const backgroundColor = currentPage?.backgroundColor ?? '#ffffff' + const backgroundGradient = currentPage?.backgroundGradient ?? { + from: '#ffffff', + to: '#e2e8f0', + angle: 135, + } const backgroundImageUrl = currentPage?.backgroundImageUrl ?? '' const [uploadedPreviews, setUploadedPreviews] = useState( backgroundImageUrl ? [backgroundImageUrl] : [] @@ -145,7 +152,20 @@ const SettingsPanel = () => {