featureBadge.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import * as React from 'react';
  2. import {useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import CircleIndicator from 'sentry/components/circleIndicator';
  5. import Tag from 'sentry/components/tagDeprecated';
  6. import Tooltip from 'sentry/components/tooltip';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. type BadgeProps = {
  10. type: 'alpha' | 'beta' | 'new';
  11. noTooltip?: boolean;
  12. title?: string;
  13. variant?: 'indicator' | 'badge';
  14. };
  15. type Props = Omit<React.HTMLAttributes<HTMLDivElement>, keyof BadgeProps> & BadgeProps;
  16. const defaultTitles = {
  17. alpha: t('This feature is internal and available for QA purposes'),
  18. beta: t('This feature is available for early adopters and may change'),
  19. new: t('This feature is new! Try it out and let us know what you think'),
  20. };
  21. const labels = {
  22. alpha: t('alpha'),
  23. beta: t('beta'),
  24. new: t('new'),
  25. };
  26. function BaseFeatureBadge({type, variant = 'badge', title, noTooltip, ...p}: Props) {
  27. const theme = useTheme();
  28. return (
  29. <div {...p}>
  30. <Tooltip title={title ?? defaultTitles[type]} disabled={noTooltip} position="right">
  31. <React.Fragment>
  32. {variant === 'badge' && <StyledTag priority={type}>{labels[type]}</StyledTag>}
  33. {variant === 'indicator' && (
  34. <CircleIndicator color={theme.badge[type].indicatorColor} size={8} />
  35. )}
  36. </React.Fragment>
  37. </Tooltip>
  38. </div>
  39. );
  40. }
  41. const StyledTag = styled(Tag)`
  42. padding: 3px ${space(0.75)};
  43. `;
  44. const FeatureBadge = styled(BaseFeatureBadge)`
  45. display: inline-flex;
  46. align-items: center;
  47. margin-left: ${space(0.75)};
  48. position: relative;
  49. top: -1px;
  50. `;
  51. export default FeatureBadge;