Skip to content

Commit dad4f10

Browse files
authored
Add collapsible, applied to P&M page (#87)
1 parent 887dcac commit dad4f10

2 files changed

Lines changed: 76 additions & 4 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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>

src/routes/dashboard/points-motions/+page.svelte

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import EditMotionContent from "$lib/components/modals/EditMotionContent.svelte";
1717
import UniModal from "$lib/components/modals/UniModal.svelte";
1818
import MotionForm, { numSpeakersStr } from "$lib/components/motions/form/MotionForm.svelte";
19+
import OrientedCollapsible from "$lib/components/OrientedCollapsible.svelte";
1920
import { getSessionContext } from "$lib/context/index.svelte";
2021
import { findDelegate } from "$lib/db/delegates";
2122
import { db } from "$lib/db/index.svelte";
@@ -141,12 +142,16 @@
141142
}
142143
</script>
143144

144-
<div class="grid gap-5 min-h-full md:grid-cols-[1fr_2fr] md:h-full">
145-
<div class="card-filled motion-form">
146-
<MotionForm submit={submitMotion} {motionSchema} />
145+
<div class="flex flex-col gap-3 min-h-full md:h-full md:flex-row @container">
146+
<div class="flex card-filled">
147+
<OrientedCollapsible>
148+
<div class="w-full md:w-[30cqw] *:md:pr-0">
149+
<MotionForm submit={submitMotion} {motionSchema} />
150+
</div>
151+
</OrientedCollapsible>
147152
</div>
148153

149-
<div class="flex flex-col gap-2 overflow-x-auto">
154+
<div class="flex flex-col gap-2 overflow-x-auto md:min-w-[60cqw] grow">
150155
<div class="grid grid-cols-[auto_1fr_auto] items-center">
151156
<button
152157
class="btn-icon-std transition-colors preset-filled-primary-500"

0 commit comments

Comments
 (0)