chartPanel.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. subtitle?: React.ReactNode;
  13. title?: React.ReactNode;
  14. };
  15. export default function ChartPanel({title, children, button, subtitle}: Props) {
  16. return (
  17. <PanelWithNoPadding>
  18. <PanelBody>
  19. {title && (
  20. <Header data-test-id="chart-panel-header">
  21. {title && (
  22. <ChartLabel>
  23. {typeof title === 'string' ? (
  24. <TextTitleContainer>{title}</TextTitleContainer>
  25. ) : (
  26. title
  27. )}
  28. </ChartLabel>
  29. )}
  30. {button}
  31. <Button
  32. aria-label={t('Expand Insight Chart')}
  33. borderless
  34. size="xs"
  35. icon={<IconExpand />}
  36. onClick={() => {
  37. openInsightChartModal({title, children});
  38. }}
  39. />
  40. </Header>
  41. )}
  42. {subtitle && (
  43. <SubtitleContainer>
  44. <Subtitle>{subtitle}</Subtitle>
  45. </SubtitleContainer>
  46. )}
  47. {children}
  48. </PanelBody>
  49. </PanelWithNoPadding>
  50. );
  51. }
  52. const PanelWithNoPadding = styled(Panel)`
  53. margin-bottom: 0;
  54. `;
  55. const TextTitleContainer = styled('div')`
  56. padding: 1px 0;
  57. `;
  58. const SubtitleContainer = styled('div')`
  59. padding-top: ${space(0.5)};
  60. `;
  61. const ChartLabel = styled('div')`
  62. ${p => p.theme.text.cardTitle}
  63. `;
  64. const PanelBody = styled('div')`
  65. padding: ${space(2)};
  66. `;
  67. const Header = styled('div')`
  68. width: 100%;
  69. display: flex;
  70. align-items: center;
  71. justify-content: space-between;
  72. `;