mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
parent
422ac528a7
commit
94dceae1fb
11 changed files with 309 additions and 2 deletions
60
src/components/Notification/ToastNotification.svelte
Normal file
60
src/components/Notification/ToastNotification.svelte
Normal file
|
@ -0,0 +1,60 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let kind = 'error';
|
||||
export let title = 'provide a title';
|
||||
export let subtitle = ''; // TODO: support subtitle slot?
|
||||
export let caption = 'provide a caption';
|
||||
export let role = 'alert';
|
||||
export let notificationType = 'toast';
|
||||
export let iconDescription = 'closes notification';
|
||||
export let hideCloseButton = false;
|
||||
export let lowContrast = false;
|
||||
export let timeout = 0;
|
||||
export let style = undefined;
|
||||
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import NotificationIcon from './NotificationIcon.svelte';
|
||||
import NotificationTextDetails from './NotificationTextDetails.svelte';
|
||||
import NotificationButton from './NotificationButton.svelte';
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const _class = cx(
|
||||
'--toast-notification',
|
||||
lowContrast && '--toast-notification--low-contrast',
|
||||
kind && `--toast-notification--${kind}`,
|
||||
className
|
||||
);
|
||||
|
||||
let open = true;
|
||||
|
||||
onMount(() => {
|
||||
if (timeout) {
|
||||
window.setTimeout(() => {
|
||||
open = false;
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
|
||||
$: if (!open) {
|
||||
dispatch('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if open}
|
||||
<div on:click on:mouseover on:mouseenter on:mouseleave class={_class} {style} {role} {kind}>
|
||||
<NotificationIcon {notificationType} {kind} {iconDescription} />
|
||||
<NotificationTextDetails {title} {subtitle} {caption} {notificationType}>
|
||||
<slot />
|
||||
</NotificationTextDetails>
|
||||
{#if !hideCloseButton}
|
||||
<NotificationButton
|
||||
{iconDescription}
|
||||
{notificationType}
|
||||
on:click={() => {
|
||||
open = false;
|
||||
}} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
Loading…
Add table
Add a link
Reference in a new issue