Files
classroomio/apps/dashboard/src/lib/components/Expandable/index.svelte
T

50 lines
1.4 KiB
Svelte
Raw Normal View History

2021-05-07 03:43:37 +03:00
<script>
import { page } from '$app/stores';
import ChevronDownIcon from 'carbon-icons-svelte/lib/ChevronDown.svelte';
import ChevronUpIcon from 'carbon-icons-svelte/lib/ChevronUp.svelte';
import LinkIcon from 'carbon-icons-svelte/lib/Link.svelte';
2021-05-07 03:43:37 +03:00
export let id = '';
export let title = '';
export let titleClass = '';
export let disableContainerPadding = false;
export let rootClass = '';
export let supportsLink = false;
2021-05-07 03:43:37 +03:00
export let isExpanded = true;
function handleClick(e) {
e.stopPropagation();
isExpanded = !isExpanded;
2021-05-07 03:43:37 +03:00
}
</script>
2023-09-16 22:44:20 +01:00
<div {id} class="w-full bg-white dark:bg-black {rootClass}">
2023-08-05 04:44:32 +01:00
<button
class="w-full relative flex items-center justify-between {!disableContainerPadding && 'p-5'}"
2021-07-01 09:31:26 +03:00
tabindex="0"
on:click={handleClick}
2021-07-01 09:31:26 +03:00
>
<p class="dark:text-white font-bold flex items-center {titleClass}">
{title}
{#if supportsLink}
<a class="ml-2" href="{$page.url.pathname}#{id}" on:click={(e) => e.stopPropagation()}>
<LinkIcon size={24} class="carbon-icon dark:text-white" />
</a>
{/if}
</p>
{#if isExpanded}
<ChevronUpIcon size={24} class="carbon-icon dark:text-white" />
{:else}
<ChevronDownIcon size={24} class="carbon-icon dark:text-white" />
2021-07-01 09:31:26 +03:00
{/if}
2023-08-05 04:44:32 +01:00
</button>
2021-07-01 09:31:26 +03:00
{#if isExpanded}
<div class="flex flex-col p-5">
2021-07-01 09:31:26 +03:00
<slot />
</div>
{/if}
</div>