Skip to content

Provide context to stories #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Common/Branding.story.luau
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
local Branding = require("./Branding")
local React = require("@pkg/React")

local Branding = require("./Branding")
local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")

return {
summary = "Icon and Typography for flipbook",
controls = {},
story = React.createElement(Branding),
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Branding = React.createElement(Branding),
}),
}
15 changes: 11 additions & 4 deletions src/Common/ScrollingFrame.story.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local ScrollingFrame = require("./ScrollingFrame")

local controls = {
Expand Down Expand Up @@ -30,11 +33,15 @@ return {
})
end

return React.createElement("Frame", {
Size = UDim2.new(1, 0, 0, 200),
BackgroundTransparency = 1,
return React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
ScrollingFrame = React.createElement(ScrollingFrame, {}, children),
Wrapper = React.createElement("Frame", {
Size = UDim2.new(1, 0, 0, 200),
BackgroundTransparency = 1,
}, {
ScrollingFrame = React.createElement(ScrollingFrame, {}, children),
}),
})
end,
}
17 changes: 12 additions & 5 deletions src/Explorer/Component.story.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local Component = require("./Component")
local React = require("@pkg/React")

local Component = require("./Component")
local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")

local childNode1 = {
name = "Button",
icon = "story",
Expand Down Expand Up @@ -37,9 +40,13 @@ local storybookNode = {
return {
summary = "Component as storybook with children",
controls = {},
story = React.createElement(Component, {
activeNode = nil,
node = storybookNode,
onClick = function() end,
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Component = React.createElement(Component, {
activeNode = nil,
node = storybookNode,
onClick = function() end,
}),
}),
}
17 changes: 11 additions & 6 deletions src/Forms/Button.story.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local Button = require("./Button")
local React = require("@pkg/React")

local Button = require("./Button")
local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")

local controls = {
text = "Click me",
}
Expand All @@ -13,11 +16,13 @@ return {
summary = "A generic button component that can be used anywhere",
controls = controls,
story = function(props: Props)
return React.createElement(Button, {
text = props.controls.text,
onClick = function()
print("click")
end,
return React.createElement(ContextProviders, { plugin = MockPlugin.new() }, {
Button = React.createElement(Button, {
text = props.controls.text,
onClick = function()
print("click")
end,
}),
})
end,
}
19 changes: 13 additions & 6 deletions src/Forms/Checkbox.story.luau
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
local Checkbox = require("./Checkbox")
local React = require("@pkg/React")

local Checkbox = require("./Checkbox")
local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")

return {
summary = "Generic checkbox used for story controls",
story = React.createElement(Checkbox, {
initialState = true,
onStateChange = function(newState)
print("Checkbox state changed to", newState)
end,
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Checkbox = React.createElement(Checkbox, {
initialState = true,
onStateChange = function(newState)
print("Checkbox state changed to", newState)
end,
}),
}),
}
23 changes: 15 additions & 8 deletions src/Forms/Dropdown.story.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local Dropdown = require("@root/Forms/Dropdown")
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local Dropdown = require("@root/Forms/Dropdown")
local MockPlugin = require("@root/Testing/MockPlugin")

local controls = {
useDefault = true,
numOptions = 3,
Expand All @@ -18,13 +21,17 @@ return {
table.insert(options, "Option " .. i)
end

return React.createElement(Dropdown, {
placeholder = "Select an option",
default = if props.controls.useDefault then options[1] else nil,
options = options,
onOptionChange = function(option)
print("Selected", option)
end,
return React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Dropdown = React.createElement(Dropdown, {
placeholder = "Select an option",
default = if props.controls.useDefault then options[1] else nil,
options = options,
onOptionChange = function(option)
print("Selected", option)
end,
}),
})
end,
}
2 changes: 1 addition & 1 deletion src/Forms/InputField.luau
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ local function InputField(providedProps: Props)
if props.validate then
setIsValid(props.validate(newText))
end
end, {})
end, { text, props.transform, props.validate, props.onTextChange })

React.useEffect(function()
if props.autoFocus then
Expand Down
33 changes: 20 additions & 13 deletions src/Forms/InputField.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
local InputField = require("./InputField")
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local InputField = require("./InputField")
local MockPlugin = require("@root/Testing/MockPlugin")

return {
story = React.createElement(InputField, {
placeholder = "Enter information...",
autoFocus = true,
onSubmit = function(text)
print(text)
end,
validate = function(text: string)
return #text <= 4
end,
transform = function(text: string)
return text:upper()
end,
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
InputField = React.createElement(InputField, {
placeholder = "Enter information...",
autoFocus = true,
onSubmit = function(text)
print(text)
end,
validate = function(text: string)
return #text <= 4
end,
transform = function(text: string)
return text:upper()
end,
}),
}),
}
9 changes: 8 additions & 1 deletion src/Forms/Searchbar.story.luau
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local Searchbar = require("./Searchbar")

return {
summary = "Searchbar used to search for components",
controls = {},
story = React.createElement(Searchbar),
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Searchbar = React.createElement(Searchbar),
}),
}
11 changes: 9 additions & 2 deletions src/Forms/SelectableTextLabel.story.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local SelectableTextLabel = require("./SelectableTextLabel")

local controls = {
Expand All @@ -13,8 +16,12 @@ return {
summary = "A styled TextLabel with selectable text. Click and drag with the mouse to select content",
controls = controls,
story = function(props: Props)
return React.createElement(SelectableTextLabel, {
Text = props.controls.text,
return React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
SelectableTextLabel = React.createElement(SelectableTextLabel, {
Text = props.controls.text,
}),
})
end,
}
27 changes: 17 additions & 10 deletions src/Panels/Sidebar.story.luau
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local Sidebar = require("./Sidebar")
local internalStorybook = require("@root/init.storybook.luau")

return {
summary = "Sidebar containing brand, searchbar, and component tree",
controls = {},
story = React.createElement(Sidebar, {
storybooks = {
internalStorybook,
},
selectStory = function(storyModule)
print(storyModule)
end,
selectStorybook = function(storybook)
print(storybook)
end,
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
Sidebar = React.createElement(Sidebar, {
storybooks = {
internalStorybook,
},
selectStory = function(storyModule)
print(storyModule)
end,
selectStorybook = function(storybook)
print(storybook)
end,
}),
}),
}
15 changes: 11 additions & 4 deletions src/Plugin/PluginApp.story.luau
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
local ModuleLoader = require("@pkg/ModuleLoader")
local PluginApp = require("./PluginApp")
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local PluginApp = require("./PluginApp")

return {
summary = "The main component that handles the entire plugin",
controls = {},
story = React.createElement(PluginApp, {
loader = ModuleLoader.new(),
plugin = plugin,
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
PluginApp = React.createElement(PluginApp, {
loader = ModuleLoader.new(),
plugin = plugin,
}),
}),
}
11 changes: 9 additions & 2 deletions src/Storybook/NoStorySelected.story.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
local NoStorySelected = require("./NoStorySelected")
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local NoStorySelected = require("./NoStorySelected")

return {
story = React.createElement(NoStorySelected),
story = React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
NoStorySelected = React.createElement(NoStorySelected),
}),
}
33 changes: 21 additions & 12 deletions src/Storybook/StoryControls.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local StoryControls = require("@root/Storybook/StoryControls")

return {
summary = "Panel for configuring the controls of a story",
story = React.createElement(StoryControls, {
controls = {
foo = "bar",
checkbox = false,
dropdown = {
"Option 1",
"Option 2",
"Option 3",
},
},
setControl = function() end,
}),
story = function()
return React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
StoryControls = React.createElement(StoryControls, {
controls = {
foo = "bar",
checkbox = false,
dropdown = {
"Option 1",
"Option 2",
"Option 3",
},
},
setControl = function() end,
}),
})
end,
}
11 changes: 9 additions & 2 deletions src/Storybook/StoryError.story.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
local React = require("@pkg/React")

local ContextProviders = require("@root/Common/ContextProviders")
local MockPlugin = require("@root/Testing/MockPlugin")
local StoryError = require("@root/Storybook/StoryError")

return {
Expand All @@ -8,8 +11,12 @@ return {
error("Oops!")
end, debug.traceback)

return React.createElement(StoryError, {
err = result,
return React.createElement(ContextProviders, {
plugin = MockPlugin.new(),
}, {
StoryError = React.createElement(StoryError, {
err = result,
}),
})
end,
}
Loading
Loading