Skip to content

Alert

A box with a title and a line or two of text that stays on screen: a server notice, a failed purchase, a rule the player should know. For a message that comes and goes on its own, use a toast instead.

Alert exampleAlert example
Lucy.Alert.new({
    title = "Party night starts in 5 minutes",
    description = "DJ Lucy takes the Booth at 8. Grab a spot on the dance floor.",
    variant = "info",
    icon = Lucy.Icon.new({ icon = "lucide-extended:party-popper-filled" }),
    children = {
        Lucy.Button.new({
            text = "Hit the floor",
            size = "sm",
            variant = "outline",
            onClick = function() app.toast("See you on the dance floor") end,
        }),
    },
    Parent = parent,
})

Props

PropTypeDefaultState keyWhat it does
titlestring""yesThe first line. Hidden when empty
descriptionstring""yesThe text under it, in a muted colour. Hidden when empty
variantstring"default"yesdefault, destructive, success, warning or info
visiblebooleantrueyesShows or hides it
iconInstance or handleShown before the text
childrentableMore content under the description, such as a button

It also takes the props every component takes.

It fills the width of its parent and grows to fit its text. Its parts are on the handle: alert.icon, alert.content, alert.title and alert.description.

Looks

A card coloured box with a border. Every variant except default fills the box with a pale wash of the theme’s matching colour (DestructiveSubtle, SuccessSubtle, WarningSubtle or InfoSubtle), rings it in the full colour, and sets the title, description and icon in a deep shade of it (DestructiveSubtleForeground and the rest), worked out to WCAG AA contrast. See Accessibility.

Examples

A failed purchase with a way to try again:

Alert exampleAlert example
Lucy.Alert.new({
    variant = "destructive",
    title = "Couldn't buy Moonwalk",
    description = "You were not charged. Try again in a moment.",
    children = {
        Lucy.Button.new({ text = "Try again", size = "sm", variant = "outline", onClick = retry }),
    },
    Parent = emoteShop,
})

A notice that follows game state:

local partyIn = Lucy.ref(0)

Lucy.Alert.new({
    variant = "info",
    title = function() return `Party night starts in {partyIn()} minutes` end,
    visible = function() return partyIn() > 0 end,
    Parent = hud,
})

Preview

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