UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

45 lines 2.95 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { ClipboardButton, Typography } from '@neo4j-ndl/react'; import { useState } from 'react'; import { ClickableUrls } from './clickable-urls'; export const ELLIPSIS = '\u2026'; export const WIDE_VIEW_THRESHOLD = 900; export const MAX_LENGTH_NARROW = 150; export const MAX_LENGTH_WIDE = 300; const ExpandableValue = ({ value, width, type }) => { const [isExpanded, setIsExpanded] = useState(false); const maxLength = width > WIDE_VIEW_THRESHOLD ? MAX_LENGTH_WIDE : MAX_LENGTH_NARROW; const handleExpandClick = () => { setIsExpanded(true); }; let valueShown = isExpanded ? value : value.slice(0, maxLength); const isValueTrimmed = valueShown.length !== value.length; valueShown += isValueTrimmed ? ELLIPSIS : ''; return (_jsxs(_Fragment, { children: [type.startsWith('Array') && '[', _jsx(ClickableUrls, { text: valueShown }), isValueTrimmed && (_jsx("button", { onClick: handleExpandClick, className: "ndl-properties-show-all-button", children: ' Show all' })), type.startsWith('Array') && ']'] })); }; export const PropertiesTable = ({ properties, paneWidth, }) => { return (_jsxs("div", { className: "ndl-graph-visualization-properties-table", children: [_jsxs("div", { className: "ndl-properties-header", children: [_jsx(Typography, { variant: "body-small", className: "ndl-properties-header-key", children: "Key" }), _jsx(Typography, { variant: "body-small", children: "Value" })] }), Object.entries(properties).map(([key, { stringified, type }]) => { return (_jsxs("div", { className: "ndl-properties-row", children: [_jsx(Typography, { variant: "body-small", className: "ndl-properties-key", children: key }), _jsx("div", { className: "ndl-properties-value", children: _jsx(ExpandableValue, { value: stringified, width: paneWidth, type: type }) }), _jsx("div", { className: "ndl-properties-clipboard-button", children: _jsx(ClipboardButton, { textToCopy: `${key}: ${stringified}`, size: "small", tooltipProps: { placement: 'left', type: 'simple' } }) })] }, key)); })] })); }; //# sourceMappingURL=properties-table.js.map