Skip to content

A comprehensive Rails 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.

Notifications You must be signed in to change notification settings

jetrockets/ui.jetrockets.com

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rails UI Component Library

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.

πŸš€ Quick Start

Requirements

  • Ruby 3.4.4+
  • Rails 7.0+
  • Node.js 18+
  • ViewComponent gem
  • TailwindCSS 4.0

Installation

  1. Clone the repository:
git clone <repository-url>
cd ui.jetrockets.com
  1. Install dependencies:
bundle install
yarn install
  1. Setup database:
bin/rails db:setup
  1. Start development servers:
bin/rails server
yarn dev  # or bin/vite dev

πŸ—οΈ Architecture

Component Structure

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

Key Features

  • 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

Base Architecture

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

πŸ’‘ Usage Examples

Basic Button

<%= render Ui::Btn::Component.new(variant: :primary, size: :lg) do %>
  Click me
<% end %>

Card with Header and Footer

<%= 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 %>

Table with Pagination

<%= 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) %>

πŸ› οΈ Development Workflow

Customizing Components

  1. Copy the component folder to your project
  2. Modify the CSS classes in component.css
  3. Adjust the Ruby logic in component.rb
  4. Update Stimulus behavior in component_controller.js

Adding New Variants

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

Styling Guidelines

  • 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

πŸ”§ Development Commands

Build and Development

yarn dev          # Start Vite development server
yarn build        # Build assets for production
yarn standard     # Run JavaScript StandardJS linting

Rails Commands

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

Quality Assurance

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

πŸ“ File Structure

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

🎯 Key Technologies

  • 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)

πŸ“ Contributing

When using this template:

  1. Copy Components - Take only what you need for your project
  2. Customize Styling - Adapt colors, spacing, and styling to your brand
  3. Extend Functionality - Add new variants and features as needed
  4. Follow Patterns - Maintain the established component architecture
  5. Test Thoroughly - Ensure components work in your specific use case

πŸ“„ License

This template is open source and available for use in your projects. Components can be freely copied, modified, and distributed.

🀝 Support

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).

About

A comprehensive Rails 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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5