Class: Shadcn::PopoverComponent

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

Overview

Popover component for rich content in an overlay Matches shadcn/ui Popover component Uses Stimulus for interactivity

Examples:

Basic popover

<%= render Shadcn::PopoverComponent.new do |popover| %>
  <% popover.with_trigger do %>
    <%= render Shadcn::ButtonComponent.new(variant: :outline) { "Open popover" } %>
  <% end %>
  <% popover.with_content do %>
    <div class="grid gap-4">
      <h4 class="font-medium leading-none">Dimensions</h4>
      <p class="text-sm text-muted-foreground">Set the dimensions for the layer.</p>
    </div>
  <% 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, side: :bottom, align: :center, modal: false, **options) ⇒ PopoverComponent

Returns a new instance of PopoverComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    Whether popover starts open

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

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

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

    Alignment (:start, :center, :end)

  • modal (Boolean) (defaults to: false)

    Whether to trap focus



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

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