@rqdhw3n/react-admin-layout 1.0.0 → 1.0.2

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,327 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { CSSProperties } from 'react';
3
+ import { JSX } from 'react/jsx-runtime';
4
+ import { LucideIcon } from 'lucide-react';
5
+ import { ReactNode } from 'react';
6
+
7
+ export declare function AdminLayout(props: AdminLayoutProps): JSX.Element;
8
+
9
+ export declare interface AdminLayoutColors {
10
+ primary?: string;
11
+ secondary?: string;
12
+ background?: string;
13
+ surface?: string;
14
+ text?: string;
15
+ textSecondary?: string;
16
+ sidebarBackground?: string;
17
+ sidebarText?: string;
18
+ headerBackground?: string;
19
+ headerText?: string;
20
+ hoverBackground?: string;
21
+ hoverText?: string;
22
+ activeBackground?: string;
23
+ activeText?: string;
24
+ border?: string;
25
+ /** Foreground on brand-colored logos and avatars. */
26
+ onPrimary?: string;
27
+ danger?: string;
28
+ onDanger?: string;
29
+ overlay?: string;
30
+ }
31
+
32
+ export declare const adminLayoutPresets: Readonly<Record<AdminLayoutStyle, Readonly<AdminLayoutTheme>>>;
33
+
34
+ export declare type AdminLayoutProps = {
35
+ children: ReactNode;
36
+ sidebarItems: SidebarItemType[];
37
+ appName?: string;
38
+ appLogo?: ReactNode;
39
+ user?: AdminUser;
40
+ notifications?: NotificationItem[];
41
+ permissions?: PermissionsMap;
42
+ breadcrumbs?: BreadcrumbItem[];
43
+ footer?: ReactNode;
44
+ showFooter?: boolean;
45
+ showSearch?: boolean;
46
+ searchPlaceholder?: string;
47
+ onSearch?: (query: string) => void;
48
+ defaultCollapsed?: boolean;
49
+ initialDarkMode?: boolean;
50
+ theme?: AdminLayoutTheme;
51
+ /** Required to let ThemeToggle change a controlled theme.mode. */
52
+ onThemeModeChange?: (mode: AdminLayoutThemeMode) => void;
53
+ storageKey?: string;
54
+ className?: string;
55
+ contentClassName?: string;
56
+ activePath?: string;
57
+ onNavigate?: (path: string) => void;
58
+ LinkComponent?: SidebarProps['LinkComponent'];
59
+ enableRouter?: boolean;
60
+ };
61
+
62
+ export declare type AdminLayoutResolvedMode = Exclude<AdminLayoutThemeMode, 'system'>;
63
+
64
+ export declare function AdminLayoutRouterSync({ children }: AdminLayoutRouterSyncProps): JSX.Element;
65
+
66
+ declare type AdminLayoutRouterSyncProps = {
67
+ children: ReactNode;
68
+ };
69
+
70
+ export declare type AdminLayoutStyle = 'modern' | 'minimal' | 'compact';
71
+
72
+ export declare interface AdminLayoutTheme {
73
+ mode?: AdminLayoutThemeMode;
74
+ style?: AdminLayoutStyle;
75
+ colors?: AdminLayoutColors;
76
+ light?: AdminLayoutColors;
77
+ dark?: AdminLayoutColors;
78
+ }
79
+
80
+ export declare type AdminLayoutThemeMode = 'light' | 'dark' | 'system';
81
+
82
+ export declare type AdminUser = {
83
+ name: string;
84
+ email: string;
85
+ avatar?: string;
86
+ };
87
+
88
+ export declare type BreadcrumbItem = {
89
+ label: string;
90
+ path?: string;
91
+ };
92
+
93
+ export declare function Breadcrumbs({ items, className, LinkComponent, onNavigate, }: BreadcrumbsProps): JSX.Element | null;
94
+
95
+ export declare type BreadcrumbsProps = {
96
+ items: BreadcrumbItem[];
97
+ className?: string;
98
+ LinkComponent?: React.ComponentType<{
99
+ to: string;
100
+ className?: string;
101
+ children: React.ReactNode;
102
+ }>;
103
+ onNavigate?: (path: string) => void;
104
+ };
105
+
106
+ export declare function cn(...inputs: ClassValue[]): string;
107
+
108
+ export declare const darkThemeColors: Readonly<Required<AdminLayoutColors>>;
109
+
110
+ export declare function filterSidebarByPermissions(items: SidebarItemType[], permissions: PermissionsMap): SidebarItemType[];
111
+
112
+ export declare function Footer({ children, className }: FooterProps): JSX.Element;
113
+
114
+ export declare type FooterProps = {
115
+ children?: React.ReactNode;
116
+ className?: string;
117
+ };
118
+
119
+ export declare function generateBreadcrumbsFromPath(pathname: string): BreadcrumbItem[];
120
+
121
+ export declare function hasPermission(permissions: PermissionsMap, permission?: string): boolean;
122
+
123
+ export declare type LayoutContextValue = LayoutState & {
124
+ toggleSidebar: () => void;
125
+ setSidebarCollapsed: (v: boolean) => void;
126
+ toggleMobile: () => void;
127
+ setMobileOpen: (v: boolean) => void;
128
+ toggleDarkMode: () => void;
129
+ setDarkMode: (v: boolean) => void;
130
+ permissions: PermissionsMap;
131
+ breadcrumbs: BreadcrumbItem[];
132
+ setBreadcrumbs: (items: BreadcrumbItem[]) => void;
133
+ activePath: string;
134
+ setActivePath: (path: string) => void;
135
+ };
136
+
137
+ export declare function LayoutProvider({ children, storageKey, defaultCollapsed, permissions, initialBreadcrumbs, initialActivePath, initialDarkMode, theme, onThemeModeChange, }: LayoutProviderProps): JSX.Element;
138
+
139
+ export declare type LayoutProviderProps = {
140
+ children: ReactNode;
141
+ storageKey?: string;
142
+ defaultCollapsed?: boolean;
143
+ permissions?: PermissionsMap;
144
+ initialBreadcrumbs?: BreadcrumbItem[];
145
+ initialActivePath?: string;
146
+ initialDarkMode?: boolean;
147
+ theme?: AdminLayoutTheme;
148
+ onThemeModeChange?: (mode: AdminLayoutThemeMode) => void;
149
+ };
150
+
151
+ export declare type LayoutState = {
152
+ sidebarCollapsed: boolean;
153
+ mobileOpen: boolean;
154
+ darkMode: boolean;
155
+ };
156
+
157
+ export declare const lightThemeColors: Readonly<Required<AdminLayoutColors>>;
158
+
159
+ export declare function MobileSidebar({ items, appName, appLogo, onNavigate, activePath: activePathProp, LinkComponent, }: MobileSidebarProps): JSX.Element | null;
160
+
161
+ export declare type MobileSidebarProps = SidebarProps;
162
+
163
+ export declare function Navbar({ user, notifications, onSearch, searchPlaceholder, showSearch, className, breadcrumbs, onMenuClick, sidebarCollapsed, onToggleSidebar, }: NavbarProps): JSX.Element;
164
+
165
+ export declare type NavbarProps = {
166
+ appName?: string;
167
+ user?: AdminUser;
168
+ notifications?: NotificationItem[];
169
+ onSearch?: (query: string) => void;
170
+ searchPlaceholder?: string;
171
+ showSearch?: boolean;
172
+ className?: string;
173
+ breadcrumbs?: BreadcrumbItem[];
174
+ onMenuClick?: () => void;
175
+ sidebarCollapsed?: boolean;
176
+ onToggleSidebar?: () => void;
177
+ };
178
+
179
+ export declare function NavbarSearch({ placeholder, onSearch, className, }: NavbarSearchProps): JSX.Element;
180
+
181
+ export declare type NavbarSearchProps = {
182
+ placeholder?: string;
183
+ onSearch?: (query: string) => void;
184
+ className?: string;
185
+ };
186
+
187
+ export declare type NotificationItem = {
188
+ id: string;
189
+ title: string;
190
+ description?: string;
191
+ time?: string;
192
+ read?: boolean;
193
+ };
194
+
195
+ export declare function NotificationMenu({ notifications, className }: NotificationMenuProps): JSX.Element;
196
+
197
+ export declare type NotificationMenuProps = {
198
+ notifications?: NotificationItem[];
199
+ className?: string;
200
+ };
201
+
202
+ export declare type PermissionsMap = Record<string, string[]>;
203
+
204
+ export declare interface ResolvedAdminLayoutTheme {
205
+ mode: AdminLayoutResolvedMode;
206
+ style: AdminLayoutStyle;
207
+ colors: Required<AdminLayoutColors>;
208
+ }
209
+
210
+ /** Defaults < generic colors < selected mode colors. Undefined values never erase defaults. */
211
+ export declare function resolveTheme(theme?: AdminLayoutTheme, systemMode?: AdminLayoutResolvedMode): ResolvedAdminLayoutTheme;
212
+
213
+ export declare function RouterLink({ to, className, children, onClick }: RouterLinkProps): JSX.Element;
214
+
215
+ declare type RouterLinkProps = {
216
+ to: string;
217
+ className?: string;
218
+ children: ReactNode;
219
+ onClick?: () => void;
220
+ };
221
+
222
+ export declare function Sidebar({ items, collapsed: collapsedProp, appName, appLogo, className, onNavigate, activePath: activePathProp, LinkComponent, }: SidebarProps): JSX.Element;
223
+
224
+ export declare function SidebarGroup({ label, children, collapsed, className }: SidebarGroupProps): JSX.Element;
225
+
226
+ export declare type SidebarGroupProps = {
227
+ label?: string;
228
+ children: ReactNode;
229
+ collapsed?: boolean;
230
+ className?: string;
231
+ };
232
+
233
+ export declare function SidebarItem({ item, collapsed, depth, activePath, onNavigate, LinkComponent, onItemClick, }: SidebarItemProps): JSX.Element;
234
+
235
+ export declare type SidebarItemProps = {
236
+ item: SidebarItemType;
237
+ collapsed?: boolean;
238
+ depth?: number;
239
+ activePath?: string;
240
+ onNavigate?: (path: string) => void;
241
+ LinkComponent?: React.ComponentType<{
242
+ to: string;
243
+ className?: string;
244
+ children: React.ReactNode;
245
+ onClick?: () => void;
246
+ }>;
247
+ onItemClick?: () => void;
248
+ };
249
+
250
+ export declare type SidebarItemType = {
251
+ label: string;
252
+ path?: string;
253
+ icon?: LucideIcon;
254
+ badge?: number | string;
255
+ permission?: string;
256
+ children?: SidebarItemType[];
257
+ disabled?: boolean;
258
+ };
259
+
260
+ export declare type SidebarProps = {
261
+ items: SidebarItemType[];
262
+ collapsed?: boolean;
263
+ appName?: string;
264
+ appLogo?: ReactNode;
265
+ className?: string;
266
+ onNavigate?: (path: string) => void;
267
+ activePath?: string;
268
+ LinkComponent?: React.ComponentType<{
269
+ to: string;
270
+ className?: string;
271
+ children: ReactNode;
272
+ onClick?: () => void;
273
+ }>;
274
+ };
275
+
276
+ /** Apply once at a layout boundary; every descendant inherits the palette. */
277
+ export declare function themeToCSSVariables(theme: ResolvedAdminLayoutTheme): CSSProperties;
278
+
279
+ export declare function ThemeToggle({ className }: ThemeToggleProps): JSX.Element;
280
+
281
+ export declare type ThemeToggleProps = {
282
+ className?: string;
283
+ };
284
+
285
+ export declare function useAdminLayoutTheme(): {
286
+ mode: AdminLayoutThemeMode;
287
+ resolvedMode: AdminLayoutResolvedMode;
288
+ style: AdminLayoutStyle;
289
+ colors: Required<AdminLayoutColors>;
290
+ setMode: (mode: AdminLayoutThemeMode) => void;
291
+ };
292
+
293
+ export declare function useBreadcrumbs(): {
294
+ items: BreadcrumbItem[];
295
+ setBreadcrumbs: (items: BreadcrumbItem[]) => void;
296
+ };
297
+
298
+ export declare function useDarkMode(): {
299
+ isDark: boolean;
300
+ toggle: () => void;
301
+ setDarkMode: (v: boolean) => void;
302
+ };
303
+
304
+ export declare function useLayoutContext(): LayoutContextValue;
305
+
306
+ export declare function useLayoutState(): LayoutContextValue;
307
+
308
+ export declare function UserMenu({ user, onLogout, onSettings, className }: UserMenuProps): JSX.Element;
309
+
310
+ export declare type UserMenuProps = {
311
+ user: AdminUser;
312
+ onLogout?: () => void;
313
+ onSettings?: () => void;
314
+ className?: string;
315
+ };
316
+
317
+ export declare function useSidebar(): {
318
+ collapsed: boolean;
319
+ mobileOpen: boolean;
320
+ toggle: () => void;
321
+ setCollapsed: (v: boolean) => void;
322
+ toggleMobile: () => void;
323
+ setMobileOpen: (v: boolean) => void;
324
+ closeMobile: () => void;
325
+ };
326
+
327
+ export { }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,36 @@
1
1
  import { ClassValue } from 'clsx';
