UNPKG

@itwin/presentation-components

Version:

React components based on iTwin.js Presentation library

57 lines 2.91 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } 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 Table */ import { useState } from "react"; import { PropertyValueFormat } from "@itwin/appui-abstract"; import { NonPrimitivePropertyRenderer, PropertyValueRendererManager } from "@itwin/components-react"; import { Orientation } from "@itwin/core-react"; import { Anchor, Modal, ModalContent } from "@itwin/itwinui-react"; /** * Renderer for single table cell. * @public */ export function TableCellRenderer(props) { const { record } = props; if (record.value.valueFormat === PropertyValueFormat.Array) { return _jsx(ArrayPropertyRenderer, { record: record }); } if (record.value.valueFormat === PropertyValueFormat.Struct) { return _jsx(StructPropertyRenderer, { record: record }); } return _jsx(_Fragment, { children: PropertyValueRendererManager.defaultManager.render(record) }); } function ArrayPropertyRenderer(props) { const { record } = props; const value = record.value; const rendererProps = { record, buttonLabel: value.items.length !== 0 ? `${value.itemsTypeName}[${value.items.length}]` : "[]", dialogLabel: `Array of type "${value.itemsTypeName}"`, uniqueKey: `table_array_${record.property.name}`, }; return _jsx(NonPrimitiveCellRenderer, { ...rendererProps }); } function StructPropertyRenderer(props) { const { record } = props; const rendererProps = { record, buttonLabel: `{${record.property.typename}}`, dialogLabel: `Struct of type "${record.property.typename}"`, uniqueKey: `table_struct_${record.property.name}`, }; return _jsx(NonPrimitiveCellRenderer, { ...rendererProps }); } function NonPrimitiveCellRenderer(props) { const { record, dialogLabel, buttonLabel, uniqueKey } = props; const [isOpen, setIsOpen] = useState(false); // modal window when opened causes findDOMNode warning https://github.com/iTwin/iTwinUI/issues/2199 return (_jsxs(_Fragment, { children: [_jsx(Anchor, { onClick: () => { setIsOpen(true); }, children: buttonLabel }), _jsx(Modal, { isOpen: isOpen, title: dialogLabel, onClose: /* c8 ignore next */ () => setIsOpen(false), className: "presentation-components-non-primitive-value", children: _jsx(ModalContent, { children: _jsx(NonPrimitivePropertyRenderer, { uniqueKey: uniqueKey, propertyRecord: record, orientation: Orientation.Horizontal }) }) })] })); } //# sourceMappingURL=CellRenderer.js.map