### Manual Installation via Git Clone Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Clone the shadcn-rails repository and run bundle install and ./bin/dev for manual setup and local testing. ```sh git clone https://github.com/aviflombaum/shadcn-rails.git cd shadcn-rails bundle install ./bin/dev ``` -------------------------------- ### Install Tailwind CSS Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Run the Tailwind CSS installation generator to set up the necessary configuration files and directories. ```ruby ./bin/rails tailwindcss:install ``` -------------------------------- ### Install shadcn-ui Gem and Tailwind Animate Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Add the shadcn-ui gem to your Gemfile, install it, and then install tailwindcss-animate using npm. ```sh bundle add shadcn-ui bundle install npm install -d tailwindcss-animate ``` -------------------------------- ### Add shadcn-ui Gem Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Add the shadcn-ui gem to your Gemfile and install it. ```sh bundle add shadcn-ui bundle install ``` -------------------------------- ### Install Tailwind CSS Animate NPM Package Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Install the tailwindcss-animate npm package, which is required for component styling. This can be done via npm or by ensuring a package.json exists. ```sh npm install -D tailwindcss-animate ``` -------------------------------- ### Render Table Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt The `render_table` helper constructs accessible data tables. Use `table_head`, `table_header`, `table_body`, `table_row`, and `table_column` to structure the table content. This example shows rendering a list of users with edit links. ```erb <%= render_table do %> <%= table_head do %> <%= table_header "Name" %> <%= table_header "Email" %> <%= table_header "Role" %> <%= table_header "Actions" %> <% end %> <%= table_body do %> <% @users.each do |user| <%= table_row do %> <%= table_column user.name %> <%= table_column user.email %> <%= table_column user.role.humanize %> <%= table_column do %> <%= render_button "Edit", variant: :ghost, as: :a, href: edit_user_path(user) %> <% end %> <% end %> <% end %> <% end %> <% end %> ``` -------------------------------- ### Configure tailwind.config.js Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Customize your Tailwind CSS configuration by defining content paths, theme settings, and extending default styles. This example includes color palettes, typography, and animation configurations. ```javascript const defaultTheme = require("tailwindcss/defaultTheme"); module.exports = { darkMode: ["class"], content: [ "./public/*.html", "./app/helpers/**/*.rb", "./app/javascript/**/*.js", "./app/views/**/*.{erb,haml,html,slim}", ], theme: { container: { center: true, padding: "2rem", screens: { "2xl": "1400px", }, }, extend: { colors: { border: "hsl(var(--border))", input: "hsl(var(--input))", ring: "hsl(var(--ring))", background: "hsl(var(--background))", foreground: "hsl(var(--foreground))", primary: { DEFAULT: "hsl(var(--primary))", foreground: "hsl(var(--primary-foreground))", }, secondary: { DEFAULT: "hsl(var(--secondary))", foreground: "hsl(var(--secondary-foreground))", }, destructive: { DEFAULT: "hsl(var(--destructive))", foreground: "hsl(var(--destructive-foreground))", }, muted: { DEFAULT: "hsl(var(--muted))", foreground: "hsl(var(--muted-foreground))", }, accent: { DEFAULT: "hsl(var(--accent))", foreground: "hsl(var(--accent-foreground))", }, popover: { DEFAULT: "hsl(var(--popover))", foreground: "hsl(var(--popover-foreground))", }, card: { DEFAULT: "hsl(var(--card))", foreground: "hsl(var(--card-foreground))", }, }, borderRadius: { lg: "var(--radius)", md: "calc(var(--radius) - 2px)", sm: "calc(var(--radius) - 4px)", }, fontFamily: { sans: ["var(--font-sans)", ...defaultTheme.fontFamily.sans], }, keyframes: { "accordion-down": { from: { height: 0 }, to: { height: "var(--radix-accordion-content-height)" }, }, "accordion-up": { from: { height: "var(--radix-accordion-content-height)" }, to: { height: 0 }, }, }, animation: { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, }, }, plugins: [ require("@tailwindcss/forms"), require("@tailwindcss/aspect-ratio"), require("@tailwindcss/typography"), require("@tailwindcss/container-queries"), require("tailwindcss-animate"), ], }; ``` -------------------------------- ### List Available shadcn-ui Components Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/generators.html.md Run this command to see a list of all available shadcn-ui components that can be generated. ```ruby rails g shadcn-ui ``` -------------------------------- ### List All Available shadcn-ui Components Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Run the generator without arguments to list all available shadcn-ui components that can be generated. ```sh rails generate shadcn-ui ``` -------------------------------- ### Tailwind CSS Configuration with shadcn/ui Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Configure your tailwind.config.js to include shadcn.tailwind.js and necessary plugins like tailwindcss-animate. ```js const defaultTheme = require("tailwindcss/defaultTheme"); const shadcnConfig = require("./shadcn.tailwind.js"); module.exports = { content: [ "./public/*.html", "./app/helpers/**/*.rb", "./app/javascript/**/*.js", "./app/views/**/*.{erb,haml,html,slim}", ], theme: { extend: { fontFamily: { sans: ["Inter var", ...defaultTheme.fontFamily.sans], }, }, }, plugins: [ require("@tailwindcss/forms"), require("@tailwindcss/aspect-ratio"), require("@tailwindcss/typography"), require("@tailwindcss/container-queries"), require("tailwindcss-animate"), ], ...shadcnConfig, }; ``` -------------------------------- ### Render Tabs Interface Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Use `render_tabs` to create a tabbed interface. Define tabs with `tab_list` and `tab`, and their content with `tab_panels` and `tab_panel`. Ensure `active` attributes are correctly set for initial display. ```erb <%= render_tabs do %> <% tab_list do %> <%= tab "Account", active: true, id: "tab_account" %> <%= tab "Password", id: "tab_password" %> <% end %> <% tab_panels do %> <%= tab_panel active: true, id: "tab_account" do %>
Manage your account details here.
<% end %> <%= tab_panel id: "tab_password" do %> <%= render_input name: "current_password", label: "Current Password", type: :password %> <%= render_input name: "new_password", label: "New Password", type: :password %> <%= render_button "Update Password" %> <% end %> <% end %> <% end %> ``` -------------------------------- ### Alternative shadcn.tailwind.js Integration Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Use shadcnConfig directly as your Tailwind configuration if you only need the default settings provided by shadcn-rails. ```js const shadcnConfig = require("./shadcn.tailwind.js"); module.exports = { ...shadcnConfig, }; ``` -------------------------------- ### Generate a Specific shadcn-ui Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Use the rails generate command to copy the source files for a specific component, like 'button', into your Rails application. ```sh rails generate shadcn-ui button ``` -------------------------------- ### Integrate shadcn.tailwind.js into tailwind.config.js Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Require and expand the shadcn.tailwind.js configuration within your project's tailwind.config.js file to apply necessary settings. ```js const defaultTheme = require("tailwindcss/defaultTheme"); const shadcnConfig = require("./shadcn.tailwind.js"); module.exports = { content: [ "./public/*.html", "./app/helpers/**/*.rb", "./app/javascript/**/*.js", "./app/views/**/*.{erb,haml,html,slim}", ], theme: { extend: { fontFamily: { sans: ["Inter var", ...defaultTheme.fontFamily.sans], }, }, }, plugins: [ require("@tailwindcss/forms"), require("@tailwindcss/aspect-ratio"), require("@tailwindcss/typography"), require("@tailwindcss/container-queries"), ], ...shadcnConfig, }; ``` -------------------------------- ### Render Input Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt The `render_input` helper creates styled text inputs. It supports labels, placeholders, types, and standard HTML attributes like `required` and `autofocus`. Use the `variant` option for different styles, such as `:borderless`. ```erb <%# Basic labeled text input %> <%= render_input name: "email", label: "Email Address", type: :email, placeholder: "you@example.com" %> <%# Required input with autofocus %> <%= render_input name: "username", label: "Username", required: true, autofocus: true %> <%# Borderless variant (e.g. for inline editing) %> <%= render_input name: "search", placeholder: "Search...", variant: :borderless %> <%# Disabled input with pre-filled value %> <%= render_input name: "plan", label: "Current Plan", value: "Pro", disabled: true %> ``` -------------------------------- ### Dialog Component Helper Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/helpers.html.md Defines the render_dialog, dialog_trigger, and dialog_content methods for the dialog component. The render_dialog method captures block content and passes it to the dialog partial. dialog_trigger and dialog_content use content_for to manage inner content. ```ruby module Components::DialogHelper def render_dialog(**options, &block) content = capture(&block) if block render "components/ui/dialog", content: content, **options end def dialog_trigger(&block) content_for :dialog_trigger, capture(&block), flush: true end def dialog_content(&block) content_for :dialog_content, capture(&block), flush: true end end ``` -------------------------------- ### `render_tooltip` — Tooltip Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a hover-triggered tooltip with a trigger and floating content. ```APIDOC ## `render_tooltip` — Tooltip Component Renders a hover-triggered tooltip with a trigger and floating content. ### Usage Example: ```erb <%= render_tooltip do %> <% tooltip_trigger do %> <%= render_button "?", variant: :ghost %> <% end %> <% tooltip_content class: "max-w-xs" do %>Your password must be at least 8 characters.
<% end %> <% end %> ``` ``` -------------------------------- ### Render Accordion Component Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Use this helper to render an accordion component within your views after copying the necessary files. It accepts a title and description for the accordion content. ```erb <%%= render_accordion title: "Did you know?", description: "You can wrap shadcn helpers in any component library you want!" %> ``` -------------------------------- ### Render Tooltip Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a hover-triggered tooltip. Requires a trigger and floating content. ```erb <%= render_tooltip do %> <% tooltip_trigger do %> <%= render_button "?", variant: :ghost %> <% end %> <% tooltip_content class: "max-w-xs" do %>Your password must be at least 8 characters.
<% end %> <% end %> ``` -------------------------------- ### Render a Default Button Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Render a default primary button with the text 'Save Changes' using the `render_button` helper. ```erb <%# Default primary button %> <%= render_button "Save Changes" %> ``` -------------------------------- ### Shadcn Form Builder with render_form_with and render_form_for Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Wraps Rails' form builders to automatically render styled shadcn components with error states. Use for new records or editing existing ones. ```erb <%# New record form %> <%= render_form_with model: @user, url: users_path do |f| %>Your session has expired. Please sign in again.
<% end %> ``` ```erb <%# Success and info variants %> <%= render_alert title: "Saved!", variant: :success, description: "Your changes have been saved." %> <%= render_alert title: "Note", variant: :info, icon: false, description: "No icon shown here." %> <%= render_alert title: "Warning", variant: :attention, description: "Action required." %> ``` -------------------------------- ### Configure Global Stylesheet Source: https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md Add Tailwind directives and CSS variables to your application's main Tailwind CSS file to define base styles and color themes for both light and dark modes. ```css @tailwind base; @tailwind components; @tailwind utilities; @layer base { :root { --background: 0 0% 100%; --foreground: 222.2 47.4% 11.2%; --muted: 210 40% 96.1%; --muted-foreground: 215.4 16.3% 46.9%; --popover: 0 0% 100%; --popover-foreground: 222.2 47.4% 11.2%; --border: 214.3 31.8% 91.4%; --input: 214.3 31.8% 91.4%; --card: 0 0% 100%; --card-foreground: 222.2 47.4% 11.2%; --primary: 222.2 47.4% 11.2%; --primary-foreground: 210 40% 98%; --secondary: 210 40% 96.1%; --secondary-foreground: 222.2 47.4% 11.2%; --accent: 210 40% 96.1%; --accent-foreground: 222.2 47.4% 11.2%; --destructive: 0 100% 50%; --destructive-foreground: 210 40% 98%; --ring: 215 20.2% 65.1%; --radius: 0.5rem; } .dark { --background: 224 71% 4%; --foreground: 213 31% 91%; --muted: 223 47% 11%; --muted-foreground: 215.4 16.3% 56.9%; --accent: 216 34% 17%; --accent-foreground: 210 40% 98%; --popover: 224 71% 4%; --popover-foreground: 215 20.2% 65.1%; --border: 216 34% 17%; --input: 216 34% 17%; --card: 224 71% 4%; --card-foreground: 213 31% 91%; --primary: 210 40% 98%; --primary-foreground: 222.2 47.4% 1.2%; --secondary: 222.2 47.4% 11.2%; --secondary-foreground: 210 40% 98%; --destructive: 0 63% 31%; --destructive-foreground: 210 40% 98%; --ring: 216 34% 17%; --radius: 0.5rem; } } @layer base { * { @apply border-border; } body { @apply bg-background text-foreground; font-feature-settings: "rlig" 1, "calt" 1; } } ``` -------------------------------- ### `render_form_with` / `render_form_for` — shadcn Form Builder Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Wraps Rails' `form_with` and `form_for` with `Shadcn::FormBuilder`, so all standard form helper methods automatically render styled shadcn components with integrated error states. ```APIDOC ## `render_form_with` / `render_form_for` — shadcn Form Builder Wraps Rails' `form_with` and `form_for` with `Shadcn::FormBuilder`, so all standard form helper methods (`text_field`, `email_field`, `password_field`, `text_area`, `label`, `submit`) automatically render styled shadcn components with integrated error states. ### Usage Examples: ```erb <%# New record form %> <%= render_form_with model: @user, url: users_path do |f| %>This action cannot be undone.
<% end %> <% alert_dialog_cancel do %> <%= render_button "Cancel", variant: :outline %> <% end %> <% alert_dialog_continue do %> <%= link_to "Yes, delete", record_path(@record), method: :delete, class: "..." %> <% end %> <% end %> ``` -------------------------------- ### Render Card Component in Rails Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a card container with optional title, subtitle, body, and footer sections. The body can accept a string or a block for complex content. ```erb <%# Simple card with all sections as arguments %> <%= render_card title: "Team Plan", subtitle: "$29/month", body: "Up to 10 members, advanced analytics, and priority support.", footer: "Billed annually" %> ``` ```erb <%# Card with block body for rich content %> <%= render_card title: "Recent Activity" do %>Starred repositories (3)
<% end %> <% collapsible_body do %>Yes — copy the files into your project and edit them freely.
<% end %> ``` ```erb <%# Using named content helpers for full control %> <%= render_accordion do %> <% accordion_title do %>Custom Title<% end %> <% accordion_description do %>Rich description content here.<% end %> <% end %> ``` -------------------------------- ### Render Combobox Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a searchable select/combobox widget. Items are passed as an array, and the trigger button appearance can be customized. ```erb <% frameworks = [ { value: "rails", label: "Ruby on Rails" }, { value: "django", label: "Django" }, { value: "laravel", label: "Laravel" } ] %> <%= render_combobox frameworks do %> <% combobox_trigger do %> <%= render_button "Select framework...", variant: :outline %> <% end %> <% end %> ``` -------------------------------- ### Render Sheet (Slide-over Panel) Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a slide-over panel from the left or right edge. Requires a trigger and content slot. ```erb <%# Left-sliding sheet (default) %> <%= render_sheet direction: "left", width: "w-1/2" do %> <% sheet_trigger do %> <%= render_button "Open Menu", variant: :outline %> <% end %> <% sheet_content do %> <% end %> <% end %> ``` ```erb <%# Right-sliding sheet %> <%= render_sheet direction: "right", width: "w-96" do %> <% sheet_trigger do %> <%= render_button "Cart (3)", variant: :ghost %> <% end %> <% sheet_content do %> <%# cart items %> <% end %> <% end %> ``` -------------------------------- ### Render Textarea Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Use `render_textarea` for multi-line text inputs. It accepts a `label`, `placeholder`, `rows` attribute, and standard HTML textarea attributes. It can also be pre-filled with a `value` and set to `readonly`. ```erb <%# Simple textarea with label %> <%= render_textarea name: "bio", label: "About You", placeholder: "Tell us about yourself..." %> <%# Larger textarea, required %> <%= render_textarea name: "message", label: "Message", rows: 6, required: true %> <%# Pre-filled read-only textarea %> <%= render_textarea name: "notes", value: @record.notes, readonly: true %> ``` -------------------------------- ### `render_popover` — Popover Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a floating content panel anchored to a trigger element. ```APIDOC ## `render_popover` — Popover Component Renders a floating content panel anchored to a trigger element. ### Usage Example: ```erb <%= render_popover do %> <% popover_trigger do %> <%= render_button "More info", variant: :outline %> <% end %> <% popover_content class: "w-64" do %>This action will permanently delete the record.
<% end %> <% end %> ``` ``` -------------------------------- ### Render Label Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Use `render_label` to create styled HTML labels associated with form inputs. It takes a `name` attribute corresponding to the input's ID and a `label` text. Custom classes can be applied. ```erb <%= render_label name: "user[email]", label: "Email Address" %> <%= render_label name: "post[title]", label: "Post Title", class: "text-destructive" %> ``` -------------------------------- ### Safely Merge Tailwind CSS Classes with `tw()` Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Use the `tw()` helper function to merge multiple Tailwind CSS class strings, resolving conflicts. It's available via ComponentsHelper. ```ruby # In any helper or component tw("px-4 py-2", "px-6") # => "py-2 px-6" (conflict resolved) tw("bg-primary text-sm", nil, "text-lg") # => "bg-primary text-lg" tw(ComponentsHelper::PRIMARY_CLASSES, "opacity-50") # => "bg-primary text-primary-foreground hover:bg-primary/80 opacity-50" ``` -------------------------------- ### Render Popover Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a floating content panel anchored to a trigger element. Use for contextual information or actions. ```erb <%= render_popover do %> <% popover_trigger do %> <%= render_button "More info", variant: :outline %> <% end %> <% popover_content class: "w-64" do %>This action will permanently delete the record.
<% end %> <% end %> ``` -------------------------------- ### Render Dialog (Modal) Component in Rails Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a modal dialog with a trigger element and a content area using `content_for`-style slots. Requires a trigger and content block. ```erb <%= render_dialog do %> <% dialog_trigger do %> <%= render_button "Open Settings" %> <% end %> <% dialog_content do %>Update your account preferences below.
<%= render_input name: "username", label: "Username", value: current_user.username %> <%= render_button "Save", variant: :default %> <% end %> <% end %> ``` -------------------------------- ### `render_sheet` — Sheet (Slide-over Panel) Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a slide-over panel from the left or right edge with a trigger and content slot. ```APIDOC ## `render_sheet` — Sheet (Slide-over Panel) Component Renders a slide-over panel from the left or right edge with a trigger and content slot. ### Usage Examples: ```erb <%# Left-sliding sheet (default) %> <%= render_sheet direction: "left", width: "w-1/2" do %> <% sheet_trigger do %> <%= render_button "Open Menu", variant: :outline %> <% end %> <% sheet_content do %> <% end %> <% end %> <%# Right-sliding sheet %> <%= render_sheet direction: "right", width: "w-96" do %> <% sheet_trigger do %> <%= render_button "Cart (3)", variant: :ghost %> <% end %> <% sheet_content do %> <%# cart items %> <% end %> <% end %> ``` ``` -------------------------------- ### Render Collapsible Component Source: https://context7.com/aviflombaum/shadcn-rails/llms.txt Renders a toggle-to-reveal section. Provides a visible preview and an expandable hidden body. ```erb <%= render_collapsible do %> <% collapsible_preview do %>Starred repositories (3)
<% end %> <% collapsible_body do %><%= @user.bio %>
<%= @user.bio %>