forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarouselIndicators.js
More file actions
49 lines (44 loc) · 1.34 KB
/
Copy pathCarouselIndicators.js
File metadata and controls
49 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules } from './utils';
function CarouselIndicators(props) {
const { items, activeIndex, cssModule, onClickHandler, className } = props;
const listClasses = mapToCssModules(
classNames(className, 'carousel-indicators'),
cssModule,
);
const indicators = items.map((item, idx) => {
const indicatorClasses = mapToCssModules(
classNames({ active: activeIndex === idx }),
cssModule,
);
return (
<button
aria-label={item.caption}
data-bs-target
type="button"
key={`${item.key || Object.values(item).join('')}`}
onClick={(e) => {
e.preventDefault();
onClickHandler(idx);
}}
className={indicatorClasses}
/>
);
});
return <div className={listClasses}>{indicators}</div>;
}
CarouselIndicators.propTypes = {
/** The current active index */
activeIndex: PropTypes.number.isRequired,
/** Add custom class */
className: PropTypes.string,
/** Change underlying component's CSS base class name */
cssModule: PropTypes.object,
/** Array of items to show */
items: PropTypes.array.isRequired,
/** Function to be triggered on click */
onClickHandler: PropTypes.func.isRequired,
};
export default CarouselIndicators;