@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
44 lines • 1.88 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/**
* @packageDocumentation
* @module Properties
*/
import { createContext, useContext, useMemo } from "react";
const navigationPropertyEditorContext = createContext(undefined);
/**
* Creates context that supplies necessary navigation property-related information for [[NavigationPropertyEditor]].
* @public
*/
export function NavigationPropertyEditorContextProvider({ children, ...props }) {
return _jsx(navigationPropertyEditorContext.Provider, { value: props, children: children });
}
/**
* Returns context provided by [[NavigationPropertyEditorContextProvider]]. The context is required for rendering [[NavigationPropertyEditor]] with editable
* navigation property values.
*
* @internal
*/
export function useNavigationPropertyEditorContext() {
return useContext(navigationPropertyEditorContext);
}
/**
* Custom hook that creates props for [[NavigationPropertyEditorContextProvider]].
* @public
*/
export function useNavigationPropertyEditorContextProviderProps(imodel, dataProvider) {
return useMemo(() => ({
imodel,
getNavigationPropertyInfo: async (property) => {
const field = await dataProvider.getFieldByPropertyDescription(property);
if (!field || !field.isPropertiesField()) {
return undefined;
}
return field.properties[0].property.navigationPropertyInfo;
},
}), [imodel, dataProvider]);
}
//# sourceMappingURL=NavigationPropertyEditorContext.js.map