import React from 'react' import { Gallery, GalleryItem, Card, CardHeader, CardTitle, CardBody, CardFooter, Label, Content, } from '@patternfly/react-core' import { SectionGalleryItem } from './SectionGallery' import { sentenceCase } from 'change-case' import { convertToReactComponent } from '@patternfly/ast-helpers' interface SectionGalleryGridLayoutProps { /** Section where the gallery is located */ section: string /** List of gallery items */ galleryItems: SectionGalleryItem[] /** Indicates the grid layout has item summary text */ hasGridText: boolean /** Indicates the grid layout has item images */ hasGridImages: boolean } export const SectionGalleryGridLayout = ({ section, galleryItems, hasGridText, hasGridImages, }: SectionGalleryGridLayoutProps) => ( {galleryItems.map(({ name, img, data }, idx) => { const itemLink = data.link || `/${section}/${name}` //TODO: rethink how JSX / enriched content is passed to framework const summaryNoLinks = data.summary.replace( /]*>([^<]+)<\/a>/gm, '$1', ) const { code } = convertToReactComponent(`<>${summaryNoLinks}`) const getSummaryComponent = new Function('React', code) return ( {sentenceCase(name)} {(hasGridImages || hasGridText) && ( {hasGridImages && img && ( {`${name} // verify whether this img.src approach is correct )} {hasGridText && ( {getSummaryComponent(React)} )} )} {data.label && ( {data.label === 'beta' && ( )} {data.label === 'deprecated' && ( )} {data.label === 'demo' && ( )} )} ) })} )