Class: Shadcn::DropdownMenuComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/dropdown_menu_component.rb

Overview

Dropdown Menu component Matches shadcn/ui DropdownMenu component Uses Stimulus for interactivity

Examples:

Basic dropdown

<%= render Shadcn::DropdownMenuComponent.new do |menu| %>
  <% menu.with_trigger do %>
    <%= render Shadcn::ButtonComponent.new(variant: :outline) { "Open Menu" } %>
  <% end %>
  <% menu.with_content do |content| %>
    <% content.with_label { "My Account" } %>
    <% content.with_separator %>
    <% content.with_item(href: "/profile") { "Profile" } %>
    <% content.with_item(href: "/settings") { "Settings" } %>
    <% content.with_separator %>
    <% content.with_item(variant: :destructive) { "Log out" } %>
  <% end %>
<% end %>

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(open: false, align: :end, side: :bottom, **options) ⇒ DropdownMenuComponent

Returns a new instance of DropdownMenuComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    Whether dropdown starts open

  • align (Symbol) (defaults to: :end)

    Content alignment (:start, :center, :end)

  • side (Symbol) (defaults to: :bottom)

    Side to show content (:top, :right, :bottom, :left)



32
33
34
35
36
37
# File 'app/components/shadcn/dropdown_menu_component.rb', line 32

def initialize(open: false, align: :end, side: :bottom, **options)
  super(**options)
  @open = open
  @align = align
  @side = side
end