2019-08-30 16:39:06 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { Container } from '../../react/base';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { styleTypeToObject } from '../../styles';
|
2019-08-30 16:39:06 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class name for the web platform, if any.
|
|
|
|
*/
|
2019-09-17 17:50:58 +00:00
|
|
|
className: string,
|
2019-08-30 16:39:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Color of the icon (if not provided by the style object).
|
|
|
|
*/
|
|
|
|
color?: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Id prop (mainly for autotests).
|
|
|
|
*/
|
|
|
|
id?: string,
|
|
|
|
|
2019-10-08 12:05:41 +00:00
|
|
|
/**
|
|
|
|
* Function to invoke on click.
|
|
|
|
*/
|
|
|
|
onClick?: Function,
|
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
/**
|
|
|
|
* The size of the icon (if not provided by the style object).
|
|
|
|
*/
|
|
|
|
size?: number | string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The preloaded icon component to render.
|
|
|
|
*/
|
|
|
|
src: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Style object to be applied.
|
|
|
|
*/
|
|
|
|
style?: Object
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DEFAULT_COLOR = navigator.product === 'ReactNative' ? 'white' : undefined;
|
|
|
|
export const DEFAULT_SIZE = navigator.product === 'ReactNative' ? 36 : 24;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an Icon component that takes a loaded SVG file as prop and renders it as an icon.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The props of the component.
|
|
|
|
* @returns {Reactelement}
|
|
|
|
*/
|
|
|
|
export default function Icon(props: Props) {
|
|
|
|
const {
|
|
|
|
className,
|
|
|
|
color,
|
|
|
|
id,
|
2019-10-08 12:05:41 +00:00
|
|
|
onClick,
|
2019-08-30 16:39:06 +00:00
|
|
|
size,
|
|
|
|
src: IconComponent,
|
|
|
|
style
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
color: styleColor,
|
|
|
|
fontSize: styleSize,
|
|
|
|
...restStyle
|
|
|
|
} = styleTypeToObject(style ?? {});
|
|
|
|
const calculatedColor = color ?? styleColor ?? DEFAULT_COLOR;
|
|
|
|
const calculatedSize = size ?? styleSize ?? DEFAULT_SIZE;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container
|
2019-09-17 17:50:58 +00:00
|
|
|
className = { `jitsi-icon ${className}` }
|
2019-10-08 12:05:41 +00:00
|
|
|
onClick = { onClick }
|
2019-08-30 16:39:06 +00:00
|
|
|
style = { restStyle }>
|
|
|
|
<IconComponent
|
|
|
|
fill = { calculatedColor }
|
|
|
|
height = { calculatedSize }
|
|
|
|
id = { id }
|
|
|
|
width = { calculatedSize } />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-17 17:50:58 +00:00
|
|
|
Icon.defaultProps = {
|
|
|
|
className: ''
|
|
|
|
};
|