@cometchat/chat-uikit-react-native
Version:
Ready-to-use Chat UI Components for React Native
35 lines • 1.43 kB
JavaScript
import React from "react";
import { Image, View, } from "react-native";
import { useTheme } from "../../theme";
import { ICONS } from "./icon-mapping";
export const Icon = (props) => {
const theme = useTheme();
const { name, color = theme.color.textSecondary, containerStyle = {}, height, width, size = theme.spacing.spacing.s6, imageStyle = { height: theme.spacing.spacing.s6, width: theme.spacing.spacing.s6 }, icon = null, } = props;
if (React.isValidElement(icon)) {
return <View style={[containerStyle]}>{props.icon}</View>;
}
if (props.icon) {
const ImageComp = () => {
if (typeof icon === "number") {
return <Image source={icon} style={imageStyle}/>;
}
else if (typeof icon === "string") {
return <Image source={{ uri: icon }} style={imageStyle}/>;
}
return <Image source={icon} style={imageStyle}/>;
};
return (<View style={[containerStyle]}>
<ImageComp />
</View>);
}
if ("name" in props && name) {
const IconComponent = ICONS[name];
if (IconComponent) {
return (<View style={[containerStyle]}>
<IconComponent color={color} height={typeof height === "number" ? height : size} width={typeof width === "number" ? width : size}/>
</View>);
}
}
return null;
};
//# sourceMappingURL=Icon.js.map