- Ensure that your app uses a node-based (i.e.
package.jsonexists) asset pipeline with Tailwind and esbuild. (TODO: Check whether other JS bundlers work)- You can create a new app that's set up correctly by passing
-j esbuild -c tailwindtorails new - Or, you can use
cssbundling-railsandjsbundling-railsto installtailwindandesbuildrespectively.
- You can create a new app that's set up correctly by passing
- Add the CfA UI Components gem by adding
gem "cfa_ui_components", github: "codeforamerica/cfa-ui-components"to yourGemfile, and runbundle install - Run
bin/rails g cfa_ui_components:install
The gem ships a CfaFormBuilder that renders CfA input components via a single input helper. Its API is inspired by simple_form — but it's a thin shim over the CfA components, not a wrapper around simple_form itself, so don't expect simple_form's wrappers, custom inputs, or config to be available.
Opt in per form:
<%= form_with model: @user, builder: CfaFormBuilder do |f| %>
<%= f.input :name %>
<%= f.input :email, as: :text %>
<%= f.input :state, as: :select, options: us_states %>
<%= f.input :birthdate, as: :date %>
<% end %>Or set it as the app default in ApplicationController:
default_form_builder CfaFormBuilderSupported as: values: :text, :currency, :select, :combobox, :tin, :checkbox, :radios, :date. The optional flag is inferred from presence/acceptance validators on the model.
- Run
bin/rails g view_component:component <COMPONENT_NAME>to create all the relevant files. - Make local changes
- Make local changes
- Run
gem build cfa_ui_components.gemspec && gem install cfa_ui_componentsto build the gem & install it locally - In your Rails app,
- Modify the Gemfile to use the locally-installed cfa_ui_components gem.
gem "cfa_ui_components"
- Run
bundle update cfa_ui_components - Ensure that you switch the Gemfile back to github & update again before merging your PR.
- Modify the Gemfile to use the locally-installed cfa_ui_components gem.
Run bin/dev and navigate to localhost:3000
We use mise to manage Ruby and Node versions (replaces rbenv/nvm):
brew install mise
# set mise to use legacy dotfiles like .ruby-version and .node-version
mise settings add idiomatic_version_file_enable_tools ruby
mise settings add idiomatic_version_file_enable_tools nodeFollow the mise activation instructions for your shell. e.g. for zsh:
echo 'eval "$(mise activate zsh)"' >> ~/.zshrc
source ~/.zshrcThen, from the project directory:
mise install # installs Ruby and NodeInstall lefthook and enable the git hooks:
brew install lefthook
lefthook installLefthook runs rubocop and erb_lint on pre-commit. To run manually:
bin/rubocop --autocorrect
bundle exec erb_lint --autocorrect 'app/**/*.erb'