svgIcon.tsx 821 B

12345678910111213141516171819202122232425262728293031
  1. import * as React from 'react';
  2. import {useTheme} from '@emotion/react';
  3. import {Aliases, Color, IconSize} from 'sentry/utils/theme';
  4. type Props = React.SVGAttributes<SVGSVGElement> & {
  5. color?: Color | keyof Aliases;
  6. // TODO (Priscila): make size prop theme icon size only
  7. size?: IconSize | string;
  8. className?: string;
  9. };
  10. const SvgIcon = React.forwardRef<SVGSVGElement, Props>(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;