Sidebar
Sidebar component with groups, nested items, badges, links and a collapsed mode with tooltips.
How to use it
Run npx @blossomui/react add sidebar, or copy src/components/UI/Sidebar/Sidebar.tsx into your React project and import it.
import { Sidebar } from './components/ui/Sidebar'Props
SidebarItem
| Prop | Type | Description |
|---|---|---|
| id (required) | string | |
| label (required) | string | |
| icon | ReactNode | Icon of the item. It is the only thing shown when the sidebar is collapsed, so give every item one. |
| href | string | Makes the item a link. Without it the item is a button that calls `onSelect`. |
| badge | ReactNode | Small text on the right, for example a counter. |
| children | SidebarItem[] | Sub items. The item opens and closes them instead of being chosen. |
| disabled | boolean | |
| onSelect | () => void |
SidebarSection
| Prop | Type | Description |
|---|---|---|
| title | string | Title of the group, shown over its items. |
| items (required) | SidebarItem[] |
SidebarLabels
| Prop | Type | Description |
|---|---|---|
| collapse (required) | string | Accessible name of the button that collapses the sidebar. |
| expand (required) | string | Accessible name of the button that expands the sidebar. |
SidebarProps
| Prop | Type | Description |
|---|---|---|
| labels | Partial<SidebarLabels> | Texts of the component. Pass only the ones you want to change, for example to translate it. |
| sections (required) | SidebarSection[] | |
| activeId | string | Id of the item that is the current page. |
| onNavigate | (id: string) => void | Called with the id of the item the user chose. |
| header | ReactNode | ((collapsed: boolean) => ReactNode) | Content at the top, for example the logo. |
| footer | ReactNode | ((collapsed: boolean) => ReactNode) | Content at the bottom, for example the user. |
| collapsed | boolean | Controlled collapsed state. Use together with `onCollapsedChange`. |
| defaultCollapsed | boolean | |
| onCollapsedChange | (collapsed: boolean) => void | |
| collapsible | boolean | Show the button that collapses the sidebar to icons. |
| color | string | Accent color of the active item: any CSS color. Without it the component uses `--blossom-accent`. |
| label | string | Accessible name of the navigation. |
| className | string | Give it a height, for example `h-[32rem]`. |