From bd4f65d590f22174abbc47702f27b1e12e1e51b3 Mon Sep 17 00:00:00 2001 From: Shakitskiy Vladislav Date: Sun, 31 Dec 2023 12:57:43 +0300 Subject: [PATCH] feat: elements naming (#34) * feat: elements naming * feat: naming section in right panel * fix: remove reduntant section * fix: rebase the branch --- .../src/components/LeftPanel/ElementRow.tsx | 78 ++++++++++++++++++- .../src/components/icons/CheckIcon.tsx | 7 ++ apps/dashboard/src/stores/elementsStore.ts | 2 + 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 apps/dashboard/src/components/icons/CheckIcon.tsx diff --git a/apps/dashboard/src/components/LeftPanel/ElementRow.tsx b/apps/dashboard/src/components/LeftPanel/ElementRow.tsx index e16b3e1..af062bb 100644 --- a/apps/dashboard/src/components/LeftPanel/ElementRow.tsx +++ b/apps/dashboard/src/components/LeftPanel/ElementRow.tsx @@ -1,5 +1,7 @@ import { useSortable } from "@dnd-kit/sortable" import { CSS } from '@dnd-kit/utilities'; +import { useRef, useState } from "react"; +import type { FormEvent } from "react"; import type { OGElement } from "../../lib/types"; import { NotVisibleIcon } from "../icons/NotVisibleIcon" import { TextIcon } from "../icons/TextIcon" @@ -8,6 +10,7 @@ import { BoxIcon } from "../icons/BoxIcon" import { CircleIcon } from "../icons/CircleIcon" import { ImageIcon } from "../icons/ImageIcon" import { MagicWandIcon } from "../icons/MagicWandIcon" +import { CheckIcon } from "../icons/CheckIcon"; import { useElementsStore } from "../../stores/elementsStore"; interface ElementRowProps { @@ -31,11 +34,47 @@ export function ElementRow({ element }: ElementRowProps) { transition, }; + const [isEditing, setIsEditing] = useState(false) + const formRef = useRef(null) + + function onSubmit(event: FormEvent) { + event.preventDefault() + + if (!element.name) { + let defaultName = "" + + if (element.tag === 'p') { + defaultName = "Text" + } else if (element.tag === 'div' && element.backgroundImage) { + defaultName = "Image" + } else if (element.tag === 'div' && !element.backgroundImage && !element.radius) { + defaultName = "Box" + } else if (element.tag === 'div' && !element.backgroundImage && element.radius) { + defaultName = "Rounded box" + } else { + defaultName = "Dynamic text" + } + + updateElement({ + ...element, + name: defaultName + }) + } + + setIsEditing(false) + } + return ( -
+
+ + ) : element.name}