@dt-dds/react-sidebar 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @dt-dds/react-sidebar
2
+
3
+ ## 1.0.0-beta.1
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: add sidebar compound component
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # Sidebar Package
2
+
3
+ A compound component for building navigation sidebars with collapsible sections, nested items, and responsive behavior.
4
+
5
+ ## Usage
6
+
7
+ ```jsx
8
+ import { useTheme } from '@emotion/react';
9
+ import { Sidebar, useSidebar } from '@dt-dds/react-sidebar';
10
+ import { Icon } from '@dt-dds/react-icon';
11
+
12
+ export const App = () => {
13
+ const theme = useTheme();
14
+
15
+ const { isExpanded, toggleSidebar } = useSidebar({ isExpanded: true });
16
+
17
+ return (
18
+ <Sidebar isExpanded={isExpanded} onToggle={toggleSidebar}>
19
+ <Sidebar.Header show={`(max-width: ${theme.breakpoints.mq3}px)`}>
20
+ <Sidebar.Item>
21
+ <Sidebar.Toggle />
22
+ <span>App Name</span>
23
+ </Sidebar.Item>
24
+ </Sidebar.Header>
25
+
26
+ <Sidebar.Divider show={`(max-width: ${theme.breakpoints.mq3}px)`} />
27
+
28
+ <Sidebar.Content>
29
+ <Sidebar.Section title='Section One'>
30
+ <Sidebar.Item href='/'>
31
+ <Icon code='dashboard' />
32
+ Menu Item
33
+ </Sidebar.Item>
34
+ <Sidebar.Item href='/'>
35
+ <Icon code='analytics' />
36
+ Menu Item
37
+ <Sidebar.SubList>
38
+ <Sidebar.Item href='/'>Nested Menu Item</Sidebar.Item>
39
+ <Sidebar.Item href='/'>Nested Menu Item</Sidebar.Item>
40
+ </Sidebar.SubList>
41
+ </Sidebar.Item>
42
+ </Sidebar.Section>
43
+ </Sidebar.Content>
44
+
45
+ <Sidebar.Divider />
46
+
47
+ <Sidebar.Footer>
48
+ <Sidebar.Item href='/settings'>
49
+ <Icon code='settings' />
50
+ Settings
51
+ </Sidebar.Item>
52
+ </Sidebar.Footer>
53
+
54
+ <Sidebar.Divider hide={`(max-width: ${theme.breakpoints.mq3}px)`} />
55
+
56
+ <Sidebar.Footer hide={`(max-width: ${theme.breakpoints.mq3}px)`}>
57
+ <Sidebar.Item>
58
+ <Sidebar.Toggle />
59
+ <span>Collapse</span>
60
+ </Sidebar.Item>
61
+ </Sidebar.Footer>
62
+ </Sidebar>
63
+ );
64
+ };
65
+ ```
66
+
67
+ ## API
68
+
69
+ ### Sidebar
70
+
71
+ | Property | Type | Default | Description |
72
+ | ------------ | ----------------------------- | -------- | --------------------------------- |
73
+ | `isExpanded` | `boolean` | required | Controls expanded/collapsed state |
74
+ | `onToggle` | `(expanded: boolean) => void` | - | Callback when toggle is triggered |
75
+ | `placement` | `'left' \| 'right'` | `'left'` | Desktop sidebar position |
76
+ | `offsetTop` | `number` | `0` | Top offset in pixels |
77
+ | `ariaLabel` | `string` | - | Accessibility label |
78
+
79
+ ### Sidebar.Item
80
+
81
+ | Property | Type | Default | Description |
82
+ | ----------------- | ----------------------------- | ------- | --------------------------------- |
83
+ | `href` | `string` | - | Navigation URL |
84
+ | `defaultExpanded` | `boolean` | `false` | Initial expanded state (SubList) |
85
+ | `expanded` | `boolean` | - | Controlled expanded state |
86
+ | `onToggle` | `(expanded: boolean) => void` | - | Callback when item is toggled |
87
+ | `children` | `ReactNode` | - | Item content and optional SubList |
88
+
89
+ ### Sidebar.Section
90
+
91
+ | Property | Type | Default | Description |
92
+ | ---------- | ----------- | ------- | ------------- |
93
+ | `title` | `string` | - | Section title |
94
+ | `children` | `ReactNode` | - | Section items |
95
+
96
+ ### Sidebar.SubList
97
+
98
+ Wrapper for nested `Sidebar.Item` elements. Auto-expands when a child item is active.
99
+
100
+ ### Sidebar.Header / Sidebar.Footer
101
+
102
+ Fixed position sections at top/bottom of the sidebar.
103
+
104
+ ### Sidebar.Content
105
+
106
+ Scrollable content area between header and footer.
107
+
108
+ ### Sidebar.Toggle
109
+
110
+ Button that triggers `onToggle`.
111
+
112
+ ### Sidebar.Divider
113
+
114
+ Visual separator between sections.
115
+
116
+ ## Hooks
117
+
118
+ ### useSidebar
119
+
120
+ Standalone state management hook.
121
+
122
+ ```jsx
123
+ const { isExpanded, setIsExpanded, toggleSidebar } = useSidebar({
124
+ isExpanded: true,
125
+ });
126
+ ```
127
+
128
+ ## Custom Link Components
129
+
130
+ Supports custom link components (React Router, Next.js, etc.):
131
+
132
+ ```jsx
133
+ <Sidebar.Item>
134
+ <Link to='/dashboard'>
135
+ <Icon code='dashboard' />
136
+ Dashboard
137
+ </Link>
138
+ </Sidebar.Item>
139
+ ```
140
+
141
+ ## Stack
142
+
143
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
144
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
145
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
146
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
147
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
148
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
149
+ - [ESLint](https://eslint.org/) for code linting
150
+ - [Prettier](https://prettier.io) for code formatting
151
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
152
+ - [Yarn](https://yarnpkg.com/) from managing packages
153
+
154
+ ## Commands
155
+
156
+ - `yarn build` - Build the package
157
+ - `yarn dev` - Run the package locally
158
+ - `yarn lint` - Lint all files within this package
159
+ - `yarn test` - Run all unit tests
160
+ - `yarn test:report` - Open the test coverage report
161
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
162
+
163
+ ## Compilation
164
+
165
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
166
+
167
+ The `/dist` folder contains the compiled output.
168
+
169
+ ```bash
170
+ sidebar
171
+ └── dist
172
+ ├── index.d.ts <-- Types
173
+ ├── index.js <-- CommonJS version
174
+ └── index.mjs <-- ES Modules version
175
+ ...
176
+ ```
177
+
178
+ ## Versioning
179
+
180
+ Follows [semantic versioning](https://semver.org/)
181
+
182
+ ## &copy; License
183
+
184
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,93 @@
1
+ import { Theme } from '@dt-dds/themes';
2
+ import * as react from 'react';
3
+ import { HTMLAttributes, ReactNode } from 'react';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import { ResponsiveProps, BaseProps } from '@dt-dds/react-core';
6
+
7
+ interface SidebarDividerProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLHRElement> {
8
+ }
9
+
10
+ interface SidebarSectionProps extends BaseProps, HTMLAttributes<HTMLElement> {
11
+ title?: string;
12
+ children: ReactNode;
13
+ }
14
+
15
+ interface SidebarHeaderProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLElement> {
16
+ children: ReactNode;
17
+ }
18
+
19
+ interface SidebarFooterProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLElement> {
20
+ children: ReactNode;
21
+ }
22
+
23
+ interface SidebarItemProps extends BaseProps, Omit<HTMLAttributes<HTMLLIElement>, 'onClick'> {
24
+ href?: string;
25
+ defaultExpanded?: boolean;
26
+ expanded?: boolean;
27
+ onToggle?: (expanded: boolean) => void;
28
+ children: ReactNode;
29
+ }
30
+
31
+ interface SidebarSubListProps extends BaseProps, HTMLAttributes<HTMLUListElement> {
32
+ children: ReactNode;
33
+ }
34
+
35
+ interface SidebarContentProps extends BaseProps, HTMLAttributes<HTMLElement> {
36
+ children: ReactNode;
37
+ }
38
+
39
+ interface SidebarToggleProps {
40
+ onClick?: () => void;
41
+ }
42
+
43
+ type SidebarPlacement = 'left' | 'right';
44
+
45
+ interface SidebarProps extends BaseProps, HTMLAttributes<HTMLElement> {
46
+ ariaLabel?: string;
47
+ isExpanded: boolean;
48
+ offsetTop?: number;
49
+ placement?: SidebarPlacement;
50
+ onToggle?: (expanded: boolean) => void;
51
+ }
52
+ declare const Sidebar: {
53
+ ({ dataTestId, offsetTop, children, ariaLabel, style, isExpanded, placement, onToggle, ...rest }: SidebarProps): react_jsx_runtime.JSX.Element;
54
+ Content: {
55
+ ({ children, dataTestId, style, ...rest }: SidebarContentProps): react_jsx_runtime.JSX.Element;
56
+ displayName: string;
57
+ };
58
+ Divider: react.ComponentType<SidebarDividerProps>;
59
+ Section: {
60
+ ({ title, children, dataTestId, style, ...rest }: SidebarSectionProps): react_jsx_runtime.JSX.Element;
61
+ displayName: string;
62
+ };
63
+ Item: {
64
+ ({ href, defaultExpanded, expanded: controlledExpanded, onToggle, children, dataTestId, style, ...rest }: SidebarItemProps): react_jsx_runtime.JSX.Element | null;
65
+ displayName: string;
66
+ };
67
+ SubList: {
68
+ ({ children, dataTestId, style, ...rest }: SidebarSubListProps): react_jsx_runtime.JSX.Element;
69
+ displayName: string;
70
+ };
71
+ Header: react.ComponentType<SidebarHeaderProps>;
72
+ Footer: react.ComponentType<SidebarFooterProps>;
73
+ Toggle: {
74
+ ({ onClick }: SidebarToggleProps): react_jsx_runtime.JSX.Element;
75
+ displayName: string;
76
+ };
77
+ };
78
+
79
+ interface UseSidebarOptions {
80
+ isExpanded?: boolean;
81
+ }
82
+ declare const useSidebar: (options?: UseSidebarOptions) => {
83
+ isExpanded: boolean;
84
+ setIsExpanded: (expanded: boolean) => void;
85
+ toggleSidebar: () => void;
86
+ };
87
+
88
+ declare module '@emotion/react' {
89
+ interface Theme extends Theme {
90
+ }
91
+ }
92
+
93
+ export { Sidebar, type SidebarProps, type UseSidebarOptions, useSidebar };
@@ -0,0 +1,93 @@
1
+ import { Theme } from '@dt-dds/themes';
2
+ import * as react from 'react';
3
+ import { HTMLAttributes, ReactNode } from 'react';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import { ResponsiveProps, BaseProps } from '@dt-dds/react-core';
6
+
7
+ interface SidebarDividerProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLHRElement> {
8
+ }
9
+
10
+ interface SidebarSectionProps extends BaseProps, HTMLAttributes<HTMLElement> {
11
+ title?: string;
12
+ children: ReactNode;
13
+ }
14
+
15
+ interface SidebarHeaderProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLElement> {
16
+ children: ReactNode;
17
+ }
18
+
19
+ interface SidebarFooterProps extends ResponsiveProps, BaseProps, HTMLAttributes<HTMLElement> {
20
+ children: ReactNode;
21
+ }
22
+
23
+ interface SidebarItemProps extends BaseProps, Omit<HTMLAttributes<HTMLLIElement>, 'onClick'> {
24
+ href?: string;
25
+ defaultExpanded?: boolean;
26
+ expanded?: boolean;
27
+ onToggle?: (expanded: boolean) => void;
28
+ children: ReactNode;
29
+ }
30
+
31
+ interface SidebarSubListProps extends BaseProps, HTMLAttributes<HTMLUListElement> {
32
+ children: ReactNode;
33
+ }
34
+
35
+ interface SidebarContentProps extends BaseProps, HTMLAttributes<HTMLElement> {
36
+ children: ReactNode;
37
+ }
38
+
39
+ interface SidebarToggleProps {
40
+ onClick?: () => void;
41
+ }
42
+
43
+ type SidebarPlacement = 'left' | 'right';
44
+
45
+ interface SidebarProps extends BaseProps, HTMLAttributes<HTMLElement> {
46
+ ariaLabel?: string;
47
+ isExpanded: boolean;
48
+ offsetTop?: number;
49
+ placement?: SidebarPlacement;
50
+ onToggle?: (expanded: boolean) => void;
51
+ }
52
+ declare const Sidebar: {
53
+ ({ dataTestId, offsetTop, children, ariaLabel, style, isExpanded, placement, onToggle, ...rest }: SidebarProps): react_jsx_runtime.JSX.Element;
54
+ Content: {
55
+ ({ children, dataTestId, style, ...rest }: SidebarContentProps): react_jsx_runtime.JSX.Element;
56
+ displayName: string;
57
+ };
58
+ Divider: react.ComponentType<SidebarDividerProps>;
59
+ Section: {
60
+ ({ title, children, dataTestId, style, ...rest }: SidebarSectionProps): react_jsx_runtime.JSX.Element;
61
+ displayName: string;
62
+ };
63
+ Item: {
64
+ ({ href, defaultExpanded, expanded: controlledExpanded, onToggle, children, dataTestId, style, ...rest }: SidebarItemProps): react_jsx_runtime.JSX.Element | null;
65
+ displayName: string;
66
+ };
67
+ SubList: {
68
+ ({ children, dataTestId, style, ...rest }: SidebarSubListProps): react_jsx_runtime.JSX.Element;
69
+ displayName: string;
70
+ };
71
+ Header: react.ComponentType<SidebarHeaderProps>;
72
+ Footer: react.ComponentType<SidebarFooterProps>;
73
+ Toggle: {
74
+ ({ onClick }: SidebarToggleProps): react_jsx_runtime.JSX.Element;
75
+ displayName: string;
76
+ };
77
+ };
78
+
79
+ interface UseSidebarOptions {
80
+ isExpanded?: boolean;
81
+ }
82
+ declare const useSidebar: (options?: UseSidebarOptions) => {
83
+ isExpanded: boolean;
84
+ setIsExpanded: (expanded: boolean) => void;
85
+ toggleSidebar: () => void;
86
+ };
87
+
88
+ declare module '@emotion/react' {
89
+ interface Theme extends Theme {
90
+ }
91
+ }
92
+
93
+ export { Sidebar, type SidebarProps, type UseSidebarOptions, useSidebar };