@@ -11,6 +11,7 @@ import { ProcessingState } from "./ICarouselState";
1111import { Spinner } from "office-ui-fabric-react/lib/Spinner" ;
1212import { isArray } from "@pnp/common" ;
1313import * as telemetry from '../../common/telemetry' ;
14+ import CarouselImage from "./CarouselImage" ;
1415
1516export class Carousel extends React . Component < ICarouselProps , ICarouselState > {
1617 constructor ( props : ICarouselProps ) {
@@ -62,7 +63,7 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
6263 return (
6364 < div className = { this . getMergedStyles ( styles . container , containerStyles ) } >
6465 < div className = { this . getMergedStyles ( this . getButtonContainerStyles ( ) , containerButtonsStyles ) }
65- onClick = { ( ) => { if ( ! prevButtonDisabled ) { this . onCarouselButtonClicked ( false ) ; } } } >
66+ onClick = { ( ) => { if ( ! prevButtonDisabled ) { this . onCarouselButtonClicked ( false ) ; } } } >
6667 < IconButton
6768 className = { this . getMergedStyles ( this . getButtonStyles ( false ) , prevButtonStyles ) }
6869 iconProps = { { iconName : prevButtonIconName } }
@@ -86,7 +87,7 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
8687 </ div >
8788
8889 < div className = { this . getMergedStyles ( this . getButtonContainerStyles ( ) , containerButtonsStyles ) }
89- onClick = { ( ) => { if ( ! nextButtonDisabled ) { this . onCarouselButtonClicked ( true ) ; } } } >
90+ onClick = { ( ) => { if ( ! nextButtonDisabled ) { this . onCarouselButtonClicked ( true ) ; } } } >
9091 < IconButton
9192 className = { this . getMergedStyles ( this . getButtonStyles ( true ) , nextButtonStyles ) }
9293 iconProps = { { iconName : nextButtonIconName } }
@@ -261,15 +262,21 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
261262 private getElementToDisplay = ( ) : JSX . Element => {
262263 const { element } = this . props ;
263264 const currentIndex = this . state . currentIndex ;
264- let result : JSX . Element = null ;
265+ let result : JSX . Element = null ;
266+ let arrayLen : number ;
265267
266268 // If no element has been provided.
267269 if ( ! element ) {
268270 result = null ;
269271 }
270- // Retrieve proper element from the array
271- else if ( isArray ( element ) && currentIndex >= 0 && ( element as JSX . Element [ ] ) . length > currentIndex ) {
272- result = element [ currentIndex ] ;
272+ else if ( isArray ( element ) && ( arrayLen = ( element as any [ ] ) . length ) > 0 ) {
273+ // Retrieve proper element from the array
274+ if ( currentIndex >= 0 && arrayLen > currentIndex ) {
275+ const arrayEl = element [ currentIndex ] ;
276+
277+ result = 'props' in arrayEl ? arrayEl as JSX . Element :
278+ < CarouselImage { ...arrayEl } /> ;
279+ }
273280 }
274281 else {
275282 result = element as JSX . Element ;
0 commit comments