ChatMenu.svelte 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. const i18n = getContext('i18n');
  14. export let shareHandler: Function;
  15. export let cloneChatHandler: Function;
  16. export let archiveChatHandler: Function;
  17. export let renameHandler: Function;
  18. export let deleteHandler: Function;
  19. export let onClose: Function;
  20. export let chatId = '';
  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-[180px] 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. renameHandler();
  46. }}
  47. >
  48. <Pencil strokeWidth="2" />
  49. <div class="flex items-center">{$i18n.t('Rename')}</div>
  50. </DropdownMenu.Item>
  51. <DropdownMenu.Item
  52. 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"
  53. on:click={() => {
  54. cloneChatHandler();
  55. }}
  56. >
  57. <DocumentDuplicate strokeWidth="2" />
  58. <div class="flex items-center">{$i18n.t('Clone')}</div>
  59. </DropdownMenu.Item>
  60. <DropdownMenu.Item
  61. 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"
  62. on:click={() => {
  63. archiveChatHandler();
  64. }}
  65. >
  66. <ArchiveBox strokeWidth="2" />
  67. <div class="flex items-center">{$i18n.t('Archive')}</div>
  68. </DropdownMenu.Item>
  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. shareHandler();
  73. }}
  74. >
  75. <Share />
  76. <div class="flex items-center">{$i18n.t('Share')}</div>
  77. </DropdownMenu.Item>
  78. <DropdownMenu.Item
  79. 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"
  80. on:click={() => {
  81. deleteHandler();
  82. }}
  83. >
  84. <GarbageBin strokeWidth="2" />
  85. <div class="flex items-center">{$i18n.t('Delete')}</div>
  86. </DropdownMenu.Item>
  87. <hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
  88. <div class="flex p-1">
  89. <Tags
  90. {chatId}
  91. on:close={() => {
  92. show = false;
  93. onClose();
  94. }}
  95. />
  96. </div>
  97. </DropdownMenu.Content>
  98. </div>
  99. </Dropdown>