Skip to content

Commit

Permalink
fix!: add close event to toast component (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
robluton authored Jul 8, 2024
1 parent 6d5352c commit 3236e52
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/toast/Toast.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
// import type { Snippet } from 'svelte';
import {createEventDispatcher} from 'svelte';
import { fade, type TransitionConfig } from 'svelte/transition';
import { twMerge } from 'tailwind-merge';
import { CloseButton } from '$lib';
Expand All @@ -20,6 +21,7 @@
export let params = {};
export let toastStatus: boolean = true;
const dispatch = createEventDispatcher();
// const divCls: string =
// 'w-full max-w-xs p-4 text-gray-500 bg-white rounded-lg shadow dark:text-gray-400 dark:bg-gray-800 gap-3';
Expand Down Expand Up @@ -94,6 +96,7 @@
{color}
on:click={() => {
toastStatus = false;
dispatch('close');
}}
/>
{/if}
Expand Down
18 changes: 17 additions & 1 deletion src/routes/component-data/Toast.json
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
{"name":"Toast","slots":["icon"],"events":[],"props":[["dismissable","boolean","true"],["color","ColorVariant","'primary'"],["position","ToastPositionType","'none'"],["divClass","string","'w-full max-w-xs p-4 text-gray-500 bg-white shadow dark:text-gray-400 dark:bg-gray-800 gap-3'"],["defaultIconClass","string","'w-8 h-8'"],["contentClass","string","'w-full text-sm font-normal'"],["align","boolean","true"],["transition","TransitionFunc","fade"],["params","string","{}"],["toastStatus","boolean","true"]]}
{
"name": "Toast",
"slots": ["icon"],
"events": ["on:close"],
"props": [
["dismissable", "boolean", "true"],
["color", "ColorVariant", "'primary'"],
["position", "ToastPositionType", "'none'"],
["divClass", "string", "'w-full max-w-xs p-4 text-gray-500 bg-white shadow dark:text-gray-400 dark:bg-gray-800 gap-3'"],
["defaultIconClass", "string", "'w-8 h-8'"],
["contentClass", "string", "'w-full text-sm font-normal'"],
["align", "boolean", "true"],
["transition", "TransitionFunc", "fade"],
["params", "string", "{}"],
["toastStatus", "boolean", "true"]
]
}
13 changes: 13 additions & 0 deletions src/routes/docs/components/toast.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ Use the position property to position these toast components relative to the mai
<Toast dismissable={false} position="bottom-right">Bottom right positioning.</Toast>
</div>
```
## Events

You can use on:close to execute custom logic when the toast is closed.

```svelte example hideScript
<script>
import { Toast } from 'flowbite-svelte';
</script>
<div class="relative h-56">
<Toast on:close={() => alert('Toast closed')}>Click the close button to see the event.</Toast>
</div>
```

## Component data

Expand Down

0 comments on commit 3236e52

Please sign in to comment.