FileItem.svelte 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 =
  10. 'bg-white dark:bg-gray-850 border border-gray-50 dark:border-gray-850';
  11. export let url: string | null = null;
  12. export let dismissible = false;
  13. export let status = 'processed';
  14. export let file = 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 file}
  22. <FileItemModal bind:show={showModal} bind:file {edit} />
  23. {/if}
  24. <button
  25. class="relative group p-1 {className} flex items-center {colorClassName} rounded-2xl text-left"
  26. type="button"
  27. on:click={async () => {
  28. if (file?.file?.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-white/10 text-white rounded-xl">
  43. {#if status === 'processed'}
  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. <svg
  61. class=" size-5 translate-y-[0.5px]"
  62. fill="currentColor"
  63. viewBox="0 0 24 24"
  64. xmlns="http://www.w3.org/2000/svg"
  65. ><style>
  66. .spinner_qM83 {
  67. animation: spinner_8HQG 1.05s infinite;
  68. }
  69. .spinner_oXPr {
  70. animation-delay: 0.1s;
  71. }
  72. .spinner_ZTLf {
  73. animation-delay: 0.2s;
  74. }
  75. @keyframes spinner_8HQG {
  76. 0%,
  77. 57.14% {
  78. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  79. transform: translate(0);
  80. }
  81. 28.57% {
  82. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  83. transform: translateY(-6px);
  84. }
  85. 100% {
  86. transform: translate(0);
  87. }
  88. }
  89. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  90. class="spinner_qM83 spinner_oXPr"
  91. cx="12"
  92. cy="12"
  93. r="2.5"
  94. /><circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="2.5" /></svg
  95. >
  96. {/if}
  97. </div>
  98. <div class="flex flex-col justify-center -space-y-0.5 px-2 w-full">
  99. <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1 mb-1">
  100. {name}
  101. </div>
  102. <div class=" flex justify-between text-gray-500 text-xs">
  103. {#if type === 'file'}
  104. {$i18n.t('File')}
  105. {:else if type === 'doc'}
  106. {$i18n.t('Document')}
  107. {:else if type === 'collection'}
  108. {$i18n.t('Collection')}
  109. {:else}
  110. <span class=" capitalize">{type}</span>
  111. {/if}
  112. {#if size}
  113. <span class="capitalize">{formatFileSize(size)}</span>
  114. {/if}
  115. </div>
  116. </div>
  117. {#if dismissible}
  118. <div class=" pr-2">
  119. <button
  120. class=" px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl group-hover:visible invisible transition"
  121. type="button"
  122. on:click={() => {
  123. dispatch('dismiss');
  124. }}
  125. >
  126. <GarbageBin />
  127. </button>
  128. </div>
  129. {/if}
  130. </button>