Sidebar
Navigation that slides in from the side
Includes a Ruby component and corresponding Rails helper
RubyThis is a paid-only premium component
PremiumIncludes a Stimulus controller
StimulusA flexible sidebar navigation component with mobile overlay behavior. Use it to build application navigation with sections, user controls, and smooth animations that automatically adapts between desktop and mobile patterns.
Basic Example
Usage
| ||
|---|---|---|
| Property | Default | Description |
title | String | Optional default title for the title bar. Can be overridden with content_for(:title). |
**attrs | HTML attributes for <div> element | |
Layout Methods
| ||
|---|---|---|
| Property | Default | Description |
block | Proc | Content for the sidebar navigation area. Use sidebar builder methods within this block. |
| ||
|---|---|---|
| Property | Default | Description |
block | Proc | Content for the main content area. Automatically handles responsive padding for sidebar. |
| ||
|---|---|---|
| Property | Default | Description |
block | Proc | Optional content for the title bar. Includes hamburger menu for mobile. |
**attrs | HTML attributes for <nav> element | |
Sidebar Builder Methods
| ||
|---|---|---|
| Property | Default | Description |
args | link_to arguments | Standard Rails link_to arguments (text, path, options). |
active | Boolean | Whether this item represents the current active page. |
**attrs | HTML attributes for <button> element | |
| ||
|---|---|---|
| Property | Default | Description |
block | Proc | Groups navigation items with consistent spacing. |
| ||
|---|---|---|
| Property | Default | Description |
| | Flexible spacer to push subsequent items to bottom of sidebar. |
Content Areas
The sidebar layout supports several content areas that can be customized:
-
title_bar_left_action: Content before the title (use
content_for) -
title_bar_right_action: Content after the title (use
content_for) -
title: Override the default title text (use
content_for)
<% content_for :title_bar_left_action do %>
<%= nk_button "Back", variant: :ghost, size: :sm %>
<% end %>
<% content_for :title, "Custom Page Title" %>
<% content_for :title_bar_right_action do %>
<%= nk_button "Save", size: :sm %>
<% end %>Responsive Design
The sidebar component automatically handles responsive behavior:
- Desktop (lg+): Sidebar permanently visible, content has left padding
- Mobile: Sidebar hidden by default, slides in as overlay when opened
- Backdrop: Semi-transparent backdrop on mobile prevents interaction with main content
- Click Outside: Automatically closes sidebar when clicking outside on mobile
- Keyboard Navigation: Proper ARIA labels and keyboard accessibility
CSS Custom Properties
The sidebar uses CSS custom properties for consistent spacing:
-
--sidebar-width:Width of the sidebar (default: 18rem/288px) -
--layout-padding:Internal content padding (responsive: 1.25rem/2rem)
Override these in your CSS for custom sizing:
:root { --sidebar-width: 20rem; --layout-padding: 3rem; }