您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Icon.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * Function to invoke on click.
  20. */
  21. onClick?: Function,
  22. /**
  23. * The size of the icon (if not provided by the style object).
  24. */
  25. size?: number | string,
  26. /**
  27. * The preloaded icon component to render.
  28. */
  29. src: Function,
  30. /**
  31. * Style object to be applied.
  32. */
  33. style?: Object
  34. };
  35. export const DEFAULT_COLOR = navigator.product === 'ReactNative' ? 'white' : undefined;
  36. export const DEFAULT_SIZE = navigator.product === 'ReactNative' ? 36 : 24;
  37. /**
  38. * Implements an Icon component that takes a loaded SVG file as prop and renders it as an icon.
  39. *
  40. * @param {Props} props - The props of the component.
  41. * @returns {Reactelement}
  42. */
  43. export default function Icon(props: Props) {
  44. const {
  45. className,
  46. color,
  47. id,
  48. onClick,
  49. size,
  50. src: IconComponent,
  51. style
  52. } = props;
  53. const {
  54. color: styleColor,
  55. fontSize: styleSize,
  56. ...restStyle
  57. } = styleTypeToObject(style ?? {});
  58. const calculatedColor = color ?? styleColor ?? DEFAULT_COLOR;
  59. const calculatedSize = size ?? styleSize ?? DEFAULT_SIZE;
  60. return (
  61. <Container
  62. className = { `jitsi-icon ${className}` }
  63. onClick = { onClick }
  64. style = { restStyle }>
  65. <IconComponent
  66. fill = { calculatedColor }
  67. height = { calculatedSize }
  68. id = { id }
  69. width = { calculatedSize } />
  70. </Container>
  71. );
  72. }
  73. Icon.defaultProps = {
  74. className: ''
  75. };