Skip to content

Commit f97fdf6

Browse files
author
Piotr Siatka
committed
#227 Provide documentation for Carousel control.
1 parent 3aa0b30 commit f97fdf6

File tree

10 files changed

+152
-0
lines changed

10 files changed

+152
-0
lines changed
43.9 KB
Loading
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
![Carousel control](../assets/Carousel.png)
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+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/Carousel)

docs/documentation/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following controls are currently available:
4242
- [PeoplePicker](./controls/PeoplePicker) (People Picker)
4343
- [WebPartTitle](./controls/WebPartTitle) (Customizable web part title control)
4444
- [IFrameDialog](./controls/IFrameDialog) (renders a Dialog with an iframe as a content)
45+
- [Carousel](./controls/Carousel) (Control displays children elements with 'previous/next element' options)
4546

4647
Field customizer controls:
4748

src/Paging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./controls/paging/paginingControl";

src/controls/paging/footerPagining/FooterPagining.module.scss

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
// import styles from './FooterPagining.module.scss';
3+
4+
export interface IFooterPaginingProps {
5+
selectedIndex: number;
6+
onPageSelect: (index: number) => void;
7+
}
8+
9+
export interface IFooterPaginingState {}
10+
11+
export class FooterPagining extends React.Component<IFooterPaginingProps, IFooterPaginingState> {
12+
public render(): React.ReactElement<IFooterPaginingProps> {
13+
return (
14+
<div>
15+
16+
</div>
17+
);
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface IPagingProps {
2+
onNextPage?: (index: number) => void; // Executed onNextPage button click
3+
onPrevPage?: (index: number) => void; // Executed onPrevPage button click
4+
5+
showFooterNavigation?: boolean; // Should 'dot' navigation be shown
6+
showArrowsNavigation?: boolean; // Should 'arrows' navigation been displayed
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface IPagingState {
2+
pageIndex: number; // Current page index
3+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import { IPagingProps, IPagingState } from '.';
3+
4+
5+
// import styles from './Paging.module.scss';
6+
7+
export class Paging extends React.Component<IPagingProps, IPagingState> {
8+
public render(): React.ReactElement<IPagingProps> {
9+
const { showFooterNavigation, showArrowsNavigation } = this.props;
10+
return (
11+
<div>
12+
13+
{
14+
15+
}
16+
</div>
17+
);
18+
}
19+
20+
private nextPage;
21+
private previousPage;
22+
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./IPagingProps";
2+
export * from "./IPagingState";
3+
export * from "./Paging";

0 commit comments

Comments
 (0)