Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: add close event to toast component #1383

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
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