Collapsible.svelte 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <script lang="ts">
  2. import { slide } from 'svelte/transition';
  3. import { quintOut } from 'svelte/easing';
  4. import ChevronUp from '../icons/ChevronUp.svelte';
  5. import ChevronDown from '../icons/ChevronDown.svelte';
  6. export let open = false;
  7. export let className = '';
  8. export let title = null;
  9. </script>
  10. <div class={className}>
  11. {#if title !== null}
  12. <button class="w-full" on:click={() => (open = !open)}>
  13. <div class=" w-full font-medium transition flex items-center justify-between gap-2">
  14. <div>
  15. {title}
  16. </div>
  17. <div>
  18. {#if open}
  19. <ChevronUp strokeWidth="3.5" className="size-3.5 " />
  20. {:else}
  21. <ChevronDown strokeWidth="3.5" className="size-3.5 " />
  22. {/if}
  23. </div>
  24. </div>
  25. </button>
  26. {:else}
  27. <button on:click={() => (open = !open)}>
  28. <div
  29. class="flex items-center gap-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition"
  30. >
  31. <slot />
  32. </div>
  33. </button>
  34. {/if}
  35. {#if open}
  36. <div transition:slide={{ duration: 300, easing: quintOut, axis: 'y' }}>
  37. <slot name="content" />
  38. </div>
  39. {/if}
  40. </div>