Skip to content
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

Adopt Component Story Format (CSF) #235

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
200aac1
Look for `.stories` files
vocksel Dec 23, 2023
2cd3465
Add a temp script for installing CSF
vocksel Dec 28, 2023
875c005
Rename *.story.lua -> *.stories.lua
vocksel Dec 29, 2023
e90e4b4
Support both file extensions
vocksel Dec 29, 2023
bb652fe
Convert example stories to CSF
vocksel Dec 29, 2023
ccf4383
Add some tests for loadStoryModule
vocksel Dec 30, 2023
5cc8758
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel Jan 3, 2024
c0bb6ca
Add example of how renderers could work
vocksel Jan 4, 2024
c7c2e15
Turn the example into markdown
vocksel Jan 4, 2024
8e343ec
Add WIP changes
vocksel Mar 3, 2024
44c6e1e
Install CSF from Wally
vocksel Apr 8, 2024
bb7f9fb
Port more stories
vocksel Apr 8, 2024
8cad5f2
Add some render test cases
vocksel Apr 12, 2024
c3934eb
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel Apr 16, 2024
c39253c
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel Apr 23, 2024
adf9a50
Fix some merge issues
vocksel Apr 22, 2024
1938f60
Continue using .story extension for now
vocksel Apr 23, 2024
9b1c28d
Fix up some non-string paths
vocksel Apr 23, 2024
f6560fa
Update Fusion renderer tests to use Jest
vocksel Apr 23, 2024
bd7a5b0
Fix Fusion expectation matchers
vocksel Apr 23, 2024
18fb9f1
Revert isStoryModule
vocksel Apr 23, 2024
a852016
Commit WIP changes
vocksel Apr 26, 2024
27c7cb1
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel May 3, 2024
5fe1ce6
WIP changes for StorytellerContext
vocksel May 3, 2024
b09922b
Move to Context folder
vocksel May 4, 2024
974dfc6
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel May 9, 2024
d91ccf4
Merge remote-tracking branch 'origin/main' into component-story-forma…
vocksel Aug 15, 2024
afbdf59
Get React/Roact renderers working
vocksel Aug 17, 2024
473f2ad
Almost stable! Everything but Fusion
vocksel Aug 18, 2024
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
26 changes: 16 additions & 10 deletions example/ArrayControls.story.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Sift = require("@pkg/Sift")
local constants = require("@root/constants")

local fonts = Sift.Array.sort(Enum.Font:GetEnumItems(), function(a: Enum.Font, z: Enum.Font)
return a.Name < z.Name
Expand All @@ -17,19 +18,24 @@ type Props = {
},
}

local stories = {}

stories.Primary = function(props: Props)
return React.createElement("TextLabel", {
Text = props.controls.font.Name,
Font = props.controls.font,
TextScaled = true,
TextColor3 = Color3.fromRGB(0, 0, 0),
BackgroundColor3 = Color3.fromRGB(255, 255, 255),
Size = UDim2.fromOffset(300, 100),
})
end

