react-styled-slider-component 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ Here's how to use the slider component in your React application:
16
16
 
17
17
  ```tsx
18
18
  import React from 'react';
19
- import Slider from 'react-styled-slider-component';
19
+ import {Slider} from 'react-styled-slider-component';
20
20
 
21
21
  const App: React.FC = () => {
22
22
  return (
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  interface SliderProps {
3
- children: React.ReactNode[];
3
+ children: React.ReactNode;
4
4
  visibleSlides?: number;
5
5
  showDots?: boolean;
6
6
  showArrows?: boolean;
@@ -10,12 +10,16 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { useState } from "react";
13
+ import React, { useState } from "react";
14
14
  import { SliderWrapper, SlideTrack, Slide, DotsWrapper, Dot, Arrow, } from "./SliderStyles.styles";
15
15
  var Slider = function (_a) {
16
16
  var children = _a.children, _b = _a.visibleSlides, visibleSlides = _b === void 0 ? 1 : _b, _c = _a.showDots, showDots = _c === void 0 ? true : _c, _d = _a.showArrows, showArrows = _d === void 0 ? true : _d, _e = _a.dotsPosition, dotsPosition = _e === void 0 ? "bottom" : _e, _f = _a.slideStep, slideStep = _f === void 0 ? 1 : _f, _g = _a.direction, direction = _g === void 0 ? "horizontal" : _g, _h = _a.arrowStyle, arrowStyle = _h === void 0 ? "minimal" : _h, _j = _a.arrowColor, arrowColor = _j === void 0 ? "black" : _j;
17
+ // Hooks must always be called unconditionally
17
18
  var _k = useState(0), currentIndex = _k[0], setCurrentIndex = _k[1];
18
- var totalSlides = children.length;
19
+ if (!children || React.Children.count(children) === 0) {
20
+ return null; // Return null if children is null, avoiding rendering anything
21
+ }
22
+ var totalSlides = React.Children.count(children);
19
23
  // Maximum index value, preventing overflow when navigating through slides.
20
24
  var maxIndex = totalSlides - visibleSlides;
21
25
  // Calculate the number of dots based on the total number of slides and the number of visible slides.
@@ -47,7 +51,7 @@ var Slider = function (_a) {
47
51
  height: isHorizontal ? "auto" : "".concat(totalSlides * 100, "%"),
48
52
  transition: "transform 0.3s ease-in-out",
49
53
  boxSizing: "border-box",
50
- } }, { children: children.map(function (child, index) { return (_jsx(Slide, __assign({ visibleSlides: visibleSlides, style: {
54
+ } }, { children: React.Children.map(children, function (child, index) { return (_jsx(Slide, __assign({ visibleSlides: visibleSlides, style: {
51
55
  flex: isHorizontal ? "0 0 ".concat(slidePercentage, "%") : "1",
52
56
  width: isHorizontal ? "".concat(slidePercentage, "%") : "100%",
53
57
  height: isHorizontal ? "auto" : "".concat(100 / totalSlides, "%"),
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default as Slider } from '../src/components/Slider';
1
+ export { default as Slider } from './components/Slider';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { default as Slider } from '../src/components/Slider';
1
+ export { default as Slider } from './components/Slider';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-styled-slider-component",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "A customizable React slider component built with react ts and styled-components.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",