svgIcon.tsx 975 B

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