chartPanel.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import styled from '@emotion/styled';
  2. import {openInsightChartModal} from 'sentry/actionCreators/modal';
  3. import {Button} from 'sentry/components/button';
  4. import Panel from 'sentry/components/panels/panel';
  5. import {IconExpand} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {Subtitle} from 'sentry/views/performance/landing/widgets/widgets/singleFieldAreaWidget';
  9. type Props = {
  10. children: React.ReactNode;
  11. button?: JSX.Element;
  12. className?: string;
  13. subtitle?: React.ReactNode;
  14. title?: React.ReactNode;
  15. };
  16. export default function ChartPanel({
  17. title,
  18. children,
  19. button,
  20. subtitle,
  21. className,
  22. }: Props) {
  23. return (
  24. <PanelWithNoPadding className={className}>
  25. <PanelBody>
  26. {title && (
  27. <Header data-test-id="chart-panel-header">
  28. {title && (
  29. <ChartLabel>
  30. {typeof title === 'string' ? (
  31. <TextTitleContainer>{title}</TextTitleContainer>
  32. ) : (
  33. title
  34. )}
  35. </ChartLabel>
  36. )}
  37. <MenuContainer>
  38. {button}
  39. <Button
  40. aria-label={t('Expand Insight Chart')}
  41. borderless
  42. size="xs"
  43. icon={<IconExpand />}
  44. onClick={() => {
  45. openInsightChartModal({title, children});
  46. }}
  47. />
  48. </MenuContainer>
  49. </Header>
  50. )}
  51. {subtitle && (
  52. <SubtitleContainer>
  53. <Subtitle>{subtitle}</Subtitle>
  54. </SubtitleContainer>
  55. )}
  56. {children}
  57. </PanelBody>
  58. </PanelWithNoPadding>
  59. );
  60. }
  61. const PanelWithNoPadding = styled(Panel)`
  62. margin-bottom: 0;
  63. `;
  64. const TextTitleContainer = styled('div')`
  65. padding: 1px 0;
  66. `;
  67. const SubtitleContainer = styled('div')`
  68. padding-top: ${space(0.5)};
  69. `;
  70. const ChartLabel = styled('div')`
  71. ${p => p.theme.text.cardTitle}
  72. `;
  73. const PanelBody = styled('div')`
  74. padding: ${space(2)};
  75. `;
  76. const Header = styled('div')`
  77. width: 100%;
  78. display: flex;
  79. align-items: center;
  80. justify-content: space-between;
  81. `;
  82. const MenuContainer = styled('span')`
  83. display: flex;
  84. `;