FunctionMenu.svelte 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 editHandler: Function;
  16. export let shareHandler: Function;
  17. export let cloneHandler: Function;
  18. export let exportHandler: Function;
  19. export let deleteHandler: Function;
  20. export let onClose: Function;
  21. let show = false;
  22. </script>
  23. <Dropdown
  24. bind:show
  25. on:change={(e) => {
  26. if (e.detail === false) {
  27. onClose();
  28. }
  29. }}
  30. >
  31. <Tooltip content={$i18n.t('More')}>
  32. <slot />
  33. </Tooltip>
  34. <div slot="content">
  35. <DropdownMenu.Content
  36. 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"
  37. sideOffset={-2}
  38. side="bottom"
  39. align="start"
  40. transition={flyAndScale}
  41. >
  42. <DropdownMenu.Item
  43. 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"
  44. on:click={() => {
  45. editHandler();
  46. }}
  47. >
  48. <svg
  49. xmlns="http://www.w3.org/2000/svg"
  50. fill="none"
  51. viewBox="0 0 24 24"
  52. stroke-width="1.5"
  53. stroke="currentColor"
  54. class="w-4 h-4"
  55. >
  56. <path
  57. stroke-linecap="round"
  58. stroke-linejoin="round"
  59. d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
  60. />
  61. </svg>
  62. <div class="flex items-center">{$i18n.t('Edit')}</div>
  63. </DropdownMenu.Item>
  64. <DropdownMenu.Item
  65. 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"
  66. on:click={() => {
  67. shareHandler();
  68. }}
  69. >
  70. <Share />
  71. <div class="flex items-center">{$i18n.t('Share')}</div>
  72. </DropdownMenu.Item>
  73. <DropdownMenu.Item
  74. 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"
  75. on:click={() => {
  76. cloneHandler();
  77. }}
  78. >
  79. <DocumentDuplicate />
  80. <div class="flex items-center">{$i18n.t('Clone')}</div>
  81. </DropdownMenu.Item>
  82. <DropdownMenu.Item
  83. 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"
  84. on:click={() => {
  85. exportHandler();
  86. }}
  87. >
  88. <ArrowDownTray />
  89. <div class="flex items-center">{$i18n.t('Export')}</div>
  90. </DropdownMenu.Item>
  91. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  92. <DropdownMenu.Item
  93. 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"
  94. on:click={() => {
  95. deleteHandler();
  96. }}
  97. >
  98. <GarbageBin strokeWidth="2" />
  99. <div class="flex items-center">{$i18n.t('Delete')}</div>
  100. </DropdownMenu.Item>
  101. </DropdownMenu.Content>
  102. </div>
  103. </Dropdown>