Install in your Rails project
Requirements
- Ruby >= 3.4
- Rails >= 7.1
- ViewComponent >= 3.20.0 (installed automatically as a dependency)
Installation
Add to Gemfile:
gem "midwest", github: "unabridged/midwest", branch: "main"Run installer:
bin/rails midwest:installThe installer handles the following automatically:
- Adds the Midwest stylesheet to your application layout
- Adds
midwest_body_stylesto your<body>tag for CSS custom property support - Pins
midwest-view-componentsvia importmap (or adds it via yarn for esbuild/webpack setups) - Includes
Midwest::ViewHelperandMidwest::UrlHelperinApplicationHelper - Registers Midwest Stimulus controllers
Configuring the design system
Set application-wide design defaults from an initializer. Because
midwest_body_styles renders these onto your <body> as CSS custom
properties, they cascade over the values shipped in the stylesheet for the
whole page — while any per-call component option still wins locally.
# config/initializers/midwest.rbMidwest.configure do |config| # Motion "design feel" — keywords resolve to design tokens, or pass raw CSS. config.motion.duration = :slow # => var(--duration-slow) config.motion.distance = :xl # => var(--space-2xl) config.motion.easing = :emphasized # => var(--ease-emphasized) config.motion.scale = 0.9 # raw values pass throughendThe same Midwest.configure block works in a Bridgetown app (place it in
config/initializers.rb).
Development
To get started contributing to the library:
- Run:
bundle install - Run:
yarn install - Run:
bin/dev
This opens the demo app with component previews at localhost:4000. Component previews are in demo/app/previews.
To run tests:
bin/test # all appraisals on the current Ruby versionbin/test --all # full matrix: Ruby 3.3, 3.4, 4.0 × Rails 7 & 8bin/test --rails 8 # Rails 8 only, current Rubybin/test --rails 8 --ruby 4.0 # Rails 8 on Ruby 4.0 onlyTo generate new components:
bin/rails midwest:generate:component YourComponent