Skip to content

Commit

Permalink
feat(Carousel): Add dark prop
Browse files Browse the repository at this point in the history
  • Loading branch information
swarajpatel authored and phwebi committed Oct 27, 2021
1 parent 2e22d7b commit 01f64df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/lib/Components/CarouselPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default class CarouselPage extends React.Component {
mouseLeave: PropTypes.func,
// controls whether the slide animation on the Carousel works or not
slide: PropTypes.bool,
// make the controls, indicators and captions dark on the Carousel
dark: PropTypes.bool,
cssModule: PropTypes.object,
// controls whether the touch gestures on the Carousel works or not (default: true)
enableTouch: PropTypes.bool,
Expand Down
7 changes: 5 additions & 2 deletions src/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ class Carousel extends React.Component {
}

render() {
const { cssModule, slide, className } = this.props;
const { cssModule, slide, className, dark } = this.props;
const outerClasses = mapToCssModules(classNames(
className,
'carousel',
slide && 'slide'
slide && 'slide',
dark && 'carousel-dark'
), cssModule);

const innerClasses = mapToCssModules(classNames(
Expand Down Expand Up @@ -260,6 +261,8 @@ Carousel.propTypes = {
mouseLeave: PropTypes.func,
// controls whether the slide animation on the Carousel works or not
slide: PropTypes.bool,
// make the controls, indicators and captions dark on the Carousel
dark: PropTypes.bool,
cssModule: PropTypes.object,
className: PropTypes.string,
enableTouch: PropTypes.bool,
Expand Down
32 changes: 32 additions & 0 deletions src/__tests__/Carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,38 @@ describe('Carousel', () => {
expect(wrapper.find(CarouselControl).length).toEqual(2);
expect(wrapper.find(CarouselIndicators).length).toEqual(1);
});

it('should not have the class "carousel-dark" by default', () => {
const slides = items.map((item, idx) => {
return (
<CarouselItem key={idx} />
);
});

const wrapper = mount(
<Carousel activeIndex={0} next={() => { }} previous={() => { }}>
{slides}
</Carousel>
);

expect(wrapper.find('.carousel-dark').length).toBe(0);
});

it('should have the class "carousel-dark" when dark prop is true', () => {
const slides = items.map((item, idx) => {
return (
<CarouselItem key={idx} />
);
});

const wrapper = mount(
<Carousel dark activeIndex={0} next={() => { }} previous={() => { }}>
{slides}
</Carousel>
);

expect(wrapper.find('.carousel-dark').length).toBe(1);
});
});

describe('carouseling', () => {
Expand Down
1 change: 1 addition & 0 deletions types/lib/Carousel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface CommonCarouselProps extends React.HTMLAttributes<HTMLElement> {
mouseEnter?: () => void;
mouseExit?: () => void;
slide?: boolean;
dark?: boolean;
cssModule?: CSSModule;
enableTouch?: boolean;
}
Expand Down

0 comments on commit 01f64df

Please sign in to comment.