chartPanel.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import styled from '@emotion/styled';
  2. import Panel from 'sentry/components/panels/panel';
  3. import {space} from 'sentry/styles/space';
  4. import {Subtitle} from 'sentry/views/performance/landing/widgets/widgets/singleFieldAreaWidget';
  5. type Props = {
  6. children: React.ReactNode;
  7. button?: JSX.Element;
  8. subtitle?: React.ReactNode;
  9. title?: React.ReactNode;
  10. };
  11. export default function ChartPanel({title, children, button, subtitle}: Props) {
  12. return (
  13. <PanelWithNoPadding>
  14. <PanelBody>
  15. {title && (
  16. <Header data-test-id="chart-panel-header">
  17. {title && (
  18. <ChartLabel>
  19. {typeof title === 'string' ? (
  20. <TextTitleContainer>{title}</TextTitleContainer>
  21. ) : (
  22. title
  23. )}
  24. </ChartLabel>
  25. )}
  26. {button}
  27. </Header>
  28. )}
  29. {subtitle && (
  30. <SubtitleContainer>
  31. <Subtitle>{subtitle}</Subtitle>
  32. </SubtitleContainer>
  33. )}
  34. {children}
  35. </PanelBody>
  36. </PanelWithNoPadding>
  37. );
  38. }
  39. const PanelWithNoPadding = styled(Panel)`
  40. margin-bottom: 0;
  41. `;
  42. const TextTitleContainer = styled('div')`
  43. padding: 1px 0;
  44. `;
  45. const SubtitleContainer = styled('div')`
  46. padding-top: ${space(0.5)};
  47. `;
  48. const ChartLabel = styled('div')`
  49. ${p => p.theme.text.cardTitle}
  50. `;
  51. const PanelBody = styled('div')`
  52. padding: ${space(2)};
  53. `;
  54. const Header = styled('div')`
  55. padding: 0 ${space(1)} 0 0;
  56. width: 100%;
  57. display: flex;
  58. align-items: center;
  59. justify-content: space-between;
  60. `;