-
Notifications
You must be signed in to change notification settings - Fork 2
/
useUiItemsProviderToolbarItems.tsx
42 lines (39 loc) · 1.56 KB
/
useUiItemsProviderToolbarItems.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Toolbar
*/
import * as React from "react";
import type {
ToolbarItem,
ToolbarOrientation,
ToolbarUsage,
} from "./ToolbarItem";
import type { ToolbarItemsManager } from "./ToolbarItemsManager";
import { useActiveStageProvidedToolbarItems } from "./useActiveStageProvidedToolbarItems";
/** Hook that retrieves active frontstage toolbar items from UiItemsProviders and manage them through [[ToolbarItemsManager]].
* @public
* @deprecated in 4.4.0. This uses ToolbarItemsManager which is internal, directly use [[ToolbarComposer]] instead.
*/
export const useUiItemsProviderToolbarItems = (
// eslint-disable-next-line deprecation/deprecation
manager: ToolbarItemsManager,
toolbarUsage: ToolbarUsage,
toolbarOrientation: ToolbarOrientation
): readonly ToolbarItem[] => {
const providedItems = useActiveStageProvidedToolbarItems(
toolbarUsage,
toolbarOrientation
);
const [items, setItems] = React.useState(providedItems);
React.useEffect(() => {
manager?.loadItems(providedItems);
setItems(manager?.items ?? providedItems);
return manager?.onItemsChanged.addListener((args) => {
setItems(args.items);
});
}, [manager, providedItems]);
return items;
};