Toasts are messages that are displayed temporarily. Toast messages are wrapped inside a Toast
component, which is created and managed by a Toaster
component.
import live-web.dom
import live-web-view.button
import live-web-view.overlay
import live-web-view.content
static any[] use = [PrimaryButton, Toaster, Content]
Toaster{
id: toaster
}
PrimaryButton{
T`Open message.`
on click: (e) => {
e.preventDefault()
toaster.add(
Toast{
ToastTitle`Toast Message`
Content{
T`Message displayed succesfully.`
}
}
)
}
}
import live-web.dom
import live-web-view.button
import live-web-view.overlay
import live-web-view.content
static any[] use = [PrimaryButton, Toaster, Content]
Toaster{
id: toaster
}
PrimaryButton{
T`Open message.`
on click: (e) => {
e.preventDefault()
toaster.data = toaster.data.concat({
id: Toaster.createToastId(),
title: 'Toast Message',
content: 'Message Displayed Successfully.'
})
}
}
Toasts can either be overwritten by the next toast, or stacked on top of each other. The example above stacks toasts on top of each other, while this one allows only a single toast to be displayed.This can e controlled by the Toaster.single
property.
import live-web.dom
import live-web-view.button
import live-web-view.overlay
import live-web-view.content
static any[] use = [PrimaryButton, Toaster, Content]
Toaster{
id: toaster
single: true
}
PrimaryButton{
T`Open message.`
on click: (e) => {
e.preventDefault()
toaster.add(
Toast{
ToastTitle`Toast Message`
Content{
T`Message displayed succesfully.`
}
}
)
}
}
By default, toasts are positioned relative to the screen, but they can be configured to be positioned in their parent by configuring the Toaster.position
property.
import live-web.dom
import live-web-view.button
import live-web-view.overlay
import live-web-view.content
static any[] use = [PrimaryButton, Toaster, Content]
Toaster{
id: toaster
single: true
position: Toaster.Position.Parent
}
PrimaryButton{
T`Open message.`
on click: (e) => {
e.preventDefault()
toaster.add(
Toast{
ToastTitle`Toast Message`
Content{
T`Message displayed succesfully.`
}
}
)
}
}