svgIcon.tsx 836 B

1234567891011121314151617181920212223242526272829303132
  1. import * as React from 'react';
  2. import {withTheme} from '@emotion/react';
  3. import {Aliases, Color, IconSize, Theme} from 'app/utils/theme';
  4. type Props = React.SVGAttributes<SVGSVGElement> & {
  5. theme: Theme;
  6. color?: Color | keyof Aliases;
  7. // TODO (Priscila): make size prop theme icon size only
  8. size?: IconSize | string;
  9. className?: string;
  10. };
  11. const SvgIcon = React.forwardRef<SVGSVGElement, Props>(function SvgIcon(
  12. {
  13. theme,
  14. color: providedColor = 'currentColor',
  15. size: providedSize = 'sm',
  16. viewBox = '0 0 16 16',
  17. ...props
  18. },
  19. ref
  20. ) {
  21. const color = theme[providedColor] ?? providedColor;
  22. const size = theme.iconSizes[providedSize] ?? providedSize;
  23. return (
  24. <svg {...props} viewBox={viewBox} fill={color} height={size} width={size} ref={ref} />
  25. );
  26. });
  27. export default withTheme(SvgIcon);