|
| 1 | +--- |
| 2 | +title: Sidepanel |
| 3 | +description: A collapsible side navigation panel component. |
| 4 | +--- |
| 5 | + |
| 6 | +## Preview |
| 7 | + |
| 8 | +<Preview> |
| 9 | + <Sidepanel.Root open={true}> |
| 10 | + <Sidepanel.Header logo={<InfoCircledIcon width={24} height={24} />} title="Company Name" /> |
| 11 | + <Sidepanel.Main> |
| 12 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />} active>Dashboard</Sidepanel.Item> |
| 13 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Analytics</Sidepanel.Item> |
| 14 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Settings</Sidepanel.Item> |
| 15 | + </Sidepanel.Main> |
| 16 | + <Sidepanel.Footer> |
| 17 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Help</Sidepanel.Item> |
| 18 | + </Sidepanel.Footer> |
| 19 | + </Sidepanel.Root> |
| 20 | +</Preview> |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +Install the component from your command line. |
| 25 | + |
| 26 | +<LiveProvider> |
| 27 | + <LiveEditor code={`npm install @raystack/apsara`} border language="shell" /> |
| 28 | +</LiveProvider> |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +The Sidepanel component provides a collapsible navigation panel with header, main content, and footer sections. |
| 33 | + |
| 34 | +<LiveProvider> |
| 35 | + <LiveEditor code={`import { Sidepanel } from '@raystack/apsara/v1' |
| 36 | +
|
| 37 | +export default function App() { |
| 38 | + return ( |
| 39 | + <Sidepanel.Root open={true}> |
| 40 | + <Sidepanel.Header logo={<InfoCircledIcon />} title="Company Name" /> |
| 41 | + <Sidepanel.Main> |
| 42 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />} active>Dashboard</Sidepanel.Item> |
| 43 | + </Sidepanel.Main> |
| 44 | + <Sidepanel.Footer> |
| 45 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Help</Sidepanel.Item> |
| 46 | + </Sidepanel.Footer> |
| 47 | + </Sidepanel.Root> |
| 48 | + ) |
| 49 | +}`} border/> |
| 50 | +</LiveProvider> |
| 51 | + |
| 52 | +## API Reference |
| 53 | + |
| 54 | +### Root Props |
| 55 | + |
| 56 | +- `open`: Controls the expanded/collapsed state (boolean) |
| 57 | +- `onOpenChange`: Callback when expanded/collapsed state changes (function) |
| 58 | +- `position`: Position of the sidepanel (`"left"` | `"right"`, default: "left") |
| 59 | +- `profile`: Optional profile information object |
| 60 | + - `icon`: ReactNode |
| 61 | + - `label`: string |
| 62 | + - `href`: string (optional) |
| 63 | + - `onIconClick`: Optional callback for icon click |
| 64 | + |
| 65 | +### Header Props |
| 66 | + |
| 67 | +- `logo`: ReactNode for the header icon/logo |
| 68 | +- `title`: string for the header text |
| 69 | +- `onLogoClick`: Optional callback for logo click |
| 70 | + |
| 71 | +### Item Props |
| 72 | + |
| 73 | +- `icon`: ReactNode for the item's icon |
| 74 | +- `href`: string for the link destination |
| 75 | +- `active`: boolean to indicate current selection |
| 76 | +- `children`: ReactNode for the item's label |
| 77 | + |
| 78 | +## Sidepanel Props |
| 79 | + |
| 80 | +The Sidepanel component consists of several parts, each with their own props: |
| 81 | + |
| 82 | +### Root |
| 83 | + |
| 84 | +- `open`: Controls the expanded/collapsed state (boolean) |
| 85 | +- `onOpenChange`: Callback when expanded/collapsed state changes (function) |
| 86 | +- `position`: Position of the sidepanel ("left" | "right", default: "left") |
| 87 | +- `account`: Optional account information object with: |
| 88 | + - `icon`: Icon element to display (ReactNode) |
| 89 | + - `label`: Text to display (string) |
| 90 | + - `href`: Optional URL the account links to (string) |
| 91 | + |
| 92 | +### Header |
| 93 | + |
| 94 | +- `logo`: Logo element to display (ReactNode) |
| 95 | +- `title`: Title text to display (string) |
| 96 | + |
| 97 | +### Item |
| 98 | + |
| 99 | +- `icon`: Icon element to display (ReactNode) |
| 100 | +- `active`: Whether the item is currently active (boolean) |
| 101 | +- `href`: URL the item links to (string) |
| 102 | + |
| 103 | +## Position |
| 104 | + |
| 105 | +The Sidepanel can be positioned on either the left or right side of the screen. |
| 106 | + |
| 107 | +<Playground |
| 108 | + scope={{ Sidepanel, InfoCircledIcon }} |
| 109 | + tabs={[ |
| 110 | + { |
| 111 | + name: "Left", |
| 112 | + code: ` |
| 113 | + <Sidepanel.Root open={true} position="left"> |
| 114 | + <Sidepanel.Header logo={<InfoCircledIcon />} title="Company Name" /> |
| 115 | + <Sidepanel.Main> |
| 116 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />} active>Dashboard</Sidepanel.Item> |
| 117 | + </Sidepanel.Main> |
| 118 | + </Sidepanel.Root> |
| 119 | + `, |
| 120 | + }, |
| 121 | + { |
| 122 | + name: "Right", |
| 123 | + code: ` |
| 124 | + <Sidepanel.Root open={true} position="right"> |
| 125 | + <Sidepanel.Header logo={<InfoCircledIcon />} title="Company Name" /> |
| 126 | + <Sidepanel.Main> |
| 127 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Dashboard</Sidepanel.Item> |
| 128 | + </Sidepanel.Main> |
| 129 | + </Sidepanel.Root> |
| 130 | + `, |
| 131 | + }, |
| 132 | + ]} |
| 133 | +/> |
| 134 | + |
| 135 | +## State |
| 136 | + |
| 137 | +The Sidepanel supports expanded and collapsed states with smooth transitions. |
| 138 | + |
| 139 | +<Playground |
| 140 | + scope={{ Sidepanel, InfoCircledIcon }} |
| 141 | + tabs={[ |
| 142 | + { |
| 143 | + name: "Expanded", |
| 144 | + code: ` |
| 145 | + <Sidepanel.Root open={true}> |
| 146 | + <Sidepanel.Header logo={<InfoCircledIcon />} title="Company Name" /> |
| 147 | + <Sidepanel.Main> |
| 148 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />} active>Dashboard</Sidepanel.Item> |
| 149 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Settings</Sidepanel.Item> |
| 150 | + </Sidepanel.Main> |
| 151 | + </Sidepanel.Root> |
| 152 | + `, |
| 153 | + }, |
| 154 | + { |
| 155 | + name: "Collapsed", |
| 156 | + code: ` |
| 157 | + <Sidepanel.Root open={false}> |
| 158 | + <Sidepanel.Header logo={<InfoCircledIcon />} title="Company Name" /> |
| 159 | + <Sidepanel.Main> |
| 160 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />} active>Dashboard</Sidepanel.Item> |
| 161 | + <Sidepanel.Item href="#" icon={<InfoCircledIcon />}>Settings</Sidepanel.Item> |
| 162 | + </Sidepanel.Main> |
| 163 | + </Sidepanel.Root> |
| 164 | + `, |
| 165 | + }, |
| 166 | + ]} |
| 167 | +/> |
| 168 | + |
| 169 | +## Accessibility |
| 170 | + |
| 171 | +The Sidepanel implements the following accessibility features: |
| 172 | + |
| 173 | +- Proper ARIA roles and attributes |
| 174 | + |
| 175 | + - `role="navigation"` for the main sidebar |
| 176 | + - `role="banner"` for the header |
| 177 | + - `role="menuitem"` for navigation items |
| 178 | + - `aria-expanded` to indicate sidebar state |
| 179 | + - `aria-current="page"` for active items |
| 180 | + |
| 181 | +- Keyboard navigation support |
| 182 | + |
| 183 | + - Enter/Space to toggle sidebar expansion |
| 184 | + - Tab navigation through interactive elements |
| 185 | + |
| 186 | +- Screen reader support |
| 187 | + - Meaningful labels for all interactive elements |
| 188 | + - Hidden decorative elements |
| 189 | + - Clear state indicators |
0 commit comments