Kanso Minimalist Banner

Kanso (簡素)

Kanso (簡素) is a Japanese design principle valuing clarity and the elimination of the non-essential. This UI component library is the embodiment of that idea: providing foundational, rigorously tested ViewComponents that act as respectful guests in your Rails application.

Prerequisites

Kanso is designed to integrate seamlessly into a standard Rails 7+ application. Please ensure your application is configured with:

  1. Hotwire (Turbo & Stimulus)
  2. Tailwind CSS (via the tailwindcss-rails gem)

Installation

  1. Add gem "kanso" to your Gemfile.
  2. Run bundle install.
  3. Run bin/rails g kanso:install.

This generator surgically and safely configures your application. It creates or modifies tailwind.config.js and updates your main stylesheet to be aware of Kanso's components and base styles without being destructive.


Component Catalogue

Each component is a self-contained, Hotwire-aware ViewComponent styled with Tailwind CSS. Interactive components include their own lightweight Stimulus controllers, which are automatically registered by the installer.


ButtonComponent

An abstraction for styled actions. It can render a simple tag (<button>, <a>) or, by leveraging Rails' button_to helper, generate a complete single-button form for server-side actions (DELETE, PATCH, etc.).

1. Usage (Simple Tag)

For links or client-side UI interactions.

<%# Renders a standard <button> %>
<%= render Kanso::ButtonComponent.new(theme: :primary) do %>
  Primary Action
<% end %>

<%# Renders an <a> tag %>
<%= render Kanso::ButtonComponent.new(tag: :a, href: dashboard_path) do %>
  Go to Dashboard
<% end %>

2. Usage (Action Form)

For any action requiring a form, like DELETE, PATCH, or POST.

<%# Generates a form with method: :delete %>
<%= render Kanso::ButtonComponent.new(theme: :danger, url: item_path(@item), method: :delete) do %>
  Delete Item
<% end %>

Options

  • theme: (Symbol): The style. Can be :primary, :danger, or :default. Defaults to :default.

  • For Simple Tag Mode:

    • tag: (Symbol): The HTML tag. Can be :button or :a. Defaults to :button.
    • href: (String): Required if tag: :a is used.
  • For Action Form Mode:

    • url: (String | UrlHelper): Activates button_to mode. The URL the form will submit to.
    • method: (Symbol): The HTTP method (e.g., :delete, :patch).

All other HTML options (id, `data-,form:, etc.) are passed through to the underlying