@kt-components/layout-header-sidebar 1.0.0 → 1.0.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/README.md +188 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,59 +1,226 @@
|
|
|
1
1
|
# KT Components Layout Header Sidebar
|
|
2
2
|
|
|
3
|
-
Reusable Header and Sidebar layout components for Next.js applications, pre-styled with Tailwind CSS.
|
|
3
|
+
Reusable Header and Sidebar layout components designed for Next.js applications, pre-styled with Tailwind CSS. Perfect for government or enterprise back-office applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Responsive Sidebar**: Automatically collapses on mobile, togglable on desktop.
|
|
8
|
+
- **Notification System**: Built-in notification bell with dropdown list.
|
|
9
|
+
- **User Profile**: Display user avatar, name, and role.
|
|
10
|
+
- **Tailwind CSS**: Beautifully styled using Tailwind utility classes.
|
|
11
|
+
- **TypeScript**: Fully typed for excellent developer experience.
|
|
4
12
|
|
|
5
13
|
## Requirements
|
|
6
14
|
|
|
7
15
|
- React 18+
|
|
8
|
-
-
|
|
16
|
+
- Next.js 13+ (App Router recommended)
|
|
17
|
+
- TailwindCSS 3 (Optional, styles are bundled)
|
|
9
18
|
|
|
10
19
|
## Installation
|
|
11
20
|
|
|
21
|
+
Install the package via npm:
|
|
22
|
+
|
|
12
23
|
```bash
|
|
13
24
|
npm install @kt-components/layout-header-sidebar
|
|
14
25
|
```
|
|
15
26
|
|
|
16
|
-
## Setup
|
|
27
|
+
## Setup (Important!)
|
|
17
28
|
|
|
18
|
-
|
|
29
|
+
You **must** import the CSS file to make the components look right. Add this line to your **root layout** file (usually `app/layout.tsx`):
|
|
19
30
|
|
|
20
31
|
```tsx
|
|
32
|
+
// app/layout.tsx
|
|
21
33
|
import "@kt-components/layout-header-sidebar/dist/styles.css";
|
|
34
|
+
// ... other imports
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If you are using Next.js Transpile Packages (to avoid build errors with local packages), add this to `next.config.js`:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const nextConfig = {
|
|
41
|
+
transpilePackages: ['@kt-components/layout-header-sidebar'],
|
|
42
|
+
};
|
|
22
43
|
```
|
|
23
44
|
|
|
24
|
-
## Usage
|
|
45
|
+
## Usage Guide
|
|
25
46
|
|
|
26
|
-
###
|
|
47
|
+
### 1. Basic Layout Setup
|
|
27
48
|
|
|
28
|
-
|
|
49
|
+
Combine `Header` and `SharedSidebar` to create a standard dashboard layout.
|
|
29
50
|
|
|
30
51
|
```tsx
|
|
31
|
-
|
|
52
|
+
// app/page.tsx
|
|
53
|
+
'use client';
|
|
54
|
+
|
|
55
|
+
import { Header, SharedSidebar, toggleSidebar, MenuItem } from '@kt-components/layout-header-sidebar';
|
|
56
|
+
import { useRouter } from 'next/navigation';
|
|
57
|
+
|
|
58
|
+
export default function Dashboard() {
|
|
59
|
+
const router = useRouter();
|
|
32
60
|
|
|
33
|
-
|
|
61
|
+
// 1. Define User Data
|
|
34
62
|
const user = {
|
|
35
|
-
firstName: '
|
|
36
|
-
lastName: '
|
|
37
|
-
pictureUrl: 'https://example.com/avatar.jpg'
|
|
63
|
+
firstName: 'John',
|
|
64
|
+
lastName: 'Doe',
|
|
65
|
+
pictureUrl: 'https://example.com/avatar.jpg',
|
|
66
|
+
role: 'ADMIN' // Optional role badge
|
|
38
67
|
};
|
|
39
|
-
|
|
40
|
-
//
|
|
68
|
+
|
|
69
|
+
// 2. Define Menu Items
|
|
70
|
+
const menuItems: MenuItem[] = [
|
|
71
|
+
{
|
|
72
|
+
id: 'dashboard',
|
|
73
|
+
title: 'Dashboard',
|
|
74
|
+
path: '/dashboard',
|
|
75
|
+
icon: <span>📊</span> // Can be any React Node (SVG, Icon component)
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'settings',
|
|
79
|
+
title: 'Settings',
|
|
80
|
+
path: '/settings',
|
|
81
|
+
icon: <span>⚙️</span>
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div className="min-h-screen bg-gray-50">
|
|
87
|
+
{/* Header Component */}
|
|
88
|
+
<Header
|
|
89
|
+
user={user}
|
|
90
|
+
sidebarId="main-sidebar" // Must match sidebarId in SharedSidebar
|
|
91
|
+
/>
|
|
92
|
+
|
|
93
|
+
{/* Sidebar Component */}
|
|
94
|
+
<SharedSidebar
|
|
95
|
+
user={user}
|
|
96
|
+
menuItems={menuItems}
|
|
97
|
+
sidebarId="main-sidebar"
|
|
98
|
+
profilePath="/profile"
|
|
99
|
+
roleLabel="Administrator"
|
|
100
|
+
roleColor="purple" // teal, purple, orange, blue, green
|
|
101
|
+
onNavigate={(path) => router.push(path)}
|
|
102
|
+
onLogout={() => console.log('User logged out')}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
{/* Main Content Area */}
|
|
106
|
+
<main className="lg:pl-64 pt-20 p-8 transition-all duration-300">
|
|
107
|
+
<h1>Welcome to Dashboard</h1>
|
|
108
|
+
</main>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
41
112
|
```
|
|
42
113
|
|
|
43
|
-
###
|
|
114
|
+
### 2. Using Notifications
|
|
115
|
+
|
|
116
|
+
The Header component accepts a `notifications` array to display a dropdown.
|
|
44
117
|
|
|
45
118
|
```tsx
|
|
46
|
-
import {
|
|
47
|
-
|
|
119
|
+
import { Header, NotificationItem } from '@kt-components/layout-header-sidebar';
|
|
120
|
+
|
|
121
|
+
const notifications: NotificationItem[] = [
|
|
122
|
+
{
|
|
123
|
+
id: 1,
|
|
124
|
+
title: 'System Update',
|
|
125
|
+
description: 'System maintenance scheduled at midnight.',
|
|
126
|
+
date: '10 mins ago',
|
|
127
|
+
type: 'info', // 'info' | 'success' | 'reminder'
|
|
128
|
+
isRead: false
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: 2,
|
|
132
|
+
title: 'Task Completed',
|
|
133
|
+
description: 'Your export task has finished successfully.',
|
|
134
|
+
date: '1 hour ago',
|
|
135
|
+
type: 'success',
|
|
136
|
+
isRead: true
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
// In your render:
|
|
141
|
+
<Header
|
|
142
|
+
user={user}
|
|
143
|
+
notifications={notifications}
|
|
144
|
+
/>
|
|
48
145
|
```
|
|
49
146
|
|
|
50
|
-
###
|
|
147
|
+
### 3. Toggling Sidebar Programmatically
|
|
148
|
+
|
|
149
|
+
You can control the sidebar state from anywhere in your app using the `toggleSidebar` utility.
|
|
51
150
|
|
|
52
151
|
```tsx
|
|
53
152
|
import { toggleSidebar } from '@kt-components/layout-header-sidebar';
|
|
54
|
-
|
|
153
|
+
|
|
154
|
+
// Toggle default sidebar ('sidebar', 'sidebar-overlay')
|
|
155
|
+
<button onClick={() => toggleSidebar()}>Menu</button>
|
|
156
|
+
|
|
157
|
+
// Toggle specific sidebar ID
|
|
158
|
+
<button onClick={() => toggleSidebar('main-sidebar')}>Menu</button>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## API Reference
|
|
162
|
+
|
|
163
|
+
### `<Header />`
|
|
164
|
+
|
|
165
|
+
Top navigation bar showing user profile, notification bell, and hamburger menu (mobile).
|
|
166
|
+
|
|
167
|
+
| Prop | Type | Default | Description |
|
|
168
|
+
|------|------|---------|-------------|
|
|
169
|
+
| `user` | `User` | - | User information object. |
|
|
170
|
+
| `notifications` | `NotificationItem[]` | `[]` | List of items for notification dropdown. |
|
|
171
|
+
| `sidebarId` | `string` | `'sidebar'` | ID used to toggle the sidebar. |
|
|
172
|
+
| `overlayId` | `string` | `'sidebar-overlay'` | ID used to toggle the overlay. |
|
|
173
|
+
| `notificationBell` | `ReactNode` | - | Custom component to replace the bell icon. |
|
|
174
|
+
|
|
175
|
+
### `<SharedSidebar />`
|
|
176
|
+
|
|
177
|
+
Responsive sidebar navigation with user profile section.
|
|
178
|
+
|
|
179
|
+
| Prop | Type | Default | Description |
|
|
180
|
+
|------|------|---------|-------------|
|
|
181
|
+
| `user` | `User` | - | User information object. |
|
|
182
|
+
| `menuItems` | `MenuItem[]` | `[]` | Array of navigation items. |
|
|
183
|
+
| `onNavigate` | `(path: string) => void` | - | Callback when a menu item is clicked. |
|
|
184
|
+
| `onLogout` | `() => void` | - | Callback when logout button is clicked. |
|
|
185
|
+
| `roleLabel` | `string` | - | Text to display below user name (e.g. "Admin"). |
|
|
186
|
+
| `roleColor` | `string` | `'orange'` | Badge color (`teal`, `blue`, `orange`, `purple`, `green`). |
|
|
187
|
+
| `profilePath` | `string` | - | URL path for the user profile page. |
|
|
188
|
+
| `sidebarId` | `string` | `'sidebar'` | DOM ID for the sidebar container. |
|
|
189
|
+
| `overlayId` | `string` | `'sidebar-overlay'` | DOM ID for the backdrop overlay. |
|
|
190
|
+
|
|
191
|
+
### Type Definitions
|
|
192
|
+
|
|
193
|
+
**User**
|
|
194
|
+
```ts
|
|
195
|
+
interface User {
|
|
196
|
+
firstName?: string;
|
|
197
|
+
lastName?: string;
|
|
198
|
+
pictureUrl?: string;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**MenuItem**
|
|
203
|
+
```ts
|
|
204
|
+
interface MenuItem {
|
|
205
|
+
id: string;
|
|
206
|
+
title: string;
|
|
207
|
+
path: string;
|
|
208
|
+
icon?: React.ReactNode;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**NotificationItem**
|
|
213
|
+
```ts
|
|
214
|
+
interface NotificationItem {
|
|
215
|
+
id: string | number;
|
|
216
|
+
title: string;
|
|
217
|
+
description: string;
|
|
218
|
+
date: string;
|
|
219
|
+
type: 'reminder' | 'success' | 'info';
|
|
220
|
+
isRead?: boolean;
|
|
221
|
+
}
|
|
55
222
|
```
|
|
56
223
|
|
|
57
|
-
##
|
|
224
|
+
## License
|
|
58
225
|
|
|
59
|
-
|
|
226
|
+
MIT
|
package/package.json
CHANGED