Skip to content

Commit a25d03c

Browse files
mxschmitttaion
authored andcommitted
feat: added 'as' prop to Carousel (fix: #3509) (#3514)
#3509
1 parent 9b8627f commit a25d03c

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"invariant": "^2.2.3",
135135
"keycode": "^2.1.2",
136136
"popper.js": "^1.14.6",
137-
"prop-types": "^15.6.2",
137+
"prop-types": "^15.7.2",
138138
"prop-types-extra": "^1.1.0",
139139
"react-context-toolbox": "^2.0.2",
140140
"react-overlays": "^1.0.0",

src/Carousel.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const propTypes = {
2222
* @default 'carousel'
2323
*/
2424
bsPrefix: PropTypes.string,
25+
as: PropTypes.elementType,
2526

2627
/**
2728
* Enables animation on the Carousel as it transitions between slides.
@@ -101,6 +102,7 @@ const propTypes = {
101102
};
102103

103104
const defaultProps = {
105+
as: 'div',
104106
slide: true,
105107
fade: false,
106108
interval: 5000,
@@ -421,6 +423,7 @@ class Carousel extends React.Component {
421423

422424
render() {
423425
const {
426+
as: Component,
424427
bsPrefix,
425428
slide,
426429
fade,
@@ -451,7 +454,7 @@ class Carousel extends React.Component {
451454

452455
return (
453456
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
454-
<div
457+
<Component
455458
{...props}
456459
className={classNames(
457460
className,
@@ -491,7 +494,7 @@ class Carousel extends React.Component {
491494
nextIcon,
492495
nextLabel,
493496
})}
494-
</div>
497+
</Component>
495498
);
496499
}
497500
}

types/components/Carousel.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import CarouselItem from './CarouselItem';
44
import CarouselCaption from './CarouselCaption';
55

6-
import { ReplaceProps, SelectCallback } from './helpers';
6+
import { ReplaceProps, SelectCallback, BsPrefixComponent } from './helpers';
77

88
export interface CarouselProps {
99
bsPrefix?: string;
@@ -24,9 +24,9 @@ export interface CarouselProps {
2424
nextLabel?: string;
2525
}
2626

27-
declare class Carousel extends React.Component<
28-
ReplaceProps<'div', CarouselProps>
29-
> {
27+
declare class Carousel<
28+
As extends React.ReactType = 'div'
29+
> extends BsPrefixComponent<As, CarouselProps> {
3030
static Item: typeof CarouselItem;
3131
static Caption: typeof CarouselCaption;
3232
}

yarn.lock

+14
Original file line numberDiff line numberDiff line change
@@ -9514,6 +9514,15 @@ prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.5.9,
95149514
loose-envify "^1.3.1"
95159515
object-assign "^4.1.1"
95169516

9517+
prop-types@^15.7.2:
9518+
version "15.7.2"
9519+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
9520+
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
9521+
dependencies:
9522+
loose-envify "^1.4.0"
9523+
object-assign "^4.1.1"
9524+
react-is "^16.8.1"
9525+
95179526
proxy-addr@~2.0.3:
95189527
version "2.0.4"
95199528
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.4.tgz#ecfc733bf22ff8c6f407fa275327b9ab67e48b93"
@@ -9830,6 +9839,11 @@ react-is@^16.6.1, react-is@^16.6.3:
98309839
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.3.tgz#d2d7462fcfcbe6ec0da56ad69047e47e56e7eac0"
98319840
integrity sha512-u7FDWtthB4rWibG/+mFbVd5FvdI20yde86qKGx4lVUTWmPlSWQ4QxbBIrrs+HnXGbxOUlUzTAP/VDmvCwaP2yA==
98329841

9842+
react-is@^16.8.1:
9843+
version "16.8.3"
9844+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.3.tgz#4ad8b029c2a718fc0cfc746c8d4e1b7221e5387d"
9845+
integrity sha512-Y4rC1ZJmsxxkkPuMLwvKvlL1Zfpbcu+Bf4ZigkHup3v9EfdYhAlWAaVyA19olXq2o2mGn0w+dFKvk3pVVlYcIA==
9846+
98339847
react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
98349848
version "3.0.4"
98359849
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

0 commit comments

Comments
 (0)