@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
60 lines • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableCellRenderer = TableCellRenderer;
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 Table
*/
const react_1 = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const components_react_1 = require("@itwin/components-react");
const core_react_1 = require("@itwin/core-react");
const itwinui_react_1 = require("@itwin/itwinui-react");
/**
* Renderer for single table cell.
* @public
*/
function TableCellRenderer(props) {
const { record } = props;
if (record.value.valueFormat === appui_abstract_1.PropertyValueFormat.Array) {
return (0, jsx_runtime_1.jsx)(ArrayPropertyRenderer, { record: record });
}
if (record.value.valueFormat === appui_abstract_1.PropertyValueFormat.Struct) {
return (0, jsx_runtime_1.jsx)(StructPropertyRenderer, { record: record });
}
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: components_react_1.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 (0, jsx_runtime_1.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 (0, jsx_runtime_1.jsx)(NonPrimitiveCellRenderer, { ...rendererProps });
}
function NonPrimitiveCellRenderer(props) {
const { record, dialogLabel, buttonLabel, uniqueKey } = props;
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
// modal window when opened causes findDOMNode warning https://github.com/iTwin/iTwinUI/issues/2199
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.Anchor, { onClick: () => {
setIsOpen(true);
}, children: buttonLabel }), (0, jsx_runtime_1.jsx)(itwinui_react_1.Modal, { isOpen: isOpen, title: dialogLabel, onClose: /* c8 ignore next */ () => setIsOpen(false), className: "presentation-components-non-primitive-value", children: (0, jsx_runtime_1.jsx)(itwinui_react_1.ModalContent, { children: (0, jsx_runtime_1.jsx)(components_react_1.NonPrimitivePropertyRenderer, { uniqueKey: uniqueKey, propertyRecord: record, orientation: core_react_1.Orientation.Horizontal }) }) })] }));
}
//# sourceMappingURL=CellRenderer.js.map