Velaguides

Recipes

Small, complete UI patterns — buttons, badges, meters, list rows, a dialog — compiled and rendered live.

This page builds the small pieces most Roblox interfaces are made of. Each preview is compiled by the same compiler rbxtsc uses. The Classes tab shows the source and the Lowered tab shows the output. The previews all stay on the static path.

Two habits repeat throughout:

  • Give everything an explicit size. Roblox instances start at zero size, so most examples set w-* and h-*. Backgrounds already start transparent (preflight), so you don’t need bg-transparent.
  • Rows and columns are UIListLayout. An element with flex, gap-*, justify-* or items-* gets one UIListLayout child, which positions every child. See layout and sizing.

Buttons

Filled, outlined, and destructive — the outline is a UIStroke, and everything else is four utility families.

A button is a textbutton with a size, a radius, a background and text classes. The outlined version adds border border-slate-600, which becomes a UIStroke child.

Add hover and press feedback with hover: and active:. Add transition to tween the change:

Hover and press tween the fill over 150ms
<textbutton
className="w-28 h-10 rounded-md bg-sky-500 hover:bg-sky-600 active:bg-sky-700 transition duration-150 text-white text-sm font-semibold"
Text="Play"
/>

Variants put the button on the runtime path. Gamepad and touch players may never hover, so use hover only as extra feedback.

To keep a button fully static, track the press yourself and switch between two complete elements:

src/client/ActionButton.tsx
export function ActionButton(props: { label: string; onClick: () => void }) {
const [pressed, setPressed] = React.useState(false);
return pressed ? (
<textbutton
className="w-28 h-10 rounded-md bg-sky-600 text-white text-sm font-semibold"
Text={props.label}
Event={{
Activated: props.onClick,
MouseButton1Up: () => setPressed(false),
MouseButton1Down: () => setPressed(true),
}}
/>
) : (
<textbutton
className="w-28 h-10 rounded-md bg-sky-500 text-white text-sm font-semibold"
Text={props.label}
Event={{
Activated: props.onClick,
MouseButton1Up: () => setPressed(false),
MouseButton1Down: () => setPressed(true),
}}
/>
);
}

Each branch is a plain literal, so the button needs no runtime host.

Buttons don’t size to their label. w-fit and h-fit lower to AutomaticSize, but a fixed w-28 h-10 is more predictable in a row of buttons.

Badges

Status pills: rounded-full, a dark shade for the fill, a light shade of the same palette for the text.

A pill is a textlabel with rounded-full. That’s new UDim(0.5, 0), half the label’s height, so it stays a capsule at any size. Roblox centers label text by default, so you need no alignment classes.

For the colors, take the fill from the dark end of a palette, the border one step lighter, and the text from the light end. Every palette has the same eleven shades, so this works with any hue.

Stat bars

A meter is a track and a fill: the fraction is the value, and the fill sits at the track's origin because a plain frame does not lay out its children.

A meter is a rounded-full track with a plain child fill at w-2/3 h-full. The track has no UIListLayout, so the fill sits at its top-left corner. w-2/3 means two thirds of the track.

For live data, set Size directly instead of computing a class:

The fraction is data — pass it as a prop
<frame className="w-72 h-2 rounded-full bg-slate-800">
<frame className="rounded-full bg-emerald-500" Size={UDim2.fromScale(health, 1)} />
</frame>

Don’t set the same property from a class and a prop. The prop wins, the class is left out, and the build warns explicit-prop-overrides-class.

List rows

A column of rows, each row its own UIListLayout. Column widths are chosen so rank, avatar, name, and score fill the row exactly.

A list is a flex flex-col gap-2 column of flex items-center gap-3 rows. Each one gets its own UIListLayout.

The score reaches the right edge because the column widths and gaps add up to the row’s width. justify-between also works in a real place, where it lowers to UIListLayout.HorizontalFlex. The preview renderer doesn’t support it. Fixed widths are also what you want when a column must not shrink.

A literal className inside a .map() callback is still static:

Still the static path
{entries.map((entry, index) => (
<frame className="flex items-center gap-3 w-full h-9 px-3 rounded-md bg-slate-800" key={entry.id}>
{/* … */}
</frame>
))}

What counts is the expression in the attribute, not where it appears.

A confirmation dialog

Column layout, wrapped body text, and a justify-end button row — the alignment half of justify-*, which is plain UIListLayout.

The dialog is a gap-3 column with a text-wrap body and a justify-end button row, which lowers to HorizontalAlignment = Right. Text doesn’t wrap by default, so long text clips without text-wrap.

For a modal, put the card inside a full-screen scrim:

src/client/Modal.tsx
<frame className="size-full bg-slate-950/60 z-50">
<frame className="origin-center left-1/2 top-1/2 w-96 h-40 …">{/* the card */}</frame>
</frame>
  • bg-slate-950/60 fades only the scrim’s background. opacity-60 would fade the card too, because it applies to everything inside the element.
  • origin-center sets AnchorPoint to (0.5, 0.5), so left-1/2 top-1/2 centers the card.
  • z-50 raises ZIndex above the rest of the interface.

When a recipe needs state

Every pattern here eventually meets data: a selected tab, a disabled button, a filling meter.

  • The look changes between known states: branch the classes, as in ["w-28 h-10 rounded-md", on ? "bg-sky-600" : "bg-slate-700"]. Both looks are resolved and checked. To skip the runtime host as well, switch between two whole elements, as the button does.
  • A number changes continuously: keep the classes static and set the property directly, as the meter does.
  • The state is hover, press or focus: use hover:, active: or focus:, ideally with transition.

Avoid building class names in template strings, such as `bg-${color}-500`. They still resolve, but nothing checks them, so a typo renders as nothing on a clean build. See dynamic class names, or the short version in the five rules.

See also