-
Notifications
You must be signed in to change notification settings - Fork 1
/
Banner.svelte
61 lines (57 loc) · 1.46 KB
/
Banner.svelte
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
<script>
/**
* @type {string} [id=""]
*/
export let id = "uswds-" + Math.random().toString(36);
/**
* @type {boolean} [expanded=false]
*/
export let expanded = false;
/**
* @type {string} [headerText="Header text"]
*/
export let headerText = "Header text";
/**
* @type {string} [buttonText="Button text"]
*/
export let buttonText = "Button text";
</script>
<section
{...$$restProps}
class:usa-banner="{true}"
class:usa-banner__header--expanded="{expanded}"
aria-label="{$$props['aria-label']}"
>
<div class="usa-accordion">
<header class="usa-banner__header">
<div class="usa-banner__inner">
<div class="grid-col-auto">
<slot name="header" />
</div>
<div class="grid-col-fill tablet:grid-col-auto">
<p class="usa-banner__header-text">{headerText}</p>
<p class="usa-banner__header-action" aria-hidden="{!expanded}">
{buttonText}
</p>
</div>
<button
class="usa-accordion__button usa-banner__button"
aria-expanded="{expanded}"
aria-controls="{id}"
on:click="{() => {
expanded = !expanded;
}}"
>
<span class="usa-banner__button-text">{buttonText}</span>
</button>
</div>
</header>
<div
id="{id}"
class="usa-banner__content usa-accordion__content"
hidden="{!expanded}"
>
<slot />
</div>
</div>
</section>