Replies: 3 comments 4 replies
-
I agree that they're very similar but also quite different. I'm not sure that the ViewComponent gem, which might one day still be merged into Rails, would want to take on all the extra Storybook logic. In the end you're using one or the other I don't see much of a use case for flipping between the two. Do others see it differently? |
Beta Was this translation helpful? Give feedback.
-
There's often a lot of boilerplate code to write for both when doing this, which does become a little tiring: # spec/components/stories/header/component_stories.rb
module Header
class ComponentStories < ViewComponent::Storybook::Stories
self.title = 'Header Component'
story(:default) do
controls do
text(:title, 'Title of the header')
select(:variant, %i[display one two], :display)
end
end
story(:display) {}
story(:header_one) {}
story(:header_two) {}
end
end # test/components/previews/header/component_preview.rb
module Header
class ComponentPreview < ViewComponent::Preview
def default(title:, variant:)
render(Header::Component.new(title: title, variant: variant))
end
def display
default(title: 'Display header', variant: :display)
end
def header_one
default(title: 'Header One', variant: :one)
end
def header_two
default(title: 'Header Two', variant: :two)
end
end
end Unless I'm doing this completely wrong? (Note: I'm using sidecars). |
Beta Was this translation helpful? Give feedback.
-
Coming back to this discussion. I just posted a proposal for a newer API for this gem which would have Storybook Stories just be a subclass of ViewComponent::Preview. Would love your thoughts on it #150 |
Beta Was this translation helpful? Give feedback.
-
All in all they're not very different, and I see as an improvement to be able to include a module in a preview and have the controls DSL included as long as retaining their function as classic previews.
Beta Was this translation helpful? Give feedback.
All reactions