|
| 1 | +# Carousel control |
| 2 | + |
| 3 | +This control renders passed elements with 'previous/next element' option. |
| 4 | + |
| 5 | +Here is an example of the control in action: |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## How to use this control in your solutions |
| 10 | + |
| 11 | +- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../#getting-started) page for more information about installing the dependency. |
| 12 | +- Import the following modules to your component: |
| 13 | + |
| 14 | +```TypeScript |
| 15 | +import { Carousel } from "@pnp/spfx-controls-react/lib/Carousel"; |
| 16 | +``` |
| 17 | + |
| 18 | +- Use the `Carousel` control in your code as follows: |
| 19 | + |
| 20 | +```TypeScript |
| 21 | +<Carousel |
| 22 | + buttonsLocation={CarouselButtonsLocation.top} |
| 23 | + buttonsDisplay={CarouselButtonsDisplay.block} |
| 24 | + |
| 25 | + contentContainerStyles={styles.carouselContent} |
| 26 | + containerButtonsStyles={styles.carouselButtonsContainer} |
| 27 | + |
| 28 | + isInfinite={true} |
| 29 | + |
| 30 | + element={this.carouselElements} |
| 31 | + onMoveNextClicked={(index: number) => { console.log(`Next button clicked: ${index}`); }} |
| 32 | + onMovePrevClicked={(index: number) => { console.log(`Prev button clicked: ${index}`); }} |
| 33 | +/> |
| 34 | + |
| 35 | +<Carousel |
| 36 | + buttonsLocation={CarouselButtonsLocation.bottom} |
| 37 | + buttonsDisplay={CarouselButtonsDisplay.buttonsOnly} |
| 38 | + |
| 39 | + contentContainerStyles={styles.carouselContent} |
| 40 | + containerButtonsStyles={styles.carouselButtonsContainer} |
| 41 | + |
| 42 | + canMoveNext={this.state.canMoveNext} |
| 43 | + canMovePrev={this.state.canMovePrev} |
| 44 | + triggerPageEvent={this.triggerNextElement} |
| 45 | + element={this.state.currentCarouselElement} |
| 46 | +/> |
| 47 | +``` |
| 48 | + |
| 49 | +## Implementation |
| 50 | + |
| 51 | +The Carousel component can be configured with the following properties: |
| 52 | + |
| 53 | +| Property | Type | Required | Description | |
| 54 | +| ---- | ---- | ---- | ---- | |
| 55 | +| startIndex | number | no | Specifies the initial index of the element to be displayed. | |
| 56 | +| isInfinite | boolean | no | Indicates if infinite scrolling is enabled. | |
| 57 | +| canMoveNext | boolean | no | Property indicates if the next item button can be clicked. If not provided, status of the button is calculated based on the current index. <br />It is mandatory when triggerPageEvent is used. | |
| 58 | +| canMovePrev | boolean | no | Property indicates if the previous item button can be clicked. If not provided, status of the button is calculated based on the current index. <br />It is mandatory when triggerPageEvent is used. | |
| 59 | +| buttonsLocation | CarouselButtonsLocation | yes | Specifies the location of the buttons inside the container. | |
| 60 | +| buttonsDisplay | CarouselButtonsDisplay | yes | Specifies the buttons container display mode. | |
| 61 | +| containerStyles | ICssInput | no | Allows to specify own styles for carousel container. | |
| 62 | +| loadingComponentContainerStyles | ICssInput | no | Allows to specify own styles for loading component. | |
| 63 | +| contentContainerStyles | ICssInput | no | Allows to specify own styles for elements container. | |
| 64 | +| containerButtonsStyles | ICssInput | no | Allows to specify own styles for buttons container. | |
| 65 | +| prevButtonStyles | ICssInput | no | Allows to specify own styles for previous item button. | |
| 66 | +| nextButtonStyles | ICssInput | no | Allows to specify own styles for next item button. | |
| 67 | +| prevButtonIconName | string | no | Name of the icon to be used for PreviousItem button. Default 'ChevronLeft'. | |
| 68 | +| nextButtonIconName | string | no | Name of the icon to be used for NextItem button. Default 'ChevronRight'. | |
| 69 | +| triggerPageEvent | (index: number) => void | no | Triggers parent control to provide new element to be displayed. After the method is executed, carousel control switches to processing mode and loadingComponent is displayed. | |
| 70 | +| element | JSX.Element \| JSX.Element[] | yes | Fixed array of elemenets to be displayed in carousel - if triggerPageEvent is not used. <br />In case triggerPageEvent is in use, JSX.Element has to be provided. Elements are distinguished based on the 'key' property. | |
| 71 | +| loadingComponent | JSX.Element | no | Allows to inject custom component when the carousel is in processing state. If not provided, Spinner is displayed. | |
| 72 | +| onMoveNextClicked | (currentIndex: number) => void | no | Callback function called after the next item button is clicked. Not used when triggerPageEvent is specified. | |
| 73 | +| onMovePrevClicked | (currentIndex: number) => void | no | Callback function called after the previous item button is clicked. Not used when triggerPageEvent is specified. | |
| 74 | + |
| 75 | +enum `CarouselButtonsLocation` |
| 76 | + |
| 77 | +Provides options for carousel buttons location. |
| 78 | + |
| 79 | +| Value | Description | |
| 80 | +| ---- | ---- | |
| 81 | +| top | Buttons are going to be placed in the top of the control. | |
| 82 | +| center | Buttons are going to be placed in the center of the control. | |
| 83 | +| bottom | Buttons are going to be placed in the bottom of the control. | |
| 84 | + |
| 85 | +enum `CarouselButtonsDisplay` |
| 86 | + |
| 87 | +Provides options for carousel buttons display mode. |
| 88 | + |
| 89 | +| Value | Description | |
| 90 | +| ---- | ---- | |
| 91 | +| block | Reserves space for buttons on both sides of the control. | |
| 92 | +| buttonsOnly | Only icon buttons are displayed. | |
| 93 | +| hidden | Buttons are not displayed. They appear onhover event. | |
| 94 | + |
| 95 | + |
0 commit comments