Skip to content

Commit

Permalink
refactor: placeholder (#32)
Browse files Browse the repository at this point in the history
* refactor: placeholders

* style: sort attribute
  • Loading branch information
bepyan authored Aug 9, 2024
1 parent 77c250f commit 9343148
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 96 deletions.
11 changes: 0 additions & 11 deletions src/components/editor/elements/container-placeholder.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions src/components/editor/elements/map-placeholder.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions src/components/editor/elements/placeholder.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/editor/elements/text-placeholder.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/editor/elements/two-columns-placeholder.tsx

This file was deleted.

62 changes: 62 additions & 0 deletions src/components/editor/placeholders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { MapIcon, TypeIcon } from "lucide-react";
import type { EditorElementType } from "~/components/editor/type";
import { cn } from "~/lib/utils";

type PlaceholderProps = {
type: EditorElementType;
children?: React.ReactNode;
className?: string;
};

function Placeholder({ type, children, className }: PlaceholderProps) {
const handleDragStart = (e: React.DragEvent) => {
if (type === null) return;
e.dataTransfer.setData("componentType", type);
};

return (
<div
draggable
onDragStart={handleDragStart}
className={cn(
"flex h-14 w-14 cursor-grab flex-row gap-1 rounded-lg bg-muted/70 p-2 active:cursor-grabbing",
className,
)}
>
{children}
</div>
);
}

export function TextPlaceholder() {
return (
<Placeholder type="text">
<TypeIcon size={40} className="text-muted-foreground" />
</Placeholder>
);
}

export function TwoColumnsPlaceholder() {
return (
<Placeholder type="2Col">
<div className="h-full w-full rounded-sm border-[1px] border-dashed border-muted-foreground/50 bg-muted"></div>
<div className="h-full w-full rounded-sm border-[1px] border-dashed border-muted-foreground/50 bg-muted"></div>
</Placeholder>
);
}

export function MapPlaceholder() {
return (
<Placeholder type="map">
<MapIcon size={40} className="text-muted-foreground" />
</Placeholder>
);
}

export function ContainerPlaceholder() {
return (
<Placeholder type="container">
<div className="h-full w-full rounded-sm border-[1px] border-dashed border-muted-foreground/50 bg-muted" />
</Placeholder>
);
}
26 changes: 14 additions & 12 deletions src/components/editor/sidebar-elements-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from "react";
import ContainerPlaceholder from "~/components/editor/elements/container-placeholder";
import MapPlaceholder from "~/components/editor/elements/map-placeholder";
import TextPlaceholder from "~/components/editor/elements/text-placeholder";
import TwoColumnsPlaceholder from "~/components/editor/elements/two-columns-placeholder";
import {
ContainerPlaceholder,
MapPlaceholder,
TextPlaceholder,
TwoColumnsPlaceholder,
} from "~/components/editor/placeholders";
import type { EditorElementType } from "~/components/editor/type";
import {
Accordion,
Expand All @@ -26,27 +28,27 @@ export default function SidebarElementsTab(props: Props) {
group: "layout" | "elements";
}[] = [
{
Component: <ContainerPlaceholder />,
label: "Container",
id: "container",
label: "Container",
Component: <ContainerPlaceholder />,
group: "layout",
},
{
Component: <TwoColumnsPlaceholder />,
label: "2 Columns",
id: "2Col",
label: "2 Columns",
Component: <TwoColumnsPlaceholder />,
group: "layout",
},
{
Component: <TextPlaceholder />,
label: "Text",
id: "text",
label: "Text",
Component: <TextPlaceholder />,
group: "elements",
},
{
Component: <MapPlaceholder />,
label: "map",
id: "map",
label: "map",
Component: <MapPlaceholder />,
group: "elements",
},
];
Expand Down

0 comments on commit 9343148

Please sign in to comment.