@chayns-components/core
Version:
A set of beautiful React components for developing your own applications with chayns.
74 lines (73 loc) • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _HighlightSliderItem = require("./HighlightSliderItem.styles");
var _ProgressBar = require("../../progress-bar/ProgressBar.styles");
var _uuid = require("../../../hooks/uuid");
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 HighlightSliderItem = ({
colors,
isActive,
isFinished,
onFinish,
index,
onClick,
duration,
isInteractive,
shouldEnableKeyboardHighlighting,
shouldShowKeyboardHighlighting = false
}) => {
const uuid = (0, _uuid.useUuid)();
const isKeyboardFocusable = isInteractive && shouldEnableKeyboardHighlighting;
const handleKeyDown = (0, _react.useCallback)(event => {
if (!isInteractive) {
return;
}
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
onClick(index);
}
}, [index, isInteractive, onClick]);
return /*#__PURE__*/_react.default.createElement(_HighlightSliderItem.StyledHighlightSliderItem, {
onClick: isInteractive ? () => onClick(index) : undefined,
onKeyDown: isKeyboardFocusable ? handleKeyDown : undefined,
tabIndex: isKeyboardFocusable ? 0 : -1,
role: isInteractive ? 'button' : undefined,
$shouldShowKeyboardHighlighting: shouldShowKeyboardHighlighting
}, /*#__PURE__*/_react.default.createElement(_ProgressBar.StyledProgressBarProgressWrapper, null, isActive && /*#__PURE__*/_react.default.createElement(_HighlightSliderItem.StyledHighlightSliderItemProgress, {
key: `highlight-slider-item-active--${uuid}`,
initial: {
width: '100%',
left: '-100%'
},
animate: {
width: '100%',
left: '0%'
},
exit: {
width: '100%',
left: '0%'
},
onAnimationComplete: () => onFinish(index),
$backgroundColor: colors.fillColor,
transition: {
ease: 'linear',
duration
}
}), isFinished && /*#__PURE__*/_react.default.createElement(_HighlightSliderItem.StyledHighlightSliderItemProgress, {
key: `highlight-slider-item-finished--${uuid}`,
style: {
width: '100%',
left: '0%'
},
$backgroundColor: colors.fillColor
}), /*#__PURE__*/_react.default.createElement(_HighlightSliderItem.StyledHighlightSliderItemBackground, {
$backgroundColor: colors.backgroundColor
})));
};
HighlightSliderItem.displayName = 'HighlightSliderItem';
var _default = exports.default = HighlightSliderItem;
//# sourceMappingURL=HighlightSliderItem.js.map