UNPKG

@itwin/presentation-hierarchies-react

Version:

React components based on `@itwin/presentation-hierarchies`

62 lines 2.97 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { useCallback } from "react"; import { createIModelHierarchyProvider } from "@itwin/presentation-hierarchies"; import { useTree, useUnifiedSelectionTree } from "./UseTree.js"; /** * A React hook that creates state for a tree component whose displayed hierarchy is based on * iModel data. * * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a * component-agnostic result which may be used to render the hierarchy using any UI framework. * * See `README.md` for an example * * @see `useTree` * @see `useIModelUnifiedSelectionTree` * @public */ export function useIModelTree(props) { const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props; return useTree({ ...rest, ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }), }); } /** * A React hook that creates state for a tree component whose displayed hierarchy is based on * iModel data and that is integrated with unified selection through the given selection * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`). * * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a * component-agnostic result which may be used to render the hierarchy using any UI framework. * * See `README.md` for an example * * @see `useIModelTree` * @see `useUnifiedSelectionTree` * @see `UnifiedSelectionProvider` * @public */ export function useIModelUnifiedSelectionTree(props) { const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props; return useUnifiedSelectionTree({ ...rest, ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }), }); } function useIModelTreeProps(props) { const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props; return { getHierarchyProvider: useCallback(() => createIModelHierarchyProvider({ imodelAccess, imodelChanged, hierarchyDefinition: getHierarchyDefinition({ imodelAccess }), localizedStrings, }), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]), getFilteredPaths: useCallback(async ({ abortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getFilteredPaths]), }; } //# sourceMappingURL=UseIModelTree.js.map