-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(carousel-item): add prop type-checking for the interval prop
Adds the proper prop type-check for the `interval` prop, improving overall developer experience. Also comes with a new export to be able to extend from the `CarouselItemProps` interface, so that our end-users (developers) who are using TS can properly type-check their encapsulated components.
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,54 @@ | ||
import createWithBsPrefix from './createWithBsPrefix'; | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useBootstrapPrefix } from './ThemeProvider'; | ||
import { | ||
BsPrefixPropsWithChildren, | ||
BsPrefixRefForwardingComponent, | ||
} from './helpers'; | ||
|
||
export default createWithBsPrefix('carousel-item'); | ||
export interface CarouselItemProps extends BsPrefixPropsWithChildren { | ||
interval?: number; | ||
} | ||
|
||
type CarouselItem = BsPrefixRefForwardingComponent<'div', CarouselItemProps>; | ||
|
||
const propTypes = { | ||
/** Set a custom element for this component */ | ||
as: PropTypes.elementType, | ||
|
||
/** @default 'carousel-item' */ | ||
bsPrefix: PropTypes.string, | ||
|
||
/** 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. */ | ||
interval: PropTypes.number, | ||
}; | ||
|
||
const CarouselItem = (React.forwardRef( | ||
( | ||
{ | ||
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595 | ||
as: Component = 'div', | ||
bsPrefix, | ||
children, | ||
className, | ||
...props | ||
}: CarouselItemProps, | ||
ref, | ||
) => { | ||
const finalClassName = classNames( | ||
className, | ||
useBootstrapPrefix(bsPrefix, 'carousel-item'), | ||
); | ||
return ( | ||
<Component ref={ref} {...props} className={finalClassName}> | ||
{children} | ||
</Component> | ||
); | ||
}, | ||
) as unknown) as CarouselItem; | ||
|
||
CarouselItem.displayName = 'CarouselItem'; | ||
CarouselItem.propTypes = propTypes; | ||
|
||
export default CarouselItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters