Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/lib/holocene/toast.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import type { HTMLAttributes } from 'svelte/elements';
import { fly } from 'svelte/transition';

import { createEventDispatcher } from 'svelte';
Expand Down Expand Up @@ -27,13 +28,18 @@
warning: 'warning',
};

function getRole(v: ToastVariant): HTMLAttributes<HTMLDivElement>['role'] {
if (v === 'error') return 'alert';
return 'status';
}

export let id: string;
export let variant: keyof typeof variants;
export let closeButtonLabel: string = '';

$: dismissLabel = closeButtonLabel || translate('common.close');

$: icon = variantIcon[variant];
$: role = getRole(variant);

const handleDismiss = () => {
dispatch('dismiss', { id });
Expand All @@ -42,6 +48,8 @@

<div
{id}
{role}
aria-atomic="true"
class={merge(
'flex grow-0 items-center justify-between gap-4 rounded-md px-3 py-2.5 shadow',
variants[variant],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/holocene/toaster.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
});
</script>

<div class={toast({ position: $position })} role="log">
<div class={toast({ position: $position })}>
{#each $toasts as { message, variant, id, link } (id)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ⚠️ Type 'ToastVariant | undefined' is not assignable to type 'ToastVariant'.
  • ⚠️ Type 'string | undefined' is not assignable to type 'string'.

<ToastComponent {closeButtonLabel} {variant} {id} on:dismiss={dismissToast}>
{#if link}
Expand Down
Loading