ImagePreview.tsx 837 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { css, cx } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { useStyles } from '@grafana/ui';
  5. export interface Props {
  6. url: string;
  7. width?: string;
  8. }
  9. export const ImagePreview = ({ url, width = '200px' }: Props) => {
  10. const styles = useStyles(getStyles);
  11. return url ? (
  12. <div
  13. className={cx(
  14. styles.wrapper,
  15. css`
  16. width: ${width};
  17. `
  18. )}
  19. >
  20. <img src={url} className={styles.img} />
  21. </div>
  22. ) : null;
  23. };
  24. const getStyles = (theme: GrafanaTheme) => {
  25. return {
  26. wrapper: css`
  27. padding: ${theme.spacing.sm};
  28. border: 1px solid ${theme.colors.border3};
  29. border-radius: ${theme.border.radius.sm};
  30. margin-bottom: ${theme.spacing.md};
  31. `,
  32. img: css`
  33. width: 100%;
  34. `,
  35. };
  36. };