Files
ianitor/packages/ui/src/Banner.svelte
T

49 lines
1.4 KiB
Svelte

<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<script lang="ts">
import type { Snippet } from "svelte";
import Icon from "./Icon.svelte";
import type { IconName } from "./icons";
// Handoff §2.8. `live` is set only for banners that appear while the user is on the page.
let {
tone = "notice",
icon,
live,
label,
title,
children,
actions,
ondismiss,
}: {
tone?: "notice" | "kept" | "down";
icon?: IconName;
live?: "alert" | "status";
label?: string;
title?: Snippet;
children?: Snippet;
actions?: Snippet;
ondismiss?: () => void;
} = $props();
const shown: IconName = $derived(
icon ?? (tone === "kept" ? "check" : tone === "down" ? "ring" : "clock"),
);
</script>
<section class="ia-banner {tone === 'notice' ? '' : tone}" role={live} aria-label={label}>
<Icon name={shown} class="ia-banner-icon" />
<div class="body">
{#if title}<div>{@render title()}</div>{/if}
{#if children}<div class="line2">{@render children()}</div>{/if}
</div>
{#if actions || ondismiss}
<div class="actions">
{@render actions?.()}
{#if ondismiss}
<button type="button" class="ia-icon-btn" aria-label="Dismiss" onclick={ondismiss}><Icon name="close" /></button>
{/if}
</div>
{/if}
</section>