pesde goatsoft / lucy

Toaster

Short notifications that slide in above every scene and dialog, then go away on their own. Every App gets one when the Toaster component is in the package (always with pesde or Forest; when copying components in, add toaster), so you never create it yourself: call app.toast.

Toaster exampleToaster example
app.toast("Now playing: Neon Nights", { description = "DJ Lucy, 124 BPM" })
app.toast.success("Set complete", { description = "+250 coins" })

Toasts sit in the bottom right corner on desktop and centred at the bottom on touch devices, unless you move them (see Position). They never take keyboard or gamepad focus.

Showing a toast

CallWhat it does
app.toast(title, options?)Shows a toast and returns its id
app.toast.success(title, options?)A green toast
app.toast.error(title, options?)A red toast
app.toast.warning(title, options?)An amber toast
app.toast.info(title, options?)A blue toast
app.toast.dismiss(id?)Closes one toast, or all of them without an id

Options

OptionTypeDefaultWhat it does
descriptionstringA second line under the title
kindstring"default"default, success, error, warning or info
mediaslotBefore the title and description: an Icon, an image, a handle, an instance, a builder or a list. An icon in it takes the toast's text colour
durationnumber4Seconds before it closes. math.huge keeps it until dismissed
actiontableA button: { label = "Join", onClick = join }
idstringmade up for youPass the id of a toast that is showing to update it in place
holderstring"default"Which holder it shows in
channelstring"default"What kind of message it is, for quiet mode
quietstring"hold"While its channel is quiet: hold shows it when quiet ends, drop throws it away, show shows it anyway
contentfunctionYour own UI in place of the title and description: called once with a getter for the toast (it follows updates by id), returns an Instance or a handle
barebooleanfalseWith content: no panel, shadow or close button round it, so it keeps its own look, as wide as it is. It slides in from the edge, eased out with no bounce (appears in place with reduced motion)
dismissOnTapbooleanfalseA tap on it dismisses it (touch), for a toast with nothing in it to press
swipebooleantrueOn touch, a swipe up off the top (down at the bottom) or sideways dismisses it

While the app is quiet (a tutorial is running, see Quiet mode), toasts on other channels wait and show when it ends, the newest visibleToasts only.

An icon

An icon on the left makes a toast easier to notice and to read at a glance. Put it in the media slot, at the size you want:

app.toast.success("New record", {
    description = "9,800 points",
    media = Lucy.Icon.new({ icon = "lucide:trophy", size = 36 }),
})

Your own UI in a toast

A toast can hold anything: a countdown, a card with a face on it. content makes it once, and an update with the same id keeps it, so it can follow your state on its own. bare = true leaves out the toast's panel so your card keeps its look, and it slides in from the toaster's edge, eased out with no bounce (it appears in place with reduced motion).

app.toast("Show in progress", {
    id = "show-status",
    content = function(toast)
        return statusCard()
    end,
    bare = true,
    duration = math.huge,
    dismissOnTap = true,
})
app.toast.dismiss("show-status")

On touch, every toast can be swiped away: up off the top, down off the bottom, or sideways. A bare toast follows the finger and springs back if let go short of that.

Settings

Change these before the first toast shows:

SettingDefaultWhat it does
Lucy.Toaster.defaults.duration4Seconds a toast stays when no duration is given
Lucy.Toaster.defaults.visibleToasts3How many show at once; the newest win
Lucy.Toaster.defaults.width356Width in pixels, never wider than the screen; App.new({ toastWidth = 480 }) sets it for the default holder, a holder's width for another (Holders)

A kind colours the whole toast with the theme's Success, Destructive, Warning or Info colour, and its text and close icon with the matching foreground, such as SuccessForeground: a dark or light shade of the toast's own colour, worked out to WCAG AA contrast (see Theming). A plain toast uses the popover colours.

Shadow and gradient

Each toast sits in the same frame as a dialog, so a theme that gives dialogs a hard offset shadow (the PanelShadow token) gives toasts one too. It is black unless a rule colours it; the frame is tagged with the toast's kind, so each kind can have its own:

app.theme:addRules("myToasts", {
    {
        selector = ".ui-toast-frame-kind-success > .ui-toast-shadow",
        priority = 210,
        properties = { BackgroundColor3 = "$Green900" },
    },
})

The shadow's corners follow the RadiusLg token, as the toast's do; a theme that rounds toasts with a rule of its own (.ui-toast::UICorner) sets .ui-toast-shadow::UICorner to match.

A theme with a GradientToast<Kind> token (GradientToastSuccess, GradientToastError, GradientToastDefault and so on, made with Tokens.gradient) fills that kind's toasts with it. A kind without one keeps its flat colour. Pick text colours that read on all of the gradient.

Position

Put toasts where they won't cover your HUD:

local app = Lucy.App.new({ toastPosition = "top-center" })

app.state:set("ui.toaster.position", "bottom-left") -- move them later

The positions are top-left, top-center, top-right, bottom-left, bottom-center and bottom-right (the default). The newest toast is the one nearest the edge. At the top, toasts sit just off the top of the screen where Roblox's top bar is free (the top centre, mostly), and drop below the bar only where they would reach Roblox's own buttons. On touch devices they sit centred, at the top or the bottom.

Holders

A holder is a place toasts show: a position, a width and how many show at once. The app makes its holders when it starts and keeps them for as long as it runs, so a toast shows the same wherever it is sent from, a button's click or the middle of an effect. There is always a default holder, set by toastPosition and toastWidth. Add as many more as your screens need, and send each toast to the one it belongs in:

Toaster exampleToaster example
app.toast.holder("events", { position = "top-center", width = 420 })

app.toast("Doors open at eight", { holder = "events", duration = math.huge })
app.toast.success("Outfit saved") -- the default holder

Declare them when you make the app instead, if you know them up front:

local app = Lucy.App.new({
    toastPosition = "bottom-right",
    toasters = {
        events = { position = "top-center", width = 480 },
        notices = { position = "bottom-left", visibleToasts = 2 },
    },
})
Holder optionDefaultWhat it does
position"bottom-right"Where its toasts sit, as for the default holder (see Position)
width356How wide its toasts are on a desktop
visibleToasts3How many of its toasts show at once; the newest win

app.toast.holder again for the same id changes it. app.toast.holders() lists them. A toast sent to a holder that was never declared is an error, so a misspelt id shows at once. app.toast.removeHolder(id) takes one down and drops its toasts, for a screen that goes away for good; the default holder always stays. The default holder's state is at ui.toaster, another's at ui.toaster-<id>, so app.state:set("ui.toaster-events.position", "top-left") moves one.

Examples

A toast that updates as work finishes:

local id = app.toast("Saving your outfit...", { duration = math.huge })
saveOutfit()
app.toast.success("Outfit saved", { id = id }) -- replaces it and starts its timer

A toast with a button:

Toaster exampleToaster example
app.toast("Nova wants to dance", {
    action = { label = "Join", onClick = joinCrew },
})

Toasts are kept in app state at toasts, newest last, so you can read or clear them like any other state:

local count = #app.state:get("toasts")
app.state:set("toasts", {}) -- clear every toast

Preview

In Studio, from the command bar: Lucy.Preview.show("Toaster").