Shadwire

Search the documentation

Search the documentation and component pages by title and by content.

Get started
Introduction
Installation
shadwire.json
Theming
Dark mode
Tools
CLI
Agent skill
Registry
llms.txt
Guides
Composition
Styling
Forms
Icons
Accessibility
Localisation
Blocks
Overview
Components
Overview
Accordion
Alert
Alert Dialog
Aspect Ratio
Avatar
Badge
Breadcrumb
Button
Button Group
Calendar
Card
Carousel
Chart
Checkbox
Collapsible
Combobox
Command
Context Menu
Data Table
Date Picker
Dialog
Drawer
Dropdown Menu
Empty
Field
Hover Card
Icon
Input
Input Group
Input OTP
Item
Kbd
Label
Menubar
Native Select
Navigation Menu
Pagination
Popover
Progress
Radio Group
Resizable
Scroll Area
Select
Separator
Sheet
Sidebar
Skeleton
Slider
Sonner
Spinner
Switch
Table
Tabs
Textarea
Toggle
Toggle Group
Tooltip

Popover

An overlaid panel, triggered by a button, for showing rich content.

Installation

Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:

shadwire add popover --yes

The popover registry item installs these files:

  • app/components/ui_component.rb
  • app/components/ui/popover_component.rb
  • app/components/ui/popover/trigger_component.rb
  • app/components/ui/popover/content_component.rb
  • app/components/ui/button_component.rb
  • app/helpers/ui/popover_helper.rb
  • app/helpers/ui/button_helper.rb
  • app/javascript/controllers/ui_popover_controller.js
  • vendor/shadwire/shadwire.css

This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.

Haven't installed the CLI yet? gem install shadwire, then shadwire init.

Usage

The ui-popover controller toggles the panel, moves focus into it on open, and hands focus back to the trigger on closing with Esc. Clicking outside closes it too. Positioning is utilities only (side/align), with no floating-ui.

<%= ui_popover do %>
  <%= ui_popover_trigger(variant: :outline) { "Open" } %>
  <%= ui_popover_content do %>
    Popover content.
  <% end %>
<% end %>

Or render the components directly:

<%= render Ui::PopoverComponent.new do %>
  <%= render Ui::Popover::TriggerComponent.new do %>
    Open
  <% end %>
  <%= render Ui::Popover::ContentComponent.new(side: :bottom, align: :start) do %>
    Content
  <% end %>
<% end %>

Composition

Popover (data-controller="ui-popover", relative)
|-- Popover::Trigger (Button, aria-expanded)
`-- Popover::Content (absolute, side: + align:)

Examples

Default

A non-modal panel: it opens on click, focuses its content, and closes on an outside click or Esc.

<%= ui_popover do %>
  <%= ui_popover_trigger(variant: :outline) { "Open dimensions" } %>
  <%= ui_popover_content do %>
    <div class="grid gap-4">
      <div class="space-y-1">
        <h4 class="font-medium leading-none">Dimensions</h4>
        <p class="text-sm text-muted-foreground">Set the dimensions for the layer.</p>
      </div>

Alignment

align: :start, :center or :end shifts the panel along the cross axis.

<% %i[start center end].each do |align| %>
  <%= ui_popover do %>
    <%= ui_popover_trigger(variant: :outline) { "align: #{align}" } %>
    <%= ui_popover_content(side: :bottom, align: align, class: "w-48") do %>
      <p class="text-sm">Aligned to the <strong><%= align %></strong> on the horizontal axis.</p>
    <% end %>
  <% end %>
<% end %>

API reference

Every part accepts class / class_name and **attrs.

Component Argument Default Description
Popover::Trigger variant, size :outline The Button that opens and closes it; keeps aria-expanded current.
Popover::Content side :bottom :top, :right, :bottom, :left.
Popover::Content align :center :start, :center, :end along the cross axis.