AddContentMenu.svelte 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script lang="ts">
  2. import { DropdownMenu } from 'bits-ui';
  3. import { flyAndScale } from '$lib/utils/transitions';
  4. import { getContext, createEventDispatcher } from 'svelte';
  5. const dispatch = createEventDispatcher();
  6. import Dropdown from '$lib/components/common/Dropdown.svelte';
  7. import Tooltip from '$lib/components/common/Tooltip.svelte';
  8. import ArrowUpCircle from '$lib/components/icons/ArrowUpCircle.svelte';
  9. import BarsArrowUp from '$lib/components/icons/BarsArrowUp.svelte';
  10. import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
  11. import ArrowPath from '$lib/components/icons/ArrowPath.svelte';
  12. const i18n = getContext('i18n');
  13. export let onClose: Function = () => {};
  14. let show = false;
  15. </script>
  16. <Dropdown
  17. bind:show
  18. on:change={(e) => {
  19. if (e.detail === false) {
  20. onClose();
  21. }
  22. }}
  23. align="end"
  24. >
  25. <Tooltip content={$i18n.t('Add Content')}>
  26. <button
  27. class=" p-1.5 rounded-xl hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition font-medium text-sm flex items-center space-x-1"
  28. on:click={(e) => {
  29. e.stopPropagation();
  30. show = true;
  31. }}
  32. >
  33. <svg
  34. xmlns="http://www.w3.org/2000/svg"
  35. viewBox="0 0 16 16"
  36. fill="currentColor"
  37. class="w-4 h-4"
  38. >
  39. <path
  40. d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
  41. />
  42. </svg>
  43. </button>
  44. </Tooltip>
  45. <div slot="content">
  46. <DropdownMenu.Content
  47. class="w-full max-w-44 rounded-xl p-1 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
  48. sideOffset={4}
  49. side="bottom"
  50. align="end"
  51. transition={flyAndScale}
  52. >
  53. <DropdownMenu.Item
  54. class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  55. on:click={() => {
  56. dispatch('upload', { type: 'files' });
  57. }}
  58. >
  59. <ArrowUpCircle strokeWidth="2" />
  60. <div class="flex items-center">{$i18n.t('Upload files')}</div>
  61. </DropdownMenu.Item>
  62. <DropdownMenu.Item
  63. class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  64. on:click={() => {
  65. dispatch('upload', { type: 'directory' });
  66. }}
  67. >
  68. <FolderOpen strokeWidth="2" />
  69. <div class="flex items-center">{$i18n.t('Upload directory')}</div>
  70. </DropdownMenu.Item>
  71. <Tooltip
  72. content={$i18n.t(
  73. 'This option will delete all existing files in the collection and replace them with newly uploaded files.'
  74. )}
  75. className="w-full"
  76. >
  77. <DropdownMenu.Item
  78. class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  79. on:click={() => {
  80. dispatch('sync', { type: 'directory' });
  81. }}
  82. >
  83. <ArrowPath strokeWidth="2" />
  84. <div class="flex items-center">{$i18n.t('Sync directory')}</div>
  85. </DropdownMenu.Item>
  86. </Tooltip>
  87. <DropdownMenu.Item
  88. class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  89. on:click={() => {
  90. dispatch('upload', { type: 'text' });
  91. }}
  92. >
  93. <BarsArrowUp strokeWidth="2" />
  94. <div class="flex items-center">{$i18n.t('Add text content')}</div>
  95. </DropdownMenu.Item>
  96. </DropdownMenu.Content>
  97. </div>
  98. </Dropdown>