FunctionMenu.svelte 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 Tooltip from '$lib/components/common/Tooltip.svelte';
  8. import Share from '$lib/components/icons/Share.svelte';
  9. import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
  10. import Download from '$lib/components/icons/Download.svelte';
  11. import Switch from '$lib/components/common/Switch.svelte';
  12. import GlobeAlt from '$lib/components/icons/GlobeAlt.svelte';
  13. const i18n = getContext('i18n');
  14. export let func;
  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 toggleGlobalHandler: Function;
  21. export let onClose: Function;
  22. let show = false;
  23. </script>
  24. <Dropdown
  25. bind:show
  26. on:change={(e) => {
  27. if (e.detail === false) {
  28. onClose();
  29. }
  30. }}
  31. >
  32. <Tooltip content={$i18n.t('More')}>
  33. <slot />
  34. </Tooltip>
  35. <div slot="content">
  36. <DropdownMenu.Content
  37. class="w-full max-w-[180px] rounded-xl px-1 py-1.5 border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-sm"
  38. sideOffset={-2}
  39. side="bottom"
  40. align="start"
  41. transition={flyAndScale}
  42. >
  43. {#if ['filter', 'action'].includes(func.type)}
  44. <div
  45. class="flex gap-2 justify-between items-center px-3 py-1.5 text-sm font-medium cursor-pointerrounded-md"
  46. >
  47. <div class="flex gap-2 items-center">
  48. <GlobeAlt />
  49. <div class="flex items-center">{$i18n.t('Global')}</div>
  50. </div>
  51. <div>
  52. <Switch on:change={toggleGlobalHandler} bind:state={func.is_global} />
  53. </div>
  54. </div>
  55. <hr class="border-gray-50 dark:border-gray-850 my-1" />
  56. {/if}
  57. <DropdownMenu.Item
  58. class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  59. on:click={() => {
  60. editHandler();
  61. }}
  62. >
  63. <svg
  64. xmlns="http://www.w3.org/2000/svg"
  65. fill="none"
  66. viewBox="0 0 24 24"
  67. stroke-width="1.5"
  68. stroke="currentColor"
  69. class="w-4 h-4"
  70. >
  71. <path
  72. stroke-linecap="round"
  73. stroke-linejoin="round"
  74. 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"
  75. />
  76. </svg>
  77. <div class="flex items-center">{$i18n.t('Edit')}</div>
  78. </DropdownMenu.Item>
  79. <DropdownMenu.Item
  80. class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  81. on:click={() => {
  82. shareHandler();
  83. }}
  84. >
  85. <Share />
  86. <div class="flex items-center">{$i18n.t('Share')}</div>
  87. </DropdownMenu.Item>
  88. <DropdownMenu.Item
  89. class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  90. on:click={() => {
  91. cloneHandler();
  92. }}
  93. >
  94. <DocumentDuplicate />
  95. <div class="flex items-center">{$i18n.t('Clone')}</div>
  96. </DropdownMenu.Item>
  97. <DropdownMenu.Item
  98. class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  99. on:click={() => {
  100. exportHandler();
  101. }}
  102. >
  103. <Download />
  104. <div class="flex items-center">{$i18n.t('Export')}</div>
  105. </DropdownMenu.Item>
  106. <hr class="border-gray-50 dark:border-gray-850 my-1" />
  107. <DropdownMenu.Item
  108. class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
  109. on:click={() => {
  110. deleteHandler();
  111. }}
  112. >
  113. <GarbageBin strokeWidth="2" />
  114. <div class="flex items-center">{$i18n.t('Delete')}</div>
  115. </DropdownMenu.Item>
  116. </DropdownMenu.Content>
  117. </div>
  118. </Dropdown>