pesde goatsoft / lucy

Accordion

A stack of sections with a header each: a settings menu, a list of quests, the help pages of a game. By default one section is open at a time, and pressing the open one closes it. Each section is a Collapsible.

Accordion exampleAccordion example
Lucy.Accordion.new({
    value = "audio",
    items = {
        { value = "audio", text = "Music volume", content = function()
            return Lucy.Slider.new({ value = app.state:ref("settings.music"), showValue = true })
        end },
        { value = "lights", text = "Lights", content = function()
            return Lucy.Switch.new({ label = "Light show", checked = app.state:ref("settings.lights") })
        end },
        { value = "controls", text = "Controls", content = Lucy.Text.new({
            text = "E to dance, Q for the queue", variant = "muted",
        }) },
    },
    Parent = parent,
})

Each header is a focus stop. Up and down move between the headers, and into an open section's content and back out. A, Enter or a click opens and closes a section.

Props

PropTypeDefaultState keyWhat it does
itemstableThe sections: { value, text, children, content, disabled } each; children go in the section header's slot
typestring"single"single: one open at a time; multiple: any number. Set at mount
valueanyfalseyessingle: the open section's value, or false. multiple: a list of values
variantstring"default"yesThe sections' look: default or details (see Collapsible)
disabledbooleanfalseyesGreys out every header and ignores presses
visiblebooleantrueyesShows or hides it
onValueChangefunctionCalled with (value, handle) when it changes

An item's content is an Instance, a handle, or a function returning either, built once at mount. An item with disabled = true can't be opened by the player.

It also takes the props every component takes.

When the player opens or closes a section, that section reports toggle with its open state for useUiSound.

Methods

NameWhat it does
accordion:toggle(value)Opens or closes that section, as if the player pressed its header

accordion.sections[value] is the Collapsible for each section. To open sections without reporting a press, set the state: accordion:set("value", "video"), or a list with type = "multiple".

Examples

Let the player keep several sections of the Queue open, starting with two:

Accordion exampleAccordion example
Lucy.Accordion.new({
    type = "multiple",
    value = { "upNext", "requests" },
    items = {
        { value = "upNext", text = "Up next", content = upNextList },
        { value = "requests", text = "Requests", content = requestList },
        { value = "party", text = "Party night", content = partyList, disabled = not partyLive },
    },
    Parent = queuePanel,
})

Preview

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