@wso2/oxygen-ui 0.6.0 → 0.7.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.
@@ -22,10 +22,11 @@ import { AppShellSidebar } from './AppShellSidebar';
22
22
  import { AppShellMain } from './AppShellMain';
23
23
  import { AppShellFooter } from './AppShellFooter';
24
24
  import { AppShellNotificationPanel } from './AppShellNotificationPanel';
25
+ import { type UseAppShellOptions } from '../../hooks/useAppShell';
25
26
  /**
26
27
  * Props for AppShell component.
27
28
  */
28
- export interface AppShellProps {
29
+ export interface AppShellProps extends UseAppShellOptions {
29
30
  /** AppShell slot components (Navbar, Sidebar, Main, Footer, NotificationPanel) */
30
31
  children: React.ReactNode;
31
32
  /** Additional sx props for the root container */
@@ -37,9 +38,13 @@ export interface AppShellProps {
37
38
  * Uses a compound component pattern where children define the layout slots.
38
39
  * This reduces boilerplate compared to manually composing Layout components.
39
40
  *
41
+ * AppShell automatically provides shell state management through context.
42
+ * Child components can use the `useAppShell()` hook to access and control
43
+ * the shell state (sidebar collapse, notification panel, active menu items).
44
+ *
40
45
  * @example
41
46
  * ```tsx
42
- * <AppShell>
47
+ * <AppShell initialCollapsed={false} collapseOnSelectOnMobile={true}>
43
48
  * <AppShell.Navbar>
44
49
  * <Header>...</Header>
45
50
  * </AppShell.Navbar>
@@ -47,14 +52,11 @@ export interface AppShellProps {
47
52
  * <Sidebar collapsed={collapsed}>...</Sidebar>
48
53
  * </AppShell.Sidebar>
49
54
  * <AppShell.Main>
50
- * <Outlet />
55
+ * <MyPage /> {/* Can use useAppShell()
51
56
  * </AppShell.Main>
52
57
  * <AppShell.Footer>
53
58
  * <Footer companyName="WSO2 LLC" />
54
59
  * </AppShell.Footer>
55
- * <AppShell.NotificationPanel>
56
- * <NotificationPanel open={open} onClose={onClose}>...</NotificationPanel>
57
- * </AppShell.NotificationPanel>
58
60
  * </AppShell>
59
61
  * ```
60
62
  */
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import * as React from 'react';
19
+ import type { UseAppShellReturn } from '../../hooks/useAppShell/useAppShell';
20
+ /**
21
+ * Context for sharing AppShell state across components.
22
+ * Allows child components to access the same shell state without prop drilling.
23
+ */
24
+ export declare const AppShellContext: React.Context<UseAppShellReturn | undefined>;
25
+ /**
26
+ * Provider component for AppShell context.
27
+ * Wrap your app shell with this to share state with child components.
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * function AppLayout() {
32
+ * const shell = useAppShell({ initialCollapsed: false });
33
+ *
34
+ * return (
35
+ * <AppShellProvider value={shell}>
36
+ * <AppShell>
37
+ * <Sidebar collapsed={shell.state.sidebarCollapsed} />
38
+ * <Outlet />
39
+ * </AppShell>
40
+ * </AppShellProvider>
41
+ * );
42
+ * }
43
+ * ```
44
+ */
45
+ export declare const AppShellProvider: React.FC<React.PropsWithChildren<{
46
+ value: UseAppShellReturn;
47
+ }>>;
48
+ /**
49
+ * Hook to access AppShell context with a helpful error message.
50
+ * Throws an error if used outside of AppShell component tree.
51
+ *
52
+ * @param componentName - Name of the component using the context (for error messages)
53
+ * @returns AppShell context value
54
+ * @throws Error if used outside AppShell
55
+ *
56
+ * @example
57
+ * ```tsx
58
+ * function MyComponent() {
59
+ * const { state, actions } = useAppShellContext('MyComponent');
60
+ * // ...
61
+ * }
62
+ * ```
63
+ */
64
+ export declare const useAppShellContext: (componentName: string) => UseAppShellReturn;
@@ -27,3 +27,4 @@ export { AppShellFooter } from './AppShellFooter';
27
27
  export type { AppShellFooterProps } from './AppShellFooter';
28
28
  export { AppShellNotificationPanel } from './AppShellNotificationPanel';
29
29
  export type { AppShellNotificationPanelProps } from './AppShellNotificationPanel';
30
+ export { AppShellContext, AppShellProvider, useAppShellContext } from './context';
@@ -21,10 +21,10 @@ import type { SxProps, Theme } from '@mui/material/styles';
21
21
  * Props for HeaderToggle component.
22
22
  */
23
23
  export interface HeaderToggleProps {
24
- /** Whether the sidebar is collapsed */
25
- collapsed: boolean;
26
- /** Callback to toggle sidebar */
27
- onToggle: () => void;
24
+ /** Whether the sidebar is collapsed (optional, uses AppShell context if available) */
25
+ collapsed?: boolean;
26
+ /** Callback to toggle sidebar (optional, uses AppShell context if available) */
27
+ onToggle?: () => void;
28
28
  /** Label for expanded state tooltip */
29
29
  expandLabel?: string;
30
30
  /** Label for collapsed state tooltip */
@@ -36,10 +36,10 @@ import { NotificationEmptyState } from './NotificationEmptyState';
36
36
  * Props for the NotificationPanel component.
37
37
  */
38
38
  export interface NotificationPanelProps {
39
- /** Whether the panel is open */
40
- open: boolean;
41
- /** Callback to close the panel */
42
- onClose: () => void;
39
+ /** Whether the panel is open (optional, uses AppShell context if available) */
40
+ open?: boolean;
41
+ /** Callback to close the panel (optional, uses AppShell context if available) */
42
+ onClose?: () => void;
43
43
  /** Panel content */
44
44
  children: React.ReactNode;
45
45
  /** Panel width (default: 380) */
@@ -33,6 +33,8 @@ export interface SidebarItemProps {
33
33
  depth?: number;
34
34
  /** Additional sx props */
35
35
  sx?: SxProps<Theme>;
36
+ /** Optional navigation link component to wrap the item button */
37
+ link?: React.ReactElement;
36
38
  }
37
39
  /**
38
40
  * SidebarItem - Individual navigation menu item.
@@ -47,6 +49,14 @@ export interface SidebarItemProps {
47
49
  * </Sidebar.Item>
48
50
  * ```
49
51
  *
52
+ * With navigation link:
53
+ * ```tsx
54
+ * <Sidebar.Item id="home" link={<Link to="/home" />}>
55
+ * <Sidebar.ItemIcon><Home size={20} /></Sidebar.ItemIcon>
56
+ * <Sidebar.ItemLabel>Home</Sidebar.ItemLabel>
57
+ * </Sidebar.Item>
58
+ * ```
59
+ *
50
60
  * Theme tokens used:
51
61
  * - `action.selected` - Active item background
52
62
  * - `primary.main` - Active item icon color
@@ -27,12 +27,19 @@ export interface AppShellState {
27
27
  activeMenuItem: string;
28
28
  /** Map of expanded menu IDs */
29
29
  expandedMenus: Record<string, boolean>;
30
+ /** Expanded sidebar width in pixels */
31
+ sidebarWidth: number;
32
+ /** Collapsed sidebar width in pixels */
33
+ sidebarCollapsedWidth: number;
30
34
  }
31
35
  /**
32
36
  * App Shell actions interface.
33
37
  */
34
38
  export interface AppShellActions {
35
39
  toggleSidebar: () => void;
40
+ setSidebarCollapsed: (collapsed: boolean) => void;
41
+ collapseSidebar: () => void;
42
+ expandSidebar: () => void;
36
43
  toggleNotificationPanel: () => void;
37
44
  setActiveMenuItem: (id: string) => void;
38
45
  toggleMenu: (id: string) => void;
@@ -45,6 +52,14 @@ export interface UseAppShellOptions {
45
52
  initialCollapsed?: boolean;
46
53
  /** Initial active menu item */
47
54
  initialActiveItem?: string;
55
+ /** Auto-collapse sidebar on menu item selection in mobile view (default: true) */
56
+ collapseOnSelectOnMobile?: boolean;
57
+ /** Auto-collapse sidebar on page load when in mobile view (default: false) */
58
+ collapseOnMobile?: boolean;
59
+ /** Expanded sidebar width in pixels (default: 250) */
60
+ sidebarWidth?: number;
61
+ /** Collapsed sidebar width in pixels (default: 64) */
62
+ sidebarCollapsedWidth?: number;
48
63
  }
49
64
  /**
50
65
  * Return type for useAppShell hook.
@@ -61,20 +76,40 @@ export interface UseAppShellReturn {
61
76
  * - Notification panel visibility
62
77
  * - Active menu item and expanded menus
63
78
  *
79
+ * Can be used in two modes:
80
+ * 1. **Create mode** (with options): Creates a new shell state instance
81
+ * 2. **Consume mode** (without options): Consumes shared state from AppShellProvider
82
+ *
64
83
  * For notification data management, use the `useNotifications` hook separately.
65
84
  *
66
85
  * @example
67
86
  * ```tsx
68
- * const { state, actions } = useAppShell({
69
- * initialCollapsed: false,
70
- * });
87
+ * // Create mode - in layout component
88
+ * function AppLayout() {
89
+ * const shell = useAppShell({
90
+ * initialCollapsed: false,
91
+ * collapseOnSelectOnMobile: true,
92
+ * sidebarWidth: 280,
93
+ * });
94
+ *
95
+ * return (
96
+ * <AppShellProvider value={shell}>
97
+ * <AppShell>
98
+ * <Sidebar collapsed={shell.state.sidebarCollapsed} />
99
+ * <Outlet />
100
+ * </AppShell>
101
+ * </AppShellProvider>
102
+ * );
103
+ * }
71
104
  *
72
- * // Use state
73
- * <Sidebar collapsed={state.sidebarCollapsed} />
74
- * <NotificationPanel open={state.notificationPanelOpen} />
105
+ * // Consume mode - in child page component
106
+ * function MyPage() {
107
+ * const { state, actions } = useAppShell(); // No options = consume from context
75
108
  *
76
- * // Use actions
77
- * <Button onClick={actions.toggleSidebar}>Toggle</Button>
109
+ * useEffect(() => {
110
+ * actions.toggleSidebar(); // Control shared sidebar state
111
+ * }, []);
112
+ * }
78
113
  * ```
79
114
  */
80
115
  export declare const useAppShell: (options?: UseAppShellOptions) => UseAppShellReturn;