ReceiversSection.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { css, cx } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { Link } from 'react-router-dom';
  4. import { GrafanaTheme2 } from '@grafana/data';
  5. import { Button, useStyles2 } from '@grafana/ui';
  6. interface Props {
  7. title: string;
  8. description: string;
  9. addButtonLabel: string;
  10. addButtonTo: string;
  11. className?: string;
  12. showButton?: boolean;
  13. }
  14. export const ReceiversSection: FC<Props> = ({
  15. className,
  16. title,
  17. description,
  18. addButtonLabel,
  19. addButtonTo,
  20. children,
  21. showButton = true,
  22. }) => {
  23. const styles = useStyles2(getStyles);
  24. return (
  25. <>
  26. <div className={cx(styles.heading, className)}>
  27. <div>
  28. <h4>{title}</h4>
  29. <p className={styles.description}>{description}</p>
  30. </div>
  31. {showButton && (
  32. <Link to={addButtonTo}>
  33. <Button type="button" icon="plus">
  34. {addButtonLabel}
  35. </Button>
  36. </Link>
  37. )}
  38. </div>
  39. {children}
  40. </>
  41. );
  42. };
  43. const getStyles = (theme: GrafanaTheme2) => ({
  44. heading: css`
  45. display: flex;
  46. justify-content: space-between;
  47. `,
  48. description: css`
  49. color: ${theme.colors.text.secondary};
  50. `,
  51. });