-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection-group.svelte
More file actions
64 lines (57 loc) · 1.51 KB
/
section-group.svelte
File metadata and controls
64 lines (57 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!--
@component
A group of sections in a card. For example, "test" or "do command"
-->
<script lang="ts">
import type { Snippet } from 'svelte'
import { Icon } from '@viamrobotics/prime-core'
import { slide } from 'svelte/transition'
interface Props {
/** Title for the group. */
title: string
/** Collapsed state. */
isCollapsed: boolean
/** Toggle collapsed state. */
toggleIsCollapsed: () => void
children?: Snippet
}
const { title, isCollapsed, toggleIsCollapsed, children }: Props = $props()
const id = $props.id()
const collapseID = `section-group-collapse-${id}`
const headingID = `section-group-heading-${id}`
</script>
<section
class="flex flex-col"
aria-labelledby={headingID}
>
<header class={['border-gray-3 bg-light hover:bg-medium h-7', !isCollapsed && 'border-b']}>
<button
class="group flex h-full w-full flex-row items-center gap-2 px-2.75"
aria-controls={collapseID}
aria-expanded={!isCollapsed}
aria-label={`${isCollapsed ? 'expand' : 'collapse'} ${title}`}
onclick={toggleIsCollapsed}
>
<Icon
name={isCollapsed ? 'unfold-more-horizontal' : 'unfold-less-horizontal'}
cx="group-hover:text-gray-7 text-[#AEAEB5]"
/>
<h2
id={headingID}
class="font-roboto-mono text-subtle-2 m-0 text-left text-xs tracking-[0.06em] uppercase"
>
{title}
</h2>
</button>
</header>
{#if !isCollapsed}
<div
id={collapseID}
role="region"
class="divide-y"
transition:slide={{ duration: 150 }}
>
{@render children?.()}
</div>
{/if}
</section>