-
-
Notifications
You must be signed in to change notification settings - Fork 725
Creating new components
At OFN we now create components with ViewComponent
(https://viewcomponent.org/) and we develop it with Storybook
(https://storybook.js.org/). This wiki page is here to explain how it works, and what is the workflow of component creation.
Lots of convention and explanations are described here, on the official doc of ViewComponent: https://viewcomponent.org/guide/
Basically, we create component like this:
rails generate component ComponentName title --sidecar
This will generate a component:
- named
ComponentName
- with one attribute
title
- assets will be stored in a
component_name_component
folder.
This will create 3 files:
-
app/components/component_name_component.rb
: the code of this component -
app/components/component_name_component/component_name_component.html.haml
: the template of this component -
spec/components/component_name_component_spec.rb
: the spec of this component
Stories must be placed into the spec/components/stories
folder.
Here's an example for the new component created with two stories one testing with short text, the second one testing with long text.
# spec/components/stories/component_name_component_stories.rb
class ComponentNameComponentStories < ViewComponent::Storybook::Stories
story(:with_short_text) do
controls do
text(:title, 'OK')
end
end
story(:with_long_text) do
controls do
text(:title, 'This is a long text')
end
end
end
You can find more example on how to write stories: https://github.com/jonspalmer/view_component_storybook#usage
We use https://github.com/jonspalmer/view_component_storybook to create links between ViewComponent and Storybook.
view_component_storybook
provide an helper to create this link. Simply run:
rake view_component_storybook:write_stories_json
To create stories in json (which will be gitignored) that can be handled by Storybook.
Once stories are created and transformed into json, simple launch Storybook to view it:
yarn storybook
Enjoy! 🎉
NB: The web application must be running to serve the assets and the components
Development environment setup
- Pipeline development process
- Bug severity
- Feature template (epic)
- Internationalisation (i18n)
- Dependency updates
Development
- Developer Guidelines
- The process of review, test, merge and deploy
- Making a great commit
- Making a great pull request
- Code Conventions
- Database migrations
- Testing and Rspec Tips
- Automated Testing Gotchas
- Rubocop
- Angular and OFN
- Feature toggles
- Stimulus and Turbo
Testing
- Testing process
- OFN Testing Documentation (Handbooks)
- Continuous Integration
- Parallelized test suite with knapsack
- Karma
Releasing
Specific features
Data and APIs
Instance-specific configuration
External services
Design