Website for showcasing all features of Tesseract Web.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

67 linhas
1.2 KiB

  1. import * as React from 'react';
  2. import {
  3. css,
  4. } from 'goober';
  5. const BadgeBase = ({ rounded }: { rounded: boolean }) => css`
  6. position: relative;
  7. height: 1.5em;
  8. min-width: 1.5em;
  9. display: inline-grid;
  10. vertical-align: middle;
  11. place-content: center;
  12. border-radius: ${rounded ? '0.75em' : '0.25rem'};
  13. overflow: hidden;
  14. font-stretch: var(--font-stretch-base, normal);
  15. padding: 0 0.25rem;
  16. box-sizing: border-box;
  17. &::before {
  18. position: absolute;
  19. top: 0;
  20. left: 0;
  21. width: 100%;
  22. height: 100%;
  23. background-color: currentColor;
  24. opacity: 0.25;
  25. content: '';
  26. }
  27. `;
  28. const Content = () => css`
  29. position: relative;
  30. font-size: 0.75em;
  31. `;
  32. export type BadgeProps = React.HTMLProps<HTMLSpanElement> & {
  33. rounded?: boolean,
  34. };
  35. export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
  36. (
  37. {
  38. children,
  39. rounded = false,
  40. },
  41. ref,
  42. ) => {
  43. const badgeStyleProps = React.useMemo(() => ({
  44. rounded,
  45. }), [rounded]);
  46. return (
  47. <strong
  48. ref={ref}
  49. className={BadgeBase(badgeStyleProps)}
  50. >
  51. <span
  52. className={Content()}
  53. >
  54. {children}
  55. </span>
  56. </strong>
  57. )
  58. }
  59. )
  60. Badge.displayName = 'Badge';