@grafana/ui
Version:
Grafana Components Library
48 lines (45 loc) • 1.56 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { css } from '@emotion/css';
import { formattedValueToString } from '@grafana/data';
import { MaybeWrapWithLink } from '../components/MaybeWrapWithLink.mjs';
import { TABLE } from '../constants.mjs';
import { getActiveCellSelector } from '../styles.mjs';
;
function AutoCell({ value, field, rowIdx }) {
const displayValue = field.display(value);
const formattedValue = formattedValueToString(displayValue);
return /* @__PURE__ */ jsx(MaybeWrapWithLink, { field, rowIdx, children: formattedValue });
}
const getStyles = (_theme, { textWrap, shouldOverflow, maxHeight }) => css({
...textWrap && { whiteSpace: "pre-line" },
...shouldOverflow && {
[getActiveCellSelector(Boolean(maxHeight))]: {
whiteSpace: "pre-line"
}
},
...maxHeight != null && textWrap && {
height: "auto",
overflowY: "hidden",
display: "-webkit-box",
WebkitBoxOrient: "vertical",
WebkitLineClamp: Math.floor(maxHeight / TABLE.LINE_HEIGHT),
[getActiveCellSelector(true)]: {
display: "flex",
WebkitLineClamp: "none",
WebkitBoxOrient: "unset",
overflowY: "auto",
height: "fit-content"
}
}
});
const getJsonCellStyles = (_theme, { textWrap, shouldOverflow, maxHeight }) => css({
fontFamily: "monospace",
...textWrap && { whiteSpace: "pre" },
...shouldOverflow && {
[getActiveCellSelector(Boolean(maxHeight))]: {
whiteSpace: "pre"
}
}
});
export { AutoCell, getJsonCellStyles, getStyles };
//# sourceMappingURL=AutoCell.mjs.map