Skip to content

Commit

Permalink
remove dup contextmenu in blank canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
lovincyrus committed Jan 30, 2025
1 parent 85e75a6 commit 6252dd8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
48 changes: 8 additions & 40 deletions web-common/src/features/canvas/BlankCanvas.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<script lang="ts">
import { PlusCircleIcon } from "lucide-svelte";
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@rilldata/web-common/components/context-menu";
import type { CanvasComponentType } from "./components/types";
import { createEventDispatcher } from "svelte";
import { menuItems } from "./components/menu-items.svelte";
const dispatch = createEventDispatcher();
function handleAddComponent(componentType: CanvasComponentType) {
dispatch("add", { type: componentType });
}
function handleButtonClick(event: MouseEvent) {
const contextMenuEvent = new MouseEvent("contextmenu", {
Expand All @@ -27,31 +12,14 @@
</script>

<div class="size-full p-4 bg-white">
<ContextMenu>
<ContextMenuTrigger>
<button
type="button"
class="blank-canvas-button flex flex-col items-center gap-2 p-8 rounded-[6px] border border-slate-200 w-full"
on:click={handleButtonClick}
>
<PlusCircleIcon class="w-6 h-6 text-slate-500" />
<span class="text-sm font-medium text-slate-500">Add a component</span>
</button>
</ContextMenuTrigger>
<ContextMenuContent>
{#each menuItems as item}
<ContextMenuItem
on:click={() => handleAddComponent(item.id)}
class="text-gray-700 text-xs"
>
<div class="flex flex-row gap-x-2">
<svelte:component this={item.icon} />
<span class="text-gray-700 text-xs font-normal">{item.label}</span>
</div>
</ContextMenuItem>
{/each}
</ContextMenuContent>
</ContextMenu>
<button
type="button"
class="blank-canvas-button flex flex-col items-center gap-2 p-8 rounded-[6px] border border-slate-200 w-full"
on:click={handleButtonClick}
>
<PlusCircleIcon class="w-6 h-6 text-slate-500" />
<span class="text-sm font-medium text-slate-500">Add a component</span>
</button>
</div>

<style lang="postcss">
Expand Down
2 changes: 1 addition & 1 deletion web-common/src/features/canvas/Canvas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
on:contextmenu={handleContextMenu}
>
{#if items.length === 0}
<BlankCanvas on:add={handleAdd} />
<BlankCanvas />
{:else}
<CanvasDashboardPreview
{items}
Expand Down
1 change: 0 additions & 1 deletion web-common/src/features/canvas/components/menu-items.ts

This file was deleted.

0 comments on commit 6252dd8

Please sign in to comment.