Skip to content

Commit 3379da0

Browse files
committed
feat: Improved UI
1 parent 2d4b02d commit 3379da0

5 files changed

Lines changed: 47 additions & 23 deletions

File tree

‎src/app/page.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export default function FormBuilderPage() {
8585
</sup>
8686
</h2>
8787
</div>
88-
<div className="p-2 flex-1 grid-cols-3 hidden md:grid">
89-
<div className="col-span-1"></div>
90-
<div className="col-span-1 flex justify-center">
88+
<div className="p-2 flex-1 grid-cols-2 xl:grid-cols-3 hidden md:grid">
89+
<div className="hidden xl:block col-span-1"></div>
90+
<div className="col-span-1 flex xl:justify-center">
9191
<div className=" text-center flex flex-row items-center justify-center gap-1 border rounded-md h-9 px-4">
9292
<div
9393
className="max-w-80 overflow-y-hidden whitespace-nowrap text-sm outline-none scrollbar-hide"
@@ -137,6 +137,7 @@ export default function FormBuilderPage() {
137137
size="sm"
138138
className="w-full cursor-pointer"
139139
onClick={handleGenerateCode}
140+
disabled={rows.length === 0}
140141
>
141142
Generate Code
142143
</Button>
@@ -160,7 +161,7 @@ export default function FormBuilderPage() {
160161
<DndContext>
161162
<div className="flex w-full h-screen justify-between">
162163
<SidebarLeft />
163-
<main className="flex-1 overflow-auto relative bg-slate-50 bg-dotted pt-14">
164+
<main className="flex-1 overflow-auto relative bg-slate-50 bg-dotted pt-14 scrollbar-hide">
164165
<MainCanvas />
165166
</main>
166167
<SidebarRight />

‎src/components/form-builder/form-components/form-input.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { InputGroup } from "../sidebar/groups/input-group";
77
import { GridGroup } from "../sidebar/groups/grid-group";
88
import { cn, escapeHtml } from "@/lib/utils";
99
import { ValidationGroup } from "../sidebar/groups/validation-group";
10+
11+
1012
export function FormInput(component: FormComponentModel) {
13+
1114
return (
1215
<Input
1316
key={component.id}

‎src/components/form-builder/helpers/iframe.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ export const IFrame = forwardRef<HTMLIFrameElement, { children: React.ReactNode,
3333
}
3434
};
3535

36+
useEffect(() => {
37+
if (!internalRef?.contentDocument?.body) return;
38+
39+
const resizeObserver = new ResizeObserver(() => {
40+
const height = internalRef.contentDocument?.body.scrollHeight;
41+
internalRef.style.height = `${height}px`;
42+
});
43+
44+
resizeObserver.observe(internalRef.contentDocument.body);
45+
46+
return () => {
47+
resizeObserver.disconnect();
48+
};
49+
}, [internalRef]);
50+
3651
return (
3752
<iframe
3853
title="iframe"

‎src/components/form-builder/mainCanvas.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function MainCanvas() {
8282
>
8383
<IFrame
8484
ref={editorIframeRef}
85-
className={cn(`${viewportEditorStyles[viewport]}`, "mx-auto scrollbar-hide")}
85+
className={cn(`${viewportEditorStyles[viewport]}`, "mx-auto")}
8686
>
8787
<Card className="mt-6">
8888
<CardContent>

‎src/components/form-builder/sidebar/sidebarRight.tsx‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,35 @@
33
import { Sidebar, SidebarContent } from "@/components/ui/sidebar";
44

55
import { useFormBuilderStore } from "@/stores/form-builder-store";
6-
import { ChevronDown } from "lucide-react";
6+
import { ChevronDown, ChevronUp } from "lucide-react";
77
import {
88
Collapsible,
99
CollapsibleContent,
1010
CollapsibleTrigger,
1111
} from "@/components/ui/collapsible";
1212
import { getComponentViews } from "@/config/available-components";
13-
import { ReactNode } from "react";
13+
import { ReactNode, useState } from "react";
1414

1515
interface PropertySectionProps {
1616
title: string;
1717
children: ReactNode;
18+
isOpen: boolean;
1819
}
1920

20-
function PropertySection({ title, children }: PropertySectionProps) {
21+
function PropertySection({ title, children, isOpen }: PropertySectionProps) {
22+
const [isOpenState, setIsOpenState] = useState(isOpen);
2123
return (
22-
<Collapsible className="border-b" defaultOpen={true}>
23-
<CollapsibleTrigger className="flex items-center justify-between w-full p-4 cursor-pointer">
24+
<Collapsible className="border-b" defaultOpen={isOpenState}>
25+
<CollapsibleTrigger
26+
className="flex items-center justify-between w-full p-4 cursor-pointer"
27+
onClick={() => setIsOpenState(!isOpenState)}
28+
>
2429
<span className="font-normal text-sm">{title}</span>
25-
<ChevronDown className="h-4 w-4" />
30+
{isOpenState ? (
31+
<ChevronUp className="h-4 w-4" />
32+
) : (
33+
<ChevronDown className="h-4 w-4" />
34+
)}
2635
</CollapsibleTrigger>
2736
<CollapsibleContent className="p-4 pt-0 space-y-2">
2837
{children}
@@ -32,14 +41,12 @@ function PropertySection({ title, children }: PropertySectionProps) {
3241
}
3342

3443
const PROPERTY_SECTIONS = [
35-
{ key: "options", title: "Options" },
36-
{ key: "base", title: "Base" },
37-
{ key: "button", title: "Button" },
38-
{ key: "input", title: "Input" },
39-
{ key: "label", title: "Label" },
40-
{ key: "grid", title: "Grid layout" },
41-
{ key: "html", title: "HTML" },
42-
{ key: "validation", title: "Validation" },
44+
{ key: "options", title: "Options", isOpen: true },
45+
{ key: "input", title: "Input", isOpen: true },
46+
{ key: "label", title: "Label", isOpen: true },
47+
{ key: "grid", title: "Grid layout", isOpen: false },
48+
{ key: "html", title: "HTML", isOpen: false },
49+
{ key: "validation", title: "Validation", isOpen: false },
4350
] as const;
4451

4552
export function SidebarRight() {
@@ -69,14 +76,12 @@ export function SidebarRight() {
6976
} else {
7077
sidebarContent = (
7178
<div>
72-
<div className="p-4 border-b">Properties</div>
73-
74-
{PROPERTY_SECTIONS.map(({ key, title }) => {
79+
{PROPERTY_SECTIONS.map(({ key, title, isOpen }) => {
7580
const content = componentViews.renderDesignProperties[key];
7681
if (!content) return null;
7782

7883
return (
79-
<PropertySection key={key} title={title}>
84+
<PropertySection key={key} title={title} isOpen={isOpen}>
8085
{content}
8186
</PropertySection>
8287
);

0 commit comments

Comments
 (0)