Hakumi Components
ViewComponent-based UI library for Ruby on Rails — 65 components, Ant Design conventions, Stimulus controllers
Source Code
·
Playground
·
Report Bug
·
Changelog
Table of Contents
| About | What Hakumi Components is and why it exists |
| Installation | Gem and npm setup |
| Configuration | Initializer options |
| Usage | Basic examples |
| Components | All 65 components by category |
| JavaScript API | Programmatic control |
| Architecture | How components are structured |
| Development | Local playground, tests |
| Contributing | How to contribute |
About
Hakumi Components is a Rails UI component library built on ViewComponent, Stimulus, and SCSS. It follows Ant Design conventions and ships 65 server-rendered components with optional JavaScript interactivity. Light and dark themes are supported via CSS variables.
Stack: ViewComponent 3.0+, Stimulus 3.0+, Rails 7.1+, SCSS.
Installation
Requirements
- Ruby 3.0+
- Rails 7.1+
- Node.js 16.9+
- A JavaScript bundler (Vite, Webpack, esbuild)
- SCSS processor
Automatic (recommended)
Add the gem:
gem 'hakumi_components', '>= 0.1.0.pre'Run the installer:
bundle install
bin/rails generate hakumi:installThe generator detects your JavaScript entry point and SCSS setup, installs the npm package, and wires up imports automatically.
Manual
1. Add the gem:
gem 'hakumi_components', '>= 0.1.0.pre'2. Install the npm package:
yarn add @hakumi-dev/hakumi-components@pre
# or
npm install @hakumi-dev/hakumi-components@pre3. JavaScript:
import { Application } from "@hotwired/stimulus"
import HakumiComponents, { registerHakumiControllers } from "@hakumi-dev/hakumi-components"
const application = Application.start()
window.HakumiComponents = HakumiComponents
registerHakumiControllers(application)4. Stylesheets:
// Vite / Webpack
@use '@hakumi-dev/hakumi-components/styles';
// Sprockets
@import "@hakumi-dev/hakumi-components/styles";Configuration
# config/initializers/hakumi_components.rb
HakumiComponents.configure do |config|
config.default_form_builder = true # Use HakumiComponents::FormBuilder as default
config.base_path = "hakumi/components" # Base URL for modal/drawer routes
end| Option | Default | Description |
|---|---|---|
default_form_builder |
false |
Set HakumiComponents::FormBuilder as the application default |
base_path |
"hakumi/components" |
Base URL path for components that require server routes |
Usage
<%= render HakumiComponents::Button::Component.new(type: :primary) do %>
Save
<% end %>
<%= form_with model: @user, builder: HakumiComponents::FormBuilder do |f| %>
<%= f.text_field :email %>
<%= f.text_field :name %>
<%= f.submit "Save", type: :primary %>
<% end %>
<%= render HakumiComponents::Modal::Component.new(id: "confirm-modal", title: "Confirm") do %>
Are you sure?
<% end %>Components
65 components organized by category. Each links to its own documentation with API reference and examples.
General
Layout
Navigation
Data Entry
- Autocomplete
- Cascader
- Checkbox
- Color Picker
- Date Picker
- Form
- Input
- Input Number
- Mentions
- Radio
- Rate
- Select
- Slider
- Switch
- Time Picker
- Transfer
- Tree Select
- Upload
Data Display
- Avatar
- Badge
- Calendar
- Card
- Carousel
- Collapse
- Descriptions
- Empty
- Image
- Popover
- QR Code
- Segmented
- Statistic
- Table
- Tabs
- Tag
- Timeline
- Tooltip
- Tour
- Tree
Feedback
Other
JavaScript API
Interactive components expose a programmatic API:
// Via element
document.getElementById('my-modal').hakumiComponent.api.open()
document.getElementById('my-modal').hakumiComponent.api.close()
// Via global registry
window.HakumiComponents.get('my-modal').open()| Component type | Methods |
|---|---|
| Toggleables (Modal, Drawer) |
open(), close(), toggle(), isOpen()
|
| Inputs (Input, Select) |
getValue(), setValue(value), clear(), focus()
|
| Navigation (Carousel, Tabs) |
next(), prev(), goTo(index), getCurrent()
|
Architecture
Each component follows a three-layer pattern:
-
Ruby component (
component.rb) — props, validation, rendering logic -
ERB template (
component.html.erb) — HTML structure -
Stimulus controller (
*_controller.js) — JavaScript interactivity (only when needed)
Purely presentational components (Typography, Space, Divider, etc.) have no JavaScript layer.
Development
Playground
bin/playgroundOpens a local Rails app at http://localhost:3000 with all components and examples. Located in test/dummy/, not included in the published gem.
To add an example:
touch test/dummy/app/views/test_examples/[component]/_[example_name].html.erbIt appears automatically at /test/[component]/[example_name].
Tests
bundle exec rake test # all tests
bundle exec rake test TEST=test/components/hakumi/button/component_test.rb # single file
bundle exec rake test:system # browser testsVersioning
Gem and npm versions must be kept in sync:
# Gemfile
gem 'hakumi_components', '0.1.16.pre'yarn add @hakumi-dev/hakumi-components@0.1.16-preUse >= 0.1.0.pre / @pre to always track the latest pre-release.
Contributing
- Fork the repository
- Set up locally:
bin/setup - Create a branch:
git checkout -b my-feature - Make changes and add tests
- Run the test suite:
bundle exec rake test - Open a pull request
License
MIT. See LICENSE.
