RuleViewerLayout.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { locationService } from '@grafana/runtime';
  5. import { PageToolbar, useStyles2 } from '@grafana/ui';
  6. import { Page } from 'app/core/components/Page/Page';
  7. type Props = {
  8. children: React.ReactNode | React.ReactNode[];
  9. title: string;
  10. wrapInContent?: boolean;
  11. };
  12. export function RuleViewerLayout(props: Props): JSX.Element | null {
  13. const { wrapInContent = true, children, title } = props;
  14. const styles = useStyles2(getPageStyles);
  15. return (
  16. <Page>
  17. <PageToolbar title={title} pageIcon="bell" onGoBack={() => locationService.push('/alerting/list')} />
  18. <div className={styles.content}>{wrapInContent ? <RuleViewerLayoutContent {...props} /> : children}</div>
  19. </Page>
  20. );
  21. }
  22. type ContentProps = {
  23. children: React.ReactNode | React.ReactNode[];
  24. padding?: number;
  25. };
  26. export function RuleViewerLayoutContent({ children, padding = 2 }: ContentProps): JSX.Element | null {
  27. const styles = useStyles2(getContentStyles(padding));
  28. return <div className={styles.wrapper}>{children}</div>;
  29. }
  30. const getPageStyles = (theme: GrafanaTheme2) => {
  31. return {
  32. content: css`
  33. margin: ${theme.spacing(0, 2, 2)};
  34. max-width: ${theme.breakpoints.values.xxl}px;
  35. `,
  36. };
  37. };
  38. const getContentStyles = (padding: number) => (theme: GrafanaTheme2) => {
  39. return {
  40. wrapper: css`
  41. background: ${theme.colors.background.primary};
  42. border: 1px solid ${theme.colors.border.weak};
  43. border-radius: ${theme.shape.borderRadius()};
  44. padding: ${theme.spacing(padding)};
  45. `,
  46. };
  47. };