Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: placeholder #32

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading