svgIcon.tsx 850 B

12345678910111213141516171819202122232425262728293031
  1. import * as React 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. // TODO (Priscila): make size prop theme icon size only
  8. size?: IconSize | string;
  9. }
  10. const SvgIcon = React.forwardRef<SVGSVGElement, SVGIconProps>(function SvgIcon(
  11. {
  12. color: providedColor = 'currentColor',
  13. size: providedSize = 'sm',
  14. viewBox = '0 0 16 16',
  15. ...props
  16. },
  17. ref
  18. ) {
  19. const theme = useTheme();
  20. const color = theme[providedColor] ?? providedColor;
  21. const size = theme.iconSizes[providedSize] ?? providedSize;
  22. return (
  23. <svg {...props} viewBox={viewBox} fill={color} height={size} width={size} ref={ref} />
  24. );
  25. });
  26. export default SvgIcon;