← 返回
未分类 中文

Tailwind Rails

Tailwind CSS component patterns for Ruby on Rails ERB views. Use when building UI components in Rails, creating shared partials, implementing dark mode, writ...
Ruby on Rails ERB 视图的 Tailwind CSS 组件模式。适用于在 Rails 中构建 UI 组件、创建共享局部视图、实现深色模式等场景。
djc00p djc00p 来源
未分类 clawhub v1.0.2 2 版本 100000 Key: 无需
★ 0
Stars
📥 445
下载
💾 2
安装
2
版本
#latest

概述

Tailwind CSS for Rails

Build consistent, dark-mode-ready component patterns in Rails ERB views using Tailwind utilities and reusable partials.

Quick Start

Add a class name helper to collapse conditional logic:

# app/helpers/application_helper.rb
def cn(*classes)
  classes.flatten.compact.join(' ').split.uniq.join(' ')
end

Use it in views to combine base and conditional classes:

<div class="<%= cn('px-4', active ? 'bg-blue-500' : 'bg-gray-200') %>">
  Content
</div>

Standard full-width container with responsive padding:

<div class="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
  <!-- Page content -->
</div>

Badge Pattern

<span class="inline-flex items-center rounded-full bg-green-100 px-3 py-1 text-sm font-medium text-green-800 dark:bg-green-900 dark:text-green-100">
  Label
</span>

Colors: Yellow=warning, Blue=info, Green=success, Red=danger, Gray=neutral

Light: bg-{color}-100 + text-{color}-800 | Dark: dark:bg-{color}-900 + dark:text-{color}-100

Common Components

Card with border and shadow:

<div class="rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-950">
  <div class="px-6 py-4">
    <!-- content -->
  </div>
</div>

Table wrapper with responsive shadow:

<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
  <table class="w-full divide-y divide-gray-200">
    <thead>...</thead>
    <tbody>...</tbody>
  </table>
</div>

Tab navigation with underline:

<nav class="flex space-x-8 border-b border-gray-300">
  <% tabs.each do |tab| %>
    <% active = current_tab == tab %>
    <%= link_to tab_path(tab),
        class: "py-2 px-1 border-b-2 font-medium text-sm #{active ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-600 hover:text-gray-700'}" do %>
      <%= tab.humanize %>
    <% end %>
  <% end %>
</nav>

Best Practices

  1. Use the cn() helper for all conditional class logic — it deduplicates and removes blanks.
  2. Pair light and dark classes alwaysbg-white dark:bg-gray-950, text-gray-900 dark:text-gray-100.
  3. Mobile-first responsive design — use sm:, md:, lg: prefixes for breakpoints.
  4. Extract repeated patterns into partials_badge.html.erb, _button.html.erb, _card.html.erb.
  5. Use semantic color names — yellow for warnings, green for success, red for errors.
  6. Ensure sufficient contrast in both light and dark modes.
  7. Test accessibility with screen readers and keyboard navigation.

References

  • references/components.md — Reusable badge, button, and card partials with usage examples.
  • references/dark-mode-responsive.md — Dark mode setup, responsive patterns, and animation utilities.

版本历史

共 2 个版本

  • v1.0.2 当前
    2026-05-03 06:38 安全 安全
  • v1.0.1
    2026-03-31 07:53

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Agent Cost Strategy

djc00p
分层模型选择与成本优化,适用于多智能体 AI 工作流。在为任务选择模型或启动子代理时使用此技能。
★ 0 📥 786
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 679 📥 328,394
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 182,148