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

56 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>
<div {id} class="w-full bg-white dark:bg-gray-800 {rootClass}">
2021-07-01 09:31:26 +03:00
<div
class="w-full relative flex items-center justify-between {!disableContainerPadding &&
'p-5'}"
2021-07-01 09:31:26 +03:00
role="button"
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" />
</a>
{/if}
</p>
{#if isExpanded}
<ChevronUpIcon size={24} class="carbon-icon" />
{:else}
<ChevronDownIcon size={24} class="carbon-icon" />
2021-07-01 09:31:26 +03:00
{/if}
</div>
{#if isExpanded}
<div class="flex flex-col p-5">
2021-07-01 09:31:26 +03:00
<slot />
</div>
{/if}
</div>