UNPKG

@chayns-components/core

Version:

A set of beautiful React components for developing your own applications with chayns.

59 lines (58 loc) 3.34 kB
"use strict"; 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")); var _useKeyboardFocusHighlighting = require("../../hooks/useKeyboardFocusHighlighting"); var _ColorSchemeProvider = require("../color-scheme-provider/ColorSchemeProvider"); 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, shouldEnableKeyboardHighlighting }) => { const colorScheme = (0, _ColorSchemeProvider.useColorScheme)(); const isInteractive = typeof onIndexChange === 'function'; const shouldEnableKeyboardHighlightingEffective = shouldEnableKeyboardHighlighting ?? (colorScheme === null || colorScheme === void 0 ? void 0 : colorScheme.shouldEnableKeyboardHighlighting) ?? false; const shouldShowKeyboardHighlighting = (0, _useKeyboardFocusHighlighting.useKeyboardFocusHighlighting)(shouldEnableKeyboardHighlightingEffective && isInteractive); 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, shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlightingEffective, shouldShowKeyboardHighlighting: shouldShowKeyboardHighlighting, isInteractive: isInteractive })), [colors, count, currentIndex, duration, handleClick, handleFinish, shouldEnableKeyboardHighlightingEffective, shouldShowKeyboardHighlighting, isInteractive]); return /*#__PURE__*/_react.default.createElement(_HighlightSlider.StyledHighlightSlider, null, content); }; HighlightSlider.displayName = 'HighlightSlider'; var _default = exports.default = HighlightSlider; //# sourceMappingURL=HighlightSlider.js.map