contextIcon.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import styled from '@emotion/styled';
  2. import {PlatformIcon} from 'platformicons';
  3. import CountTooltipContent from 'sentry/components/replays/countTooltipContent';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {generatePlatformIconName} from 'sentry/utils/replays/generatePlatformIconName';
  8. import commonTheme from 'sentry/utils/theme';
  9. type Props = {
  10. name: string;
  11. version: undefined | string;
  12. className?: string;
  13. showTooltip?: boolean;
  14. showVersion?: boolean;
  15. };
  16. const iconSize = '16px';
  17. const iconStyle = {
  18. border: '1px solid ' + commonTheme.translucentGray100,
  19. };
  20. const ContextIcon = styled(
  21. ({className, name, version, showVersion, showTooltip}: Props) => {
  22. const icon = generatePlatformIconName(name, version);
  23. if (!showTooltip) {
  24. return <PlatformIcon platform={icon} size={iconSize} style={iconStyle} />;
  25. }
  26. const title = (
  27. <CountTooltipContent>
  28. <dt>{t('Name:')}</dt>
  29. <dd>{name}</dd>
  30. {version ? <dt>{t('Version:')}</dt> : null}
  31. {version ? <dd>{version}</dd> : null}
  32. </CountTooltipContent>
  33. );
  34. return (
  35. <Tooltip title={title} className={className}>
  36. <PlatformIcon platform={icon} size={iconSize} style={iconStyle} />
  37. {showVersion ? (version ? version : null) : undefined}
  38. </Tooltip>
  39. );
  40. }
  41. )`
  42. display: flex;
  43. gap: ${space(1)};
  44. font-variant-numeric: tabular-nums;
  45. align-items: center;
  46. `;
  47. export default ContextIcon;