Sidebar
A composable, themeable and customizable sidebar component.
Usage
First of all, create a Sidebar component in your application.
Preview
Provider
Then, add a SidebarProvider, SidebarTrigger and AppSidebar at the root of your application.
app/layout.tsx
import { SidebarProvider, SidebarTrigger } from "@medway-ui/core"
import { AppSidebar } from "@/components/AppSidebar"
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<SidebarProvider>
<AppSidebar />
<main>
<SidebarTrigger
showTooltip
enableHover
tooltipContent={{
open: "Esconder sidebar",
closed: "Mostrar sidebar"
}}
/>
{children}
</main>
</SidebarProvider>
)
}Examples
Sidebar with tooltip and hover effects
The Sidebar component now supports enhanced tooltip functionality and hover effects:
- SidebarTrigger: Use
enableHoverto show different icons on hover (ChevronLeftMd when open, ChevronRightMd when closed) - SidebarMenuButton: Use
tooltipprop to show tooltips when the sidebar is collapsed - Custom tooltip content: Use
tooltipContentprop on SidebarTrigger to customize tooltip messages
Sidebar with switcher header, hover effect on trigger and tooltip
You can enable the hover effect on the SidebarTrigger by setting enableHover to true, which will show ChevronLeftMd when the sidebar is open and ChevronRightMd when closed on hover. You can also customize the tooltip content by setting tooltipContent with custom messages for open and closed states.
Preview
API
Sidebar Structure
| Component | Description | Usage |
|---|---|---|
| SidebarProvider | Root component that manages the sidebar state | Must wrap the entire application where the Sidebar will be used |
| Sidebar | Main component that renders the sidebar | Main container for the entire sidebar structure |
| SidebarContent | Container for the sidebar content | Manages layout and scrolling of main content |
| SidebarHeader | Top section of the sidebar | Ideal for logos, titles or main controls |
| SidebarFooter | Bottom section of the sidebar | Useful for status information, user controls or secondary actions |
| SidebarGroup | Groups related items | Container for groups of items with common title |
| SidebarGroupLabel | Group title | Defines the header of a group of items |
| SidebarGroupContent | Container for group content | Wraps items within a group |
| SidebarGroupAction | Action button for a group | Contextual actions related to the group |
| SidebarMenu | List of menu items | Container for navigation items |
| SidebarMenuItem | Individual menu item | Container for a navigation item |
| SidebarMenuButton | Clickable menu button | Interactive element for navigation |
| SidebarMenuItemTitle | Item title and icon | Displays the visual content of the menu item |
| SidebarMenuItemCollapse | Menu item collapse | Displays the menu item with a collapse icon |
| SidebarMenuAction | Item action button | Contextual actions for a specific item |
| SidebarMenuBadge | Badge or counter | Displays additional information about the item |
| SidebarMenuSub | Submenu container | Groups nested submenu items |
| SidebarMenuSubItem | Submenu item | Container for a submenu item |
| SidebarMenuSubButton | Submenu button | Interactive element for submenu navigation |
| SidebarTrigger | Toggle button | Controls sidebar visibility |
| SidebarRail | Separator element | Visually separates sidebar from content |
| SidebarSeparator | Divider line | Separates sections within the sidebar |
| SidebarInput | Input field | Styled text field for the sidebar |
| SidebarInset | Content container | Adjusts main content to the sidebar |
| SidebarMenuSkeleton | Loading component | Displays loading state for menu items |
Sidebar
| Property | Type | Possible Values | Default | Description |
|---|---|---|---|---|
| side | ”left” | “right" | "left”, “right" | "left” | Defines which side the sidebar will be displayed on. |
| variant | ”sidebar” | “floating” | “inset" | "sidebar”, “floating”, “inset" | "sidebar” | Defines the visual style of the sidebar. |
| collapsible | ”offcanvas” | “icon” | “none" | "offcanvas”, “icon”, “none" | "offcanvas” | Defines the sidebar collapse behavior. |
| defaultOpen | boolean | true, false | true | Defines if the sidebar should be open by default. |
| open | boolean | true, false | - | Controls the sidebar open state (controlled). |
| onOpenChange | (open: boolean) => void | - | - | Callback called when the open state changes. |
| containerClassName | string | Any CSS class string | - | Additional CSS classes for the sidebar container element. |
SidebarMenuButton
| Property | Type | Possible Values | Default | Description |
|---|---|---|---|---|
| variant | ”default” | “outline" | "default”, “outline" | "default” | Defines the visual style of the menu button. |
| size | ”md” | “sm” | “lg" | "md”, “sm”, “lg" | "md” | Defines the size of the menu button. |
| isActive | boolean | true, false | false | Defines if the menu button is active. |
| tooltip | string | TooltipContentProps | - | - | Defines the text or settings for the button tooltip. When provided as string, it will be converted to TooltipContentProps with the string as children. |
| asChild | boolean | true, false | false | Allows rendering the button as a custom child element. |
SidebarMenuSubButton
| Property | Type | Possible Values | Default | Description |
|---|---|---|---|---|
| size | ”sm” | “md" | "sm”, “md" | "md” | Defines the size of the submenu button. |
| isActive | boolean | true, false | false | Defines if the submenu button is active. When active, applies active styling with semibold font weight and secondary foreground color. |
| asChild | boolean | true, false | false | Allows rendering the button as a custom child element. |
SidebarTrigger
| Property | Type | Possible Values | Default | Description |
|---|---|---|---|---|
| icon | React.ReactNode | Any React node | <HamburgerMd /> | Icon displayed when the sidebar is closed. |
| className | string | Any CSS class string | - | Additional CSS classes for styling customization. |
| onClick | (event: React.MouseEvent) => void | - | - | Callback function called when the trigger is clicked. |
| showTooltip | boolean | true, false | false | Defines whether to show a tooltip when the trigger is hovered. |
| tooltipContent | { open?: string; closed?: string } | - | { open: "Esconder", closed: "Mostrar" } | Custom tooltip content for open and closed states. |
| sizeIcon | string | Any CSS class string | ”size-5” | Defines the size of the icon. |
| enableHover | boolean | true, false | false | Defines whether the hover effect (icon change) is enabled. When enabled, shows ChevronLeftMd when open and ChevronRightMd when closed on hover. |
Last updated on