FileItem.svelte 3.9 KB

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