svgIcon.tsx 881 B

1234567891011121314151617181920212223242526272829303132333435
  1. import {forwardRef} from 'react';
  2. import {useTheme} from '@emotion/react';
  3. import {Aliases, Color, IconSize} from 'sentry/utils/theme';
  4. export interface SVGIconProps extends React.SVGAttributes<SVGSVGElement> {
  5. className?: string;
  6. color?: Color | keyof Aliases;
  7. /**
  8. * DO NOT USE THIS! Please use the `size` prop
  9. *
  10. * @deprecated
  11. */
  12. legacySize?: string;
  13. size?: IconSize;
  14. }
  15. export const SvgIcon = forwardRef<SVGSVGElement, SVGIconProps>(function SvgIcon(
  16. {
  17. color: providedColor = 'currentColor',
  18. size: providedSize = 'sm',
  19. legacySize,
  20. viewBox = '0 0 16 16',
  21. ...props
  22. },
  23. ref
  24. ) {
  25. const theme = useTheme();
  26. const color = theme[providedColor] ?? providedColor;
  27. const size = legacySize ?? theme.iconSizes[providedSize];
  28. return (
  29. <svg {...props} viewBox={viewBox} fill={color} height={size} width={size} ref={ref} />
  30. );
  31. });