Button Edit

Displays a button or a component that looks like a button.

Examples

Link Ghost Link

Installation


  rails generate shadcn-ui button

Usage

<%= render_button(label, text: nil,
      variant: :default,
      as: :button,
      href: nil,
      data: {},
      **options, &block) %>

The Button component introduces:

  • app/helpers/components/button_helper.rb
  • app/views/components/ui/_button.html.erb

The method render_button defined in app/helpers/components/button_helper.rb accepts a first argument for the text of the button or as a text: keyword argument.

Optional arguments for the button include:

  • variant:, including :secondary, :destructive, :outline, and :ghost
  • as: which allows the button to be rendered as a <a> tag.
  • A block can be passed to render the text including other elements such as icons.