OperationExplainedBox.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2, renderMarkdown } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. export interface Props {
  6. title?: React.ReactNode;
  7. children?: React.ReactNode;
  8. markdown?: string;
  9. stepNumber?: number;
  10. }
  11. export function OperationExplainedBox({ title, stepNumber, markdown, children }: Props) {
  12. const styles = useStyles2(getStyles);
  13. return (
  14. <div className={styles.box}>
  15. {stepNumber !== undefined && <div className={styles.stepNumber}>{stepNumber}</div>}
  16. <div className={styles.boxInner}>
  17. {title && (
  18. <div className={styles.header}>
  19. <span>{title}</span>
  20. </div>
  21. )}
  22. <div className={styles.body}>
  23. {markdown && <div dangerouslySetInnerHTML={{ __html: renderMarkdown(markdown) }}></div>}
  24. {children}
  25. </div>
  26. </div>
  27. </div>
  28. );
  29. }
  30. const getStyles = (theme: GrafanaTheme2) => {
  31. return {
  32. box: css({
  33. background: theme.colors.background.secondary,
  34. padding: theme.spacing(1),
  35. borderRadius: theme.shape.borderRadius(),
  36. position: 'relative',
  37. }),
  38. boxInner: css({
  39. marginLeft: theme.spacing(4),
  40. }),
  41. stepNumber: css({
  42. fontWeight: theme.typography.fontWeightMedium,
  43. background: theme.colors.secondary.main,
  44. width: '20px',
  45. height: '20px',
  46. borderRadius: '50%',
  47. display: 'flex',
  48. alignItems: 'center',
  49. justifyContent: 'center',
  50. position: 'absolute',
  51. top: '10px',
  52. left: '11px',
  53. fontSize: theme.typography.bodySmall.fontSize,
  54. }),
  55. header: css({
  56. paddingBottom: theme.spacing(0.5),
  57. display: 'flex',
  58. alignItems: 'center',
  59. fontFamily: theme.typography.fontFamilyMonospace,
  60. }),
  61. body: css({
  62. color: theme.colors.text.secondary,
  63. 'p:last-child': {
  64. margin: 0,
  65. },
  66. a: {
  67. color: theme.colors.text.link,
  68. textDecoration: 'underline',
  69. },
  70. }),
  71. };
  72. };