Tabs.svelte 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <script>
  2. import { createEventDispatcher } from 'svelte';
  3. export let tabs = [];
  4. export let active = 0;
  5. export let showCloseIcon = false;
  6. const dispatch = createEventDispatcher();
  7. function selectTab(index) {
  8. active = index;
  9. const event = new CustomEvent("change", { detail: index });
  10. dispatch('change', { detail: index });
  11. }
  12. function handleClose() {
  13. dispatch('close');
  14. }
  15. </script>
  16. <div class="flex border-b border-gray-200 justify-between items-center">
  17. <div class="flex">
  18. {#each tabs as tab, i}
  19. <button
  20. class={`px-4 py-2 -mb-px border-b-2 ${
  21. i === active
  22. ? "border-blue-600 text-blue-600 font-medium"
  23. : "border-transparent text-gray-500 hover:text-gray-700"
  24. }`}
  25. on:click={() => selectTab(i)}
  26. >
  27. {tab}
  28. </button>
  29. {/each}
  30. </div>
  31. {#if showCloseIcon}
  32. <button
  33. class="p-2 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full transition-colors"
  34. on:click={handleClose}
  35. title="Cancelar criação"
  36. >
  37. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  38. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  39. </svg>
  40. </button>
  41. {/if}
  42. </div>