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

Sidebar

A composable, collapsible, responsive sidebar for application layouts.

See the sidebar in a complete layout

The sidebar-01 block shows collapsing, the Cmd/Ctrl+B shortcut, and the mobile drawer.

Open the block

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 sidebar --yes

The sidebar registry item installs these files:

  • app/components/ui_component.rb
  • app/components/ui/sidebar_component.rb
  • app/components/ui/sidebar/provider_component.rb
  • app/components/ui/sidebar/trigger_component.rb
  • app/components/ui/sidebar/rail_component.rb
  • app/components/ui/sidebar/inset_component.rb
  • app/components/ui/sidebar/input_component.rb
  • app/components/ui/sidebar/header_component.rb
  • app/components/ui/sidebar/footer_component.rb
  • app/components/ui/sidebar/separator_component.rb
  • app/components/ui/sidebar/content_component.rb
  • app/components/ui/sidebar/group_component.rb
  • app/components/ui/sidebar/group_label_component.rb
  • app/components/ui/sidebar/group_action_component.rb
  • app/components/ui/sidebar/group_content_component.rb
  • app/components/ui/sidebar/menu_component.rb
  • app/components/ui/sidebar/menu_item_component.rb
  • app/components/ui/sidebar/menu_button_component.rb
  • app/components/ui/sidebar/menu_action_component.rb
  • app/components/ui/sidebar/menu_badge_component.rb
  • app/components/ui/sidebar/menu_skeleton_component.rb
  • app/components/ui/sidebar/menu_sub_component.rb
  • app/components/ui/sidebar/menu_sub_item_component.rb
  • app/components/ui/sidebar/menu_sub_button_component.rb
  • app/helpers/ui/sidebar_helper.rb
  • app/javascript/controllers/ui_sidebar_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

Wrap the page in ui_sidebar_provider; it hosts the controller and exposes the widths as CSS variables.

<%= ui_sidebar_provider do %>
  <%= ui_sidebar do %>
    <%= ui_sidebar_content do %>
      <%= ui_sidebar_group do %>
        <%= ui_sidebar_group_label { "Application" } %>
        <%= ui_sidebar_group_content do %>
          <%= ui_sidebar_menu do %>
            <%= ui_sidebar_menu_item do %>

Or render the components directly:

<%= render Ui::Sidebar::ProviderComponent.new do %>
  <%= render Ui::SidebarComponent.new(collapsible: :icon) do %>
    <%= render Ui::Sidebar::ContentComponent.new do %>
      <%= render Ui::Sidebar::MenuComponent.new do %>
        <%= render Ui::Sidebar::MenuItemComponent.new do %>
          <%= render Ui::Sidebar::MenuButtonComponent.new(tooltip: "Home") { "Home" } %>
        <% end %>
      <% end %>

Composition

Sidebar::Provider (data-controller="ui-sidebar"; sets the widths as CSS vars)
|-- Sidebar (peer/group; data-state/collapsible/side/variant/mobile)
|   |-- Sidebar::Header  (e.g. a switcher + Sidebar::Input)
|   |-- Sidebar::Content
|   |   `-- Sidebar::Group > Sidebar::GroupLabel + Sidebar::GroupContent
|   |       `-- Sidebar::Menu > Sidebar::MenuItem
|   |           > Sidebar::MenuButton (+ MenuAction / MenuBadge / MenuSub)
|   |-- Sidebar::Footer

Examples

Preview

A contained sidebar (collapsible: :none) with a header, groups and a menu. The full block, with collapsing and a mobile drawer, is at /blocks/sidebar-01.

Acme Inc
Content
<div class="flex h-80 w-full max-w-md overflow-hidden rounded-lg border bg-card text-left"
     style="--sidebar-width: 14rem; --sidebar-width-icon: 3rem; --sidebar-width-mobile: 14rem;">
  <%= ui_sidebar(collapsible: :none, class: "border-r") do %>
    <%= ui_sidebar_header do %>
      <div class="px-2 py-1.5 text-sm font-semibold">Acme Inc</div>
    <% end %>
    <%= ui_sidebar_content do %>
      <%= ui_sidebar_group do %>

API reference

API Element Description
ui_sidebar_providerdivHosts the ui-sidebar controller; accepts default_open: and cookie_name:.
ui_sidebardivThe panel. Accepts side: (:left/:right), variant: (:sidebar/:floating/:inset) and collapsible: (:offcanvas/:icon/:none).
ui_sidebar_triggerbuttonToggles the sidebar (click or Cmd/Ctrl+B).
ui_sidebar_railbuttonThe strip along the inner edge that toggles collapsing.
ui_sidebar_insetmainThe content area beside the sidebar.
ui_sidebar_header / ui_sidebar_footerdivThe top and bottom regions.
ui_sidebar_contentdivThe scrollable region holding the groups.
ui_sidebar_group / _group_label / _group_contentdivA labelled menu section. The label takes tag:.
ui_sidebar_group_actionbuttonAn action pinned to the group's label; tag:.
ui_sidebar_menu / _menu_itemul / liThe list of menu items.
ui_sidebar_menu_buttonbutton/ais_active:, variant:, size:, tag: and tooltip: (visible in icon mode only).
ui_sidebar_menu_action / _menu_badgebutton / divAn action and a badge pinned to the right of the item. The action takes tag:, and show_on_hover: to show it only while the row is hovered or focused.
ui_sidebar_menu_sub / _menu_sub_item / _menu_sub_buttonul / li / aA nested submenu. The button takes is_active:, size: and tag:.
ui_sidebar_menu_skeletondivA loading placeholder; show_icon:.