@wso2/oxygen-ui 0.24.0 → 0.25.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/.claude/components.md +80 -0
- package/dist/components/HeaderBreadcrumbs/HeaderBreadcrumbs.d.ts +100 -0
- package/dist/components/HeaderBreadcrumbs/HeaderBreadcrumbsSegment.d.ts +54 -0
- package/dist/components/HeaderBreadcrumbs/index.d.ts +26 -0
- package/dist/components/HeaderBreadcrumbs/persistence.d.ts +87 -0
- package/dist/components/HeaderBreadcrumbs/types.d.ts +125 -0
- package/dist/components/HeaderBreadcrumbs/useHeaderBreadcrumbs.d.ts +150 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +1809 -738
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/.claude/components.md
CHANGED
|
@@ -13,6 +13,7 @@ Complete API reference for custom Oxygen UI components. For MUI components, refe
|
|
|
13
13
|
- [Footer](#footer)
|
|
14
14
|
- [UserMenu](#usermenu)
|
|
15
15
|
- [ContextSwitcher](#contextswitcher)
|
|
16
|
+
- [HeaderBreadcrumbs](#headerbreadcrumbs)
|
|
16
17
|
- [AppSwitcher](#appswitcher)
|
|
17
18
|
- [Form](#form)
|
|
18
19
|
- [FullScreenWizard](#fullscreenwizard)
|
|
@@ -1361,6 +1362,85 @@ const [value, setValue] = useState<ContextSwitcherValue>({
|
|
|
1361
1362
|
</ContextSwitcher>
|
|
1362
1363
|
```
|
|
1363
1364
|
|
|
1365
|
+
## HeaderBreadcrumbs
|
|
1366
|
+
|
|
1367
|
+
A trail of the current organization / project / component, like `thunder-id / thunderid ▾`. Each segment has two targets: the name goes to that entry's page, and the caret opens a menu to switch to another entry of the same level. After the trail, a › button opens the next level's menu; its tooltip and accessible name are "Open project" (on an organization) or "Open component" (on a project). Use it when the header should read as plain text. Use `ContextSwitcher` when each level should be a labeled field.
|
|
1368
|
+
|
|
1369
|
+
```tsx
|
|
1370
|
+
import { HeaderBreadcrumbs, useHeaderBreadcrumbs, readHeaderBreadcrumbsState, clearHeaderBreadcrumbsState } from '@wso2/oxygen-ui';
|
|
1371
|
+
import type { HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel, HeaderBreadcrumbsValue } from '@wso2/oxygen-ui';
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
### HeaderBreadcrumbs Props
|
|
1375
|
+
|
|
1376
|
+
| Prop | Type | Default | Description |
|
|
1377
|
+
|------|------|---------|-------------|
|
|
1378
|
+
| `levels` | `HeaderBreadcrumbsLevel[]` | required | Levels in order. The trail runs up to the first level without `selectedId`, which shows as a › button. Leave a level out to remove it |
|
|
1379
|
+
| `onNavigate` | `(levelId, item) => void` | - | A name was clicked |
|
|
1380
|
+
| `onSelect` | `(levelId, item) => void` | - | A different entry was picked in a switch menu |
|
|
1381
|
+
| `onOpen` | `(levelId) => void` | - | A switch menu opened |
|
|
1382
|
+
| `onCreate` | `(levelId, { levelId, value }) => void` | - | Adds "New {label}" to every level's menu, such as "New project" |
|
|
1383
|
+
| `onManage` | `(levelId, { levelId, value }) => void` | - | Adds "Manage {pluralLabel}" to every level's menu, such as "Manage projects" |
|
|
1384
|
+
| `showLabels` | `boolean` | `false` | Show each level's name (Organization, Project) in small text above it |
|
|
1385
|
+
| `showIcons` | `boolean` | `true` | Show each level's `icon` before its name. Set `false` to hide them; `showLabels` replaces them. Hovering the icon shows the level name; screen readers hear it through `aria-describedby` |
|
|
1386
|
+
| `linkComponent` | `ElementType` | `'a'` | Used for items with `href`, such as a router `Link` |
|
|
1387
|
+
| `separator` | `ReactNode` | `'/'` | Node between segments |
|
|
1388
|
+
|
|
1389
|
+
`HeaderBreadcrumbsLevel`: `id`, `label`, `icon`, `items`, `selectedId`, `selectedItem` (name fallback before items load), `openLabel`, `loading`, `error`, `emptyText`, `menuTitle`, `searchPlaceholder`, `searchable` (`'auto'` shows search above 6 items), `pluralLabel`, `createAction` and `manageAction` (relabel, add `href`, own `onClick`, or `false` to hide the built-in action for that level), and `actions` (more `{ key, label, icon, href, onClick }` items).
|
|
1390
|
+
|
|
1391
|
+
Every action's `onClick(event, { levelId, value })` runs after the menu closes. With `href`, the action renders through `linkComponent`; call `event.preventDefault()` to run your own logic instead of navigating. A level's own `onClick` wins over `onCreate` / `onManage`.
|
|
1392
|
+
|
|
1393
|
+
`HeaderBreadcrumbsItem`: `id`, `name`, `description`, `avatar`, `href`, `disabled`.
|
|
1394
|
+
|
|
1395
|
+
### useHeaderBreadcrumbs
|
|
1396
|
+
|
|
1397
|
+
Holds the selection, fetches each level from its parents' selection, and aborts stale requests. Picking a different entry clears the levels under it. Clicking a name drops the levels under it (`truncateOnNavigate`, default `true`).
|
|
1398
|
+
|
|
1399
|
+
| Option | Type | Description |
|
|
1400
|
+
|--------|------|-------------|
|
|
1401
|
+
| `levels` | `HeaderBreadcrumbsLevelConfig[]` | Level display props plus `fetchItems({ parents, signal })` or fixed `items` |
|
|
1402
|
+
| `value` / `defaultValue` | `HeaderBreadcrumbsValue` | Controlled or initial selection (`Record<levelId, itemId>`) |
|
|
1403
|
+
| `onChange` | `(value, change) => void` | `change.type` is `select`, `navigate`, `clear` or `set` |
|
|
1404
|
+
| `onNavigate` | `(levelId, item) => void` | A name was clicked |
|
|
1405
|
+
| `refreshOnOpen` | `boolean` | Fetch a level again each time its menu opens |
|
|
1406
|
+
| `formatError` | `(error, levelId) => ReactNode` | Message for a failed fetch |
|
|
1407
|
+
| `persist` | `boolean \| { key?, storage?, sync? }` | Keep the selected ids (not the items) in `localStorage` (default key `oxygen-ui:header-breadcrumbs`). Apps on the same origin share it and, with `sync` (default `true`), follow each other's changes; `onChange` gets type `sync`. Uncontrolled, the stored value wins over `defaultValue` |
|
|
1408
|
+
|
|
1409
|
+
Returns `value`, `levels`, `selected` (item per level), `select`, `clear`, `setValue`, `refresh`, `setItems`, `addItem`, `updateItem`, `removeItem`, and `breadcrumbProps` to spread on `HeaderBreadcrumbs`.
|
|
1410
|
+
|
|
1411
|
+
### Usage
|
|
1412
|
+
|
|
1413
|
+
```tsx
|
|
1414
|
+
const breadcrumb = useHeaderBreadcrumbs({
|
|
1415
|
+
levels: [
|
|
1416
|
+
{ id: 'organization', label: 'Organization', fetchItems: ({ signal }) => api.organizations({ signal }) },
|
|
1417
|
+
{ id: 'project', label: 'Project', fetchItems: ({ parents, signal }) => api.projects(parents.organization, { signal }) },
|
|
1418
|
+
{ id: 'component', label: 'Component', fetchItems: ({ parents, signal }) => api.components(parents.project, { signal }) },
|
|
1419
|
+
],
|
|
1420
|
+
value: valueFromRoute,
|
|
1421
|
+
onChange: (next) => navigate(routeFor(next)),
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
<Header.Switchers>
|
|
1425
|
+
<HeaderBreadcrumbs {...breadcrumb.breadcrumbProps} />
|
|
1426
|
+
</Header.Switchers>
|
|
1427
|
+
|
|
1428
|
+
// After creating, renaming or deleting:
|
|
1429
|
+
breadcrumb.addItem('project', created);
|
|
1430
|
+
breadcrumb.updateItem('project', id, { name: 'New name' });
|
|
1431
|
+
breadcrumb.removeItem('project', id);
|
|
1432
|
+
|
|
1433
|
+
// Share the selection across apps on the same origin:
|
|
1434
|
+
useHeaderBreadcrumbs({ levels, persist: true });
|
|
1435
|
+
const { organization, project } = useHeaderBreadcrumbsValue(); // from any app, re-renders on change
|
|
1436
|
+
readHeaderBreadcrumbsState()?.value.organization; // outside React
|
|
1437
|
+
clearHeaderBreadcrumbsState(); // on sign-out
|
|
1438
|
+
```
|
|
1439
|
+
|
|
1440
|
+
localStorage is per origin (protocol, host and port), so apps on different subdomains do not share it.
|
|
1441
|
+
|
|
1442
|
+
---
|
|
1443
|
+
|
|
1364
1444
|
## AppSwitcher
|
|
1365
1445
|
|
|
1366
1446
|
Popover for navigating between WSO2 Cloud platforms.
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { SxProps, Theme } from '@mui/material/styles';
|
|
20
|
+
import type { HeaderBreadcrumbsActionContext, HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel } from './types';
|
|
21
|
+
/**
|
|
22
|
+
* Props for HeaderBreadcrumbs.
|
|
23
|
+
*/
|
|
24
|
+
export interface HeaderBreadcrumbsProps extends Omit<React.ComponentPropsWithoutRef<'nav'>, 'onSelect'> {
|
|
25
|
+
/**
|
|
26
|
+
* Levels in order, for example organization, project and component. The trail
|
|
27
|
+
* runs up to the first level without a selection, which shows as a › button. Leave
|
|
28
|
+
* a level out to remove it, such as the component level in an app without one.
|
|
29
|
+
*/
|
|
30
|
+
levels: HeaderBreadcrumbsLevel[];
|
|
31
|
+
/** Called when a name is clicked, to go to that entry's page. */
|
|
32
|
+
onNavigate?: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
33
|
+
/** Called when a different entry is picked in a level's switch menu. */
|
|
34
|
+
onSelect?: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
35
|
+
/** Called when a level's switch menu opens. Use it to load or refresh that level. */
|
|
36
|
+
onOpen?: (levelId: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Adds "New {label}" to every level's menu, such as "New project". Called with the
|
|
39
|
+
* level and the current selection, so you can open a dialog or navigate. A level's
|
|
40
|
+
* `createAction` can relabel, link or hide it.
|
|
41
|
+
*/
|
|
42
|
+
onCreate?: (levelId: string, context: HeaderBreadcrumbsActionContext) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Adds "Manage {pluralLabel}" to every level's menu, such as "Manage projects". A
|
|
45
|
+
* level's `manageAction` can relabel, link or hide it.
|
|
46
|
+
*/
|
|
47
|
+
onManage?: (levelId: string, context: HeaderBreadcrumbsActionContext) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Show each level's name (such as "Organization") in small text above it, so users
|
|
50
|
+
* can tell the levels apart.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
showLabels?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Show each level's `icon` before its name, so users can tell the levels apart
|
|
56
|
+
* without labels. Hovering an icon shows the level name. Levels without an `icon`
|
|
57
|
+
* show none, and `showLabels` replaces the icons.
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
showIcons?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Element used for items with an `href`, such as a router `Link`.
|
|
63
|
+
* @default 'a'
|
|
64
|
+
*/
|
|
65
|
+
linkComponent?: React.ElementType;
|
|
66
|
+
/**
|
|
67
|
+
* Node between segments.
|
|
68
|
+
* @default '/'
|
|
69
|
+
*/
|
|
70
|
+
separator?: React.ReactNode;
|
|
71
|
+
/** The sx prop for styling with the MUI system. */
|
|
72
|
+
sx?: SxProps<Theme>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* HeaderBreadcrumbs - A trail of the current organization, project and component.
|
|
76
|
+
*
|
|
77
|
+
* Each segment has two targets. The name goes to that entry's page. The caret opens a
|
|
78
|
+
* menu to switch to another entry of the same level. The last segment is the current
|
|
79
|
+
* page. While a level has no selection, it shows as a › button after the trail,
|
|
80
|
+
* named "Open {label}", such as "Open project" on an organization page. Pair it with `useHeaderBreadcrumbs` to fetch each level's items and keep the
|
|
81
|
+
* selection, and place it in `Header.Switchers`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const breadcrumb = useHeaderBreadcrumbs({
|
|
86
|
+
* levels: [
|
|
87
|
+
* { id: 'organization', label: 'Organization', fetchItems: fetchOrganizations },
|
|
88
|
+
* { id: 'project', label: 'Project', fetchItems: ({ parents }) => fetchProjects(parents.organization) },
|
|
89
|
+
* ],
|
|
90
|
+
* defaultValue: { organization: 'thunder-id', project: 'thunderid' },
|
|
91
|
+
* onNavigate: (levelId, item) => navigate(item.href!),
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* <Header.Switchers>
|
|
95
|
+
* <HeaderBreadcrumbs {...breadcrumb.breadcrumbProps} />
|
|
96
|
+
* </Header.Switchers>
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare const HeaderBreadcrumbs: React.ForwardRefExoticComponent<HeaderBreadcrumbsProps & React.RefAttributes<HTMLElement>>;
|
|
100
|
+
export default HeaderBreadcrumbs;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { HeaderBreadcrumbsActionContext, HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel, HeaderBreadcrumbsValue } from './types';
|
|
20
|
+
/** Height of the name row with labels, so names, carets and the open button line up. */
|
|
21
|
+
export declare const LABELED_ROW_HEIGHT = 32;
|
|
22
|
+
/**
|
|
23
|
+
* Props for one segment of the trail.
|
|
24
|
+
*/
|
|
25
|
+
export interface HeaderBreadcrumbsSegmentProps {
|
|
26
|
+
/** The level this segment shows. */
|
|
27
|
+
level: HeaderBreadcrumbsLevel;
|
|
28
|
+
/** The last segment is the current page, marked with `aria-current="page"`. */
|
|
29
|
+
current: boolean;
|
|
30
|
+
/** Element used for items with an `href`. */
|
|
31
|
+
linkComponent: React.ElementType;
|
|
32
|
+
/** Called when the name is clicked. */
|
|
33
|
+
onNavigate?: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
34
|
+
/** Called when an entry in the switch menu is picked. */
|
|
35
|
+
onSelect?: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
36
|
+
/** Called when the switch menu opens. */
|
|
37
|
+
onOpen?: (levelId: string) => void;
|
|
38
|
+
/** Show the level name in small text above the segment. */
|
|
39
|
+
showLabel?: boolean;
|
|
40
|
+
/** Show the level's `icon` before the name. Hovering the icon shows the level name. */
|
|
41
|
+
showIcon?: boolean;
|
|
42
|
+
/** Selected id of every level, passed to action handlers. */
|
|
43
|
+
value?: HeaderBreadcrumbsValue;
|
|
44
|
+
/** Adds "New {label}" to the menu. */
|
|
45
|
+
onCreate?: (levelId: string, context: HeaderBreadcrumbsActionContext) => void;
|
|
46
|
+
/** Adds "Manage {pluralLabel}" to the menu. */
|
|
47
|
+
onManage?: (levelId: string, context: HeaderBreadcrumbsActionContext) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* HeaderBreadcrumbsSegment - The name of the selected entry, and a caret that opens
|
|
51
|
+
* a menu to switch to another entry of the same level.
|
|
52
|
+
*/
|
|
53
|
+
export declare const HeaderBreadcrumbsSegment: React.FC<HeaderBreadcrumbsSegmentProps>;
|
|
54
|
+
export default HeaderBreadcrumbsSegment;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export { HeaderBreadcrumbs, default } from './HeaderBreadcrumbs';
|
|
19
|
+
export type { HeaderBreadcrumbsProps } from './HeaderBreadcrumbs';
|
|
20
|
+
export { HeaderBreadcrumbsSegment } from './HeaderBreadcrumbsSegment';
|
|
21
|
+
export type { HeaderBreadcrumbsSegmentProps } from './HeaderBreadcrumbsSegment';
|
|
22
|
+
export { useHeaderBreadcrumbs } from './useHeaderBreadcrumbs';
|
|
23
|
+
export type { HeaderBreadcrumbsChange, HeaderBreadcrumbsFetchContext, HeaderBreadcrumbsLevelConfig, UseHeaderBreadcrumbsOptions, UseHeaderBreadcrumbsReturn, } from './useHeaderBreadcrumbs';
|
|
24
|
+
export { HEADER_BREADCRUMBS_STORAGE_KEY, useHeaderBreadcrumbsValue, readHeaderBreadcrumbsState, writeHeaderBreadcrumbsState, clearHeaderBreadcrumbsState, subscribeHeaderBreadcrumbsState, } from './persistence';
|
|
25
|
+
export type { HeaderBreadcrumbsPersistOptions, HeaderBreadcrumbsStoredState, } from './persistence';
|
|
26
|
+
export type { HeaderBreadcrumbsAction, HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel, HeaderBreadcrumbsValue, } from './types';
|
|
@@ -0,0 +1,87 @@
|
|
|
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 type { HeaderBreadcrumbsValue } from './types';
|
|
19
|
+
/** Default storage key. Every app that uses the same key shares one selection. */
|
|
20
|
+
export declare const HEADER_BREADCRUMBS_STORAGE_KEY = "oxygen-ui:header-breadcrumbs";
|
|
21
|
+
/**
|
|
22
|
+
* What is kept in storage: the selected id of each level, never the items. Readable by
|
|
23
|
+
* any app on the same origin, with or without HeaderBreadcrumbs, through
|
|
24
|
+
* `useHeaderBreadcrumbsValue` or `readHeaderBreadcrumbsState`.
|
|
25
|
+
*/
|
|
26
|
+
export interface HeaderBreadcrumbsStoredState {
|
|
27
|
+
version: 1;
|
|
28
|
+
/** Selected id of each level. */
|
|
29
|
+
value: HeaderBreadcrumbsValue;
|
|
30
|
+
/** When the state was written, in milliseconds since the epoch. */
|
|
31
|
+
updatedAt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Where and how the state is kept.
|
|
35
|
+
*/
|
|
36
|
+
export interface HeaderBreadcrumbsPersistOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Storage key. Apps that share a key share the selection.
|
|
39
|
+
* @default 'oxygen-ui:header-breadcrumbs'
|
|
40
|
+
*/
|
|
41
|
+
key?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Storage area. Pass `sessionStorage` to keep it per tab.
|
|
44
|
+
* @default window.localStorage
|
|
45
|
+
*/
|
|
46
|
+
storage?: Storage;
|
|
47
|
+
/**
|
|
48
|
+
* Follow changes made by other tabs, windows and apps on the same origin, and by
|
|
49
|
+
* other breadcrumbs on the same page.
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
sync?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads the stored breadcrumb state, or `null` when there is none or it cannot be read.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const organizationId = readHeaderBreadcrumbsState()?.value.organization;
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const readHeaderBreadcrumbsState: (options?: HeaderBreadcrumbsPersistOptions) => HeaderBreadcrumbsStoredState | null;
|
|
63
|
+
/**
|
|
64
|
+
* Writes the selection and tells listeners on this page.
|
|
65
|
+
*/
|
|
66
|
+
export declare const writeHeaderBreadcrumbsState: (value: HeaderBreadcrumbsValue, options?: HeaderBreadcrumbsPersistOptions) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the stored breadcrumb state, such as on sign-out.
|
|
69
|
+
*/
|
|
70
|
+
export declare const clearHeaderBreadcrumbsState: (options?: HeaderBreadcrumbsPersistOptions) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Calls `listener` when the stored state changes, from another tab, window or app on
|
|
73
|
+
* the same origin, or from this page. Returns a function that stops listening.
|
|
74
|
+
*/
|
|
75
|
+
export declare const subscribeHeaderBreadcrumbsState: (listener: (state: HeaderBreadcrumbsStoredState | null) => void, options?: HeaderBreadcrumbsPersistOptions) => (() => void);
|
|
76
|
+
/**
|
|
77
|
+
* Returns the stored selection, such as `{ organization: 'wso2', project: 'oxygen-ui' }`,
|
|
78
|
+
* and re-renders when it changes in this page, another tab or another app on the same
|
|
79
|
+
* origin. Returns an empty object when nothing is stored. Works without rendering
|
|
80
|
+
* HeaderBreadcrumbs, so any app can read the current context.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* const { organization, project } = useHeaderBreadcrumbsValue();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const useHeaderBreadcrumbsValue: (options?: HeaderBreadcrumbsPersistOptions) => HeaderBreadcrumbsValue;
|
|
@@ -0,0 +1,125 @@
|
|
|
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 type * as React from 'react';
|
|
19
|
+
/**
|
|
20
|
+
* One entry a level can switch to, such as an organization, a project or a component.
|
|
21
|
+
*/
|
|
22
|
+
export interface HeaderBreadcrumbsItem {
|
|
23
|
+
/** Stable identifier. Stored in the breadcrumb value. */
|
|
24
|
+
id: string;
|
|
25
|
+
/** Display name, shown in the trail and in the switch menu. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Secondary text under the name in the switch menu. */
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Leading node in the switch menu, such as an Avatar or an icon. */
|
|
30
|
+
avatar?: React.ReactNode;
|
|
31
|
+
/** When set, the trail name and the menu entry render as links to this URL. */
|
|
32
|
+
href?: string;
|
|
33
|
+
/** A disabled entry is listed but cannot be picked. */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What an action handler receives.
|
|
38
|
+
*/
|
|
39
|
+
export interface HeaderBreadcrumbsActionContext {
|
|
40
|
+
/** The level whose menu holds the action. */
|
|
41
|
+
levelId: string;
|
|
42
|
+
/** Selected id of every level, such as the organization a new project goes into. */
|
|
43
|
+
value: HeaderBreadcrumbsValue;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An action at the bottom of a level's menu, such as "New project" or "Manage projects".
|
|
47
|
+
*/
|
|
48
|
+
export interface HeaderBreadcrumbsAction {
|
|
49
|
+
/** Stable key. */
|
|
50
|
+
key: string;
|
|
51
|
+
/** Visible label. */
|
|
52
|
+
label: React.ReactNode;
|
|
53
|
+
/** Leading icon. */
|
|
54
|
+
icon?: React.ReactNode;
|
|
55
|
+
/** Renders the action as a link to this URL, through `linkComponent`. */
|
|
56
|
+
href?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Called after the menu closes. With `href`, call `event.preventDefault()` to run
|
|
59
|
+
* your own logic in place of following the link.
|
|
60
|
+
*/
|
|
61
|
+
onClick?: (event: React.MouseEvent<HTMLElement>, context: HeaderBreadcrumbsActionContext) => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Changes to a built-in action for one level. `false` hides it.
|
|
65
|
+
*/
|
|
66
|
+
export type HeaderBreadcrumbsActionOverride = false | Partial<Omit<HeaderBreadcrumbsAction, 'key'>>;
|
|
67
|
+
/**
|
|
68
|
+
* One level of the trail, ready to render. `useHeaderBreadcrumbs` builds these.
|
|
69
|
+
*/
|
|
70
|
+
export interface HeaderBreadcrumbsLevel {
|
|
71
|
+
/** Level key, for example `organization`. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Level name, for example `Organization`. Used in menu titles and accessible names. */
|
|
74
|
+
label: string;
|
|
75
|
+
/**
|
|
76
|
+
* Icon for the level, such as a building for organizations. Shown before the name
|
|
77
|
+
* unless `showIcons` is `false`.
|
|
78
|
+
*/
|
|
79
|
+
icon?: React.ReactNode;
|
|
80
|
+
/** Entries the level can switch to. */
|
|
81
|
+
items: HeaderBreadcrumbsItem[];
|
|
82
|
+
/** Selected entry id. A level without a selection ends the trail. */
|
|
83
|
+
selectedId?: string | null;
|
|
84
|
+
/**
|
|
85
|
+
* The selected entry, used for its name while `items` does not include it yet,
|
|
86
|
+
* such as a name kept in storage by another app.
|
|
87
|
+
*/
|
|
88
|
+
selectedItem?: HeaderBreadcrumbsItem | null;
|
|
89
|
+
/** Items are being fetched. The menu shows a progress indicator. */
|
|
90
|
+
loading?: boolean;
|
|
91
|
+
/** Fetching failed. Shown in the menu in place of the list. */
|
|
92
|
+
error?: React.ReactNode;
|
|
93
|
+
/** Shown in the menu when there are no items. Defaults to "No {label} found". */
|
|
94
|
+
emptyText?: React.ReactNode;
|
|
95
|
+
/**
|
|
96
|
+
* Tooltip and accessible name of the › button shown while this level has no
|
|
97
|
+
* selection, such as on an organization page. Defaults to "Open {label}".
|
|
98
|
+
*/
|
|
99
|
+
openLabel?: string;
|
|
100
|
+
/** Title over the menu. Defaults to "Switch {label}", or `openLabel` with no selection. */
|
|
101
|
+
menuTitle?: React.ReactNode;
|
|
102
|
+
/** Placeholder for the search field. Defaults to "Find {label}…". */
|
|
103
|
+
searchPlaceholder?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Show a search field in the menu. Defaults to `'auto'`, which shows it when the
|
|
106
|
+
* level has more than 6 items.
|
|
107
|
+
*/
|
|
108
|
+
searchable?: boolean | 'auto';
|
|
109
|
+
/** Plural level name for "Manage {pluralLabel}". Defaults to `label` plus "s". */
|
|
110
|
+
pluralLabel?: string;
|
|
111
|
+
/**
|
|
112
|
+
* "New {label}" for this level. Shown when HeaderBreadcrumbs has `onCreate`, or
|
|
113
|
+
* when this sets `onClick` or `href`. `false` hides it.
|
|
114
|
+
*/
|
|
115
|
+
createAction?: HeaderBreadcrumbsActionOverride;
|
|
116
|
+
/**
|
|
117
|
+
* "Manage {pluralLabel}" for this level. Shown when HeaderBreadcrumbs has
|
|
118
|
+
* `onManage`, or when this sets `onClick` or `href`. `false` hides it.
|
|
119
|
+
*/
|
|
120
|
+
manageAction?: HeaderBreadcrumbsActionOverride;
|
|
121
|
+
/** More actions, after "New" and "Manage". */
|
|
122
|
+
actions?: HeaderBreadcrumbsAction[];
|
|
123
|
+
}
|
|
124
|
+
/** Selected item id for each level id. */
|
|
125
|
+
export type HeaderBreadcrumbsValue = Record<string, string>;
|
|
@@ -0,0 +1,150 @@
|
|
|
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 { HeaderBreadcrumbsProps } from './HeaderBreadcrumbs';
|
|
20
|
+
import { type HeaderBreadcrumbsPersistOptions } from './persistence';
|
|
21
|
+
import type { HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel, HeaderBreadcrumbsValue } from './types';
|
|
22
|
+
/**
|
|
23
|
+
* What `fetchItems` receives.
|
|
24
|
+
*/
|
|
25
|
+
export interface HeaderBreadcrumbsFetchContext {
|
|
26
|
+
/** Selected ids of the levels above this one, for example `{ organization: 'wso2' }`. */
|
|
27
|
+
parents: HeaderBreadcrumbsValue;
|
|
28
|
+
/** Aborted when the parents change, the level is refreshed again, or the hook unmounts. */
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One level the hook manages.
|
|
33
|
+
*/
|
|
34
|
+
export interface HeaderBreadcrumbsLevelConfig extends Omit<HeaderBreadcrumbsLevel, 'items' | 'selectedId' | 'loading' | 'error'> {
|
|
35
|
+
/**
|
|
36
|
+
* Loads the level's items. Called when every level above it has a selection, and
|
|
37
|
+
* again when one of those selections changes. The first level without a selection
|
|
38
|
+
* is fetched too, so its "Open {label}" menu is ready.
|
|
39
|
+
*/
|
|
40
|
+
fetchItems?: (context: HeaderBreadcrumbsFetchContext) => Promise<HeaderBreadcrumbsItem[]>;
|
|
41
|
+
/** Fixed items, used when there is no `fetchItems` or before it resolves. */
|
|
42
|
+
items?: HeaderBreadcrumbsItem[];
|
|
43
|
+
}
|
|
44
|
+
/** Why the value changed. */
|
|
45
|
+
export interface HeaderBreadcrumbsChange {
|
|
46
|
+
/** `sync` means another tab, app or breadcrumb changed the stored state. */
|
|
47
|
+
type: 'select' | 'navigate' | 'clear' | 'set' | 'sync';
|
|
48
|
+
/** The level that was acted on. Absent for `set`. */
|
|
49
|
+
levelId?: string;
|
|
50
|
+
/** The picked or clicked item, for `select` and `navigate`. */
|
|
51
|
+
item?: HeaderBreadcrumbsItem;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for useHeaderBreadcrumbs.
|
|
55
|
+
*/
|
|
56
|
+
export interface UseHeaderBreadcrumbsOptions {
|
|
57
|
+
/** Levels in order. */
|
|
58
|
+
levels: HeaderBreadcrumbsLevelConfig[];
|
|
59
|
+
/** Controlled selection. Pair with `onChange`. */
|
|
60
|
+
value?: HeaderBreadcrumbsValue;
|
|
61
|
+
/** Initial selection when uncontrolled. */
|
|
62
|
+
defaultValue?: HeaderBreadcrumbsValue;
|
|
63
|
+
/** Called with the next selection, such as to route to the new context. */
|
|
64
|
+
onChange?: (value: HeaderBreadcrumbsValue, change: HeaderBreadcrumbsChange) => void;
|
|
65
|
+
/** Called when a name in the trail is clicked. */
|
|
66
|
+
onNavigate?: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Clicking a name drops the levels under it, because the user is now on that
|
|
69
|
+
* entry's page.
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
truncateOnNavigate?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Fetch a level again each time its menu opens.
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
refreshOnOpen?: boolean;
|
|
78
|
+
/** Message for a failed fetch. Defaults to the error's `message`. */
|
|
79
|
+
formatError?: (error: unknown, levelId: string) => React.ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Keep the selection in `localStorage` (or the given storage) so other apps on the
|
|
82
|
+
* same origin can read it and start where the user left off. Only the selected ids
|
|
83
|
+
* are stored; each app fetches its own items. Read the value anywhere with
|
|
84
|
+
* `useHeaderBreadcrumbsValue`.
|
|
85
|
+
*
|
|
86
|
+
* Uncontrolled, the stored selection wins over `defaultValue`. Controlled, `value`
|
|
87
|
+
* wins and is written to storage. With `sync` (on by default), a change from another
|
|
88
|
+
* tab, app or breadcrumb updates this one and calls `onChange` with type `sync`.
|
|
89
|
+
* Read the state elsewhere with `readHeaderBreadcrumbsState`.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
persist?: boolean | HeaderBreadcrumbsPersistOptions;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What useHeaderBreadcrumbs returns.
|
|
96
|
+
*/
|
|
97
|
+
export interface UseHeaderBreadcrumbsReturn {
|
|
98
|
+
/** Current selection. */
|
|
99
|
+
value: HeaderBreadcrumbsValue;
|
|
100
|
+
/** Levels with their items, selection and loading state, ready for HeaderBreadcrumbs. */
|
|
101
|
+
levels: HeaderBreadcrumbsLevel[];
|
|
102
|
+
/** The selected item of each level, or `null` while it is not selected or not loaded. */
|
|
103
|
+
selected: Record<string, HeaderBreadcrumbsItem | null>;
|
|
104
|
+
/** Select an item. Levels under it are cleared when the id changes. */
|
|
105
|
+
select: (levelId: string, itemId: string) => void;
|
|
106
|
+
/** Clear a level and every level under it. */
|
|
107
|
+
clear: (levelId: string) => void;
|
|
108
|
+
/** Replace the whole selection, for example from the URL. */
|
|
109
|
+
setValue: (value: HeaderBreadcrumbsValue) => void;
|
|
110
|
+
/** Fetch one level again, or every reachable level when no id is given. */
|
|
111
|
+
refresh: (levelId?: string) => Promise<void>;
|
|
112
|
+
/** Replace a level's items, for example after a mutation. */
|
|
113
|
+
setItems: (levelId: string, items: HeaderBreadcrumbsItem[] | ((items: HeaderBreadcrumbsItem[]) => HeaderBreadcrumbsItem[])) => void;
|
|
114
|
+
/** Add an item to a level, such as a newly created project. */
|
|
115
|
+
addItem: (levelId: string, item: HeaderBreadcrumbsItem) => void;
|
|
116
|
+
/** Change fields of one item, such as after a rename. */
|
|
117
|
+
updateItem: (levelId: string, itemId: string, patch: Partial<HeaderBreadcrumbsItem>) => void;
|
|
118
|
+
/** Remove an item. Removing the selected item clears that level and those under it. */
|
|
119
|
+
removeItem: (levelId: string, itemId: string) => void;
|
|
120
|
+
/** Spread onto HeaderBreadcrumbs. */
|
|
121
|
+
breadcrumbProps: Pick<HeaderBreadcrumbsProps, 'levels' | 'onNavigate' | 'onSelect' | 'onOpen'>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* useHeaderBreadcrumbs - Fetches and keeps the data behind a HeaderBreadcrumbs.
|
|
125
|
+
*
|
|
126
|
+
* Holds the selected id of each level, loads each level's items from its parents'
|
|
127
|
+
* selection, and drops stale responses when the parents change. Picking a different
|
|
128
|
+
* item clears the levels under it. Clicking a name drops the levels under it. Use the
|
|
129
|
+
* item helpers to keep the menus current after creating, renaming or deleting.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* const breadcrumb = useHeaderBreadcrumbs({
|
|
134
|
+
* levels: [
|
|
135
|
+
* { id: 'organization', label: 'Organization', fetchItems: () => api.organizations() },
|
|
136
|
+
* {
|
|
137
|
+
* id: 'project',
|
|
138
|
+
* label: 'Project',
|
|
139
|
+
* fetchItems: ({ parents, signal }) => api.projects(parents.organization, { signal }),
|
|
140
|
+
* },
|
|
141
|
+
* ],
|
|
142
|
+
* value: fromRoute,
|
|
143
|
+
* onChange: (next) => navigate(toRoute(next)),
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* <HeaderBreadcrumbs {...breadcrumb.breadcrumbProps} />
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare const useHeaderBreadcrumbs: (options: UseHeaderBreadcrumbsOptions) => UseHeaderBreadcrumbsReturn;
|
|
150
|
+
export default useHeaderBreadcrumbs;
|
|
@@ -56,6 +56,8 @@ export { Header } from './Header';
|
|
|
56
56
|
export type { HeaderProps, HeaderSpacerProps, HeaderToggleProps, HeaderBrandProps, HeaderBrandLogoProps, HeaderBrandTitleProps, HeaderSwitchersProps, HeaderActionsProps, HeaderContextValue, } from './Header';
|
|
57
57
|
export { ContextSwitcher } from './ContextSwitcher';
|
|
58
58
|
export type { ContextSwitcherProps, ContextSwitcherValue, ContextSwitcherLevelProps, ContextSwitcherGroupProps, ContextSwitcherOptionProps, } from './ContextSwitcher';
|
|
59
|
+
export { HeaderBreadcrumbs, useHeaderBreadcrumbs, useHeaderBreadcrumbsValue, HEADER_BREADCRUMBS_STORAGE_KEY, readHeaderBreadcrumbsState, writeHeaderBreadcrumbsState, clearHeaderBreadcrumbsState, subscribeHeaderBreadcrumbsState, } from './HeaderBreadcrumbs';
|
|
60
|
+
export type { HeaderBreadcrumbsProps, HeaderBreadcrumbsItem, HeaderBreadcrumbsLevel, HeaderBreadcrumbsAction, HeaderBreadcrumbsValue, HeaderBreadcrumbsChange, HeaderBreadcrumbsFetchContext, HeaderBreadcrumbsLevelConfig, UseHeaderBreadcrumbsOptions, UseHeaderBreadcrumbsReturn, HeaderBreadcrumbsPersistOptions, HeaderBreadcrumbsStoredState, } from './HeaderBreadcrumbs';
|
|
59
61
|
export { AppSwitcher } from './AppSwitcher';
|
|
60
62
|
export type { AppSwitcherProps, AppSwitcherTriggerProps, AppSwitcherSectionProps, AppSwitcherAppProps, AppSwitcherAppItem, AppSwitcherAppTone, AppSwitcherFooterProps, AppSwitcherFooterLink, AppSwitcherContextValue, } from './AppSwitcher';
|
|
61
63
|
export { Sidebar, useSidebar } from './Sidebar';
|