@bomjan133/react-crud-ui 1.2.5

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.
@@ -0,0 +1,402 @@
1
+ # Layout Components Guide
2
+
3
+ Complete reference for layout components in @sujanbomjan/react-crud-ui.
4
+
5
+ ## Table of Contents
6
+ 1. [AuthLayout](#authlayout)
7
+ 2. [LoginPage](#loginpage)
8
+ 3. [DashboardLayout](#dashboardlayout)
9
+ 4. [SidebarProvider](#sidebarprovider)
10
+
11
+ ---
12
+
13
+ ## AuthLayout
14
+
15
+ A centered layout for authentication pages (login, register, forgot password).
16
+
17
+ ### Props
18
+
19
+ | Prop | Type | Default | Description |
20
+ |------|------|---------|-------------|
21
+ | `children` | `node` | - | Content to render |
22
+ | `className` | `string` | - | Additional CSS classes |
23
+
24
+ ### Usage
25
+
26
+ ```jsx
27
+ import { AuthLayout } from '@sujanbomjan/react-crud-ui';
28
+
29
+ function LoginPage() {
30
+ return (
31
+ <AuthLayout>
32
+ <div className="w-full max-w-md space-y-6 p-8 bg-white rounded-lg shadow">
33
+ <h1 className="text-2xl font-bold text-center">Login</h1>
34
+ {/* Login form */}
35
+ </div>
36
+ </AuthLayout>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### Styling
42
+
43
+ The AuthLayout provides:
44
+ - Full viewport height centered container
45
+ - Gradient background
46
+ - Responsive padding
47
+ - Dark mode support
48
+
49
+ ---
50
+
51
+ ## LoginPage
52
+
53
+ A complete, styled login page component.
54
+
55
+ ### Props
56
+
57
+ | Prop | Type | Default | Description |
58
+ |------|------|---------|-------------|
59
+ | `onSubmit` | `function` | - | Form submit handler `({ email, password }) => Promise` |
60
+ | `loading` | `boolean` | `false` | Show loading state |
61
+ | `error` | `string` | - | Error message to display |
62
+ | `title` | `string` | `'Login'` | Page title |
63
+ | `description` | `string` | `'Enter your credentials'` | Page description |
64
+ | `logo` | `node` | - | Logo component |
65
+ | `brandName` | `string` | - | Brand name text |
66
+ | `showForgotPassword` | `boolean` | `true` | Show forgot password link |
67
+ | `forgotPasswordPath` | `string` | `'/forgot-password'` | Forgot password URL |
68
+ | `showRegister` | `boolean` | `true` | Show register link |
69
+ | `registerPath` | `string` | `'/register'` | Register URL |
70
+ | `registerText` | `string` | `"Don't have an account?"` | Register prompt text |
71
+
72
+ ### Usage
73
+
74
+ ```jsx
75
+ import { LoginPage } from '@sujanbomjan/react-crud-ui';
76
+ import { useNavigate } from 'react-router-dom';
77
+ import { useAuthStore } from '@/stores/useAuthStore';
78
+ import Logo from '@/assets/logo.svg';
79
+
80
+ function Login() {
81
+ const navigate = useNavigate();
82
+ const { login, loading, error } = useAuthStore();
83
+
84
+ const handleSubmit = async ({ email, password }) => {
85
+ const success = await login(email, password);
86
+ if (success) {
87
+ navigate('/dashboard');
88
+ }
89
+ };
90
+
91
+ return (
92
+ <LoginPage
93
+ onSubmit={handleSubmit}
94
+ loading={loading}
95
+ error={error}
96
+ title="Welcome Back"
97
+ description="Sign in to your account"
98
+ logo={<img src={Logo} alt="Logo" className="h-12 w-auto" />}
99
+ brandName="My App"
100
+ showForgotPassword
101
+ forgotPasswordPath="/forgot-password"
102
+ showRegister
103
+ registerPath="/register"
104
+ />
105
+ );
106
+ }
107
+ ```
108
+
109
+ ---
110
+
111
+ ## DashboardLayout
112
+
113
+ A complete admin dashboard layout with sidebar and header.
114
+
115
+ ### Props
116
+
117
+ | Prop | Type | Default | Description |
118
+ |------|------|---------|-------------|
119
+ | `sidebarProps` | `object` | - | Sidebar configuration |
120
+ | `headerProps` | `object` | - | Header configuration |
121
+ | `children` | `node` | - | Page content |
122
+
123
+ ### Sidebar Props
124
+
125
+ | Prop | Type | Description |
126
+ |------|------|-------------|
127
+ | `items` | `array` | Navigation items |
128
+ | `brandName` | `string` | Brand name in sidebar |
129
+ | `brandLogo` | `node` | Brand logo component |
130
+ | `user` | `object` | Current user `{ name, email, avatar }` |
131
+ | `onLogout` | `function` | Logout handler |
132
+
133
+ ### Header Props
134
+
135
+ | Prop | Type | Description |
136
+ |------|------|-------------|
137
+ | `pathNames` | `object` | URL to title mapping for breadcrumbs |
138
+ | `title` | `string` | Static page title (overrides pathNames) |
139
+
140
+ ### Navigation Item Structure
141
+
142
+ ```ts
143
+ interface NavItem {
144
+ name: string; // Display name
145
+ path: string; // Route path
146
+ icon: Component; // Lucide icon component
147
+ children?: NavItem[]; // Submenu items (optional)
148
+ badge?: string; // Badge text (optional)
149
+ badgeVariant?: string; // Badge variant (optional)
150
+ }
151
+ ```
152
+
153
+ ### Usage
154
+
155
+ ```jsx
156
+ import { DashboardLayout } from '@sujanbomjan/react-crud-ui';
157
+ import { Outlet, useNavigate } from 'react-router-dom';
158
+ import {
159
+ LayoutDashboard,
160
+ Users,
161
+ Settings,
162
+ Package,
163
+ ShoppingCart,
164
+ BarChart,
165
+ } from 'lucide-react';
166
+ import { useAuthStore } from '@/stores/useAuthStore';
167
+
168
+ const sidebarItems = [
169
+ {
170
+ name: 'Dashboard',
171
+ path: '/dashboard',
172
+ icon: LayoutDashboard,
173
+ },
174
+ {
175
+ name: 'Products',
176
+ path: '/products',
177
+ icon: Package,
178
+ },
179
+ {
180
+ name: 'Orders',
181
+ path: '/orders',
182
+ icon: ShoppingCart,
183
+ badge: '12',
184
+ badgeVariant: 'destructive',
185
+ },
186
+ {
187
+ name: 'Users',
188
+ path: '/users',
189
+ icon: Users,
190
+ children: [
191
+ { name: 'All Users', path: '/users', icon: Users },
192
+ { name: 'Roles', path: '/users/roles', icon: Settings },
193
+ ],
194
+ },
195
+ {
196
+ name: 'Analytics',
197
+ path: '/analytics',
198
+ icon: BarChart,
199
+ },
200
+ {
201
+ name: 'Settings',
202
+ path: '/settings',
203
+ icon: Settings,
204
+ },
205
+ ];
206
+
207
+ const pathNames = {
208
+ '/dashboard': 'Dashboard',
209
+ '/products': 'Products',
210
+ '/products/create': 'Create Product',
211
+ '/products/:id': 'Product Details',
212
+ '/products/:id/edit': 'Edit Product',
213
+ '/users': 'Users',
214
+ '/users/roles': 'Roles',
215
+ '/settings': 'Settings',
216
+ };
217
+
218
+ export default function MainLayout() {
219
+ const navigate = useNavigate();
220
+ const { user, logout } = useAuthStore();
221
+
222
+ const handleLogout = async () => {
223
+ await logout();
224
+ navigate('/login');
225
+ };
226
+
227
+ return (
228
+ <DashboardLayout
229
+ sidebarProps={{
230
+ items: sidebarItems,
231
+ brandName: 'My Admin',
232
+ user: {
233
+ name: user?.name,
234
+ email: user?.email,
235
+ avatar: user?.avatar,
236
+ },
237
+ onLogout: handleLogout,
238
+ }}
239
+ headerProps={{
240
+ pathNames: pathNames,
241
+ }}
242
+ >
243
+ <Outlet />
244
+ </DashboardLayout>
245
+ );
246
+ }
247
+ ```
248
+
249
+ ### Route Configuration
250
+
251
+ ```jsx
252
+ // routes.jsx
253
+ import { Route, Routes } from 'react-router-dom';
254
+ import MainLayout from '@/layouts/MainLayout';
255
+ import Dashboard from '@/pages/Dashboard';
256
+ import ProductList from '@/pages/products/ProductList';
257
+ import ProductForm from '@/pages/products/ProductForm';
258
+ import ProductDetail from '@/pages/products/ProductDetail';
259
+
260
+ function AppRoutes() {
261
+ return (
262
+ <Routes>
263
+ {/* Public routes */}
264
+ <Route path="/login" element={<LoginPage />} />
265
+
266
+ {/* Protected routes with dashboard layout */}
267
+ <Route element={<MainLayout />}>
268
+ <Route path="/dashboard" element={<Dashboard />} />
269
+ <Route path="/products" element={<ProductList />} />
270
+ <Route path="/products/create" element={<ProductForm />} />
271
+ <Route path="/products/:id" element={<ProductDetail />} />
272
+ <Route path="/products/:id/edit" element={<ProductForm />} />
273
+ </Route>
274
+ </Routes>
275
+ );
276
+ }
277
+ ```
278
+
279
+ ---
280
+
281
+ ## SidebarProvider
282
+
283
+ Context provider for sidebar state management (collapse/expand).
284
+
285
+ ### Usage
286
+
287
+ The `DashboardLayout` automatically includes the `SidebarProvider`. If you need to access sidebar state outside the layout:
288
+
289
+ ```jsx
290
+ import { useSidebarContext } from '@sujanbomjan/react-crud-ui';
291
+
292
+ function SomeComponent() {
293
+ const { isCollapsed, toggleCollapse } = useSidebarContext();
294
+
295
+ return (
296
+ <button onClick={toggleCollapse}>
297
+ {isCollapsed ? 'Expand' : 'Collapse'} Sidebar
298
+ </button>
299
+ );
300
+ }
301
+ ```
302
+
303
+ ### Context Values
304
+
305
+ | Value | Type | Description |
306
+ |-------|------|-------------|
307
+ | `isOpen` | `boolean` | Whether sidebar is open (mobile) |
308
+ | `isCollapsed` | `boolean` | Whether sidebar is collapsed (desktop) |
309
+ | `setOpen` | `function` | Set open state directly |
310
+ | `setCollapsed` | `function` | Set collapsed state directly |
311
+ | `toggle` | `function` | Toggle open state |
312
+ | `toggleCollapse` | `function` | Toggle collapsed state |
313
+
314
+ ---
315
+
316
+ ## Full Example: App Setup
317
+
318
+ ```jsx
319
+ // src/App.jsx
320
+ import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
321
+ import MainLayout from '@/layouts/MainLayout';
322
+ import Login from '@/pages/Login';
323
+ import Dashboard from '@/pages/Dashboard';
324
+ import ProductListPage from '@/pages/products/ProductListPage';
325
+ import ProductFormPage from '@/pages/products/ProductFormPage';
326
+ import ProductDetailPage from '@/pages/products/ProductDetailPage';
327
+
328
+ function App() {
329
+ return (
330
+ <BrowserRouter>
331
+ <Routes>
332
+ {/* Redirect root to dashboard */}
333
+ <Route path="/" element={<Navigate to="/dashboard" replace />} />
334
+
335
+ {/* Auth routes */}
336
+ <Route path="/login" element={<Login />} />
337
+
338
+ {/* Dashboard routes */}
339
+ <Route element={<MainLayout />}>
340
+ <Route path="/dashboard" element={<Dashboard />} />
341
+ <Route path="/products" element={<ProductListPage />} />
342
+ <Route path="/products/create" element={<ProductFormPage />} />
343
+ <Route path="/products/:id" element={<ProductDetailPage />} />
344
+ <Route path="/products/:id/edit" element={<ProductFormPage />} />
345
+ </Route>
346
+
347
+ {/* 404 */}
348
+ <Route path="*" element={<Navigate to="/dashboard" replace />} />
349
+ </Routes>
350
+ </BrowserRouter>
351
+ );
352
+ }
353
+
354
+ export default App;
355
+ ```
356
+
357
+ ```jsx
358
+ // src/layouts/MainLayout.jsx
359
+ import { DashboardLayout } from '@sujanbomjan/react-crud-ui';
360
+ import { Outlet, useNavigate } from 'react-router-dom';
361
+ import { LayoutDashboard, Package, Settings } from 'lucide-react';
362
+ import { useAuthStore } from '@/stores/useAuthStore';
363
+
364
+ const sidebarItems = [
365
+ { name: 'Dashboard', path: '/dashboard', icon: LayoutDashboard },
366
+ { name: 'Products', path: '/products', icon: Package },
367
+ { name: 'Settings', path: '/settings', icon: Settings },
368
+ ];
369
+
370
+ const pathNames = {
371
+ '/dashboard': 'Dashboard',
372
+ '/products': 'Products',
373
+ '/products/create': 'Create Product',
374
+ '/products/:id': 'Product Details',
375
+ '/products/:id/edit': 'Edit Product',
376
+ '/settings': 'Settings',
377
+ };
378
+
379
+ export default function MainLayout() {
380
+ const navigate = useNavigate();
381
+ const { user, logout } = useAuthStore();
382
+
383
+ const handleLogout = async () => {
384
+ await logout();
385
+ navigate('/login');
386
+ };
387
+
388
+ return (
389
+ <DashboardLayout
390
+ sidebarProps={{
391
+ items: sidebarItems,
392
+ brandName: 'Admin Panel',
393
+ user: { name: user?.name, email: user?.email },
394
+ onLogout: handleLogout,
395
+ }}
396
+ headerProps={{ pathNames }}
397
+ >
398
+ <Outlet />
399
+ </DashboardLayout>
400
+ );
401
+ }
402
+ ```