Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Icon.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import React from 'react';
  3. import { styleTypeToObject } from '../../styles';
  4. import { Container } from '../../react/base';
  5. type Props = {
  6. /**
  7. * Class name for the web platform, if any.
  8. */
  9. className: string,
  10. /**
  11. * Color of the icon (if not provided by the style object).
  12. */
  13. color?: string,
  14. /**
  15. * Id prop (mainly for autotests).
  16. */
  17. id?: string,
  18. /**
  19. * The size of the icon (if not provided by the style object).
  20. */
  21. size?: number | string,
  22. /**
  23. * The preloaded icon component to render.
  24. */
  25. src: Function,
  26. /**
  27. * Style object to be applied.
  28. */
  29. style?: Object
  30. };
  31. export const DEFAULT_COLOR = navigator.product === 'ReactNative' ? 'white' : undefined;
  32. export const DEFAULT_SIZE = navigator.product === 'ReactNative' ? 36 : 24;
  33. /**
  34. * Implements an Icon component that takes a loaded SVG file as prop and renders it as an icon.
  35. *
  36. * @param {Props} props - The props of the component.
  37. * @returns {Reactelement}
  38. */
  39. export default function Icon(props: Props) {
  40. const {
  41. className,
  42. color,
  43. id,
  44. size,
  45. src: IconComponent,
  46. style
  47. } = props;
  48. const {
  49. color: styleColor,
  50. fontSize: styleSize,
  51. ...restStyle
  52. } = styleTypeToObject(style ?? {});
  53. const calculatedColor = color ?? styleColor ?? DEFAULT_COLOR;
  54. const calculatedSize = size ?? styleSize ?? DEFAULT_SIZE;
  55. return (
  56. <Container
  57. className = { `jitsi-icon ${className}` }
  58. style = { restStyle }>
  59. <IconComponent
  60. fill = { calculatedColor }
  61. height = { calculatedSize }
  62. id = { id }
  63. width = { calculatedSize } />
  64. </Container>
  65. );
  66. }
  67. Icon.defaultProps = {
  68. className: ''
  69. };