Story Container
Problem
- Consumers of Storyteller shouldn’t have to interact with the
renderAPI directly, or manage the lifecycle themselves. This is currently what Flipbook has to do inStoryPreview.luau(link) - Flipbook can’t easily pass along arbitrary props like theme or locale to the story function. The original intention was to have Storyteller manage these things, but it makes more sense for Flipbook to handle that state. Storyteller doesn’t need to know about the surrounding UI, it just needs to care about what goes into the sandbox
Solution
Provide a new Storyteller.StoryContainer component that handles a story’s lifecycle
Inputs:
story: LoadedStory<T>controls: StoryControls- Reminder that
story.controlsdefines the controls schema, and this defines which controls have been modified
- Reminder that
extraProps: { [string]: any }2. Arbitrary props that get passed along to the story function. Flipbook sets some values on here likethemeandlocale,
Outputs:
- Rendered story within the StoryContainer bounds
Props Sources
When rendering a story, the props parameter of the story function gets hydrated from the following sources:
- StoryContainer’s
extraProps - A Story definition’s
propsfield - Storyteller’s reserved story props and StoryContainer’s
controls
The props are combined together in that same order. As such, a user can provide props that overrides Flipbook’s theme and locale, but cannot override Storyteller’s container, controls, or story.
Here’s an example of all of these coming together:
-- Sample.story.luau
return {
controls = {
foo = true,
font = {
Enum.Font.BuilderSans,
Enum.Font.GothamBold,
}
},
props = {
staticMessage = "Hello, World"
},
story = function(props)
print(props)
end,
}
This should output an object that looks like:
{
-- Dynamic values provided by Flipbook
theme = "Dark",
locale = "en-us",
-- Arbitrary values from the story's props
staticMessage = "Hello, World!"
-- Storyteller's reserved props
container = Instance,
story = ...,
controls = {
foo = true,
font = Enum.Font.BuilderSans,
},
}