Reputation: 301
I am using the react-responsive-carousel library. Here, I want to change the default indicators CSS, dots shape to line shape. My code is,
<CarouselWrapper
sx={{ marginTop: "124px", maxHeight: "486px", minHeight: "150px" }}
>
<Carousel autoPlay infiniteLoop showArrows={false}>
<div>
<Image src={image1} />
</div>
<div>
<Image src={image1} />
</div>
<div>
<Image src={image1} />
</div>
</Carousel>
</CarouselWrapper>
the current shape of those indicators,
Is it possible to customize that dots shape indicators?
Upvotes: 5
Views: 17625
Reputation: 6895
Yes, you can customize the dots with a JSX passing renderIndicator
prop as a function to Carousel
component. You can take a look at this stackblitz for a live working example of this usage.
<Carousel
autoPlay
infiniteLoop
showArrows={false}
renderIndicator={(onClickHandler, isSelected, index, label) => {
const defStyle = { marginLeft: 20, color: "white", cursor: "pointer" };
const style = isSelected
? { ...defStyle, color: "red" }
: { ...defStyle };
return (
<span
style={style}
onClick={onClickHandler}
onKeyDown={onClickHandler}
value={index}
key={index}
role="button"
tabIndex={0}
aria-label={`${label} ${index + 1}`}
>
{"cust " + index}
</span>
);
}}
>
<div>
<img src={"1.jpeg"} />
</div>
<div>
<img src={"2.jpeg"} />
</div>
<div>
<img src={"3.jpeg"} />
</div>
</Carousel>
);
Upvotes: 9
Reputation: 174
A solution if using SCSS and needing less customisation. Using a wrapping selector you can use:
.yourSelector {
:global(.carousel .control-dots .dot) {
background-color: blue;
}
}
Upvotes: 3