FileItem.svelte 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. const i18n = getContext('i18n');
  7. const dispatch = createEventDispatcher();
  8. export let className = 'w-60';
  9. export let colorClassName = 'bg-white dark:bg-gray-850 border border-gray-50 dark:border-white/5';
  10. export let url: string | null = null;
  11. export let dismissible = false;
  12. export let status = 'processed';
  13. export let file = null;
  14. export let edit = false;
  15. export let name: string;
  16. export let type: string;
  17. export let size: number;
  18. let showModal = false;
  19. </script>
  20. {#if file}
  21. <FileItemModal bind:show={showModal} bind:file {edit} />
  22. {/if}
  23. <button
  24. class="relative group p-1.5 {className} flex items-center {colorClassName} rounded-2xl text-left"
  25. type="button"
  26. on:click={async () => {
  27. if (file?.file?.content) {
  28. showModal = !showModal;
  29. } else {
  30. if (url) {
  31. if (type === 'file') {
  32. window.open(`${url}/content`, '_blank').focus();
  33. } else {
  34. window.open(`${url}`, '_blank').focus();
  35. }
  36. }
  37. }
  38. dispatch('click');
  39. }}
  40. >
  41. <div class="p-3 bg-white/10 text-white rounded-xl">
  42. {#if status === 'processed'}
  43. <svg
  44. xmlns="http://www.w3.org/2000/svg"
  45. viewBox="0 0 24 24"
  46. fill="currentColor"
  47. class=" size-5"
  48. >
  49. <path
  50. fill-rule="evenodd"
  51. 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"
  52. clip-rule="evenodd"
  53. />
  54. <path
  55. 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"
  56. />
  57. </svg>
  58. {:else}
  59. <svg
  60. class=" size-5 translate-y-[0.5px]"
  61. fill="currentColor"
  62. viewBox="0 0 24 24"
  63. xmlns="http://www.w3.org/2000/svg"
  64. ><style>
  65. .spinner_qM83 {
  66. animation: spinner_8HQG 1.05s infinite;
  67. }
  68. .spinner_oXPr {
  69. animation-delay: 0.1s;
  70. }
  71. .spinner_ZTLf {
  72. animation-delay: 0.2s;
  73. }
  74. @keyframes spinner_8HQG {
  75. 0%,
  76. 57.14% {
  77. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  78. transform: translate(0);
  79. }
  80. 28.57% {
  81. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  82. transform: translateY(-6px);
  83. }
  84. 100% {
  85. transform: translate(0);
  86. }
  87. }
  88. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  89. class="spinner_qM83 spinner_oXPr"
  90. cx="12"
  91. cy="12"
  92. r="2.5"
  93. /><circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="2.5" /></svg
  94. >
  95. {/if}
  96. </div>
  97. <div class="flex flex-col justify-center -space-y-0.5 px-2.5 w-full">
  98. <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1 mb-1">
  99. {name}
  100. </div>
  101. <div class=" flex justify-between text-gray-500 text-xs">
  102. {#if type === 'file'}
  103. {$i18n.t('File')}
  104. {:else if type === 'doc'}
  105. {$i18n.t('Document')}
  106. {:else if type === 'collection'}
  107. {$i18n.t('Collection')}
  108. {:else}
  109. <span class=" capitalize">{type}</span>
  110. {/if}
  111. {#if size}
  112. <span class="capitalize">{formatFileSize(size)}</span>
  113. {/if}
  114. </div>
  115. </div>
  116. {#if dismissible}
  117. <div class=" absolute -top-2 -right-2">
  118. <button
  119. class=" bg-gray-400 text-white border border-white rounded-full group-hover:visible invisible transition"
  120. type="button"
  121. on:click|stopPropagation={() => {
  122. dispatch('dismiss');
  123. }}
  124. >
  125. <svg
  126. xmlns="http://www.w3.org/2000/svg"
  127. viewBox="0 0 20 20"
  128. fill="currentColor"
  129. class="w-4 h-4"
  130. >
  131. <path
  132. 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"
  133. />
  134. </svg>
  135. </button>
  136. <!-- <button
  137. 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"
  138. type="button"
  139. on:click={() => {
  140. }}
  141. >
  142. <GarbageBin />
  143. </button> -->
  144. </div>
  145. {/if}
  146. </button>