pesde goatsoft / lucy

Components

Every component, grouped by what it does.

Actions and choices

ComponentWhat it is
ButtonA button, in six variants and four sizes
CheckboxA box that can be checked, with an optional label
Inline ConfirmAsks "Are you sure?" in place, with YES and NO
MenuActions that open as a list, a ring or a fan and close once one is picked
PressableA surface the player can click that holds anything
Radio GroupA list of options where the player picks exactly one
SelectA button that opens a list of options to pick one from
SwitchAn on and off switch, with an optional label
ToggleA button that stays pressed until it is clicked again
Toggle GroupA row of toggles where the player picks one or several

Forms and inputs

ComponentWhat it is
InputA text field, on one line or several
Number FieldA number with minus and plus buttons, typed or stepped
SliderPicks a number in a range by dragging or with the arrows

Layout and surfaces

ComponentWhat it is
AccordionSections the player opens and closes, one or several at a time
CollapsibleA header that shows or hides what is under it
GradientOne of the theme's gradients on a frame, a panel or a button
GridRows of equal cells, such as shop items or emotes
PanelA card with a header, content and footer
Scroll AreaA region that scrolls when its content does not fit
SeparatorA thin line between items
SlotWhat goes inside a badge, button, tab or option, and how it takes the component's colours
StackA row or column that lays out its children
TabsA tab bar with one panel per tab

Lists and data

ComponentWhat it is
DataGridA table the player can sort by pressing its headers
ItemA row in a list, with media, a title, a description and actions
LeaderboardRanked players with medals for the top three and the player's own row pinned
ListBulleted, numbered or clickable vertical list whose rows take any Slot content
SortButtonA column heading that sorts a list when pressed
TableRows and columns for leaderboards, friends lists and inventories

Overlays, tours and alerts

ComponentWhat it is
AlertA box that calls attention to a message
ArrowA big arrow that points at something on screen, grows in and bounces
DialogA modal window, and alert dialogs that ask for a yes or no
DialogueAn NPC conversation panel with portrait, typewriter text and branching choices
PromptA world interaction prompt with key caps, hold progress and ProximityPrompt restyling
SheetA panel from the side of the screen, a drawer from the bottom on touch
ToasterToast notifications through app.toast
TooltipA floating label or card beside a control or over a part, on hover, focus, press, proximity or always
TourA guided walk through your game's own UI, one step at a time

Display, motion and media

ComponentWhat it is
AttributionA badge displaying "Built with Lucy" with Lucy's mascot head
AvatarA player's headshot, or a monogram for a bot
BadgeA small label for a status or count
EffectAn animated celebration behind a reward or a level up: rays, outline, or your own
IconA small picture in the theme's colours, by name or asset id
IconStackSeveral icons drawn as one, overlapping, in a fan, a row, a pile or where you place them
ImageA picture from an asset id or a thumbnail
KbdThe key to press, for the player's keyboard or controller
MarqueeOne line of text that scrolls, back and forth or round like a ticker, when it is too long to fit
ProgressA bar that fills from 0 to a maximum
SkeletonA pulsing placeholder while content loads
SpinnerA turning ring while something loads
TextHeadings, body copy and labels
WaveformA row of columns from levels: a song's loudness, an equaliser, a meter

Using a component

Every component is X.new(props) and returns a handle:

  • handle.Instance: the root Instance
  • handle:get(key?), handle:set(patch): read and write its state at ui.<id>
  • handle:destroy()

Every component also takes these props:

PropWhat it does
idWhere its state lives: ui.<id>. Made up for you if left out
ParentThe Instance to put it in
appThe App it belongs to. Defaults to the current App
nameThe root Instance's Name
layoutOrderThe root Instance's LayoutOrder
colorA named colour for it and everything in it, or a ref or getter of one (Arrow and Waveform take color as their own colour)
persistKeep its state in the app after it is destroyed

Any state key can be changed from the app: app.state:set("ui.<id>.<key>", value).

A prop a component doesn't know is ignored, without an error, so check the component's page for its name. To place a component, put it in a Stack or Grid, or set layout properties on its root after making it:

Components exampleComponents example
local gear = Lucy.Button.new({ icon = "lucide-extended:settings-filled", size = "icon", Parent = scene.gui })
gear.Instance.AnchorPoint = Vector2.new(1, 0)
gear.Instance.Position = UDim2.new(1, -16, 0, 16)

Position, AnchorPoint, ZIndex and LayoutOrder are safe to set this way. Leave Size and colours alone on components whose size comes from the theme, such as Button and Input: a rule sets them and would win.

Where a component takes children, each one is an Instance, a component, or a function called with the frame to fill. A function's return value is not used, so for a list from state, put Lucy.each in a Lucy.new frame and pass that (see Work with app state).

Reactive props

Every state key listed on a component's page also accepts a ref, a computed or a getter function. The component follows it and nothing else runs again.

Components exampleComponents example
local coins = Lucy.ref(0)
local isBusy = Lucy.ref(false)
local lights = Lucy.ref(true)

Lucy.Stack.new({
    gap = "Space3",
    children = {
        Lucy.Button.new({
            text = function() return `Buy ({coins()})` end,
            disabled = isBusy,
        }),
        Lucy.Switch.new({ label = "Club lights", checked = lights }),
    },
    Parent = parent,
})
  • Writable sources bind both ways. A ref, or a computed made with { get, set }, is written back when the key changes: the player flips the Switch and lights becomes false. checked, value and open are the usual ones to bind this way.
  • Getters only flow in. A plain getter, or a computed without set, is read but never written back. If the app or the player changes that key, the next change of the source wins.
  • App state still works. Bound values land in ui.<id> like any other, so app.state subscribers and handle:get see them.
  • Lifetime. A component created inside an effect, a show branch, an each item or a scope is destroyed when that owner stops. Destroying it stops its bindings. Destroying its frame, or a panel or gui above it, destroys it too, so nothing it watches keeps running; app:destroy() stops every component before it removes their guis.
  • Callback and layout props (onClick, children, gap, ...) stay plain.

Responsive values

Lucy.Stack.new({
    direction = { mobile = "vertical", default = "horizontal" },
    gap = { console = "Space6", touch = "Space4", default = "Space2" },
})
local columns = Lucy.Responsive.pick(app, { console = 4, tablet = 3, mobile = 2, default = 5 })

-- In a render, an effect or a scope: a getter that follows the input state.
local gap = Lucy.useResponsive(app, { touch = 16, default = 8 })
Lucy.new "UIListLayout" { Padding = function() return UDim.new(0, gap()) end }

Keys: device (mobile tablet desktop console), input mode (touch gamepad keyboard mouse), breakpoint (compact regular wide), orientation (portrait landscape), height (short tall: short is under 500 pixels, a phone held sideways or a short window), default. First match in that order wins.

Writing a component

A component is a spec table passed to Lucy.Component.mount with each mount's props. render runs once to describe the instances, and bindings keep them in step with state from then on. A spec with style rules is declared once, at the end of its module, with Lucy.Component.define(spec): an app made afterwards has its rules from the start, so none are added while a player plays. For the full walkthrough, rules and performance notes, see Build a component and Benchmarks.

Roadmap

After 0.1.0: Carousel, Field, Empty, toast.promise, pausing toasts on hover.