ImagePreview.svelte 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script lang="ts">
  2. export let show = false;
  3. export let src = '';
  4. export let alt = '';
  5. </script>
  6. {#if show}
  7. <!-- svelte-ignore a11y-click-events-have-key-events -->
  8. <!-- svelte-ignore a11y-no-static-element-interactions -->
  9. <div
  10. class="fixed top-0 right-0 left-0 bottom-0 bg-black text-white w-full min-h-screen h-screen flex justify-center z-50 overflow-hidden overscroll-contain"
  11. >
  12. <div class=" absolute left-0 w-full flex justify-between">
  13. <div>
  14. <button
  15. class=" p-5"
  16. on:click={() => {
  17. show = false;
  18. }}
  19. >
  20. <svg
  21. xmlns="http://www.w3.org/2000/svg"
  22. fill="none"
  23. viewBox="0 0 24 24"
  24. stroke-width="2"
  25. stroke="currentColor"
  26. class="w-6 h-6"
  27. >
  28. <path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
  29. </svg>
  30. </button>
  31. </div>
  32. <div>
  33. <button
  34. class=" p-5"
  35. on:click={() => {
  36. const a = document.createElement('a');
  37. a.href = src;
  38. a.download = 'Image.png';
  39. a.click();
  40. }}
  41. >
  42. <svg
  43. xmlns="http://www.w3.org/2000/svg"
  44. viewBox="0 0 20 20"
  45. fill="currentColor"
  46. class="w-6 h-6"
  47. >
  48. <path
  49. d="M10.75 2.75a.75.75 0 0 0-1.5 0v8.614L6.295 8.235a.75.75 0 1 0-1.09 1.03l4.25 4.5a.75.75 0 0 0 1.09 0l4.25-4.5a.75.75 0 0 0-1.09-1.03l-2.955 3.129V2.75Z"
  50. />
  51. <path
  52. d="M3.5 12.75a.75.75 0 0 0-1.5 0v2.5A2.75 2.75 0 0 0 4.75 18h10.5A2.75 2.75 0 0 0 18 15.25v-2.5a.75.75 0 0 0-1.5 0v2.5c0 .69-.56 1.25-1.25 1.25H4.75c-.69 0-1.25-.56-1.25-1.25v-2.5Z"
  53. />
  54. </svg>
  55. </button>
  56. </div>
  57. </div>
  58. <img {src} {alt} class=" mx-auto h-full object-scale-down" />
  59. </div>
  60. {/if}