@wso2/oxygen-ui 0.12.0 → 0.13.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 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
 
@@ -39,11 +39,11 @@ export interface HeaderToggleProps {
39
39
  /**
40
40
  * HeaderToggle - Sidebar toggle button for the header.
41
41
  *
42
- * Displays an animated icon that indicates the current sidebar state
42
+ * Displays an icon that indicates the current sidebar state
43
43
  * and toggles between expanded/collapsed states.
44
44
  *
45
45
  * Custom icons can be provided via `expandIcon` and `collapseIcon` props.
46
- * If not provided, defaults to Menu icon.
46
+ * Defaults: `Menu` when collapsed (expand), `PanelLeftClose` when expanded (collapse).
47
47
  *
48
48
  * Theme tokens used:
49
49
  * - `text.secondary` - Icon color
@@ -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';
package/dist/index.js CHANGED
@@ -324,6 +324,27 @@ var init_createOxygenTheme = __esm({
324
324
  if (typeof document !== "undefined") {
325
325
  const style = document.createElement("style");
326
326
  style.setAttribute("data-oxygen-fonts", "true");
327
+ let nonce;
328
+ try {
329
+ if (typeof __webpack_nonce__ !== "undefined" && __webpack_nonce__) {
330
+ nonce = __webpack_nonce__;
331
+ } else {
332
+ const viteMeta = document.querySelector('meta[property="csp-nonce"]');
333
+ if (viteMeta) {
334
+ nonce = viteMeta.nonce || viteMeta.getAttribute("nonce") || viteMeta.getAttribute("content");
335
+ }
336
+ if (!nonce) {
337
+ const muiMeta = document.querySelector('meta[name="csp-nonce"]');
338
+ if (muiMeta) {
339
+ nonce = muiMeta.getAttribute("content");
340
+ }
341
+ }
342
+ }
343
+ } catch (e) {
344
+ }
345
+ if (nonce) {
346
+ style.setAttribute("nonce", nonce);
347
+ }
327
348
  style.textContent = `/**
328
349
  * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
329
350
  *
@@ -419,7 +440,7 @@ var init_createOxygenTheme = __esm({
419
440
  // package.json
420
441
  var package_default = {
421
442
  name: "@wso2/oxygen-ui",
422
- version: "0.12.0",
443
+ version: "0.13.0",
423
444
  description: "WSO2 Oxygen UI | Design System - Powered with Material-UI component library with TypeScript support",
424
445
  type: "module",
425
446
  main: "./dist/index.js",
@@ -460,7 +481,7 @@ var package_default = {
460
481
  lint: "eslint src",
461
482
  "lint:fix": "eslint src --fix",
462
483
  clean: "rimraf dist",
463
- test: "vitest run --passWithNoTests",
484
+ test: "vitest run",
464
485
  "test:watch": "vitest"
465
486
  },
466
487
  keywords: [
@@ -485,6 +506,7 @@ var package_default = {
485
506
  },
486
507
  homepage: "https://github.com/wso2/oxygen-ui#readme",
487
508
  dependencies: {
509
+ "@emotion/cache": "catalog:",
488
510
  "@emotion/react": "catalog:",
489
511
  "@emotion/styled": "catalog:",
490
512
  "@fontsource-variable/inter": "5.2.8",
@@ -503,6 +525,8 @@ var package_default = {
503
525
  },
504
526
  devDependencies: {
505
527
  "@eslint/js": "catalog:",
528
+ "@testing-library/dom": "catalog:",
529
+ "@testing-library/react": "catalog:",
506
530
  "@types/prismjs": "^1.26.5",
507
531
  "@types/react": "catalog:",
508
532
  "@types/react-dom": "catalog:",
@@ -515,6 +539,7 @@ var package_default = {
515
539
  eslint: "catalog:",
516
540
  "eslint-plugin-react": "catalog:",
517
541
  "eslint-plugin-react-hooks": "catalog:",
542
+ jsdom: "catalog:",
518
543
  rimraf: "catalog:",
519
544
  typescript: "catalog:",
520
545
  vite: "catalog:",
@@ -1871,7 +1896,9 @@ var WSO2Theme_default = WSO2Theme;
1871
1896
  // src/contexts/OxygenUIThemeProvider/OxygenUIThemeProvider.tsx
1872
1897
  import { ThemeProvider, StyledEngineProvider } from "@mui/material/styles";
1873
1898
  import { CssBaseline } from "@mui/material";
1874
- import { createContext, useContext, useState, useEffect } from "react";
1899
+ import { CacheProvider } from "@emotion/react";
1900
+ import createCache from "@emotion/cache";
1901
+ import { createContext, useContext, useState, useEffect, useMemo } from "react";
1875
1902
  import { jsx, jsxs } from "react/jsx-runtime";
1876
1903
  var THEME_STORAGE_KEY = "oxygen-theme";
1877
1904
  var defaultThemes = [
@@ -1959,11 +1986,22 @@ function OxygenUIThemeProvider({
1959
1986
  theme,
1960
1987
  themes,
1961
1988
  initialTheme,
1962
- onThemesLoaded
1989
+ onThemesLoaded,
1990
+ nonce,
1991
+ emotionCache
1963
1992
  }) {
1964
1993
  var _a, _b;
1965
1994
  const [resolvedThemes, setResolvedThemes] = useState([]);
1966
1995
  const [themesLoaded, setThemesLoaded] = useState(false);
1996
+ const styleCache = useMemo(() => {
1997
+ if (emotionCache) {
1998
+ return emotionCache;
1999
+ }
2000
+ if (nonce) {
2001
+ return createCache({ key: "css", nonce, prepend: true });
2002
+ }
2003
+ return null;
2004
+ }, [emotionCache, nonce]);
1967
2005
  useEffect(() => {
1968
2006
  const allThemes = themes || defaultThemes;
1969
2007
  const themesToLoad = allThemes.filter((t) => typeof t.theme === "string");
@@ -2049,16 +2087,20 @@ function OxygenUIThemeProvider({
2049
2087
  if (useThemeSwitching && !themesLoaded) {
2050
2088
  return null;
2051
2089
  }
2052
- const content = /* @__PURE__ */ jsx(StyledEngineProvider, { injectFirst: true, children: /* @__PURE__ */ jsxs(ThemeProvider, { theme: resolvedTheme, children: [
2090
+ const themedContent = /* @__PURE__ */ jsxs(ThemeProvider, { theme: resolvedTheme, children: [
2053
2091
  /* @__PURE__ */ jsx(CssBaseline, { enableColorScheme: true }),
2054
2092
  children
2055
- ] }) });
2093
+ ] });
2094
+ const content = styleCache ? /* @__PURE__ */ jsx(CacheProvider, { value: styleCache, children: themedContent }) : /* @__PURE__ */ jsx(StyledEngineProvider, { injectFirst: true, children: themedContent });
2056
2095
  if (useThemeSwitching) {
2057
2096
  return /* @__PURE__ */ jsx(ThemeSwitcherContext.Provider, { value: contextValue, children: content });
2058
2097
  }
2059
2098
  return content;
2060
2099
  }
