mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
chore: lift components folder
This commit is contained in:
parent
76df51674d
commit
2200b29b92
301 changed files with 57 additions and 76 deletions
63
src/Notification/ToastNotification.svelte
Normal file
63
src/Notification/ToastNotification.svelte
Normal file
|
@ -0,0 +1,63 @@
|
|||
<script>
|
||||
export let iconDescription = "closes notification";
|
||||
export let notificationType = "toast"; // "toast" | "inline"
|
||||
export let kind = "error";
|
||||
export let hideCloseButton = false;
|
||||
export let lowContrast = false;
|
||||
export let timeout = 0;
|
||||
export let role = "alert";
|
||||
export let title = "provide a title";
|
||||
export let subtitle = "";
|
||||
export let caption = "provide a caption";
|
||||
|
||||
import { createEventDispatcher, onMount } from "svelte";
|
||||
import NotificationButton from "./NotificationButton.svelte";
|
||||
import NotificationIcon from "./NotificationIcon.svelte";
|
||||
import NotificationTextDetails from "./NotificationTextDetails.svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: open = true;
|
||||
$: timeoutId = undefined;
|
||||
|
||||
onMount(() => {
|
||||
if (timeout) {
|
||||
timeoutId = window.setTimeout(() => {
|
||||
open = false;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if open}
|
||||
<div
|
||||
{role}
|
||||
{kind}
|
||||
class:bx--toast-notification={true}
|
||||
class:bx--toast-notification--low-contrast={lowContrast}
|
||||
class={kind && `bx--toast-notification--${kind}`}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave>
|
||||
<NotificationIcon {notificationType} {kind} {iconDescription} />
|
||||
<NotificationTextDetails {title} {subtitle} {caption} {notificationType}>
|
||||
<slot />
|
||||
</NotificationTextDetails>
|
||||
{#if !hideCloseButton}
|
||||
<NotificationButton
|
||||
{iconDescription}
|
||||
{notificationType}
|
||||
on:click={() => {
|
||||
open = false;
|
||||
dispatch('close');
|
||||
}} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
Loading…
Add table
Add a link
Reference in a new issue