@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 1.27 kB
JavaScript
import{jsx as o,jsxs as h}from"react/jsx-runtime";import"./Gallery.scss";import j from"classnames";import C,{useEffect as E,useState as s}from"react";import U from"./GalleryBadges/GalleryBadges";import u from"./GalleryItem/GalleryItem";import k from"./GalleryModal/GalleryModal";import H from"./GalleryPreLoader";const L=x=>{const{images:a,leading:t=!1,onImageLoadHeightUpdate:n,onOpenGallery:c,onCloseGallery:m,className:d}=x,[y,g]=s(!1),[I,G]=s(0),[M,p]=s(!1),i=e=>{G(e),g(!0),c&&c()},O=()=>{g(!1),m&&m()},N=e=>{let l=e.split("/");const r=l[l.length-1];return r.indexOf("original-")===-1&&(l[l.length-1]="original-"+r),l.join("/")},f=(e,l)=>l?N(e):e;return E(()=>{(async()=>{if(a.length>0){const l=f(a[0],!0);try{await H.load(l),p(!0)}catch{p(!1)}}})()},[a]),h(C.Fragment,{children:[h("div",{className:j("gallery",{"gallery-leading":t},d),children:[o("div",{className:"gallery__wrapper",children:t?o(u,{url:a[0],leading:t,setHeight:!0,fillMode:"contain",onClick:()=>i(0),onImageLoadHeightUpdate:n}):a.map((e,l)=>o(u,{url:e,position:"top",fillMode:"cover",onClick:()=>i(l),onImageLoadHeightUpdate:n},e+l))}),!t&&o(U,{onFullscreen:()=>i(0),count:a.length})]}),y&&o(k,{className:d,images:a.map(e=>f(e,M)),leading:t,initialSlideIndex:I,onClose:O})]})};export default L;