|
1 |
| -import createWithBsPrefix from './createWithBsPrefix'; |
| 1 | +import classNames from 'classnames'; |
| 2 | +import React from 'react'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | +import { useBootstrapPrefix } from './ThemeProvider'; |
| 5 | +import { |
| 6 | + BsPrefixPropsWithChildren, |
| 7 | + BsPrefixRefForwardingComponent, |
| 8 | +} from './helpers'; |
2 | 9 |
|
3 |
| -export default createWithBsPrefix('carousel-item'); |
| 10 | +export interface CarouselItemProps extends BsPrefixPropsWithChildren { |
| 11 | + interval?: number; |
| 12 | +} |
| 13 | + |
| 14 | +type CarouselItem = BsPrefixRefForwardingComponent<'div', CarouselItemProps>; |
| 15 | + |
| 16 | +const propTypes = { |
| 17 | + /** Set a custom element for this component */ |
| 18 | + as: PropTypes.elementType, |
| 19 | + |
| 20 | + /** @default 'carousel-item' */ |
| 21 | + bsPrefix: PropTypes.string, |
| 22 | + |
| 23 | + /** The amount of time to delay between automatically cycling this specific item. Will default to the Carousel's `interval` prop value if none is specified. */ |
| 24 | + interval: PropTypes.number, |
| 25 | +}; |
| 26 | + |
| 27 | +const CarouselItem = (React.forwardRef( |
| 28 | + ( |
| 29 | + { |
| 30 | + // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595 |
| 31 | + as: Component = 'div', |
| 32 | + bsPrefix, |
| 33 | + children, |
| 34 | + className, |
| 35 | + ...props |
| 36 | + }: CarouselItemProps, |
| 37 | + ref, |
| 38 | + ) => { |
| 39 | + const finalClassName = classNames( |
| 40 | + className, |
| 41 | + useBootstrapPrefix(bsPrefix, 'carousel-item'), |
| 42 | + ); |
| 43 | + return ( |
| 44 | + <Component ref={ref} {...props} className={finalClassName}> |
| 45 | + {children} |
| 46 | + </Component> |
| 47 | + ); |
| 48 | + }, |
| 49 | +) as unknown) as CarouselItem; |
| 50 | + |
| 51 | +CarouselItem.displayName = 'CarouselItem'; |
| 52 | +CarouselItem.propTypes = propTypes; |
| 53 | + |
| 54 | +export default CarouselItem; |
0 commit comments