FileItem.svelte 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <script lang="ts">
  2. import { createEventDispatcher, getContext } from 'svelte';
  3. import { formatFileSize } from '$lib/utils';
  4. import FileItemModal from './FileItemModal.svelte';
  5. import GarbageBin from '../icons/GarbageBin.svelte';
  6. import Spinner from './Spinner.svelte';
  7. const i18n = getContext('i18n');
  8. const dispatch = createEventDispatcher();
  9. export let className = 'w-60';
  10. export let colorClassName = 'bg-white dark:bg-gray-850 border border-gray-50 dark:border-white/5';
  11. export let url: string | null = null;
  12. export let dismissible = false;
  13. export let loading = false;
  14. export let item = null;
  15. export let edit = false;
  16. export let name: string;
  17. export let type: string;
  18. export let size: number;
  19. let showModal = false;
  20. </script>
  21. {#if item}
  22. <FileItemModal bind:show={showModal} bind:item {edit} />
  23. {/if}
  24. <button
  25. class="relative group p-1.5 {className} flex items-center {colorClassName} rounded-2xl text-left"
  26. type="button"
  27. on:click={async () => {
  28. if (item?.file?.data?.content) {
  29. showModal = !showModal;
  30. } else {
  31. if (url) {
  32. if (type === 'file') {
  33. window.open(`${url}/content`, '_blank').focus();
  34. } else {
  35. window.open(`${url}`, '_blank').focus();
  36. }
  37. }
  38. }
  39. dispatch('click');
  40. }}
  41. >
  42. <div class="p-3 bg-black/20 dark:bg-white/10 text-white rounded-xl">
  43. {#if !loading}
  44. <svg
  45. xmlns="http://www.w3.org/2000/svg"
  46. viewBox="0 0 24 24"
  47. fill="currentColor"
  48. class=" size-5"
  49. >
  50. <path
  51. fill-rule="evenodd"
  52. d="M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z"
  53. clip-rule="evenodd"
  54. />
  55. <path
  56. d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"
  57. />
  58. </svg>
  59. {:else}
  60. <Spinner />
  61. {/if}
  62. </div>
  63. <div class="flex flex-col justify-center -space-y-0.5 ml-1 px-2.5 w-full">
  64. <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1 mb-1">
  65. {name}
  66. </div>
  67. <div class=" flex justify-between text-gray-500 text-xs line-clamp-1">
  68. {#if type === 'file'}
  69. {$i18n.t('File')}
  70. {:else if type === 'doc'}
  71. {$i18n.t('Document')}
  72. {:else if type === 'collection'}
  73. {$i18n.t('Collection')}
  74. {:else}
  75. <span class=" capitalize line-clamp-1">{type}</span>
  76. {/if}
  77. {#if size}
  78. <span class="capitalize">{formatFileSize(size)}</span>
  79. {/if}
  80. </div>
  81. </div>
  82. {#if dismissible}
  83. <div class=" absolute -top-1 -right-1">
  84. <button
  85. class=" bg-gray-400 text-white border border-white rounded-full group-hover:visible invisible transition"
  86. type="button"
  87. on:click|stopPropagation={() => {
  88. dispatch('dismiss');
  89. }}
  90. >
  91. <svg
  92. xmlns="http://www.w3.org/2000/svg"
  93. viewBox="0 0 20 20"
  94. fill="currentColor"
  95. class="w-4 h-4"
  96. >
  97. <path
  98. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  99. />
  100. </svg>
  101. </button>
  102. <!-- <button
  103. class=" p-1 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-full group-hover:visible invisible transition"
  104. type="button"
  105. on:click={() => {
  106. }}
  107. >
  108. <GarbageBin />
  109. </button> -->
  110. </div>
  111. {/if}
  112. </button>