1+ <!-- @component A collapsible component, which collapses right to left if longer than wider,
2+ and collapses bottom to top if wider than longer.
3+ -->
4+ <script lang =" ts" >
5+ import { Collapsible } from " @skeletonlabs/skeleton-svelte" ;
6+ import type { Snippet } from " svelte" ;
7+ import { slide } from " svelte/transition" ;
8+
9+ import MdiChevronLeft from " ~icons/mdi/chevron-left" ;
10+
11+ interface Props {
12+ /** Whether the collapsible is open (bindable). */
13+ open? : boolean ,
14+ /**
15+ * The uncollapsed content.
16+ *
17+ * This also decides the width/height of the collapsible,
18+ * so it should be set accordingly to the ratio of
19+ * uncollapsed content to everything else on the page.
20+ **/
21+ children: Snippet <[]>
22+ }
23+
24+ let { open = $bindable (true ), children }: Props = $props ();
25+
26+ let collapsibleEl = $state <HTMLDivElement >();
27+ let collapsibleHoriz = $state (getCHoriz ());
28+ function getCHoriz() {
29+ return collapsibleEl ? getComputedStyle (collapsibleEl ).flexDirection == " row" : true ;
30+ }
31+ </script >
32+ <Collapsible
33+ class =" flex-col md:flex-row items-stretch gap-0"
34+ {open }
35+ onOpenChange ={e => open = e .open }
36+ >
37+ {#snippet element (attributes )}
38+ <div {...attributes } bind:this ={collapsibleEl }>
39+ <Collapsible .Content class =" grow" >
40+ {#snippet element (attributes )}
41+ {#if ! attributes .hidden }
42+ <div
43+ {...attributes }
44+ class =" overflow-hidden"
45+ transition:slide ={{ duration : 150 , axis : collapsibleHoriz ? " x" : " y" }}
46+ >
47+ {@render children ()}
48+ </div >
49+ {/if }
50+ {/ snippet }
51+ </Collapsible .Content >
52+ <div class =" flex items-center justify-center" >
53+ <Collapsible .Trigger class =" btn-icon-std p-0 m-1 hover:preset-tonal" >
54+ <MdiChevronLeft
55+ class ={[
56+ " transition-transform duration-150" ,
57+ open ? " rotate-90 md:rotate-0" : " rotate-270 md:rotate-180"
58+ ]}
59+ />
60+ </Collapsible .Trigger >
61+ </div >
62+ </div >
63+ {/ snippet }
64+ </Collapsible >
65+
66+ <!-- HACK: Get orientation of collapsible in JS -->
67+ <svelte:window onresize ={() => collapsibleHoriz = getCHoriz ()}></svelte:window >
0 commit comments