Skip to content

Commit

Permalink
Fix readme; missed mounting the Previews engine; bump to 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Barone committed Sep 13, 2024
1 parent ff00095 commit f4a422c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,29 @@ Restart your processes (stop and restart `./bin/dev`) and viola! Opens up a Stor

## Usage

Write a preview for your component, just like normal - but include the StoryBook::Preview module. You can also use the `PartialPreviewComponent` to render regular Rails partials as previews.
Write [rails-previews](https://github.com/rangerscience/rails-previews) for your partials, view components, and react-on-rails components -

```ruby
class ExampleComponentPreview < ViewComponent::Preview
include Storybook::Preview
def default
render(ExampleComponent.new(title: "title"))
end

def default
render(PartialPreviewComponent.new(partial: "application/example"))
module Previews
class Example < Rails::Previews::Preview
def partial
render_partial "application/example", title: "Hello, World!"
end

def view_component
ExampleComponent.new(title: "Hello, World!")
end

def react_component
render_react_on_rails "HelloWorld", name: "Hello, World!"
end
end
end
```
Note that the module will set the preview's layout to `storybook`, as there's steps to be done to make it look good (and work!) inside of Storybook.

Then run `rake storybook:stories` to generate the CSF JSON that Storybook uses to find your previews.

And... that's it! :D

And... that's it! :D Just turn on Storybook to see your examples :)

## Development

Expand Down
4 changes: 4 additions & 0 deletions lib/generators/storybook/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def install_rack_cors
RUBY
end

def mount_previews
insert_into_file "config/routes.rb", " mount Rails::Previews::Engine => \"/previews\"\n", after: "Rails.application.routes.draw do\n"
end

def update_storybook
# Main.js
insert_into_file ".storybook/main.js", "\n \"@storybook/server\",", after: "addons: ["
Expand Down
2 changes: 1 addition & 1 deletion lib/storybook/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

module Storybook
VERSION = "0.2.0"
VERSION = "0.2.1"
end

0 comments on commit f4a422c

Please sign in to comment.