A compound component for building navigation sidebars with collapsible sections, nested items, and responsive behavior.
npm install @dt-dds/react-sidebarA compound component for building navigation sidebars with collapsible sections, nested items, and responsive behavior.
``jsx
import { useTheme } from '@emotion/react';
import { Sidebar, useSidebar } from '@dt-dds/react-sidebar';
import { Icon } from '@dt-dds/react-icon';
export const App = () => {
const theme = useTheme();
const { isExpanded, toggleSidebar } = useSidebar({ isExpanded: true });
return (
}>
App Name
} />
Menu Item
Menu Item
Settings
} />
}>
Collapse
);
};
`
| Property | Type | Default | Description |
| ------------ | ----------------------------- | -------- | --------------------------------- |
| isExpanded | boolean | required | Controls expanded/collapsed state |onToggle
| | (expanded: boolean) => void | - | Callback when toggle is triggered |placement
| | 'left' \| 'right' | 'left' | Desktop sidebar position |offsetTop
| | number | 0 | Top offset in pixels |ariaLabel
| | string | - | Accessibility label |
| Property | Type | Default | Description |
| ----------------- | ----------------------------- | ------- | --------------------------------- |
| href | string | - | Navigation URL |defaultExpanded
| | boolean | false | Initial expanded state (SubList) |expanded
| | boolean | - | Controlled expanded state |onToggle
| | (expanded: boolean) => void | - | Callback when item is toggled |children
| | ReactNode | - | Item content and optional SubList |
| Property | Type | Default | Description |
| ---------- | ----------- | ------- | ------------- |
| title | string | - | Section title |children
| | ReactNode | - | Section items |
Wrapper for nested Sidebar.Item elements. Auto-expands when a child item is active.
Fixed position sections at top/bottom of the sidebar.
Scrollable content area between header and footer.
Button that triggers onToggle.
Visual separator between sections.
Standalone state management hook.
`jsx`
const { isExpanded, setIsExpanded, toggleSidebar } = useSidebar({
isExpanded: true,
});
Supports custom link components (React Router, Next.js, etc.):
`jsx`
Dashboard
- TypeScript for static type checking
- React — JavaScript library for user interfaces
- Emotion — for writing css styles with JavaScript
- Storybook — UI component environment powered by Vite
- Jest - JavaScript Testing Framework
- React Testing Library - to test UI components in a user-centric way
- ESLint for code linting
- Prettier for code formatting
- Tsup — TypeScript bundler powered by esbuild
- Yarn from managing packages
- yarn build - Build the packageyarn dev
- - Run the package locallyyarn lint
- - Lint all files within this packageyarn test
- - Run all unit testsyarn test:report
- - Open the test coverage reportyarn test:update:snapshot
- - Run all unit tests and update the snapshot
Running yarn build from the root of the package will use tsup to compile the raw TypeScript and React code to plain JavaScript.
The /dist folder contains the compiled output.
`bash``
sidebar
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
...
Follows semantic versioning
Licensed under MIT License