The buttons component provides a set of pre-styled buttons for your Rails app.
rails g instrumental:buttons
To insert a component into a view:
rails g instrumental:buttons:insert
To make any link a button, simply add the btn
class to the link or button element, along with the class for the type of button you want to display. Here's a simple "primary" button:
<%= link_to "Click me!", "#", class: "btn btn-primary" %>
Buttons have flex layouts built-in, which makes it easy to display a button with a icon to the left or right of the button text, like this:
<%= link_to "#", class: "btn btn-primary" do %>
<%= icon("rocket") %>
<span>Let's go!</span>
<% end %>
As of this writing, here's a list of all of the available button styles and their corresponding Tailwind CSS classes.
btn btn-primary
btn btn-secondary
btn btn-ghost
btn btn-primary btn-large
btn btn-primary btn-small
You can inspect (or customize) your button styles in this file:
app/assets/tailwind/buttons.css
You can add additional Tailwind CSS classes to any button element or link to override or customize the button's appearance (without needing to create are add new button styles in the app/assets/tailwind/buttons.css
file).
Here's an example of making a button that spans the full width of its container:
<%= link_to "Click me!", "#", class: "btn btn-primary w-full" %>
I created Instrumental Components to make designing and building professional apps with Ruby on Rails easy, fast, and fun. I use it on all of my projects and I hope it helps you build something great.