@grafana/ui
Version:
Grafana Components Library
30 lines (27 loc) • 974 B
JavaScript
import { jsx } from 'react/jsx-runtime';
import { css } from '@emotion/css';
import { useState } from 'react';
import '../../types.mjs';
import { MaybeWrapWithLink } from '../components/MaybeWrapWithLink.mjs';
import { TableCellDisplayMode } from '@grafana/schema';
;
const ImageCell = ({ cellOptions, field, value, rowIdx }) => {
const [error, setError] = useState(false);
const { text } = field.display(value);
const { alt, title } = cellOptions.type === TableCellDisplayMode.Image ? cellOptions : { alt: void 0, title: void 0 };
if (!text) {
return null;
}
return /* @__PURE__ */ jsx(MaybeWrapWithLink, { field, rowIdx, children: error ? text : /* @__PURE__ */ jsx("img", { alt, src: text, title, onError: () => setError(true) }) });
};
const getStyles = () => css({
"&, a, img": {
width: "100%",
height: "100%"
},
img: {
objectFit: "contain"
}
});
export { ImageCell, getStyles };
//# sourceMappingURL=ImageCell.mjs.map