Skip to content

Commit 791cff1

Browse files
committed
Toast Dismiss
Added the ability to allow or disallow toasts to be dismissed.
1 parent 3708c30 commit 791cff1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

client/packages/lowcoder/src/comps/hooks/toastComp.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ const showNotification = (
1919
const text = params?.[0] as string;
2020
const options = params?.[1] as JSONObject;
2121

22-
const { message , duration, id, placement } = options;
22+
const { message , duration, id, placement, dismissible } = options;
23+
24+
const closeIcon: boolean | undefined = dismissible === true ? undefined : (dismissible === false ? false : undefined);
2325

24-
// Convert duration to a number or null, if it's not a valid number, default to null
2526
const durationNumberOrNull: number | null = typeof duration === 'number' ? duration : null;
2627

2728
const notificationArgs: ArgsProps = {
2829
message: text,
2930
description: message as React.ReactNode,
3031
duration: durationNumberOrNull ?? 3,
31-
key: id as React.Key, // Ensure id is a valid React.Key
32-
placement: placement as NotificationPlacement ?? "bottomRight", // Ensure placement is a valid NotificationPlacement or undefined
32+
key: id as React.Key,
33+
placement: placement as NotificationPlacement ?? "bottomRight",
34+
closeIcon: closeIcon as boolean,
3335
};
3436

3537
// Use notificationArgs to trigger the notification

docs/build-apps/write-javascript/built-in-javascript-functions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ The id field can be used to update previous toasts. Or used to destroy the previ
132132
Destroy function used without an id will remove all toast.
133133

134134
```javascript
135-
// toast.open( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight" } )
135+
// toast.open( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight", dismissible?: boolean = true } )
136136
toast.open("This Is a Notification", {message: "I do not go away automatically.", duration: 0})
137-
// toast.info( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight" } )
137+
// toast.info( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight", dismissible?: boolean = true } )
138138
toast.info("Order #1519", {message: "Shipped out on Tuesday, Jan 3rd.", duration: 5})
139-
// toast.success( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight" } )
139+
// toast.success( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight", dismissible?: boolean = true } )
140140
toast.success("Query runs successfully", { duration: 10 })
141-
// toast.warn( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight" } )
141+
// toast.warn( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight", dismissible?: boolean = true } )
142142
toast.warn("Duplicate Action", {message: "The email was previously sent on Jan 3rd. Click the button again to send.", duration: 5})
143-
// toast.error( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight" } )
143+
// toast.error( title: string, options?: { message?: string, duration?: number = 3, id?: string, placement?: "top" | "topLeft" | "topRight" | "bottom" | "bottomRight", "bottomRight" = "bottomRight", dismissible?: boolean = true } )
144144
toast.error("Your credentials were invalid", {message: "You have 5 tries left", duration: 5})
145145
//toast.destroy(id?: string)
146146
toast.destroy()

0 commit comments

Comments
 (0)