@chayns-components/core
Version:
A set of beautiful React components for developing your own applications with chayns.
49 lines (48 loc) • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _HighlightSlider = require("./HighlightSlider.styles");
var _HighlightSliderItem = _interopRequireDefault(require("./highlight-slider-item/HighlightSliderItem"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const DEFAULT_HIGHLIGHT_SLIDER_COLORS = {
backgroundColor: '#E0E0E0',
fillColor: '#808080'
};
const HighlightSlider = ({
count,
colors = DEFAULT_HIGHLIGHT_SLIDER_COLORS,
onIndexChange,
currentIndex,
duration = 10
}) => {
const handleFinish = (0, _react.useCallback)(index => {
if (typeof onIndexChange === 'function') {
onIndexChange(index >= count - 1 ? 0 : index + 1);
}
}, [count, onIndexChange]);
const handleClick = (0, _react.useCallback)(index => {
if (typeof onIndexChange === 'function') {
onIndexChange(index);
}
}, [onIndexChange]);
const content = (0, _react.useMemo)(() => Array.from({
length: count
}).map((value, index) => /*#__PURE__*/_react.default.createElement(_HighlightSliderItem.default, {
key: `highlight-slider-item--${value}`,
index: index,
duration: duration,
colors: colors,
isActive: currentIndex === index,
isFinished: currentIndex > index,
onClick: handleClick,
onFinish: handleFinish
})), [colors, count, currentIndex, duration, handleClick, handleFinish]);
return /*#__PURE__*/_react.default.createElement(_HighlightSlider.StyledHighlightSlider, null, content);
};
HighlightSlider.displayName = 'HighlightSlider';
var _default = exports.default = HighlightSlider;
//# sourceMappingURL=HighlightSlider.js.map