Design system.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

58 righe
1.2 KiB

  1. import * as React from 'react';
  2. import clsx from 'clsx';
  3. /**
  4. * Derived HTML element of the {@link Badge} component.
  5. */
  6. export type BadgeDerivedElement = HTMLSpanElement;
  7. /**
  8. * Props of the {@link Badge} component.
  9. */
  10. export interface BadgeProps extends React.HTMLProps<BadgeDerivedElement> {
  11. /**
  12. * Is the component rounded?
  13. */
  14. rounded?: boolean;
  15. }
  16. /**
  17. * Component for displaying textual information in a small container.
  18. */
  19. export const Badge = React.forwardRef<BadgeDerivedElement, BadgeProps>((
  20. {
  21. children,
  22. rounded = false,
  23. className,
  24. style,
  25. ...etcProps
  26. },
  27. forwardedRef,
  28. ) => (
  29. <span
  30. {...etcProps}
  31. ref={forwardedRef}
  32. className={clsx(
  33. 'relative h-6 min-w-6 flex items-center justify-center text-xs font-bold overflow-hidden font-semi-expanded',
  34. 'before:absolute before:top-0 before:left-0 before:w-full before:h-full before:bg-current before:opacity-25',
  35. {
  36. 'rounded-full px-2': rounded,
  37. 'rounded px-1': !rounded,
  38. },
  39. className,
  40. )}
  41. style={style}
  42. data-testid="badge"
  43. >
  44. <span className="relative w-full">
  45. {children}
  46. </span>
  47. </span>
  48. ));
  49. Badge.displayName = 'Badge';
  50. Badge.defaultProps = {
  51. rounded: false,
  52. };