0

I am trying to build a basic Image carousel in SPFx using the PnP Carousel control. Documentation here.

I have added the code based on the documentation including the imports and dependancies to set up the carousel but no images appear when I run using gulp serve. I comment out contentContainerStyles because I am not sure exactly how I want the images styled yet.

export default class PnpTest2 extends React.Component<IPnpTest2Props, {}> {
public render(): React.ReactElement<IPnpTest2Props> {
return (
  <div className={ styles.pnpTest2 }>
    <div className={ styles.container }>
      <div className={ styles.row }>
        <div className={ styles.column }>
          <span className={ styles.title }>Carousel Test</span>
          <Carousel
          buttonsLocation={CarouselButtonsLocation.center}
          buttonsDisplay={CarouselButtonsDisplay.buttonsOnly}
          contentContainerStyles={styles.carouselImageContent}
          isInfinite={true}
          indicatorShape={CarouselIndicatorShape.circle}
          pauseOnHover={true}

          element={[
            {
              imageSrc: 'https://images.unsplash.com/photo-1588614959060-4d144f28b207?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3078&q=80',
              title: 'Colosseum',
              description: 'This is Colosseum',
              url: 'https://en.wikipedia.org/wiki/Colosseum',
              showDetailsOnHover: true,
              imageFit: ImageFit.cover
            },
            {
              imageSrc: 'https://images.unsplash.com/photo-1588614959060-4d144f28b207?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3078&q=80',
              title: 'Colosseum',
              description: 'This is Colosseum',
              url: 'https://en.wikipedia.org/wiki/Colosseum',
              showDetailsOnHover: true,
              imageFit: ImageFit.cover
            },
            {
              imageSrc: 'https://images.unsplash.com/photo-1588614959060-4d144f28b207?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3078&q=80',
              title: 'Colosseum',
              description: 'This is Colosseum',
              url: 'https://en.wikipedia.org/wiki/Colosseum',
              showDetailsOnHover: true,
              imageFit: ImageFit.cover
            }
          ]}
          onMoveNextClicked={(index: number) => { console.log(`Next button clicked: ${index}`); }}
          onMovePrevClicked={(index: number) => { console.log(`Prev button clicked: ${index}`); }}
        />
        </div>
      </div>
    </div>
  </div>
);
}}

I think I am missing a piece of code somewhere but I am not sure where. Below is my render() function located in my .tsx file, I believe everything in it should work but I am not sure if anything else needs to be changed elsewhere. Any help would be appreciated.

Striped
  • 2,544
  • 3
  • 25
  • 31
Msco
  • 1
  • 1

2 Answers2

1

enter image description here You could check if the above error is reported. If it is, I suggest you post an issue in the PNP control Github repository. enter image description here But in the ICarouselImageProps interface, I did not find the key property. enter image description here

Amos
  • 2,030
  • 1
  • 5
  • 9
0

In my opinion, it is better to use react-slick Library for this purpose (Because it is easier to use for this purpose.)

import Slider from "react-slick";

const SimpleSlider = ()=>{
    const settings = {
      dots: true,
      infinite: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1
    };
    return (
      <div>
        <h2> Single Item</h2>
        <Slider {...settings}>
          <div>
            <h3>Slide 1</h3>
          </div>
          <div>
            <h3>Slide 2</h3>
          </div>
          <div>
            <h3>Slide 3</h3>
          </div>
          <div>
            <h3>Slide 4</h3>
          </div>
          <div>
            <h3>Slide 5</h3>
          </div>
          <div>
            <h3>Slide 6</h3>
          </div>
        </Slider>
      </div>
    );
  }
}

DOCS: https://react-slick.neostack.com/

github repository: https://github.com/akiran/react-slick

all example: https://react-slick.neostack.com/docs/example/simple-slider

Mahdi Sheibak
  • 620
  • 1
  • 4
  • 13
  • I have switched over to trying to use this library and I have gotten my images to show but they are not scaled correctly. I have tried altering the .scss with the object-fit option but it does not change the scale at all. Using max-height and max-width does not change anything either. – Msco Dec 23 '20 at 16:19
  • see this codesand box for custom css https://codesandbox.io/s/react-slick-custom-css-example-forked-jvjph?file=/src/App.js – Mahdi Sheibak Dec 23 '20 at 16:41