Skip to content

Commit

Permalink
feat(v5): Add Carousel dark variant (#5464)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyletsang committed Dec 9, 2020
1 parent 50781e1 commit ce6230c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
BsPrefixRefForwardingComponent,
} from './helpers';

export type CarouselVariant = 'dark';

export interface CarouselProps
extends BsPrefixPropsWithChildren,
Pick<
Expand Down Expand Up @@ -55,6 +57,7 @@ export interface CarouselProps
prevLabel?: React.ReactNode;
nextIcon?: React.ReactNode;
nextLabel?: React.ReactNode;
variant?: CarouselVariant;
}

type Carousel = BsPrefixRefForwardingComponent<'div', CarouselProps> & {
Expand Down Expand Up @@ -165,6 +168,12 @@ const propTypes = {
* Set to null to deactivate.
*/
nextLabel: PropTypes.string,

/**
* Color variant that controls the colors of the controls, indicators
* and captions.
*/
variant: PropTypes.oneOf<CarouselVariant>(['dark']),
};

const defaultProps = {
Expand Down Expand Up @@ -234,6 +243,7 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
prevLabel,
nextIcon,
nextLabel,
variant,
className,
children,
...props
Expand Down Expand Up @@ -541,6 +551,7 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
prefix,
slide && 'slide',
fade && `${prefix}-fade`,
variant && `${prefix}-${variant}`,
)}
>
{indicators && (
Expand Down
8 changes: 8 additions & 0 deletions test/CarouselSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe('<Carousel>', () => {
wrapper.find('.carousel-indicators li').first().simulate('click');
});

it('should render variant', () => {
mount(
<Carousel activeIndex={1} interval={null} variant="dark">
{items}
</Carousel>,
).assertSingle('.carousel.carousel-dark');
});

describe('ref testing', () => {
let clock;

Expand Down
35 changes: 35 additions & 0 deletions www/src/examples/Carousel/DarkVariant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Carousel variant="dark">
<Carousel.Item>
<img
className="d-block w-100"
src="holder.js/800x400?text=First slide&bg=f5f5f5"
alt="First slide"
/>
<Carousel.Caption>
<h5>First slide label</h5>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</Carousel.Caption>
</Carousel.Item>
<Carousel.Item>
<img
className="d-block w-100"
src="holder.js/800x400?text=Second slide&bg=eee"
alt="Second slide"
/>
<Carousel.Caption>
<h5>Second slide label</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</Carousel.Caption>
</Carousel.Item>
<Carousel.Item>
<img
className="d-block w-100"
src="holder.js/800x400?text=Third slide&bg=e5e5e5"
alt="Third slide"
/>
<Carousel.Caption>
<h5>Third slide label</h5>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</Carousel.Caption>
</Carousel.Item>
</Carousel>;
7 changes: 7 additions & 0 deletions www/src/pages/components/carousel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ReactPlayground from '../../components/ReactPlayground';
import CarouselControlled from '../../examples/Carousel/Controlled';
import CarouselUncontrolled from '../../examples/Carousel/Uncontrolled';
import IndividualIntervals from '../../examples/Carousel/IndividualIntervals';
import DarkVariant from '../../examples/Carousel/DarkVariant';

# Carousels

Expand Down Expand Up @@ -37,6 +38,12 @@ prop.

<ReactPlayground codeText={IndividualIntervals} />

## Dark variant

Add `variant="dark"` to the `Carousel` for darker controls, indicators, and captions.

<ReactPlayground codeText={DarkVariant} />

## API

<ComponentApi metadata={props.data.carousel} />
Expand Down

0 comments on commit ce6230c

Please sign in to comment.