@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
49 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigationPropertyEditorContextProvider = NavigationPropertyEditorContextProvider;
exports.useNavigationPropertyEditorContext = useNavigationPropertyEditorContext;
exports.useNavigationPropertyEditorContextProviderProps = useNavigationPropertyEditorContextProviderProps;
const jsx_runtime_1 = require("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
*/
const react_1 = require("react");
const navigationPropertyEditorContext = (0, react_1.createContext)(undefined);
/**
* Creates context that supplies necessary navigation property-related information for [[NavigationPropertyEditor]].
* @public
*/
function NavigationPropertyEditorContextProvider({ children, ...props }) {
return (0, jsx_runtime_1.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
*/
function useNavigationPropertyEditorContext() {
return (0, react_1.useContext)(navigationPropertyEditorContext);
}
/**
* Custom hook that creates props for [[NavigationPropertyEditorContextProvider]].
* @public
*/
function useNavigationPropertyEditorContextProviderProps(imodel, dataProvider) {
return (0, react_1.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