Skip to main content

Controls

Stories can define controls that make it possible to quickly test out the behavior and variants of the UI you're working on.

Here's an example React component that we will build a Story around. The props it takes in will be configurable by the Story's controls.

ReactButtonControls.luau
local React = require("@pkg/React")

local function ReactButton(props: {
text: string,
isDisabled: boolean,
onActivated: () -> (),
})
return React.createElement("TextButton", {
Text = props.text,
TextSize = 16,
Font = Enum.Font.BuilderSansExtraBold,
TextColor3 = Color3.fromRGB(50, 50, 50),
BackgroundColor3 = Color3.fromRGB(255, 255, 255),
AutoButtonColor = if props.isDisabled then false else true,
BorderSizePixel = 0,
Size = UDim2.fromOffset(200, 40),
[React.Event.Activated] = if props.isDisabled then nil else props.onActivated,
}, {
Overlay = if props.isDisabled
then React.createElement("Frame", {
Size = UDim2.fromScale(1, 1),
BackgroundColor3 = Color3.fromRGB(0, 0, 0),
BackgroundTransparency = 0.6,
})
else nil,
})
end

return ReactButton

The Story creates the element and passes in controls through the props argument.

ReactButtonControls.story.luau
local React = require("@pkg/React")

local ReactButtonControls = require("./ReactButtonControls")

local controls = {
text = "Click Me",
isDisabled = false,
}

type Props = {
controls: typeof(controls),
}

return {
controls = controls,
story = function(props: Props)
return React.createElement(ReactButtonControls, {
text = props.controls.text,
isDisabled = props.controls.isDisabled,
onActivated = function()
print("click")
end,
})
end,
}

Opening the ReactButtonControls Story in Flipbook will include an accompanying panel for configuring the controls.

The ReactButtonControls story with its controls panel

As Controls are modified, the Story updates with the new props. If the Story source reloads while it is open, the replacement Controls store stays connected to both the panel and the preview, so later changes do not require reopening the Story.

The same story re-rendered after changing its controls

Controls aren't specific to React. The same controls and props.controls pattern works with the function-based renderer and plain Roblox Instances:

ButtonWithControls.story.luau
local controls = {
isDisabled = false,
}

type Props = {
controls: typeof(controls),
}

return {
controls = controls,
story = function(props: Props)
local button = Instance.new("TextButton")
button.Text = if props.controls.isDisabled then "Disabled" else "Click Me"
button.TextSize = 16
button.Font = Enum.Font.BuilderSansExtraBold
button.TextColor3 = Color3.fromRGB(50, 50, 50)
button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
button.AutoButtonColor = not props.controls.isDisabled
button.BorderSizePixel = 0
button.Size = UDim2.fromOffset(200, 40)

button.Activated:Connect(function()
if not props.controls.isDisabled then
print("clicked")
end
end)

return button
end,
}

Simple Controls​

The quickest way to declare a control is to give it a starting value. Flipbook infers the control from the value's type:

controls = {
label = "Click Me", -- text input
isDisabled = false, -- toggle
count = 3, -- number input
}

Richer Controls​

When a control needs more than a starting value, such as a fixed set of options, a numeric range, or a color, use the constructor functions exported by Storyteller. Each returns a control definition that goes in the same controls table, so simple and constructor-based controls can be mixed freely:

local Storyteller = require(path.to.Storyteller)

controls = {
label = "Click Me",
size = Storyteller.createSliderControl(16, NumberRange.new(8, 32), 1),
weight = Storyteller.createSelectControl({ "Light", "Regular", "Bold" }),
}
tip

The constructors come from Storyteller, which also provides the types for typechecking your Stories. See Frameworks for more on the relationship between Storyteller and Flipbook.

Control Types​

Every control accepts an optional default. The number-based controls add range and step; the list-based controls take an items array and an options table (default, a tostring label formatter, and sort).

ControlDeclarationValue
Booleaninferred from a boolean, or createBooleanControl(default?)boolean
Stringinferred from a string, or createStringControl(default?)string
Numberinferred from a number, or createNumberControl(default?, range?, step?)number
SlidercreateSliderControl(default?, range?, step?)number
SelectcreateSelectControl(items, options?)one value from items
RadiocreateRadioControl(items, options?)one value from items
MultiSelectcreateMultiSelectControl(items, options?)many values from items
CheckcreateCheckControl(items, options?)many values from items
ColorcreateColorControl(default?)Color3
DatecreateDateControl(default?)DateTime
ObjectcreateObjectControl(default?)Instance

A control's value is always a boolean, number, string, Color3, DateTime, EnumItem, or Instance, or an array of these for the multi-select controls.

Migrating Existing Controls​

Flipbook automatically migrates controls written in UI Labs' schema or an older Storyteller schema when it loads your Story, so controls authored for those keep working without changes. A dedicated migration guide covers converting them to the native schema.