import * as React from "react"; import { ImageSource, FuncStyle, StaticStyle } from "./fb-collage.type"; import staticStyles from "./fb-collage.style"; export default class FBCollage extends React.Component { private styles: StaticStyle; static defaultProps = {}; constructor(props: any) { super(props); this.styles = staticStyles( props.width, props.height, props.borderRadius, props.spacing ); } __renderImage = ( image: ImageSource, index: number, length: number = 0 ) => { const { images, imageOnClick, textStyle: textStyleOverride, overlayStyle: overlayStyleOverride, } = this.props; const check = index === 4 && images.length > 5, text = check ? images.length - 5 : undefined return (
imageOnClick && imageOnClick(index, images)} key={`image${index}`} role='button' > no logo {check && (
{"+" + text}
)}
); }; __renderImages = (images: ImageSource[]) => { const length = images.length, check = length > 4, childs = check ? images.slice(0, 4) : images; return (
{childs.map((image, index) => { return this.__renderImage(image, index + 1, length + 1); })}
); }; __renderContent = (images: ImageSource[]) => { return ( <>
{this.__renderImage(images[0], 0, 1)}
{images.length > 1 && this.__renderImages(images.slice(1))} ); }; render() { const { images, style: styleOverride } = this.props; return (
{this.__renderContent(images)}
); } }