ChatMenu.svelte 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 Star from '$lib/components/icons/Star.svelte';
  14. const i18n = getContext('i18n');
  15. export let pinHandler: Function;
  16. export let shareHandler: Function;
  17. export let cloneChatHandler: Function;
  18. export let archiveChatHandler: Function;
  19. export let renameHandler: Function;
  20. export let deleteHandler: Function;
  21. export let onClose: Function;
  22. export let chatId = '';
  23. let show = false;
  24. </script>
  25. <Dropdown
  26. bind:show
  27. on:change={(e) => {
  28. if (e.detail === false) {
  29. onClose();
  30. }
  31. }}
  32. >
  33. <Tooltip content={$i18n.t('More')}>
  34. <slot />
  35. </Tooltip>
  36. <div slot="content">
  37. <DropdownMenu.Content
  38. 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"
  39. sideOffset={-2}
  40. side="bottom"
  41. align="start"
  42. transition={flyAndScale}
  43. >
  44. <DropdownMenu.Item
  45. 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"
  46. on:click={() => {
  47. pinHandler();
  48. }}
  49. >
  50. <Star strokeWidth="2" />
  51. <div class="flex items-center">{$i18n.t('Pin')}</div>
  52. </DropdownMenu.Item>
  53. <DropdownMenu.Item
  54. 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"
  55. on:click={() => {
  56. renameHandler();
  57. }}
  58. >
  59. <Pencil strokeWidth="2" />
  60. <div class="flex items-center">{$i18n.t('Rename')}</div>
  61. </DropdownMenu.Item>
  62. <DropdownMenu.Item
  63. 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"
  64. on:click={() => {
  65. cloneChatHandler();
  66. }}
  67. >
  68. <DocumentDuplicate strokeWidth="2" />
  69. <div class="flex items-center">{$i18n.t('Clone')}</div>
  70. </DropdownMenu.Item>
  71. <DropdownMenu.Item
  72. 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"
  73. on:click={() => {
  74. archiveChatHandler();
  75. }}
  76. >
  77. <ArchiveBox strokeWidth="2" />
  78. <div class="flex items-center">{$i18n.t('Archive')}</div>
  79. </DropdownMenu.Item>
  80. <DropdownMenu.Item
  81. 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"
  82. on:click={() => {
  83. shareHandler();
  84. }}
  85. >
  86. <Share />
  87. <div class="flex items-center">{$i18n.t('Share')}</div>
  88. </DropdownMenu.Item>
  89. <DropdownMenu.Item
  90. 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"
  91. on:click={() => {
  92. deleteHandler();
  93. }}
  94. >
  95. <GarbageBin strokeWidth="2" />
  96. <div class="flex items-center">{$i18n.t('Delete')}</div>
  97. </DropdownMenu.Item>
  98. <hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
  99. <div class="flex p-1">
  100. <Tags
  101. {chatId}
  102. on:close={() => {
  103. show = false;
  104. onClose();
  105. }}
  106. />
  107. </div>
  108. </DropdownMenu.Content>
  109. </div>
  110. </Dropdown>