UNPKG

2.83 kBJavaScriptView Raw
1var _excluded = ["items", "activeIndex", "cssModule", "onClickHandler", "className"];
2function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5import React from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules } from './utils';
9function CarouselIndicators(props) {
10 var items = props.items,
11 activeIndex = props.activeIndex,
12 cssModule = props.cssModule,
13 onClickHandler = props.onClickHandler,
14 className = props.className,
15 attributes = _objectWithoutProperties(props, _excluded);
16 var listClasses = mapToCssModules(classNames(className, 'carousel-indicators'), cssModule);
17 var indicators = items.map(function (item, idx) {
18 var indicatorClasses = mapToCssModules(classNames({
19 active: activeIndex === idx
20 }), cssModule);
21 return /*#__PURE__*/React.createElement("button", {
22 "aria-label": item.caption,
23 "data-bs-target": true,
24 type: "button",
25 key: "".concat(item.key || Object.values(item).join('')),
26 onClick: function onClick(e) {
27 e.preventDefault();
28 onClickHandler(idx);
29 },
30 className: indicatorClasses
31 });
32 });
33 return /*#__PURE__*/React.createElement("div", _extends({
34 className: listClasses
35 }, attributes), indicators);
36}
37CarouselIndicators.propTypes = {
38 /** The current active index */
39 activeIndex: PropTypes.number.isRequired,
40 /** Add custom class */
41 className: PropTypes.string,
42 /** Change underlying component's CSS base class name */
43 cssModule: PropTypes.object,
44 /** Array of items to show */
45 items: PropTypes.array.isRequired,
46 /** Function to be triggered on click */
47 onClickHandler: PropTypes.func.isRequired
48};
49export default CarouselIndicators;
\No newline at end of file