Skip to content

Commit 259ef80

Browse files
authored
Merge pull request #1801 from pnp/carousel-defaults
Carousel: make buttonLocation and buttonDisplay optional, add contentHeight property
2 parents fa196a5 + 4e82afa commit 259ef80

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

docs/documentation/docs/controls/Carousel.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ The Carousel component can be configured with the following properties:
104104
| isInfinite | boolean | no | Indicates if infinite scrolling is enabled. |
105105
| 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. |
106106
| 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. |
107-
| buttonsLocation | CarouselButtonsLocation | yes | Specifies the location of the buttons inside the container. |
108-
| buttonsDisplay | CarouselButtonsDisplay | yes | Specifies the buttons container display mode. |
107+
| buttonsLocation | CarouselButtonsLocation | no | Specifies the location of the buttons inside the container. Default: center |
108+
| buttonsDisplay | CarouselButtonsDisplay | no | Specifies the buttons container display mode. Default: block |
109109
| containerStyles | ICssInput | no | Allows to specify own styles for carousel container. |
110110
| loadingComponentContainerStyles | ICssInput | no | Allows to specify own styles for loading component. |
111111
| contentContainerStyles | ICssInput | no | Allows to specify own styles for elements container. |
@@ -134,6 +134,7 @@ The Carousel component can be configured with the following properties:
134134
| indicatorsContainerStyles | ICssInput | no | Allows to specify own styles for indicators container when indicatorsDisplay is set to "block" |
135135
| prevButtonAriaLabel | string | no | Aria label of the PreviousItem button. Default 'Previous item'. |
136136
| nextButtonAriaLabel | string | no | Aria label of the NextItem button. Default 'Next item'. |
137+
| contentHeight | number | no | Allows to specify the height of the content. Can be used instead of providing styles for the content container (`contentContainerStyles`). |
137138

138139
enum `CarouselButtonsLocation`
139140

src/controls/carousel/Carousel.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { isArray } from "@pnp/common";
1414
import * as telemetry from '../../common/telemetry';
1515
import CarouselImage, { ICarouselImageProps } from "./CarouselImage";
1616
import { CarouselIndicatorsDisplay } from "./ICarouselProps";
17+
import { mergeStyles } from "@fluentui/react/lib/Styling";
1718

1819
export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
1920
private _intervalId: number | undefined;
@@ -74,7 +75,8 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
7475
interval,
7576
indicatorsDisplay,
7677
rootStyles,
77-
indicatorsContainerStyles
78+
indicatorsContainerStyles,
79+
contentHeight
7880
} = this.props;
7981

8082
const processing = processingState === ProcessingState.processing;
@@ -84,6 +86,17 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
8486

8587
const element = this.getElementToDisplay(currentIndex);
8688

89+
let contentContainerCustomClassName: ICssInput | undefined = undefined;
90+
if (contentContainerStyles) {
91+
contentContainerCustomClassName = contentContainerStyles;
92+
}
93+
else if (contentHeight) {
94+
contentContainerCustomClassName = mergeStyles({
95+
height: `${contentHeight}px`
96+
});
97+
}
98+
99+
87100
return (
88101
<div className={this.getMergedStyles(styles.root, rootStyles)}>
89102
<div className={this.getMergedStyles(styles.container, containerStyles)}>
@@ -97,7 +110,7 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
97110
onClick={() => { this.onCarouselButtonClicked(false); }} />
98111
</div>
99112
<div
100-
className={this.getMergedStyles(styles.contentContainer, contentContainerStyles)}
113+
className={this.getMergedStyles(styles.contentContainer, contentContainerCustomClassName)}
101114
onMouseOver={pauseOnHover && interval !== null ? this.pauseCycle : undefined}
102115
onTouchStart={pauseOnHover && interval !== null ? this.pauseCycle : undefined}
103116
onMouseLeave={pauseOnHover && interval !== null ? this.startCycle : undefined}
@@ -259,7 +272,7 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
259272
return "";
260273
}
261274

262-
const buttonsLocation = this.props.buttonsLocation ? this.props.buttonsLocation : CarouselButtonsLocation.top;
275+
const buttonsLocation = this.props.buttonsLocation ? this.props.buttonsLocation : CarouselButtonsLocation.center;
263276
let buttonsLocationCss = "";
264277
switch (buttonsLocation) {
265278
case CarouselButtonsLocation.top:

src/controls/carousel/ICarouselProps.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ export interface ICarouselProps {
8282

8383
/**
8484
* Specifies the location of the buttons inside the container.
85+
*
86+
* Default: CarouselButtonsLocation.center
8587
*/
86-
buttonsLocation: CarouselButtonsLocation;
88+
buttonsLocation?: CarouselButtonsLocation;
8789
/**
8890
* Specifies the buttons container display mode.
91+
*
92+
* Default: CarouselButtonsDisplay.block
8993
*/
90-
buttonsDisplay: CarouselButtonsDisplay;
94+
buttonsDisplay?: CarouselButtonsDisplay;
9195

9296
/**
9397
* Allows to specify own styles for carousel container.
@@ -221,4 +225,9 @@ export interface ICarouselProps {
221225
*/
222226
indicatorsContainerStyles?: ICssInput;
223227

228+
/**
229+
* Allows to specify the height of the content. Can be used instead of providing styles for the content container.
230+
*/
231+
contentHeight?: number;
232+
224233
}

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,13 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
17991799
element={this.state.currentCarouselElement}
18001800
/>
18011801
</div>
1802+
<div>
1803+
<h3>Carousel with minimal configuration:</h3>
1804+
<Carousel
1805+
element={this.carouselElements}
1806+
contentHeight={200}
1807+
/>
1808+
</div>
18021809
</div>
18031810
<div id="SiteBreadcrumbDiv" className={styles.container} hidden={!controlVisibility.SiteBreadcrumb}>
18041811
<div className={styles.siteBreadcrumb}>

0 commit comments

Comments
 (0)