2
+ import { CSSProperties } from 'react';
2
3
  import { JSX } from 'react/jsx-runtime';
3
4
  import { LucideIcon } from 'lucide-react';
4
5
  import { ReactNode } from 'react';
5
6
 
6
7
  export declare function AdminLayout(props: AdminLayoutProps): JSX.Element;
7
8
 
9
+ export declare interface AdminLayoutColors {
10
+ primary?: string;
11
+ secondary?: string;
12
+ background?: string;
13
+ surface?: string;
14
+ text?: string;
15
+ textSecondary?: string;
16
+ sidebarBackground?: string;
17
+ sidebarText?: string;
18
+ headerBackground?: string;
19
+ headerText?: string;
20
+ hoverBackground?: string;
21
+ hoverText?: string;
22
+ activeBackground?: string;
23
+ activeText?: string;
24
+ border?: string;
25
+ /** Foreground on brand-colored logos and avatars. */
26
+ onPrimary?: string;
27
+ danger?: string;
28
+ onDanger?: string;
29
+ overlay?: string;
30
+ }
31
+
32
+ export declare const adminLayoutPresets: Readonly<Record<AdminLayoutStyle, Readonly<AdminLayoutTheme>>>;
33
+
8
34
  export declare type AdminLayoutProps = {
9
35
  children: ReactNode;
10
36
  sidebarItems: SidebarItemType[];
@@ -21,6 +47,9 @@ export declare type AdminLayoutProps = {
21
47
  onSearch?: (query: string) => void;
22
48
  defaultCollapsed?: boolean;
23
49
  initialDarkMode?: boolean;
50
+ theme?: AdminLayoutTheme;
51
+ /** Required to let ThemeToggle change a controlled theme.mode. */
52
+ onThemeModeChange?: (mode: AdminLayoutThemeMode) => void;
24
53
  storageKey?: string;
25
54
  className?: string;
26
55
  contentClassName?: string;
@@ -30,12 +59,26 @@ export declare type AdminLayoutProps = {
30
59
  enableRouter?: boolean;
31
60
  };
32
61
 
62
+ export declare type AdminLayoutResolvedMode = Exclude<AdminLayoutThemeMode, 'system'>;
63
+
33
64
  export declare function AdminLayoutRouterSync({ children }: AdminLayoutRouterSyncProps): JSX.Element;
34
65
 
35
66
  declare type AdminLayoutRouterSyncProps = {
36
67
  children: ReactNode;
37
68
  };
38
69
 
70
+ export declare type AdminLayoutStyle = 'modern' | 'minimal' | 'compact';
71
+
72
+ export declare interface AdminLayoutTheme {
73
+ mode?: AdminLayoutThemeMode;
74
+ style?: AdminLayoutStyle;
75
+ colors?: AdminLayoutColors;
76
+ light?: AdminLayoutColors;
77
+ dark?: AdminLayoutColors;
78
+ }
79
+
80
+ export declare type AdminLayoutThemeMode = 'light' | 'dark' | 'system';
81
+
39
82
  export declare type AdminUser = {
40
83
  name: string;
41
84
  email: string;
@@ -62,6 +105,8 @@ export declare type BreadcrumbsProps = {
62
105
 
63
106
  export declare function cn(...inputs: ClassValue[]): string;
64
107
 
108
+ export declare const darkThemeColors: Readonly<Required<AdminLayoutColors>>;
109
+
65
110
  export declare function filterSidebarByPermissions(items: SidebarItemType[], permissions: PermissionsMap): SidebarItemType[];
66
111
 
67
112
  export declare function Footer({ children, className }: FooterProps): JSX.Element;
@@ -89,9 +134,9 @@ export declare type LayoutContextValue = LayoutState & {
89
134
  setActivePath: (path: string) => void;
90
135
  };
91
136
 
92
- export declare function LayoutProvider({ children, storageKey, defaultCollapsed, permissions, initialBreadcrumbs, initialActivePath, initialDarkMode, }: LayoutProviderProps): JSX.Element;
137
+ export declare function LayoutProvider({ children, storageKey, defaultCollapsed, permissions, initialBreadcrumbs, initialActivePath, initialDarkMode, theme, onThemeModeChange, }: LayoutProviderProps): JSX.Element;
93
138
 
94
- declare type LayoutProviderProps = {
139
+ export declare type LayoutProviderProps = {
95
140
  children: ReactNode;
96
141
  storageKey?: string;
97
142
  defaultCollapsed?: boolean;
@@ -99,6 +144,8 @@ declare type LayoutProviderProps = {
99
144
  initialBreadcrumbs?: BreadcrumbItem[];
100
145
  initialActivePath?: string;
101
146
  initialDarkMode?: boolean;
147
+ theme?: AdminLayoutTheme;
148
+ onThemeModeChange?: (mode: AdminLayoutThemeMode) => void;
102
149
  };
103
150
 
104
151
  export declare type LayoutState = {
@@ -107,6 +154,8 @@ export declare type LayoutState = {
107
154
  darkMode: boolean;
108
155
  };
109
156
 
157
+ export declare const lightThemeColors: Readonly<Required<AdminLayoutColors>>;
158
+
110
159
  export declare function MobileSidebar({ items, appName, appLogo, onNavigate, activePath: activePathProp, LinkComponent, }: MobileSidebarProps): JSX.Element | null;
111
160
 
112
161
  export declare type MobileSidebarProps = SidebarProps;
@@ -152,6 +201,15 @@ export declare type NotificationMenuProps = {
152
201
 
153
202
  export declare type PermissionsMap = Record<string, string[]>;
154
203
 
204
+ export declare interface ResolvedAdminLayoutTheme {
205
+ mode: AdminLayoutResolvedMode;
206
+ style: AdminLayoutStyle;
207
+ colors: Required<AdminLayoutColors>;
208
+ }
209
+
210
+ /** Defaults < generic colors < selected mode colors. Undefined values never erase defaults. */
211
+ export declare function resolveTheme(theme?: AdminLayoutTheme, systemMode?: AdminLayoutResolvedMode): ResolvedAdminLayoutTheme;
212
+
155
213
  export declare function RouterLink({ to, className, children, onClick }: RouterLinkProps): JSX.Element;
156
214
 
157
215
  declare type RouterLinkProps = {
@@ -215,12 +273,23 @@ export declare type SidebarProps = {
215
273
  }>;
216
274
  };
217
275
 
276
+ /** Apply once at a layout boundary; every descendant inherits the palette. */
277
+ export declare function themeToCSSVariables(theme: ResolvedAdminLayoutTheme): CSSProperties;
278
+
218
279
  export declare function ThemeToggle({ className }: ThemeToggleProps): JSX.Element;
219
280
 
220
281
  export declare type ThemeToggleProps = {
221
282
  className?: string;
222
283
  };
223
284
 
285
+ export declare function useAdminLayoutTheme(): {
286
+ mode: AdminLayoutThemeMode;
287
+ resolvedMode: AdminLayoutResolvedMode;
288
+ style: AdminLayoutStyle;
289
+ colors: Required<AdminLayoutColors>;
290
+ setMode: (mode: AdminLayoutThemeMode) => void;
291
+ };
292
+
224
293
  export declare function useBreadcrumbs(): {
225
294
  items: BreadcrumbItem[];
226
295
  setBreadcrumbs: (items: BreadcrumbItem[]) => void;