2061
2100
 
2101
+ // src/contexts/index.ts
2102
+ import { default as default2 } from "@emotion/cache";
2103
+
2062
2104
  // src/components/AppBreadcrumbs/AppBreadcrumbs.tsx
2063
2105
  import Breadcrumbs from "@mui/material/Breadcrumbs";
2064
2106
  import MenuItem from "@mui/material/MenuItem";
@@ -3490,7 +3532,7 @@ import * as React8 from "react";
3490
3532
  import IconButton3 from "@mui/material/IconButton";
3491
3533
  import Tooltip2 from "@mui/material/Tooltip";
3492
3534
  import { styled as styled16 } from "@mui/material/styles";
3493
- import { Menu } from "@wso2/oxygen-ui-icons-react";
3535
+ import { Menu, PanelLeftClose } from "@wso2/oxygen-ui-icons-react";
3494
3536
 
3495
3537
  // src/components/AppShell/context.tsx
3496
3538
  import * as React7 from "react";
@@ -3526,7 +3568,7 @@ var HeaderToggle = ({
3526
3568
  const collapsed = (_a = collapsedProp != null ? collapsedProp : appShellContext == null ? void 0 : appShellContext.state.sidebarCollapsed) != null ? _a : false;
3527
3569
  const onToggle = (_b = onToggleProp != null ? onToggleProp : appShellContext == null ? void 0 : appShellContext.actions.toggleSidebar) != null ? _b : (() => {
3528
3570
  });
3529
- return /* @__PURE__ */ jsx29(Tooltip2, { title: collapsed ? expandLabel : collapseLabel, children: /* @__PURE__ */ jsx29(HeaderToggleRoot, { onClick: onToggle, size: "small", sx, children: collapsed ? expandIcon || /* @__PURE__ */ jsx29(Menu, { size: 20 }) : collapseIcon || /* @__PURE__ */ jsx29(Menu, { size: 20 }) }) });
3571
+ return /* @__PURE__ */ jsx29(Tooltip2, { title: collapsed ? expandLabel : collapseLabel, children: /* @__PURE__ */ jsx29(HeaderToggleRoot, { onClick: onToggle, size: "small", sx, children: collapsed ? expandIcon || /* @__PURE__ */ jsx29(Menu, { size: 20 }) : collapseIcon || /* @__PURE__ */ jsx29(PanelLeftClose, { size: 20 }) }) });
3530
3572
  };
3531
3573
 
3532
3574
  // src/components/Header/HeaderBrand.tsx
@@ -5916,14 +5958,14 @@ import {
5916
5958
  Divider as Divider10
5917
5959
  } from "@mui/material";
5918
5960
  import { styled as styled62 } from "@mui/material/styles";
5919
- import { useMemo as useMemo5 } from "react";
5961
+ import { useMemo as useMemo6 } from "react";
5920
5962
  import { jsx as jsx83, jsxs as jsxs30 } from "react/jsx-runtime";
5921
5963
  var StyledWizardActionsStack = styled62(Stack2)(() => ({
5922
5964
  justifyContent: "space-between",
5923
5965
  flexGrow: 1
5924
5966
  }));
5925
5967
  function Wizard({ steps, activeStep, actions }) {
5926
- const step = useMemo5(() => activeStep < steps.length ? steps[activeStep] : null, [steps, activeStep]);
5968
+ const step = useMemo6(() => activeStep < steps.length ? steps[activeStep] : null, [steps, activeStep]);
5927
5969
  return /* @__PURE__ */ jsx83(Card4, { children: /* @__PURE__ */ jsx83(CardContent4, { children: /* @__PURE__ */ jsxs30(Stack2, { children: [
5928
5970
  /* @__PURE__ */ jsx83(Stepper, { activeStep, children: steps.map((step2) => /* @__PURE__ */ jsx83(Step, { children: /* @__PURE__ */ jsx83(StepLabel, { children: step2.label }) }, step2.label)) }),
5929
5971
  /* @__PURE__ */ jsx83(Divider10, {}),
@@ -6962,7 +7004,7 @@ function ListingTableCellIcon({
6962
7004
  var ListingTableCellIcon_default = ListingTableCellIcon;
6963
7005
 
6964
7006
  // src/components/ListingTable/ListingTableProvider.tsx
6965
- import { useMemo as useMemo7 } from "react";
7007
+ import { useMemo as useMemo8 } from "react";
6966
7008
  import { jsx as jsx108 } from "react/jsx-runtime";
6967
7009
  function ListingTableProvider({
6968
7010
  children,
@@ -7001,7 +7043,7 @@ function ListingTableProvider({
7001
7043
  // Loading
7002
7044
  loading
7003
7045
  }) {
7004
- const contextValue = useMemo7(
7046
+ const contextValue = useMemo8(
7005
7047
  () => ({
7006
7048
  // Search
7007
7049
  searchValue,
@@ -7478,6 +7520,7 @@ export {
7478
7520
  UserMenu,
7479
7521
  WSO2Theme_default as WSO2Theme,
7480
7522
  colors,
7523
+ default2 as createEmotionCache,
7481
7524
  createOxygenTheme,
7482
7525
  formatRelativeTime,
7483
7526
  pxToRem,