FunctionMenu.svelte 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <script lang="ts">
  2. import { DropdownMenu } from 'bits-ui';
  3. import { flyAndScale } from '$lib/utils/transitions';
  4. import { getContext } from 'svelte';
  5. import Dropdown from '$lib/components/common/Dropdown.svelte';
  6. import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
  7. import Pencil from '$lib/components/icons/Pencil.svelte';
  8. import Tooltip from '$lib/components/common/Tooltip.svelte';
  9. import Tags from '$lib/components/chat/Tags.svelte';
  10. import Share from '$lib/components/icons/Share.svelte';
  11. import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
  12. import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
  13. import ArrowDownTray from '$lib/components/icons/ArrowDownTray.svelte';
  14. const i18n = getContext('i18n');
  15. export let shareHandler: Function;
  16. export let cloneHandler: Function;
  17. export let exportHandler: Function;
  18. export let deleteHandler: Function;
  19. export let onClose: Function;
  20. let show = false;
  21. </script>
  22. <Dropdown
  23. bind:show
  24. on:change={(e) => {
  25. if (e.detail === false) {
  26. onClose();
  27. }
  28. }}
  29. >
  30. <Tooltip content={$i18n.t('More')}>
  31. <slot />
  32. </Tooltip>
  33. <div slot="content">
  34. <DropdownMenu.Content
  35. class="w-full max-w-[160px] rounded-xl px-1 py-1.5 border border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
  36. sideOffset={-2}
  37. side="bottom"
  38. align="start"
  39. transition={flyAndScale}
  40. >
  41. <DropdownMenu.Item
  42. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  43. on:click={() => {
  44. shareHandler();
  45. }}
  46. >
  47. <Share />
  48. <div class="flex items-center">{$i18n.t('Share')}</div>
  49. </DropdownMenu.Item>
  50. <DropdownMenu.Item
  51. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  52. on:click={() => {
  53. cloneHandler();
  54. }}
  55. >
  56. <DocumentDuplicate />
  57. <div class="flex items-center">{$i18n.t('Clone')}</div>
  58. </DropdownMenu.Item>
  59. <DropdownMenu.Item
  60. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  61. on:click={() => {
  62. exportHandler();
  63. }}
  64. >
  65. <ArrowDownTray />
  66. <div class="flex items-center">{$i18n.t('Export')}</div>
  67. </DropdownMenu.Item>
  68. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  69. <DropdownMenu.Item
  70. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  71. on:click={() => {
  72. deleteHandler();
  73. }}
  74. >
  75. <GarbageBin strokeWidth="2" />
  76. <div class="flex items-center">{$i18n.t('Delete')}</div>
  77. </DropdownMenu.Item>
  78. </DropdownMenu.Content>
  79. </div>
  80. </Dropdown>