pesde goatsoft / lucy

Collapsible

A header the player presses to show or hide what is under it: advanced settings, the rules of a round, a long list they rarely need. For a set of sections where opening one can close the others, use an Accordion.

Collapsible exampleCollapsible example
Lucy.Collapsible.new({
    text = "Booth extras",
    open = true,
    content = function()
        return Lucy.Stack.new({
            gap = "Space2",
            children = {
                Lucy.Switch.new({ label = "Sync lights to the beat", checked = true }),
                Lucy.Switch.new({ label = "Show BPM on the decks" }),
            },
        })
    end,
    Parent = parent,
})

It fills the width of its parent. Opening and closing slide the height over a short tween, and the chevron turns with it; with reduced motion both happen at once. Closed content is hidden, so keyboard and gamepad focus skip it; when it is open, up and down move from the header into the content and back.

Variants

  • default: a full width header with the chevron on the right and a line under the section.
  • details: a compact header with the chevron before the text and the content indented under it, for a "show more" in the middle of other content.

Props

PropTypeDefaultState keyWhat it does
textstring""yesThe header text
childrentableAnything after the text in the header's slot (a count, a badge), before the chevron. They take the header's look and fade when disabled
contentInstance, handle or functionWhat it shows and hides; a function is called once at mount
openbooleanfalseyesWhether it is open
variantstring"default"yesdefault or details
disabledbooleanfalseyesGreys out the header and ignores presses
visiblebooleantrueyesShows or hides it
onOpenChangefunctionCalled with (open, handle) when it changes

It also takes the props every component takes.

When the player opens or closes it, it reports toggle with the new open state for useUiSound.

Methods

NameWhat it does
collapsible:toggle()Opens it if closed, closes it if open, as if the player pressed the header

To open or close it without reporting a press, set the state: collapsible:set("open", true).

Examples

Keep it open across visits with app state:

Collapsible exampleCollapsible example
Lucy.Collapsible.new({
    text = "Show the club rules",
    variant = "details",
    open = app.state:ref("settings.rulesOpen"),
    content = rulesText,
    Parent = lobby,
})

Preview

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