@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
62 lines • 2.61 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.
*--------------------------------------------------------------------------------------------*/
import { createRef, forwardRef, PureComponent } from "react";
import { PropertyEditorBase } from "@itwin/components-react";
import { NavigationPropertyTargetSelector, ReadonlyNavigationPropertyTarget } from "../inputs/NavigationPropertyTargetSelector.js";
import { useNavigationPropertyEditorContext } from "./NavigationPropertyEditorContext.js";
/**
* Editor for navigation properties.
*
* **Note:** Should be used inside [[navigationPropertyEditorContext]].
* @internal
*/
export class NavigationPropertyEditor extends PropertyEditorBase {
/* c8 ignore start */
get containerHandlesEnter() {
return false;
}
get reactNode() {
return _jsx(NavigationPropertyTargetEditor, {});
}
}
/**
* Component that renders navigation property target selector for navigation property value editing.
*
* **Note:** Should be used inside [[navigationPropertyEditorContext]].
* @internal
*/
export class NavigationPropertyTargetEditor extends PureComponent {
_ref = createRef();
/* c8 ignore start */
async getPropertyValue() {
return this._ref.current?.getValue();
}
get htmlElement() {
return this._ref.current?.htmlElement ?? null;
}
get hasFocus() {
if (!this._ref.current?.htmlElement || !document.activeElement) {
return false;
}
return this._ref.current.htmlElement.contains(document.activeElement);
}
/* c8 ignore end */
render() {
return _jsx(NavigationPropertyTargetEditorInner, { ref: this._ref, ...this.props });
}
}
const NavigationPropertyTargetEditorInner = forwardRef((props, ref) => {
const context = useNavigationPropertyEditorContext();
if (!props.propertyRecord) {
return null;
}
if (!context) {
return _jsx(ReadonlyNavigationPropertyTarget, { record: props.propertyRecord });
}
return (_jsx(NavigationPropertyTargetSelector, { ...props, ref: ref, imodel: context.imodel, getNavigationPropertyInfo: context.getNavigationPropertyInfo, propertyRecord: props.propertyRecord }));
});
NavigationPropertyTargetEditorInner.displayName = "NavigationPropertyTargetEditorInner";
//# sourceMappingURL=NavigationPropertyEditor.js.map