pesde goatsoft / lucy

Input

A text field for names, codes, search and chat, on one line or several. Its height grows on touch and console, and a focus ring shows while the player types in it. It can also limit what the player types: a number only, or a maximum length.

Input exampleInput example
Lucy.Stack.new({
    direction = "horizontal",
    gap = "Space2",
    align = "center",
    children = {
        Lucy.Input.new({
            id = "playerName",
            placeholder = "Your DJ name",
            width = UDim.new(0, 280),
            onSubmit = function(name)
                app.toast(`See you on the floor, {name}`)
            end,
        }),
        Lucy.Button.new({ text = "Save", icon = "lucide-extended:sparkles-filled" }),
    },
    Parent = parent,
})

Props

PropTypeDefaultState keyWhat it does
valuestring""yesThe text in the field
placeholderstring""yesGrey text shown while the field is empty
sizestring"md"yessm, md, lg or xl: the field's height and text, as a Button of the same size, so they line up in a row or a form
disabledbooleanfalseyesGreys it out and stops typing
visiblebooleantrueyesShows or hides it
widthUDimfills the parentHow wide the field is
maxLengthnumberThe most characters the player can type
numericbooleanfalseOnly digits, a minus at the start and one point can be typed
multilinebooleanfalseWraps text over several lines; Enter starts a new line
rowsnumber3How many lines tall a multiline field is
onChangefunctionCalled with (value, handle) as the text changes
onSubmitfunctionCalled with (value, handle) on Enter or the gamepad confirm button (not in a multiline field)

It also takes the props every component takes.

maxLength and numeric apply to what the player types. The value is always a string.

Methods

NameWhat it does
input:focus()Puts the cursor in the field

Examples

Read the value by id:

local name = app.state:get("ui.playerName.value")

Keep a ref and the field in step:

Input exampleInput example
local search = Lucy.ref("")

Lucy.Input.new({ placeholder = "Search emotes", value = search, Parent = emoteShop })

-- The emotes whose name has the search text, for a list's `data`
local shown = Lucy.computed(function()
    local text = string.lower(search())
    local found = {}
    for _, emote in emotes do
        if string.find(string.lower(emote.name), text, 1, true) then
            table.insert(found, emote)
        end
    end
    return found
end)

A message box that holds 200 characters:

Input exampleInput example
Lucy.Input.new({
    placeholder = "Message your crew",
    multiline = true,
    rows = 4,
    maxLength = 200,
    Parent = form,
})

A party code of six digits:

Input exampleInput example
Lucy.Input.new({ placeholder = "Party code", numeric = true, maxLength = 6, Parent = form })

A fixed width:

Input exampleInput example
Lucy.Input.new({ placeholder = "Party code", width = UDim.new(0, 160), Parent = row })

Preview

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