A comprehensive Rails 7 component library built with ViewComponent, TailwindCSS 4.0, and Stimulus. This template provides a complete set of reusable UI components that developers can copy and customize for their projects.
- Ruby 3.4.4+
- Rails 7.0+
- Node.js 18+
- ViewComponent gem
- TailwindCSS 4.0
- Clone the repository:
git clone <repository-url>
cd ui.jetrockets.com
- Install dependencies:
bundle install
yarn install
- Setup database:
bin/rails db:setup
- Start development servers:
bin/rails server
yarn dev # or bin/vite dev
Each component follows a consistent pattern:
app/components/ui/[component_name]/
βββ component.rb # Main component class
βββ component.html.erb # Template (when needed)
βββ component.css # Component-specific styles
βββ component_controller.js # Stimulus controller (when needed)
βββ [nested_components]/ # Sub-components
- ViewComponent Integration - Server-side component rendering
- TailwindCSS 4.0 - Utility-first CSS with custom component styles
- Stimulus Controllers - Client-side behavior and interactivity
- Turbo Compatible - Works seamlessly with Turbo Drive and Frames
- Responsive Design - Mobile-first responsive components
- Accessibility - ARIA attributes and keyboard navigation support
All components inherit from ApplicationComponent
which extends ViewComponent::Base
:
class ApplicationComponent < ViewComponent::Base
# Shared component functionality
end
Components are namespaced under the Ui::
module:
class Ui::Button::Component < ApplicationComponent
def initialize(variant: :primary, size: :md, **options)
@variant = variant
@size = size
@options = options
end
end
<%= render Ui::Btn::Component.new(variant: :primary, size: :lg) do %>
Click me
<% end %>
<%= render Ui::Card::Component.new do %>
<%= render Ui::Card::Header::Component.new do %>
Card Title
<% end %>
<p>Card content goes here</p>
<%= render Ui::Card::Footer::Component.new do %>
<div class="flex justify-end gap-2">
<%= render Ui::Btn::Component.new(variant: :secondary) { "Cancel" } %>
<%= render Ui::Btn::Component.new(variant: :primary) { "Save" } %>
</div>
<% end %>
<% end %>
<%= render Ui::Table::Component.new do %>
<%= render Ui::Table::Thead::Component.new do %>
<%= render Ui::Table::Tr::Component.new do %>
<%= render Ui::Table::Th::Component.new { "Name" } %>
<%= render Ui::Table::Th::Component.new { "Email" } %>
<%= render Ui::Table::Th::Component.new { "Actions" } %>
<% end %>
<% end %>
<%= render Ui::Table::Tbody::Component.new do %>
<% @users.each do |user| %>
<%= render Ui::Table::Tr::Component.new do %>
<%= render Ui::Table::Td::Component.new { user.name } %>
<%= render Ui::Table::Td::Component.new { user.email } %>
<%= render Ui::Table::Td::Component.new do %>
<%= render Ui::Btn::Component.new(size: :sm, variant: :outline) { "Edit" } %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= render Ui::Pagy::Component.new(pagy: @pagy) %>
- Copy the component folder to your project
- Modify the CSS classes in
component.css
- Adjust the Ruby logic in
component.rb
- Update Stimulus behavior in
component_controller.js
Components support variants through CSS classes:
def initialize(variant: :primary, size: :md, **options)
@variant = variant
@size = size
end
private
def css_classes
class_names(
"btn",
"btn-#{@variant}",
"btn-#{@size}",
@options[:class]
)
end
- Use TailwindCSS utilities for basic styling
- Create component-specific CSS for complex interactions
- Follow BEM-like naming for component CSS classes
- Maintain responsive design principles
yarn dev # Start Vite development server
yarn build # Build assets for production
yarn standard # Run JavaScript StandardJS linting
bin/rails server # Start Rails development server
bin/rails console # Open Rails console
bin/vite dev # Alternative Vite dev server
bin/vite build # Alternative Vite build
bundle exec rubocop # Ruby code style checks
bundle exec brakeman # Security analysis
bundle exec bundler-audit # Vulnerability checks
bundle exec erb_lint # ERB template linting
app/
βββ components/ui/ # UI Components library
β βββ accordion/ # Accordion component
β βββ alert/ # Alert component
β βββ avatar/ # Avatar component
β βββ badge/ # Badge component
β βββ btn/ # Button component
β βββ btn_group/ # Button group component
β βββ card/ # Card component with sub-components
β βββ clipboard/ # Clipboard component
β βββ drawer/ # Drawer component
β βββ dropdown/ # Dropdown component with sub-components
β βββ flash/ # Flash message component
β βββ icon/ # Icon component
β βββ modal/ # Modal component
β βββ pagy/ # Pagination component
β βββ popover/ # Popover component with sub-components
β βββ table/ # Table component with sub-components
β βββ tabs/ # Tabs component
β βββ tooltip/ # Tooltip component
β βββ turbo_confirm/ # Turbo confirmation component
βββ assets/
β βββ controllers/ # Stimulus controllers
β βββ entrypoints/ # Vite entry points
β βββ stylesheets/ # Global styles
βββ views/
βββ layouts/ # Application layouts
- Rails 8.0 - Backend framework with modern features
- ViewComponent - Component-based architecture for views
- Vite - Fast build tool for frontend assets
- TailwindCSS 4.0 - Utility-first CSS framework
- Stimulus - Modest JavaScript framework
- Turbo - SPA-like page acceleration
- Pagy - Fast pagination gem
- Rodauth - Authentication framework (in template)
When using this template:
- Copy Components - Take only what you need for your project
- Customize Styling - Adapt colors, spacing, and styling to your brand
- Extend Functionality - Add new variants and features as needed
- Follow Patterns - Maintain the established component architecture
- Test Thoroughly - Ensure components work in your specific use case
This template is open source and available for use in your projects. Components can be freely copied, modified, and distributed.
This is a template library designed for copying components into your projects. Each component is self-contained and can be adapted to your needs.
For issues or questions about specific implementations, refer to the documentation of the underlying technologies (Rails, ViewComponent, TailwindCSS, Stimulus).