import React, { PropsWithChildren } from 'react';
import './index.scss'
import { Image as TaroImage, ImageProps } from '@tarojs/components';



interface IImageProps extends ImageProps {
    src: string;
    size?: number | { width?: number, height?: number };
    /**计算的宽度 */
    calculationWidth?: number;
}

const Image = (props: PropsWithChildren<IImageProps>) => {
    const { style = {}, src, ...imgProps } = props;
    let imgStyle: React.CSSProperties = style as React.CSSProperties;
    if (props.size) {
        if (typeof props.size === "number") {
            imgStyle.width = props.size;
            imgStyle.height = props.size;
        }
        else {
            imgStyle = { ...imgStyle, ...props.size }
        }
    }
    return (
        <TaroImage
            style={imgStyle}
            src={src}
            {...imgProps}
        />
    )
}

export default Image;