return {
summary = "Example of using array controls to set the font for a TextLabel",
controls = controls,
react = React,
reactRoblox = ReactRoblox,
story = function(props: Props)
return React.createElement("TextLabel", {
Text = props.controls.font.Name,
Font = props.controls.font,
TextScaled = true,
TextColor3 = Color3.fromRGB(0, 0, 0),
BackgroundColor3 = Color3.fromRGB(255, 255, 255),
Size = UDim2.fromOffset(300, 100),
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
24 changes: 16 additions & 8 deletions example/Button.story.luau
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
local Button = require("./Button")
local Roact = require("@pkg/Roact")
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
local constants = require(Example.Parent.constants)
local Button = require(script.Parent.Button)

local stories = {}

stories.Primary = Roact.createElement(Button, {
text = "Click me",
onActivated = function()
print("click")
end,
})

return {
summary = "A generic button component that can be used anywhere",
roact = Roact,
story = Roact.createElement(Button, {
text = "Click me",
onActivated = function()
print("click")
end,
}),
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
30 changes: 19 additions & 11 deletions example/ButtonWithControls.story.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local ButtonWithControls = require("./ButtonWithControls")
local Roact = require("@pkg/Roact")
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
local constants = require(Example.Parent.constants)
local ButtonWithControls = require(script.Parent.ButtonWithControls)

local controls = {
isDisabled = false,
Expand All @@ -9,17 +12,22 @@ type Props = {
controls: typeof(controls),
}

local stories = {}

stories.Primary = function(props: Props)
return Roact.createElement(ButtonWithControls, {
text = "Click me",
isDisabled = props.controls.isDisabled,
onActivated = function()
print("click")
end,
})
end

return {
summary = "A generic button component that can be used anywhere",
controls = controls,
roact = Roact,
story = function(props: Props)
return Roact.createElement(ButtonWithControls, {
text = "Click me",
isDisabled = props.controls.isDisabled,
onActivated = function()
print("click")
end,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
32 changes: 20 additions & 12 deletions example/CanvasTests/AutomaticSize.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
local ReactRoblox = require(Example.Parent.Packages.ReactRoblox)
local constants = require(Example.Parent.constants)

local stories = {}

stories.Primary = function()
return React.createElement("TextLabel", {
Size = UDim2.new(0, 0, 0, 0),
AutomaticSize = Enum.AutomaticSize.XY,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end

return {
summary = "AutoamticSize test for the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement("TextLabel", {
Size = UDim2.new(0, 0, 0, 0),
AutomaticSize = Enum.AutomaticSize.XY,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
32 changes: 20 additions & 12 deletions example/CanvasTests/AutomaticSizeExceedsBounds.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
local ReactRoblox = require(Example.Parent.Packages.ReactRoblox)
local constants = require(Example.Parent.constants)

local stories = {}

stories.Primary = function()
return React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 0),
AutomaticSize = Enum.AutomaticSize.Y,

TextSize = 24,
Text = script.Name .. string.rep("\nLine", 100),
Font = Enum.Font.GothamBold,
})
end

return {
summary = "AutoamticSize test using a height that exceeds the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 0),
AutomaticSize = Enum.AutomaticSize.Y,

TextSize = 24,
Text = script.Name .. string.rep("\nLine", 100),
Font = Enum.Font.GothamBold,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
32 changes: 20 additions & 12 deletions example/CanvasTests/Offset.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
local ReactRoblox = require(Example.Parent.Packages.ReactRoblox)
local constants = require(Example.Parent.constants)

local stories = {}

stories.Primary = function()
return React.createElement("TextLabel", {
Size = UDim2.fromOffset(2000, 2000),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end

return {
summary = "Offset test for the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement("TextLabel", {
Size = UDim2.fromOffset(2000, 2000),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
14 changes: 11 additions & 3 deletions example/CanvasTests/Resizing.story.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local RunService = game:GetService("RunService")

local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local constants = require("@root/constants")

local RESIZE_DURATIOn = 3 -- seconds
local MAX_SIZE = 2000 -- px
Expand Down Expand Up @@ -32,11 +33,18 @@ local function Story()
})
end

local stories = {}

stories.Primary = React.createElement(Story)

return {
summary = "Resizing test for the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement(Story)
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT
then nil
else function()
return React.createElement(Story)
end,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
32 changes: 20 additions & 12 deletions example/CanvasTests/Scale.story.luau
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
local ReactRoblox = require(Example.Parent.Packages.ReactRoblox)
local constants = require(Example.Parent.constants)

local stories = {}

stories.Primary = function()
return React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 1),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end

return {
summary = "Scale test for the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 1),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
40 changes: 24 additions & 16 deletions example/CanvasTests/ScrollingFrame.story.luau
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
local React = require("@pkg/React")
local ReactRoblox = require("@pkg/ReactRoblox")
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
local ReactRoblox = require(Example.Parent.Packages.ReactRoblox)
local constants = require(Example.Parent.constants)

local stories = {}

stories.Primary = function()
return React.createElement("ScrollingFrame", {
Size = UDim2.fromScale(1, 1),
}, {
Label = React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 1),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
}),
})
end

return {
summary = "ScrollingFrame test for the story preview",
react = React,
reactRoblox = ReactRoblox,
story = function()
return React.createElement("ScrollingFrame", {
Size = UDim2.fromScale(1, 1),
}, {
Label = React.createElement("TextLabel", {
Size = UDim2.fromScale(1, 1),
AutomaticSize = Enum.AutomaticSize.None,

TextSize = 24,
Text = script.Name,
Font = Enum.Font.GothamBold,
}),
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
24 changes: 16 additions & 8 deletions example/Counter.story.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local Counter = require("./Counter")
local Roact = require("@pkg/Roact")
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
local constants = require(Example.Parent.constants)
local Counter = require(script.Parent.Counter)

local controls = {
increment = 1,
Expand All @@ -10,14 +13,19 @@ type Props = {
controls: typeof(controls),
}

local stories = {}

stories.Primary = function(props: Props)
return Roact.createElement(Counter, {
increment = props.controls.increment,
waitTime = props.controls.waitTime,
})
end

return {
summary = "A simple counter that increments every second",
controls = controls,
roact = Roact,
story = function(props: Props)
return Roact.createElement(Counter, {
increment = props.controls.increment,
waitTime = props.controls.waitTime,
})
end,
story = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then nil else stories.Primary,
stories = if constants.FLAG_ENABLE_COMPONENT_STORY_FORMAT then stories else nil,
}
Loading
Loading