izen-react-starter 1.1.0
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 +597 -0
- package/dist/App.d.ts +3 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/MIMHJGAX-Brj9G5XE.js +9168 -0
- package/dist/Q7LWSL4U-CPoRPcQS.js +33 -0
- package/dist/VLTTJS3N-BeVVV6a8.js +42 -0
- package/dist/components/Button/Button.d.ts +17 -0
- package/dist/components/Button/Button.d.ts.map +1 -0
- package/dist/components/Button/index.d.ts +3 -0
- package/dist/components/Button/index.d.ts.map +1 -0
- package/dist/components/Card/Card.d.ts +25 -0
- package/dist/components/Card/Card.d.ts.map +1 -0
- package/dist/components/Card/index.d.ts +3 -0
- package/dist/components/Card/index.d.ts.map +1 -0
- package/dist/components/ui/accordion.d.ts +8 -0
- package/dist/components/ui/accordion.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +21 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert.d.ts +9 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/aspect-ratio.d.ts +4 -0
- package/dist/components/ui/aspect-ratio.d.ts.map +1 -0
- package/dist/components/ui/avatar.d.ts +7 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/badge.d.ts +10 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +20 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/button.d.ts +12 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/calendar.d.ts +9 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/carousel.d.ts +19 -0
- package/dist/components/ui/carousel.d.ts.map +1 -0
- package/dist/components/ui/chart.d.ts +50 -0
- package/dist/components/ui/chart.d.ts.map +1 -0
- package/dist/components/ui/checkbox.d.ts +5 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/command.d.ts +81 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/context-menu.d.ts +28 -0
- package/dist/components/ui/context-menu.d.ts.map +1 -0
- package/dist/components/ui/dialog.d.ts +20 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/drawer.d.ts +23 -0
- package/dist/components/ui/drawer.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/form.d.ts +13 -0
- package/dist/components/ui/form.d.ts.map +1 -0
- package/dist/components/ui/hover-card.d.ts +7 -0
- package/dist/components/ui/hover-card.d.ts.map +1 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.d.ts.map +1 -0
- package/dist/components/ui/index.d.ts +53 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/input-otp.d.ts +35 -0
- package/dist/components/ui/input-otp.d.ts.map +1 -0
- package/dist/components/ui/input.d.ts +4 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/label.d.ts +6 -0
- package/dist/components/ui/label.d.ts.map +1 -0
- package/dist/components/ui/menubar.d.ts +34 -0
- package/dist/components/ui/menubar.d.ts.map +1 -0
- package/dist/components/ui/modal.d.ts +13 -0
- package/dist/components/ui/modal.d.ts.map +1 -0
- package/dist/components/ui/navigation-menu.d.ts +13 -0
- package/dist/components/ui/navigation-menu.d.ts.map +1 -0
- package/dist/components/ui/pagination.d.ts +37 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/progress.d.ts +5 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/protected-components.d.ts +7 -0
- package/dist/components/ui/protected-components.d.ts.map +1 -0
- package/dist/components/ui/radio-group.d.ts +6 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/resizable.d.ts +8 -0
- package/dist/components/ui/resizable.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +10 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/select.d.ts +14 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/sheet.d.ts +26 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sidebar.d.ts +66 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/skeleton.d.ts +4 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/slider.d.ts +5 -0
- package/dist/components/ui/slider.d.ts.map +1 -0
- package/dist/components/ui/sonner.d.ts +5 -0
- package/dist/components/ui/sonner.d.ts.map +1 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.d.ts.map +1 -0
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/tabs.d.ts +8 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/textarea.d.ts +6 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/components/ui/toast.d.ts +16 -0
- package/dist/components/ui/toast.d.ts.map +1 -0
- package/dist/components/ui/toaster.d.ts +2 -0
- package/dist/components/ui/toaster.d.ts.map +1 -0
- package/dist/components/ui/toggle-group.d.ts +13 -0
- package/dist/components/ui/toggle-group.d.ts.map +1 -0
- package/dist/components/ui/toggle.d.ts +13 -0
- package/dist/components/ui/toggle.d.ts.map +1 -0
- package/dist/components/ui/tooltip.d.ts +8 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/use-toast.d.ts +45 -0
- package/dist/components/ui/use-toast.d.ts.map +1 -0
- package/dist/contexts/LayoutContext.d.ts +41 -0
- package/dist/contexts/LayoutContext.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.d.ts +2 -0
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/index-lCrdXFfH.js +45405 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/izen-react-starter.css +1 -0
- package/dist/lib/cache-util.d.ts +11 -0
- package/dist/lib/cache-util.d.ts.map +1 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +10 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/providers/AppProvider.d.ts +13 -0
- package/dist/providers/AppProvider.d.ts.map +1 -0
- package/dist/providers/AuthProvider.d.ts +26 -0
- package/dist/providers/AuthProvider.d.ts.map +1 -0
- package/dist/providers/FormContext.d.ts +5 -0
- package/dist/providers/FormContext.d.ts.map +1 -0
- package/dist/providers/ModalProvider.d.ts +11 -0
- package/dist/providers/ModalProvider.d.ts.map +1 -0
- package/dist/providers/OverlayProvider.d.ts +11 -0
- package/dist/providers/OverlayProvider.d.ts.map +1 -0
- package/dist/providers/ThemeProvider.d.ts +14 -0
- package/dist/providers/ThemeProvider.d.ts.map +1 -0
- package/dist/providers/index.d.ts +11 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/rbac/AccessControlWrapper.d.ts +16 -0
- package/dist/rbac/AccessControlWrapper.d.ts.map +1 -0
- package/dist/rbac/UpdateAccessControlWrapper.d.ts +10 -0
- package/dist/rbac/UpdateAccessControlWrapper.d.ts.map +1 -0
- package/dist/rbac/access-rules.d.ts +52 -0
- package/dist/rbac/access-rules.d.ts.map +1 -0
- package/dist/rbac/index.d.ts +8 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/useAccessControl.d.ts +8 -0
- package/dist/rbac/useAccessControl.d.ts.map +1 -0
- package/dist/react-starter.js +304 -0
- package/dist/react-starter.umd.cjs +1573 -0
- package/dist/routes/RequiredAuth.d.ts +6 -0
- package/dist/routes/RequiredAuth.d.ts.map +1 -0
- package/dist/routes/hooks/index.d.ts +4 -0
- package/dist/routes/hooks/index.d.ts.map +1 -0
- package/dist/routes/hooks/usePathname.d.ts +2 -0
- package/dist/routes/hooks/usePathname.d.ts.map +1 -0
- package/dist/routes/hooks/useRouter.d.ts +9 -0
- package/dist/routes/hooks/useRouter.d.ts.map +1 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/services/apiService.d.ts +26 -0
- package/dist/services/apiService.d.ts.map +1 -0
- package/dist/with-styles.d.ts +2 -0
- package/dist/with-styles.d.ts.map +1 -0
- package/package.json +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
# React Starter
|
|
2
|
+
|
|
3
|
+
A modern React component library built with Vite, TypeScript, and best practices.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **UI Components**: Pre-built, customizable components (Button, Card, etc.)
|
|
8
|
+
- 🎭 **Layout Context**: Context API for managing layout state (sidebar, theme)
|
|
9
|
+
- 🔐 **Authentication Provider**: Built-in auth context with cookie management
|
|
10
|
+
- 🛣️ **Routing Utilities**: Protected routes and navigation hooks
|
|
11
|
+
- 🎨 **Theme Provider**: Dark/light mode with system preference support
|
|
12
|
+
- 🌐 **API Service**: Axios-based service for data fetching and posting
|
|
13
|
+
- 🔄 **React Query Integration**: Built-in query client and provider
|
|
14
|
+
- � **RBAC System**: Role-based access control with customizable permissions
|
|
15
|
+
- 🎣 **Custom Hooks**: Utility hooks like useIsMobile, useRouter, usePathname
|
|
16
|
+
- 🛠️ **Utility Functions**: Helper functions for common tasks (cn, debounce, throttle, etc.)
|
|
17
|
+
- 💾 **Cache Utilities**: React Query cache manipulation helpers
|
|
18
|
+
- �📦 **TypeScript**: Full type safety and IntelliSense support
|
|
19
|
+
- ⚡ **Vite**: Lightning-fast development and optimized builds
|
|
20
|
+
- 🌳 **Tree-shakeable**: Optimized for minimal bundle size
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install react-starter
|
|
26
|
+
# or
|
|
27
|
+
yarn add react-starter
|
|
28
|
+
# or
|
|
29
|
+
pnpm add react-starter
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Import Styles
|
|
33
|
+
|
|
34
|
+
Don't forget to import the CSS file in your app entry point:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
// In your main.tsx or App.tsx
|
|
38
|
+
import 'react-starter/style.css';
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The library includes Tailwind CSS with pre-configured theme variables for:
|
|
42
|
+
- Light/Dark modes
|
|
43
|
+
- Customizable color schemes
|
|
44
|
+
- Geist font family
|
|
45
|
+
- Custom CSS variables for theming
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### App Provider (All-in-one)
|
|
50
|
+
|
|
51
|
+
Wrap your application with `AppProvider` to get all providers in one go:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { AppProvider } from 'react-starter';
|
|
55
|
+
import { AppRouter } from './routes';
|
|
56
|
+
|
|
57
|
+
function App() {
|
|
58
|
+
return (
|
|
59
|
+
<AppProvider
|
|
60
|
+
defaultTheme="light"
|
|
61
|
+
showReactQueryDevtools={true}
|
|
62
|
+
>
|
|
63
|
+
<AppRouter />
|
|
64
|
+
</AppProvider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Authentication
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { AuthProvider, useAuth } from 'react-starter';
|
|
73
|
+
|
|
74
|
+
function LoginPage() {
|
|
75
|
+
const { setAuthData } = useAuth();
|
|
76
|
+
|
|
77
|
+
const handleLogin = async (credentials) => {
|
|
78
|
+
const response = await fetch('/api/login', {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
body: JSON.stringify(credentials)
|
|
81
|
+
});
|
|
82
|
+
const { user, tokens } = await response.json();
|
|
83
|
+
|
|
84
|
+
// Store user and tokens in cookies
|
|
85
|
+
setAuthData(user, tokens);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return <div>Login Form</div>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ProfilePage() {
|
|
92
|
+
const { user, tokens } = useAuth();
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div>
|
|
96
|
+
<h1>Welcome {user?.name}</h1>
|
|
97
|
+
<p>Token: {tokens?.access_token}</p>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Protected Routes
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { RequiredAuth } from 'react-starter';
|
|
107
|
+
import { Routes, Route } from 'react-router-dom';
|
|
108
|
+
|
|
109
|
+
function AppRouter() {
|
|
110
|
+
return (
|
|
111
|
+
<Routes>
|
|
112
|
+
<Route path="/login" element={<LoginPage />} />
|
|
113
|
+
|
|
114
|
+
{/* Protected routes */}
|
|
115
|
+
<Route element={<RequiredAuth redirectTo="/login" />}>
|
|
116
|
+
<Route path="/dashboard" element={<Dashboard />} />
|
|
117
|
+
<Route path="/profile" element={<Profile />} />
|
|
118
|
+
</Route>
|
|
119
|
+
</Routes>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Router Hooks
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { useRouter, usePathname } from 'react-starter';
|
|
128
|
+
|
|
129
|
+
function MyComponent() {
|
|
130
|
+
const router = useRouter();
|
|
131
|
+
const pathname = usePathname();
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<p>Current path: {pathname}</p>
|
|
136
|
+
<button onClick={() => router.push('/dashboard')}>
|
|
137
|
+
Go to Dashboard
|
|
138
|
+
</button>
|
|
139
|
+
<button onClick={() => router.back()}>
|
|
140
|
+
Go Back
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Theme Provider
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { ThemeProvider, useTheme } from 'react-starter';
|
|
151
|
+
|
|
152
|
+
function ThemeToggle() {
|
|
153
|
+
const { theme, setTheme } = useTheme();
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
|
157
|
+
Current theme: {theme}
|
|
158
|
+
</button>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Modal and Overlay
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { ModalProvider, useModal, OverlayProvider, useOverlay } from 'react-starter';
|
|
167
|
+
|
|
168
|
+
function MyComponent() {
|
|
169
|
+
const { isOpen, setIsOpen } = useModal();
|
|
170
|
+
const { showOverlay, setShowOverlay } = useOverlay();
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<div>
|
|
174
|
+
<button onClick={() => setIsOpen('my-modal')}>Open Modal</button>
|
|
175
|
+
{isOpen === 'my-modal' && <div>Modal Content</div>}
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Components
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import { Button, Card } from 'react-starter';
|
|
185
|
+
|
|
186
|
+
function MyApp() {
|
|
187
|
+
return (
|
|
188
|
+
<Card title="Hello World">
|
|
189
|
+
<p>Card content goes here</p>
|
|
190
|
+
<Button variant="primary" onClick={() => alert('Clicked!')}>
|
|
191
|
+
Click Me
|
|
192
|
+
</Button>
|
|
193
|
+
</Card>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Layout Context
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
import { LayoutProvider, useLayout } from 'react-starter';
|
|
202
|
+
|
|
203
|
+
function App() {
|
|
204
|
+
return (
|
|
205
|
+
<LayoutProvider initialTheme="light" initialSidebarOpen={true}>
|
|
206
|
+
<MyComponent />
|
|
207
|
+
</LayoutProvider>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function MyComponent() {
|
|
212
|
+
const { theme, toggleTheme, sidebarOpen, toggleSidebar } = useLayout();
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div>
|
|
216
|
+
<button onClick={toggleTheme}>
|
|
217
|
+
Current theme: {theme}
|
|
218
|
+
</button>
|
|
219
|
+
<button onClick={toggleSidebar}>
|
|
220
|
+
Sidebar is {sidebarOpen ? 'open' : 'closed'}
|
|
221
|
+
</button>
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### API Service
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import { apiService } from 'react-starter';
|
|
231
|
+
|
|
232
|
+
// Configure base URL
|
|
233
|
+
apiService.setBaseURL('https://api.example.com');
|
|
234
|
+
|
|
235
|
+
// Set auth token
|
|
236
|
+
apiService.setAuthToken('your-token-here');
|
|
237
|
+
|
|
238
|
+
// Make API calls
|
|
239
|
+
async function fetchData() {
|
|
240
|
+
try {
|
|
241
|
+
const data = await apiService.get('/users');
|
|
242
|
+
console.log(data);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.error('Error fetching data:', error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function postData() {
|
|
249
|
+
try {
|
|
250
|
+
const response = await apiService.post('/users', {
|
|
251
|
+
name: 'John Doe',
|
|
252
|
+
email: 'john@example.com'
|
|
253
|
+
});
|
|
254
|
+
console.log(response);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.error('Error posting data:', error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Role-Based Access Control (RBAC)
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import {
|
|
265
|
+
useAccessControl,
|
|
266
|
+
AccessControlWrapper,
|
|
267
|
+
withAccessControl,
|
|
268
|
+
Action,
|
|
269
|
+
Resource
|
|
270
|
+
} from 'react-starter';
|
|
271
|
+
|
|
272
|
+
// Using the hook
|
|
273
|
+
function AdminPanel() {
|
|
274
|
+
const { isAllowed } = useAccessControl();
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<div>
|
|
278
|
+
{isAllowed(Action.Create, Resource.Users) && (
|
|
279
|
+
<button>Create User</button>
|
|
280
|
+
)}
|
|
281
|
+
{isAllowed(Action.Delete, Resource.Users) && (
|
|
282
|
+
<button>Delete User</button>
|
|
283
|
+
)}
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Using the wrapper component
|
|
289
|
+
function Dashboard() {
|
|
290
|
+
return (
|
|
291
|
+
<AccessControlWrapper resource={Resource.Reports} action={Action.Read}>
|
|
292
|
+
<ReportsPanel />
|
|
293
|
+
</AccessControlWrapper>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Using the HOC
|
|
298
|
+
const ProtectedComponent = withAccessControl(MyComponent);
|
|
299
|
+
|
|
300
|
+
<ProtectedComponent
|
|
301
|
+
accessedResource={Resource.Users}
|
|
302
|
+
accessAction={Action.Update}
|
|
303
|
+
otherProp="value"
|
|
304
|
+
/>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Utility Functions
|
|
308
|
+
|
|
309
|
+
```tsx
|
|
310
|
+
import { cn, debounce, throttle, capitalize, formatDate } from 'react-starter';
|
|
311
|
+
|
|
312
|
+
// Combine classnames with Tailwind merge
|
|
313
|
+
const className = cn('bg-blue-500', 'text-white', 'hover:bg-blue-600');
|
|
314
|
+
|
|
315
|
+
// Debounce function calls
|
|
316
|
+
const debouncedSearch = debounce((query: string) => {
|
|
317
|
+
console.log('Searching for:', query);
|
|
318
|
+
}, 300);
|
|
319
|
+
|
|
320
|
+
// Throttle function calls
|
|
321
|
+
const throttledScroll = throttle(() => {
|
|
322
|
+
console.log('Scroll event');
|
|
323
|
+
}, 100);
|
|
324
|
+
|
|
325
|
+
// Capitalize strings
|
|
326
|
+
const capitalized = capitalize('hello'); // 'Hello'
|
|
327
|
+
|
|
328
|
+
// Format dates
|
|
329
|
+
const formatted = formatDate(new Date(), 'yyyy-MM-dd');
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Custom Hooks
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
import { useIsMobile } from 'react-starter';
|
|
336
|
+
|
|
337
|
+
function ResponsiveComponent() {
|
|
338
|
+
const isMobile = useIsMobile();
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<div>
|
|
342
|
+
{isMobile ? <MobileView /> : <DesktopView />}
|
|
343
|
+
</div>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Cache Management
|
|
349
|
+
|
|
350
|
+
```tsx
|
|
351
|
+
import { handleEditCache, handleSingleEditCache } from 'react-starter';
|
|
352
|
+
|
|
353
|
+
// Update cache after editing an item
|
|
354
|
+
handleEditCache({
|
|
355
|
+
item: updatedUser,
|
|
356
|
+
type: 'edit',
|
|
357
|
+
cacheKey: 'users'
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Add new item to cache
|
|
361
|
+
handleEditCache({
|
|
362
|
+
item: newUser,
|
|
363
|
+
type: 'add',
|
|
364
|
+
cacheKey: 'users'
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Delete item from cache
|
|
368
|
+
handleEditCache({
|
|
369
|
+
item: { id: userId },
|
|
370
|
+
type: 'delete',
|
|
371
|
+
cacheKey: 'users'
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Development
|
|
376
|
+
|
|
377
|
+
### Setup
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
# Install dependencies
|
|
381
|
+
npm install
|
|
382
|
+
|
|
383
|
+
# Start development server
|
|
384
|
+
npm run dev
|
|
385
|
+
|
|
386
|
+
# Build library
|
|
387
|
+
npm run build
|
|
388
|
+
|
|
389
|
+
# Lint code
|
|
390
|
+
npm run lint
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Project Structure
|
|
394
|
+
|
|
395
|
+
```
|
|
396
|
+
src/
|
|
397
|
+
├── components/ # UI components
|
|
398
|
+
│ ├── Button/
|
|
399
|
+
│ │ ├── Button.tsx
|
|
400
|
+
│ │ ├── Button.css
|
|
401
|
+
│ │ └── index.ts
|
|
402
|
+
│ └── Card/
|
|
403
|
+
│ ├── Card.tsx
|
|
404
|
+
│ ├── Card.css
|
|
405
|
+
│ └── index.ts
|
|
406
|
+
├── contexts/ # React contexts
|
|
407
|
+
│ └── LayoutContext.tsx
|
|
408
|
+
├── hooks/ # Custom hooks
|
|
409
|
+
│ ├── useIsMobile.ts
|
|
410
|
+
│ └── index.ts
|
|
411
|
+
├── lib/ # Utility functions
|
|
412
|
+
│ ├── utils.ts
|
|
413
|
+
│ ├── cache-util.ts
|
|
414
|
+
│ └── index.ts
|
|
415
|
+
├── providers/ # Context providers
|
|
416
|
+
│ ├── AuthProvider.tsx
|
|
417
|
+
│ ├── ModalProvider.tsx
|
|
418
|
+
│ ├── OverlayProvider.tsx
|
|
419
|
+
│ ├── ThemeProvider.tsx
|
|
420
|
+
│ ├── AppProvider.tsx
|
|
421
|
+
│ └── index.ts
|
|
422
|
+
├── rbac/ # Role-based access control
|
|
423
|
+
│ ├── access-rules.ts
|
|
424
|
+
│ ├── useAccessControl.ts
|
|
425
|
+
│ ├── AccessControlWrapper.tsx
|
|
426
|
+
│ ├── UpdateAccessControlWrapper.tsx
|
|
427
|
+
│ └── index.ts
|
|
428
|
+
├── routes/ # Routing utilities
|
|
429
|
+
│ ├── RequiredAuth.tsx
|
|
430
|
+
│ ├── hooks/
|
|
431
|
+
│ │ ├── usePathname.ts
|
|
432
|
+
│ │ ├── useRouter.ts
|
|
433
|
+
│ │ └── index.ts
|
|
434
|
+
│ └── index.ts
|
|
435
|
+
│ └── index.ts
|
|
436
|
+
├── services/ # API and utility services
|
|
437
|
+
│ └── apiService.ts
|
|
438
|
+
├── index.ts # Main export file
|
|
439
|
+
└── main.tsx # Dev preview entry
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## API Documentation
|
|
443
|
+
|
|
444
|
+
### AppProvider
|
|
445
|
+
|
|
446
|
+
A comprehensive provider that wraps your app with all necessary providers.
|
|
447
|
+
|
|
448
|
+
Props:
|
|
449
|
+
- `children`: ReactNode (required)
|
|
450
|
+
- `ErrorFallback`: React.ComponentType<FallbackProps> (optional)
|
|
451
|
+
- `showReactQueryDevtools`: boolean (default: false)
|
|
452
|
+
- `defaultTheme`: 'dark' | 'light' | 'system' (default: 'light')
|
|
453
|
+
- `storageKey`: string (default: 'vite-ui-theme')
|
|
454
|
+
|
|
455
|
+
### AuthProvider
|
|
456
|
+
|
|
457
|
+
Authentication context provider with cookie-based storage.
|
|
458
|
+
|
|
459
|
+
Hooks:
|
|
460
|
+
- `useAuth()`: Returns auth context with user, tokens, and management methods
|
|
461
|
+
|
|
462
|
+
Context value:
|
|
463
|
+
- `user`: User | undefined
|
|
464
|
+
- `tokens`: BackendTokens | undefined
|
|
465
|
+
- `setAuthData(user, tokens)`: Store auth data in cookies
|
|
466
|
+
- `otherData`: any (for additional app data)
|
|
467
|
+
- `setOtherData(data)`: Set additional data
|
|
468
|
+
|
|
469
|
+
### RequiredAuth
|
|
470
|
+
|
|
471
|
+
Protected route component that redirects unauthenticated users.
|
|
472
|
+
|
|
473
|
+
Props:
|
|
474
|
+
- `redirectTo`: string (default: '/login') - Where to redirect if not authenticated
|
|
475
|
+
|
|
476
|
+
### Router Hooks
|
|
477
|
+
|
|
478
|
+
**useRouter()**
|
|
479
|
+
- `back()`: Navigate back
|
|
480
|
+
- `forward()`: Navigate forward
|
|
481
|
+
- `reload()`: Reload page
|
|
482
|
+
- `push(href)`: Navigate to route
|
|
483
|
+
- `replace(href)`: Replace current route
|
|
484
|
+
|
|
485
|
+
**usePathname()**
|
|
486
|
+
- Returns current pathname string
|
|
487
|
+
|
|
488
|
+
### ThemeProvider
|
|
489
|
+
|
|
490
|
+
Theme management with localStorage persistence.
|
|
491
|
+
|
|
492
|
+
Props:
|
|
493
|
+
- `children`: ReactNode
|
|
494
|
+
- `defaultTheme`: 'dark' | 'light' | 'system' (default: 'light')
|
|
495
|
+
- `storageKey`: string (default: 'vite-ui-theme')
|
|
496
|
+
|
|
497
|
+
Hook:
|
|
498
|
+
- `useTheme()`: Returns { theme, setTheme }
|
|
499
|
+
|
|
500
|
+
### ModalProvider
|
|
501
|
+
|
|
502
|
+
Modal state management.
|
|
503
|
+
|
|
504
|
+
Hook:
|
|
505
|
+
- `useModal()`: Returns { isOpen, setIsOpen }
|
|
506
|
+
|
|
507
|
+
### OverlayProvider
|
|
508
|
+
|
|
509
|
+
Overlay state management.
|
|
510
|
+
|
|
511
|
+
Hook:
|
|
512
|
+
- `useOverlay()`: Returns { showOverlay, setShowOverlay }
|
|
513
|
+
|
|
514
|
+
### Button Component
|
|
515
|
+
|
|
516
|
+
Props:
|
|
517
|
+
- `variant`: 'primary' | 'secondary' | 'outline' (default: 'primary')
|
|
518
|
+
- `size`: 'small' | 'medium' | 'large' (default: 'medium')
|
|
519
|
+
- `loading`: boolean (default: false)
|
|
520
|
+
- All standard HTML button attributes
|
|
521
|
+
|
|
522
|
+
### Card Component
|
|
523
|
+
|
|
524
|
+
Props:
|
|
525
|
+
- `title`: string (optional)
|
|
526
|
+
- `children`: ReactNode (required)
|
|
527
|
+
- `footer`: ReactNode (optional)
|
|
528
|
+
- `elevation`: 'none' | 'low' | 'medium' | 'high' (default: 'medium')
|
|
529
|
+
- `className`: string (optional)
|
|
530
|
+
|
|
531
|
+
### Layout Context
|
|
532
|
+
|
|
533
|
+
Context value:
|
|
534
|
+
- `sidebarOpen`: boolean
|
|
535
|
+
- `toggleSidebar`: () => void
|
|
536
|
+
- `setSidebarOpen`: (open: boolean) => void
|
|
537
|
+
- `theme`: 'light' | 'dark'
|
|
538
|
+
- `toggleTheme`: () => void
|
|
539
|
+
- `setTheme`: (theme: 'light' | 'dark') => void
|
|
540
|
+
|
|
541
|
+
### API Service
|
|
542
|
+
|
|
543
|
+
Methods:
|
|
544
|
+
- `get<T>(url, config?)`: Promise<T>
|
|
545
|
+
- `post<T>(url, data?, config?)`: Promise<T>
|
|
546
|
+
- `put<T>(url, data?, config?)`: Promise<T>
|
|
547
|
+
- `patch<T>(url, data?, config?)`: Promise<T>
|
|
548
|
+
- `delete<T>(url, config?)`: Promise<T>
|
|
549
|
+
- `setBaseURL(baseURL)`: void
|
|
550
|
+
- `setAuthToken(token)`: void
|
|
551
|
+
- `removeAuthToken()`: void
|
|
552
|
+
|
|
553
|
+
### RBAC System
|
|
554
|
+
|
|
555
|
+
**Enums:**
|
|
556
|
+
- `Action`: Manage, Create, Read, Update, Delete
|
|
557
|
+
- `Resource`: Users, UserGroups, Clients, Reports, etc.
|
|
558
|
+
- `Role`: Admin, Manager, Reader, Client
|
|
559
|
+
|
|
560
|
+
**Functions:**
|
|
561
|
+
- `userCan(roles, action, resource)`: Check if user can perform action
|
|
562
|
+
- `useAccessControl()`: Hook for access control
|
|
563
|
+
- `isAllowed(action, resource)`: boolean
|
|
564
|
+
- `getResourceByUrl(url)`: Resource
|
|
565
|
+
|
|
566
|
+
**Components:**
|
|
567
|
+
- `<AccessControlWrapper>`: Conditionally render based on permissions
|
|
568
|
+
- `withAccessControl(Component)`: HOC for access control
|
|
569
|
+
- `<UpdateAccessControlWrapper>`: Wrapper specifically for Update action
|
|
570
|
+
|
|
571
|
+
### Utility Functions
|
|
572
|
+
|
|
573
|
+
- `cn(...inputs)`: Merge Tailwind classes with clsx
|
|
574
|
+
- `capitalize(str)`: Capitalize first letter
|
|
575
|
+
- `convertToHourMinuteString(hours)`: Convert decimal hours to HH:MM
|
|
576
|
+
- `formatErrorToList(errors)`: Format errors as HTML list
|
|
577
|
+
- `formatDate(date, format)`: Format date strings
|
|
578
|
+
- `appendFormData(data)`: Convert object to FormData
|
|
579
|
+
- `debounce(func, wait)`: Debounce function calls
|
|
580
|
+
- `throttle(func, limit)`: Throttle function calls
|
|
581
|
+
|
|
582
|
+
### Cache Utilities
|
|
583
|
+
|
|
584
|
+
- `handleEditCache({ item, type, cacheKey })`: Manipulate React Query cache
|
|
585
|
+
- type: 'edit' | 'add' | 'delete'
|
|
586
|
+
- `handleSingleEditCache({ item, cacheKey })`: Update single item in cache
|
|
587
|
+
|
|
588
|
+
### Custom Hooks
|
|
589
|
+
|
|
590
|
+
- `useIsMobile()`: Detect if viewport is mobile (<768px)
|
|
591
|
+
- `useRouter()`: Navigation utilities
|
|
592
|
+
- `usePathname()`: Get current pathname
|
|
593
|
+
- `useAccessControl()`: Access control utilities
|
|
594
|
+
|
|
595
|
+
## License
|
|
596
|
+
|
|
597
|
+
MIT
|
package/dist/App.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AAIA,OAAO,WAAW,CAAC;AAiEnB,iBAAS,GAAG,4CAMX;AAED,eAAe,GAAG,CAAC"}
|