react-auto-image-slider
Version:
The React Auto Image Slider Component
39 lines (38 loc) • 2.45 kB
JavaScript
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import styled from "styled-components";
import { generateKeys } from "../utils/helper";
var Indicator = function (_a) {
var total = _a.total, currentIndex = _a.currentIndex;
var renderIndicatorItem = function () {
var keys = generateKeys(total);
return keys.map(function (key, index) {
if (index === currentIndex) {
return _jsx(IndicatorItem, { isCurrent: true }, key);
}
else {
return _jsx(IndicatorItem, {}, key);
}
});
};
return (_jsx(Container, __assign({ "data-testid": "indicatorContainer" }, { children: total < 10 ? (renderIndicatorItem()) : (_jsxs(TextIndicator, { children: [currentIndex + 1, " of ", total] })) })));
};
export default Indicator;
var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n box-sizing: border-box;\n position: absolute;\n top: 95%;\n width: 100%;\n display: flex;\n justify-content: center;\n"], ["\n box-sizing: border-box;\n position: absolute;\n top: 95%;\n width: 100%;\n display: flex;\n justify-content: center;\n"])));
var IndicatorItem = styled.span(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n width: 1rem;\n height: 1rem;\n margin: 0.4rem;\n border-radius: 50%;\n background: ", ";\n cursor: pointer;\n"], ["\n width: 1rem;\n height: 1rem;\n margin: 0.4rem;\n border-radius: 50%;\n background: ", ";\n cursor: pointer;\n"])), function (props) { return (props.isCurrent ? "#242424d9" : "#585858c2"); });
var TextIndicator = styled.p(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n color: \"#242424d9\";\n"], ["\n color: \"#242424d9\";\n"])));
var templateObject_1, templateObject_2, templateObject_3;