asset-select-context-menu.svelte 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <script lang="ts" context="module">
  2. import { createContext } from '$lib/utils/context';
  3. const { get: getMenuContext, set: setContext } = createContext<() => void>();
  4. export { getMenuContext };
  5. </script>
  6. <script lang="ts">
  7. import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
  8. import ContextMenu from '$lib/components/shared-components/context-menu/context-menu.svelte';
  9. import type Icon from 'svelte-material-icons/AbTesting.svelte';
  10. export let icon: typeof Icon;
  11. export let title: string;
  12. let showContextMenu = false;
  13. let contextMenuPosition = { x: 0, y: 0 };
  14. const handleShowMenu = ({ x, y }: MouseEvent) => {
  15. contextMenuPosition = { x, y };
  16. showContextMenu = !showContextMenu;
  17. };
  18. setContext(() => (showContextMenu = false));
  19. </script>
  20. <CircleIconButton {title} logo={icon} on:click={handleShowMenu} />
  21. {#if showContextMenu}
  22. <ContextMenu {...contextMenuPosition} on:outclick={() => (showContextMenu = false)}>
  23. <div class="flex flex-col rounded-lg">
  24. <slot />
  25. </div>
  26. </ContextMenu>
  27. {/if}