@wso2/oxygen-ui 0.12.1 → 0.13.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 CHANGED
@@ -309,6 +309,94 @@ function MyComponent() {
309
309
  }
310
310
  ```
311
311
 
312
+ ## Content Security Policy (CSP)
313
+
314
+ Oxygen UI (via MUI and Emotion) injects styles at runtime using `<style>` tags. If your application enforces a strict CSP, pass a nonce so those tags are allowed. Follow the same directives recommended in the [MUI Content Security Policy guide](https://mui.com/material-ui/guides/content-security-policy/):
315
+
316
+ ```text
317
+ Content-Security-Policy:
318
+ default-src 'self';
319
+ style-src-elem 'self' 'nonce-<value>';
320
+ style-src-attr 'unsafe-inline';
321
+ font-src 'self' data:;
322
+ ```
323
+
324
+ - **`style-src-elem`** — Emotion injects `<style>` elements; each needs a matching nonce.
325
+ - **`style-src-attr 'unsafe-inline'`** — MUI components apply dynamic inline `style` attributes (dimensions, CSS custom properties, positioning). Nonces cannot cover style attributes.
326
+ - **`font-src 'self' data:`** — The bundled Inter font is embedded as base64 `data:` URIs. Without `data:` in `font-src` (which otherwise falls back to `default-src 'self'`), the browser blocks the fonts even when the style tag itself is allowed.
327
+ - **`script-src 'nonce-...'`** — Only required if your app uses MUI's `InitColorSchemeScript`. Oxygen UI does not ship that script.
328
+
329
+ ### Using the `nonce` prop
330
+
331
+ Pass your server-generated nonce to `OxygenUIThemeProvider`. It is applied to every style tag injected by the styling engine (components, `CssBaseline`, theme styles). The value must match the nonce in your CSP header:
332
+
333
+ ```typescript
334
+ import { OxygenUIThemeProvider } from '@wso2/oxygen-ui';
335
+
336
+ // `serverNonce` is generated per request on the server and must match the CSP header.
337
+ function App({ serverNonce }: { serverNonce: string }) {
338
+ return (
339
+ <OxygenUIThemeProvider nonce={serverNonce}>
340
+ <YourApp />
341
+ </OxygenUIThemeProvider>
342
+ );
343
+ }
344
+ ```
345
+
346
+ ### Using a custom Emotion cache
347
+
348
+ For full control over style injection (cache key, insertion point, stylis plugins, shadow DOM containers, SSR caches), pass a custom Emotion cache. `createEmotionCache` is re-exported from `@emotion/cache` for convenience.
349
+
350
+ Set `prepend: true` to preserve the previous `injectFirst` cascade (application styles can override Oxygen UI styles). Omitting it changes style order.
351
+
352
+ ```typescript
353
+ import { OxygenUIThemeProvider, createEmotionCache } from '@wso2/oxygen-ui';
354
+
355
+ const cache = createEmotionCache({
356
+ key: 'css',
357
+ nonce: serverNonce,
358
+ prepend: true,
359
+ });
360
+
361
+ function App() {
362
+ return (
363
+ <OxygenUIThemeProvider emotionCache={cache}>
364
+ <YourApp />
365
+ </OxygenUIThemeProvider>
366
+ );
367
+ }
368
+ ```
369
+
370
+ `emotionCache` takes precedence over `nonce` if both are provided.
371
+
372
+ Note that the `nonce` prop creates an Emotion cache per provider instance. If your app mounts multiple providers or remounts the provider (for example, on route-level key changes), each mount injects a fresh set of style tags. In that case, prefer a module-level cache passed via `emotionCache` (as in the example above) so styles are injected only once.
373
+
374
+ ### Server-side rendering (SSR)
375
+
376
+ Generate a unique nonce per request on the server, include it in the CSP header, and pass the same value to `OxygenUIThemeProvider` via `nonce` or a shared `emotionCache` on both server and client. Keep server and client Emotion caches aligned (same key, nonce, and insertion options). See the [MUI CSP guide](https://mui.com/material-ui/guides/content-security-policy/) for framework-specific examples (Next.js, Vite, and Emotion SSR).
377
+
378
+ ### Bundled fonts and theme CSS
379
+
380
+ The bundled CSS — the Inter Variable font styles and the theme CSS — is injected as separate `<style>` tags when the package is imported (before React renders), so the nonce for those tags is resolved from well-known conventions instead of a prop:
381
+
382
+ 1. The `__webpack_nonce__` global ([webpack convention](https://webpack.js.org/guides/csp/))
383
+ 2. A `<meta property="csp-nonce" nonce="...">` tag ([Vite convention](https://vite.dev/guide/features.html#content-security-policy-csp)); `content` is also accepted as a fallback
384
+ 3. A `<meta name="csp-nonce" content="...">` tag ([MUI / Next.js convention](https://mui.com/material-ui/guides/content-security-policy/))
385
+
386
+ Because the nonce is read at module evaluation time, the meta tag (or the `__webpack_nonce__` assignment) must already be present in the document before the app bundle executes. A meta tag added later from JavaScript silently results in style tags without a nonce.
387
+
388
+ ```html
389
+ <!-- Vite convention -->
390
+ <meta property="csp-nonce" nonce="YOUR_SERVER_GENERATED_NONCE" />
391
+
392
+ <!-- MUI / Next.js convention -->
393
+ <meta name="csp-nonce" content="YOUR_SERVER_GENERATED_NONCE" />
394
+ ```
395
+
396
+ ### Known limitation: runtime theme loading
397
+
398
+ Loading themes from URLs (`themes: [{ key: 'x', label: 'X', theme: '/themes/x.js' }]`) evaluates the fetched theme file with `new Function(...)`, which additionally requires `script-src 'unsafe-eval'`. Under a strict CSP, prefer passing theme objects directly instead of URL-based themes.
399
+
312
400
  ## Available Exports
313
401
 
314
402
  ### Custom Oxygen UI Components
@@ -322,6 +410,8 @@ function MyComponent() {
322
410
  - `ColorSchemeToggle` - Toggle for light/dark mode
323
411
  - `Layout` - Layout components
324
412
  - `useThemeSwitcher` - Hook to access theme switcher context
413
+ - `createEmotionCache` - Create a custom Emotion cache (re-export of `@emotion/cache`, for CSP and advanced style injection)
414
+ - `EmotionCache` - Type for Emotion cache instances
325
415
 
326
416
  ### Material-UI Components
327
417
 
@@ -1,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  import { IconButtonProps } from '@mui/material/IconButton';
2
3
  /**
3
4
  * Props for the ColorSchemeToggle component.
@@ -9,5 +10,5 @@ interface ColorSchemeToggleProps extends IconButtonProps {
9
10
  lightModeIcon?: React.ReactNode;
10
11
  systemModeIcon?: React.ReactNode;
11
12
  }
12
- export declare const ColorSchemeToggle: React.FC<ColorSchemeToggleProps>;
13
+ export declare const ColorSchemeToggle: React.ForwardRefExoticComponent<Omit<ColorSchemeToggleProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
13
14
  export default ColorSchemeToggle;
@@ -25,6 +25,8 @@ import { HeaderBrandTitle } from './HeaderBrandTitle';
25
25
  export interface HeaderBrandProps {
26
26
  /** Click handler for brand area */
27
27
  onClick?: () => void;
28
+ /** Accessible name for the brand button when onClick is provided */
29
+ 'aria-label'?: string;
28
30
  /** Child components (BrandLogo, BrandTitle) */
29
31
  children: React.ReactNode;
30
32
  /** Additional sx props */
@@ -32,6 +32,9 @@ export interface NotificationListProps {
32
32
  * NotificationList - Scrollable container for notification items.
33
33
  *
34
34
  * Renders a list of NotificationItem components with optional dividers.
35
+ * Does not auto-announce list changes (filtering/tabs can change child count
36
+ * without new arrivals). Consumers should publish via `liveAnnouncement` or
37
+ * `useNotificationPanel().setLiveAnnouncement` when items actually arrive.
35
38
  */
36
39
  export declare const NotificationList: React.FC<NotificationListProps>;
37
40
  export default NotificationList;
@@ -48,6 +48,17 @@ export interface NotificationPanelProps {
48
48
  anchor?: 'left' | 'right';
49
49
  /** Drawer variant (default: 'temporary') */
50
50
  variant?: 'permanent' | 'persistent' | 'temporary';
51
+ /**
52
+ * Accessible name for the drawer dialog (default: `"Notifications"`).
53
+ * Override when the visible header title differs.
54
+ */
55
+ 'aria-label'?: string;
56
+ /**
57
+ * Polite live-region message for status updates (e.g. new arrivals or sync).
58
+ * List child-count changes are not announced automatically — publish here
59
+ * (or via `useNotificationPanel().setLiveAnnouncement`) when items arrive.
60
+ */
61
+ liveAnnouncement?: string;
51
62
  /** Additional sx props */
52
63
  sx?: SxProps<Theme>;
53
64
  }
@@ -22,6 +22,13 @@ import * as React from 'react';
22
22
  export interface NotificationPanelContextValue {
23
23
  /** Callback to close the panel */
24
24
  onClose: () => void;
25
+ /** Whether the panel drawer is open */
26
+ open: boolean;
27
+ /**
28
+ * Announce a status message via the panel's polite live region.
29
+ * Use when new notifications arrive (list child-count changes are not auto-announced).
30
+ */
31
+ setLiveAnnouncement: (message: string) => void;
25
32
  }
26
33
  /**
27
34
  * Context for sharing state between NotificationPanel compound components.
@@ -1,5 +1,6 @@
1
+ import * as React from 'react';
1
2
  import { TextFieldProps } from '@mui/material/TextField';
2
3
  export interface SearchBarProps extends Omit<TextFieldProps, 'variant'> {
3
4
  }
4
- export declare function SearchBar({ placeholder, ...props }: SearchBarProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare const SearchBar: React.ForwardRefExoticComponent<Omit<SearchBarProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
6
  export default SearchBar;
@@ -3,5 +3,5 @@ import { TextFieldProps } from '@mui/material/TextField';
3
3
  export interface SearchBarBaseProps extends Omit<TextFieldProps, 'variant'> {
4
4
  endAdornment?: React.ReactNode;
5
5
  }
6
- export declare function SearchBarBase({ placeholder, endAdornment, slotProps, sx, ...props }: SearchBarBaseProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare const SearchBarBase: React.ForwardRefExoticComponent<Omit<SearchBarBaseProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
7
7
  export default SearchBarBase;
@@ -29,7 +29,11 @@ export interface UserMenuUser {
29
29
  name: string;
30
30
  /** User email address */
31
31
  email: string;
32
- /** Avatar text or initials */
32
+ /**
33
+ * Avatar image URL or initials text.
34
+ * Image-like values (`http(s):`, `/`, `data:`, `blob:`) are used as `src`.
35
+ * Other strings (e.g. `"JD"`) are shown as initials. If omitted, falls back to the first letter of `name`.
36
+ */
33
37
  avatar?: string;
34
38
  /** Role or plan badge (e.g., "Pro", "Admin") */
35
39
  role?: string;
@@ -24,7 +24,11 @@ export interface UserMenuHeaderProps {
24
24
  name: string;
25
25
  /** User email address */
26
26
  email: string;
27
- /** Avatar image URL (if null, falls back to initials) */
27
+ /**
28
+ * Avatar image URL or initials text.
29
+ * Image-like values (`http(s):`, `/`, `data:`, `blob:`) are used as `src`.
30
+ * Other strings (e.g. `"JD"`) are shown as initials. If omitted, falls back to the first letter of `name`.
31
+ */
28
32
  avatar?: string | null;
29
33
  /** Role or plan badge (e.g., "Pro", "Admin") */
30
34
  role?: string;
@@ -16,13 +16,18 @@
16
16
  * under the License.
17
17
  */
18
18
  import * as React from 'react';
19
+ import IconButton from '@mui/material/IconButton';
19
20
  /**
20
21
  * Props for the UserMenu.Trigger component.
21
22
  */
22
- export interface UserMenuTriggerProps {
23
+ export interface UserMenuTriggerProps extends Omit<React.ComponentProps<typeof IconButton>, 'children'> {
23
24
  /** User display name */
24
25
  name: string;
25
- /** Avatar image URL (if null, falls back to initials) */
26
+ /**
27
+ * Avatar image URL or initials text.
28
+ * Image-like values (`http(s):`, `/`, `data:`, `blob:`) are used as `src`.
29
+ * Other strings (e.g. `"JD"`) are shown as initials. If omitted, falls back to the first letter of `name`.
30
+ */
26
31
  avatar?: string | null;
27
32
  /** Whether to show the name text after the avatar */
28
33
  showName?: boolean;
@@ -30,4 +35,4 @@ export interface UserMenuTriggerProps {
30
35
  /**
31
36
  * UserMenu.Trigger - Avatar button that opens the menu.
32
37
  */
33
- export declare const UserMenuTrigger: React.FC<UserMenuTriggerProps>;
38
+ export declare const UserMenuTrigger: React.ForwardRefExoticComponent<Omit<UserMenuTriggerProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,39 @@
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
+ /**
19
+ * Props resolved for MUI Avatar from a UserMenu `avatar` value.
20
+ */
21
+ export interface UserMenuAvatarProps {
22
+ /** Image URL when `avatar` looks like a URL; otherwise undefined */
23
+ src?: string;
24
+ /** Initials or fallback letter shown when there is no image (or image fails) */
25
+ children: string;
26
+ }
27
+ /**
28
+ * Returns whether a string should be treated as an avatar image URL.
29
+ */
30
+ export declare function isUserMenuAvatarImageUrl(value: string): boolean;
31
+ /**
32
+ * Resolves MUI Avatar `src` and children from a UserMenu `avatar` value.
33
+ *
34
+ * - Image-like values (`http(s):`, `/`, `data:`, `blob:`) are used as `src`,
35
+ * with the name initial as children for failed loads.
36
+ * - Other non-empty strings (e.g. `"JD"`) are treated as initials children.
37
+ * - Null/undefined falls back to the first character of `name`.
38
+ */
39
+ export declare function getUserMenuAvatarProps(name: string, avatar?: string | null): UserMenuAvatarProps;
@@ -1,4 +1,5 @@
1
1
  import { Theme } from '@mui/material/styles';
2
+ import type { EmotionCache } from '@emotion/cache';
2
3
  import { ReactNode } from 'react';
3
4
  export interface ThemeOption {
4
5
  /**
@@ -64,6 +65,52 @@ interface OxygenUIThemeProviderProps {
64
65
  * Receives the array of resolved theme configurations.
65
66
  */
66
67
  onThemesLoaded?: (themes: ThemeOption[]) => void;
68
+ /**
69
+ * CSP (Content Security Policy) nonce applied to all style tags injected by
70
+ * the styling engine (Emotion). Use this when your application enforces a
71
+ * strict `style-src` CSP directive.
72
+ *
73
+ * When provided, an Emotion cache is created internally with
74
+ * `createCache({ key: 'css', nonce, prepend: true })` and supplied via
75
+ * Emotion's `CacheProvider`. The cache is created per provider instance, so
76
+ * apps that mount multiple providers or remount the provider should prefer
77
+ * passing a module-level cache via `emotionCache` to avoid re-injecting
78
+ * styles on every mount.
79
+ *
80
+ * Ignored if `emotionCache` is provided.
81
+ */
82
+ nonce?: string;
83
+ /**
84
+ * A custom Emotion cache instance, for full control over style injection
85
+ * (cache key, nonce, insertion point, stylis plugins, container, etc.).
86
+ * Create one with `createEmotionCache` (re-exported from `@emotion/cache`).
87
+ *
88
+ * Set `prepend: true` when creating the cache to preserve the previous
89
+ * `StyledEngineProvider injectFirst` cascade (application styles can override
90
+ * Oxygen UI styles). Omitting `prepend: true` changes style insertion order.
91
+ *
92
+ * Takes precedence over the `nonce` prop.
93
+ */
94
+ emotionCache?: EmotionCache;
67
95
  }
68
- export default function OxygenUIThemeProvider({ children, theme, themes, initialTheme, onThemesLoaded, }: OxygenUIThemeProviderProps): import("react/jsx-runtime").JSX.Element | null;
96
+ /**
97
+ * Root theme provider for Oxygen UI applications.
98
+ *
99
+ * Wraps children with MUI's ThemeProvider and CssBaseline. When `themes` is
100
+ * provided, enables theme switching via context (`useThemeSwitcher`).
101
+ *
102
+ * For CSP-restricted environments, pass `nonce` to apply a Content Security
103
+ * Policy nonce to Emotion-injected style tags, or supply a fully custom
104
+ * Emotion cache via `emotionCache` (takes precedence over `nonce`).
105
+ *
106
+ * @param props - Provider configuration
107
+ * @param props.children - Application content to theme
108
+ * @param props.theme - Optional single theme (disables switching)
109
+ * @param props.themes - Optional theme options enabling switching
110
+ * @param props.initialTheme - Initial theme key when switching is enabled
111
+ * @param props.onThemesLoaded - Callback when themes finish resolving
112
+ * @param props.nonce - CSP nonce for Emotion style tags
113
+ * @param props.emotionCache - Custom Emotion cache (overrides `nonce`)
114
+ */
115
+ export default function OxygenUIThemeProvider({ children, theme, themes, initialTheme, onThemesLoaded, nonce, emotionCache, }: OxygenUIThemeProviderProps): import("react/jsx-runtime").JSX.Element | null;
69
116
  export {};
@@ -17,3 +17,5 @@
17
17
  */
18
18
  export { default as OxygenUIThemeProvider, useThemeSwitcher } from './OxygenUIThemeProvider/OxygenUIThemeProvider';
19
19
  export type { ThemeOption, ThemeSwitcherContextValue } from './OxygenUIThemeProvider/OxygenUIThemeProvider';
20
+ export { default as createEmotionCache } from '@emotion/cache';
21
+ export type { EmotionCache } from '@emotion/cache';