viewcomponent-coder

Create and test reusable ViewComponent-based UI components in Rails.

47|11|Updated Nov 26, 2025
One-click install
npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill viewcomponent-coder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: viewcomponent-coder
Source: https://github.com/majesticlabs-dev/majestic-marketplace/tree/main/plugins/majestic-rails/skills/viewcomponent-coder
Command: npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill viewcomponent-coder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Builds reusable UI components with ViewComponent and view_component-contrib, promoting slots, style variants, and component previews.

Core Features & Use Cases

  • Base components, slots, and variants
  • Lookbook previews for component previews
  • Testing components in isolation
  • Patterns for composition and Turbo/Hotwire integration

Quick Start

Create a simple ButtonComponent with slots and preview it in Lookbook.

Frequently Asked Questions about viewcomponent-coder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build reusable UI components in Rails using ViewComponent?

ViewComponent is a framework for creating encapsulated, testable UI components in Rails. It replaces partials with component classes, enabling slots for flexible content injection, style variants for multiple appearances, and isolated testing. This approach keeps components modular and prevents tight coupling to view logic.

What are slots in ViewComponent and how do I use them?

Slots are named content areas within a ViewComponent that accept flexible content from parent templates. Instead of passing data through partials, slots let you define what content goes where—headers, bodies, footers—making components reusable across different layouts without parameter explosion.

How do I create component previews with Lookbook?

Lookbook generates interactive preview pages for your ViewComponents, letting you showcase variants, slots, and edge cases without running the full Rails app. It integrates directly with ViewComponent to auto-document component behavior and helps validate design consistency across your UI library.

Can I test ViewComponent components in isolation?

Yes, ViewComponent supports isolated unit testing through RSpec or Minitest. You test component rendering, slot behavior, and variant logic independently without loading entire Rails views, making tests faster and more focused on component behavior.

Should I refactor all my Rails partials into ViewComponents?

Refactoring partials to ViewComponents works best for reusable, stateful UI patterns—buttons, cards, modals, form fields. Simple one-off template snippets don't need the overhead. Prioritize partials that are used multiple times or need variant logic, style customization, or isolated testing.

Does ViewComponent work with Turbo and Hotwire?

ViewComponent integrates with Turbo and Hotwire for dynamic updates. Components render predictably on server and integrate with Turbo Streams for partial page replacement, making them suitable for real-time UI patterns without JavaScript framework lock-in.