badge.tsx 883 B

1234567891011121314151617181920212223242526272829303132333435
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import space from 'app/styles/space';
  4. import type {Theme} from 'app/utils/theme';
  5. type Props = React.HTMLProps<HTMLSpanElement> & {
  6. children?: React.ReactNode;
  7. text?: string | number | null;
  8. type?: keyof Theme['badge'];
  9. className?: string;
  10. };
  11. const Badge = styled(({children, text, ...props}: Props) => (
  12. <span {...props}>{children ?? text}</span>
  13. ))<Props>`
  14. display: inline-block;
  15. height: 20px;
  16. min-width: 20px;
  17. line-height: 20px;
  18. border-radius: 20px;
  19. padding: 0 5px;
  20. margin-left: ${space(0.5)};
  21. font-size: 75%;
  22. font-weight: 600;
  23. text-align: center;
  24. color: ${p => p.theme.badge[p.type ?? 'default'].color};
  25. background: ${p => p.theme.badge[p.type ?? 'default'].background};
  26. transition: background 100ms linear;
  27. position: relative;
  28. top: -1px;
  29. `;
  30. export default Badge;