widgetDescription.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {IconInfo} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. export interface WidgetDescriptionProps {
  8. description?: React.ReactElement | string;
  9. forceDescriptionTooltip?: boolean;
  10. title?: string;
  11. }
  12. export function WidgetDescription(props: WidgetDescriptionProps) {
  13. return (
  14. <Tooltip
  15. title={
  16. <span>
  17. {props.title && <WidgetTooltipTitle>{props.title}</WidgetTooltipTitle>}
  18. {props.description && (
  19. <WidgetTooltipDescription>{props.description}</WidgetTooltipDescription>
  20. )}
  21. </span>
  22. }
  23. containerDisplayMode="grid"
  24. isHoverable
  25. forceVisible={props.forceDescriptionTooltip}
  26. >
  27. <WidgetTooltipButton
  28. aria-label={t('Widget description')}
  29. borderless
  30. size="xs"
  31. icon={<IconInfo size="sm" />}
  32. />
  33. </Tooltip>
  34. );
  35. }
  36. const WidgetTooltipTitle = styled('div')`
  37. font-weight: bold;
  38. font-size: ${p => p.theme.fontSizeMedium};
  39. text-align: left;
  40. `;
  41. const WidgetTooltipDescription = styled('div')`
  42. margin-top: ${space(0.5)};
  43. font-size: ${p => p.theme.fontSizeSmall};
  44. text-align: left;
  45. `;
  46. // We're using a button here to preserve tab accessibility
  47. const WidgetTooltipButton = styled(Button)`
  48. pointer-events: none;
  49. padding-top: 0;
  50. padding-bottom: 0;
  51. `;