svgIcon.tsx 828 B

1234567891011121314151617181920212223242526272829
  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. // TODO (Priscila): make size prop theme icon size only
  8. size?: IconSize | string;
  9. }
  10. export const SvgIcon = 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. });