import React, { JSX } from "react"; import { ColorValue, DimensionValue, Image, ImageSourcePropType, ImageStyle, StyleProp, View, ViewStyle, } from "react-native"; import { useTheme } from "../../theme"; import { ICONS } from "./icon-mapping"; export type IconName = keyof typeof ICONS; type IconProps = { name?: IconName; color?: ColorValue; size?: DimensionValue; height?: DimensionValue; width?: DimensionValue; containerStyle?: StyleProp; imageStyle?: StyleProp; icon?: ImageSourcePropType | JSX.Element; }; export const Icon = (props: IconProps) => { 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 {props.icon as JSX.Element}; } if (props.icon) { const ImageComp = () => { if (typeof icon === "number") { return ; } else if (typeof icon === "string") { return ; } return ; }; return ( ); } if ("name" in props && name) { const IconComponent = ICONS[name]; if (IconComponent) { return ( ); } } return null; };