react-styled-slider-component 0.1.7 → 0.1.9

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
@@ -1,74 +1,142 @@
1
- # React Styled Slider Component
1
+ # react-styled-slider-component
2
2
 
3
- A customizable and reusable slider component built with React and styled-components. This component allows developers to easily implement a slider/carousel with various configuration options, such as the number of visible slides, navigation arrows, dots, and different directions.
3
+ A highly customizable, responsive React slider component built with TypeScript and Styled Components.
4
4
 
5
- ## Installation
5
+ ## 🚀 Features
6
6
 
7
- To install the package, use npm or yarn:
7
+ - **Compound Components:** Full control over slider layout (`Slider.Track`, `Slider.Button`, `Slider.Dots`).
8
+ - **Responsive Breakpoints:** Easily adjust visible slides for Mobile, Tablet, and Desktop.
9
+ - **Touch & Swipe Support:** Native feel on mobile devices.
10
+ - **Infinite Loop:** Seamless back-to-start navigation.
11
+ - **Autoplay:** Smart timer with pause on interaction.
12
+ - **Customizable Arrows:** Multiple styles (`minimal`, `filled`, `outlined`, `plain`) and custom icons.
13
+ - **Gap Support:** Add consistent spacing between slides.
14
+ - **TypeScript Ready:** Fully typed for a better developer experience.
15
+
16
+ ## 📦 Installation
8
17
 
9
18
  ```bash
10
19
  npm install react-styled-slider-component
20
+ # or
21
+ yarn add react-styled-slider-component
11
22
  ```
12
23
 
13
- ## Usage
24
+ ## 🛠 Usage Examples
25
+
26
+ ### 1. Full Width Hero Slider (Autoplay)
27
+
28
+ Perfect for landing pages. Shows one large image at a time.
14
29
 
15
- Here's how to use the slider component in your React application:
30
+ <img src= "https://res.cloudinary.com/dxqyvjf5r/image/upload/v1772570316/npm%20package/full_width_slider_v2vcbh.png"/>
16
31
 
17
32
  ```tsx
18
- import React from 'react';
19
- import {Slider} from 'react-styled-slider-component';
20
-
21
- const App: React.FC = () => {
22
- return (
23
- <div>
24
- <Slider
25
- visibleSlides={2}
26
- showDots={true}
27
- showArrows={true}
28
- dotsPosition="bottom"
29
- slideStep={1}
30
- direction="horizontal"
31
- arrowStyle="minimal"
32
- >
33
- <div style={{ backgroundColor: 'red', height: '200px' }}>Slide 1</div>
34
- <div style={{ backgroundColor: 'blue', height: '200px' }}>Slide 2</div>
35
- <div style={{ backgroundColor: 'green', height: '200px' }}>Slide 3</div>
36
- <div style={{ backgroundColor: 'yellow', height: '200px' }}>Slide 4</div>
37
- <div style={{ backgroundColor: 'red', height: '200px' }}>Slide 5</div>
38
- <div style={{ backgroundColor: 'blue', height: '200px' }}>Slide 6</div>
39
- <div style={{ backgroundColor: 'green', height: '200px' }}>Slide 7</div>
40
- <div style={{ backgroundColor: 'yellow', height: '200px' }}>Slide 8</div>
41
- </Slider>
42
- </div>
43
- );
44
- };
45
-
46
- export default App;
33
+ import { Slider } from "react-styled-slider-component";
34
+
35
+ const HeroSlider = () => (
36
+ <Slider
37
+ visibleSlides={1}
38
+ infinite={true}
39
+ autoplay={true}
40
+ autoplaySpeed={4000}
41
+ >
42
+ <Slider.Button type="prev" style="minimal" />
43
+ <Slider.Track>
44
+ <div style={{ height: "400px" }}>
45
+ <img
46
+ src="image1.jpg"
47
+ style={{ width: "100%", height: "100%", objectFit: "cover" }}
48
+ />
49
+ </div>
50
+ <div style={{ height: "400px" }}>
51
+ <img
52
+ src="image2.jpg"
53
+ style={{ width: "100%", height: "100%", objectFit: "cover" }}
54
+ />
55
+ </div>
56
+ </Slider.Track>
57
+ <Slider.Button type="next" style="minimal" />
58
+ <Slider.Dots position="bottom" />
59
+ </Slider>
60
+ );
47
61
  ```
48
62
 
49
- ## Props
63
+ ### 2. Multi-Item Responsive Carousel
50
64
 
51
- The `Slider` component accepts the following props:
65
+ Shows multiple items at once and adjusts automatically based on screen size.
66
+ <img src= "https://res.cloudinary.com/dxqyvjf5r/image/upload/v1772570315/npm%20package/multi_Item_slider_ittwfh.png"/>
67
+
68
+ ```tsx
69
+ const Carousel = () => (
70
+ <Slider
71
+ visibleSlides={1}
72
+ infinite={true}
73
+ gap={20}
74
+ breakpoints={{
75
+ 768: { visibleSlides: 2 },
76
+ 1024: { visibleSlides: 4 },
77
+ }}
78
+ >
79
+ <Slider.Button type="prev" style="filled" />
80
+ <Slider.Track>
81
+ <div style={{ height: "200px", background: "#FFD700" }}>Item 1</div>
82
+ <div style={{ height: "200px", background: "#FF8C00" }}>Item 2</div>
83
+ <div style={{ height: "200px", background: "#FF4500" }}>Item 3</div>
84
+ <div style={{ height: "200px", background: "#FF0000" }}>Item 4</div>
85
+ <div style={{ height: "200px", background: "#C71585" }}>Item 5</div>
86
+ </Slider.Track>
87
+ <Slider.Button type="next" style="filled" />
88
+ <Slider.Dots position="bottom" />
89
+ </Slider>
90
+ );
91
+ ```
52
92
 
53
- | Prop Name | Type | Default | Description |
54
- | --------------- | -------------------------------------------------- | --------- | --------------------------------------------------------------------------- |
55
- | `children` | `React.ReactNode[]` | - | The slides to be displayed in the slider. |
56
- | `visibleSlides` | `number` | `1` | Number of slides visible at one time. |
57
- | `showDots` | `boolean` | `true` | Whether to show navigation dots below the slider. |
58
- | `showArrows` | `boolean` | `true` | Whether to show navigation arrows on the slider. |
59
- | `dotsPosition` | `'top' ,'bottom' , 'left' , 'right'` | `'bottom'` | Position of the navigation dots. |
60
- | `slideStep` | `number` | `1` | Number of slides to move on each navigation action. |
61
- | `direction` | `'horizontal' , 'vertical'` | `'horizontal'` | Direction of the slider, either horizontal or vertical. |
62
- | `arrowStyle` | `'minimal' , 'filled' , 'outlined'` | `'minimal'` | Style of the navigation arrows. |
63
- | `arrowColor` | `'black' , 'white'` | `'black'` | Color of the navigation arrows. |
93
+ ### 3. Vertical Slider
94
+
95
+ Slides items from bottom to top. Ideal for sidebars or vertical lists.
96
+
97
+ <img src= "https://res.cloudinary.com/dxqyvjf5r/image/upload/v1772570316/npm%20package/vertical_slider_oagp8i.png"/>
98
+
99
+ ```tsx
100
+ const VerticalSlider = () => (
101
+ <div style={{ height: "500px" }}>
102
+ <Slider direction="vertical" visibleSlides={2} infinite={true} gap={10}>
103
+ <Slider.Button type="prev" style="outlined" />
104
+ <Slider.Track>
105
+ <div style={{ height: "200px", background: "#f0f0f0" }}>Vertical 1</div>
106
+ <div style={{ height: "200px", background: "#e0e0e0" }}>Vertical 2</div>
107
+ <div style={{ height: "200px", background: "#d0d0d0" }}>Vertical 3</div>
108
+ </Slider.Track>
109
+ <Slider.Button type="next" style="outlined" />
110
+ <Slider.Dots position="right" />
111
+ </Slider>
112
+ </div>
113
+ );
114
+ ```
64
115
 
116
+ ## ⚙️ Props
65
117
 
66
- ## Customization
118
+ ### Slider (Main Container)
67
119
 
68
- The slider component uses `styled-components` for styling, making it highly customizable. You can override the styles by extending the styled components used in the slider.
120
+ | Prop | Type | Default | Description |
121
+ | :-------------- | :--------------------------- | :------------- | :-------------------------------------------------------- |
122
+ | `visibleSlides` | `number` | `1` | Number of slides to show at once. |
123
+ | `direction` | `'horizontal' \| 'vertical'` | `'horizontal'` | Sliding orientation. |
124
+ | `infinite` | `boolean` | `false` | Enable infinite looping. |
125
+ | `autoplay` | `boolean` | `false` | Automatically transition slides. |
126
+ | `autoplaySpeed` | `number` | `3000` | Delay in ms for autoplay. |
127
+ | `gap` | `number` | `0` | Spacing between slides in pixels. |
128
+ | `breakpoints` | `object` | `undefined` | Responsive rules (e.g., `{ 768: { visibleSlides: 2 } }`). |
69
129
 
70
- ## Contributing
130
+ ### Slider.Button
71
131
 
72
- Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
132
+ | Prop | Type | Default | Description |
133
+ | :--------- | :----------------------------------------------- | :------------ | :------------------------------------- |
134
+ | `type` | `'prev' \| 'next'` | **Required** | Direction of the button. |
135
+ | `style` | `'minimal' \| 'filled' \| 'outlined' \| 'plain'` | `'minimal'` | Visual style of the button. |
136
+ | `children` | `ReactNode` | Default Icons | Custom text or icon inside the button. |
73
137
 
138
+ ### Slider.Dots
74
139
 
140
+ | Prop | Type | Default | Description |
141
+ | :--------- | :--------------------------------------- | :--------- | :---------------------------- |
142
+ | `position` | `'top' \| 'bottom' \| 'left' \| 'right'` | `'bottom'` | Placement of navigation dots. |
package/dist/App.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  declare const App: React.FC;
3
3
  export default App;
package/dist/App.js CHANGED
@@ -10,8 +10,105 @@ 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 Slider from './components/Slider';
13
+ import { Slider } from "./components/Slider";
14
14
  var App = function () {
15
- return (_jsx("div", { children: _jsxs(Slider, __assign({ visibleSlides: 2, showDots: true, showArrows: true, dotsPosition: "bottom", slideStep: 1, direction: "horizontal", arrowStyle: "minimal" }, { children: [_jsx("div", __assign({ style: { backgroundColor: 'red', height: '200px' } }, { children: "Slide 1" })), _jsx("div", __assign({ style: { backgroundColor: 'blue', height: '200px' } }, { children: "Slide 2" })), _jsx("div", __assign({ style: { backgroundColor: 'green', height: '200px' } }, { children: "Slide 3" })), _jsx("div", __assign({ style: { backgroundColor: 'yellow', height: '200px' } }, { children: "Slide 4" })), _jsx("div", __assign({ style: { backgroundColor: 'red', height: '200px' } }, { children: "Slide 5" })), _jsx("div", __assign({ style: { backgroundColor: 'blue', height: '200px' } }, { children: "Slide 6" })), _jsx("div", __assign({ style: { backgroundColor: 'green', height: '200px' } }, { children: "Slide 7" })), _jsx("div", __assign({ style: { backgroundColor: 'yellow', height: '200px' } }, { children: "Slide 8" }))] })) }));
15
+ return (_jsxs("div", __assign({ style: {
16
+ padding: "50px",
17
+ maxWidth: "1200px",
18
+ margin: "0 auto",
19
+ fontFamily: "Arial, sans-serif",
20
+ } }, { children: [_jsx("h1", __assign({ style: { textAlign: "center", marginBottom: "50px" } }, { children: "Slider Component Test Lab" })), _jsxs("section", __assign({ style: { marginBottom: "80px" } }, { children: [_jsx("h3", { children: "1. Full Width Hero (1 slide at a time)" }), _jsxs(Slider, __assign({ visibleSlides: 1, infinite: true, autoplay: true, autoplaySpeed: 4000, gap: 0 }, { children: [_jsx(Slider.Button, { type: "prev", style: "minimal" }), _jsxs(Slider.Track, { children: [_jsx("div", __assign({ style: { width: "100%", height: "400px" } }, { children: _jsx("img", { src: "https://picsum.photos/1200/400?random=11", alt: "1", style: { width: "100%", height: "100%", objectFit: "cover" } }) })), _jsx("div", __assign({ style: { width: "100%", height: "400px" } }, { children: _jsx("img", { src: "https://picsum.photos/1200/400?random=12", alt: "2", style: { width: "100%", height: "100%", objectFit: "cover" } }) })), _jsx("div", __assign({ style: { width: "100%", height: "400px" } }, { children: _jsx("img", { src: "https://picsum.photos/1200/400?random=13", alt: "3", style: { width: "100%", height: "100%", objectFit: "cover" } }) }))] }), _jsx(Slider.Button, { type: "next", style: "minimal" }), _jsx(Slider.Dots, { position: "bottom" })] }))] })), _jsxs("section", __assign({ style: { marginBottom: "80px" } }, { children: [_jsx("h3", { children: "2. Multi-Item Carousel (8 items total)" }), _jsxs(Slider, __assign({ visibleSlides: 1, infinite: true, gap: 20, breakpoints: {
21
+ 768: { visibleSlides: 2 },
22
+ 1024: { visibleSlides: 4 },
23
+ } }, { children: [_jsx(Slider.Button, { type: "prev", style: "filled" }), _jsxs(Slider.Track, { children: [_jsx("div", __assign({ style: {
24
+ height: "200px",
25
+ background: "#FFD700",
26
+ display: "flex",
27
+ alignItems: "center",
28
+ justifyContent: "center",
29
+ borderRadius: "8px",
30
+ } }, { children: "Item 1" })), _jsx("div", __assign({ style: {
31
+ height: "200px",
32
+ background: "#FF8C00",
33
+ display: "flex",
34
+ alignItems: "center",
35
+ justifyContent: "center",
36
+ borderRadius: "8px",
37
+ } }, { children: "Item 2" })), _jsx("div", __assign({ style: {
38
+ height: "200px",
39
+ background: "#FF4500",
40
+ display: "flex",
41
+ alignItems: "center",
42
+ justifyContent: "center",
43
+ borderRadius: "8px",
44
+ } }, { children: "Item 3" })), _jsx("div", __assign({ style: {
45
+ height: "200px",
46
+ background: "#FF0000",
47
+ display: "flex",
48
+ alignItems: "center",
49
+ justifyContent: "center",
50
+ borderRadius: "8px",
51
+ } }, { children: "Item 4" })), _jsx("div", __assign({ style: {
52
+ height: "200px",
53
+ background: "#C71585",
54
+ display: "flex",
55
+ alignItems: "center",
56
+ justifyContent: "center",
57
+ borderRadius: "8px",
58
+ } }, { children: "Item 5" })), _jsx("div", __assign({ style: {
59
+ height: "200px",
60
+ background: "#8B008B",
61
+ display: "flex",
62
+ alignItems: "center",
63
+ justifyContent: "center",
64
+ borderRadius: "8px",
65
+ } }, { children: "Item 6" })), _jsx("div", __assign({ style: {
66
+ height: "200px",
67
+ background: "#483D8B",
68
+ display: "flex",
69
+ alignItems: "center",
70
+ justifyContent: "center",
71
+ borderRadius: "8px",
72
+ } }, { children: "Item 7" })), _jsx("div", __assign({ style: {
73
+ height: "200px",
74
+ background: "#2F4F4F",
75
+ display: "flex",
76
+ alignItems: "center",
77
+ justifyContent: "center",
78
+ borderRadius: "8px",
79
+ } }, { children: "Item 8" }))] }), _jsx(Slider.Button, { type: "next", style: "filled" }), _jsx(Slider.Dots, { position: "bottom" })] }))] })), _jsxs("section", __assign({ style: { marginBottom: "80px" } }, { children: [_jsx("h3", { children: "3. Vertical Slider (2 slides visible)" }), _jsx("div", __assign({ style: {
80
+ height: "500px",
81
+ border: "1px solid #ddd",
82
+ borderRadius: "12px",
83
+ padding: "20px",
84
+ } }, { children: _jsxs(Slider, __assign({ direction: "vertical", visibleSlides: 2, infinite: true, gap: 10 }, { children: [_jsx(Slider.Button, { type: "prev", style: "outlined" }), _jsxs(Slider.Track, { children: [_jsx("div", __assign({ style: {
85
+ height: "200px",
86
+ backgroundColor: "#f0f0f0",
87
+ borderRadius: "8px",
88
+ display: "flex",
89
+ alignItems: "center",
90
+ justifyContent: "center",
91
+ } }, { children: "Vertical 1" })), _jsx("div", __assign({ style: {
92
+ height: "200px",
93
+ backgroundColor: "#e0e0e0",
94
+ borderRadius: "8px",
95
+ display: "flex",
96
+ alignItems: "center",
97
+ justifyContent: "center",
98
+ } }, { children: "Vertical 2" })), _jsx("div", __assign({ style: {
99
+ height: "200px",
100
+ backgroundColor: "#d0d0d0",
101
+ borderRadius: "8px",
102
+ display: "flex",
103
+ alignItems: "center",
104
+ justifyContent: "center",
105
+ } }, { children: "Vertical 3" })), _jsx("div", __assign({ style: {
106
+ height: "200px",
107
+ backgroundColor: "#c0c0c0",
108
+ borderRadius: "8px",
109
+ display: "flex",
110
+ alignItems: "center",
111
+ justifyContent: "center",
112
+ } }, { children: "Vertical 4" }))] }), _jsx(Slider.Button, { type: "next", style: "outlined" }), _jsx(Slider.Dots, { position: "right" })] })) }))] })), _jsx("footer", __assign({ style: { textAlign: "center", paddingBottom: "50px" } }, { children: _jsx("p", { children: "All sliders are working with the same component logic!" }) }))] })));
16
113
  };
17
114
  export default App;
package/dist/App.test.js CHANGED
@@ -1,8 +1,26 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { render, screen } from '@testing-library/react';
3
- import App from './App';
4
- test('renders learn react link', function () {
5
- render(_jsx(App, {}));
6
- var linkElement = screen.getByText(/learn react/i);
7
- expect(linkElement).toBeInTheDocument();
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { render, screen } from "@testing-library/react";
14
+ import { Slider } from "./components/Slider";
15
+ describe("Slider Component Test", function () {
16
+ // Step 2: Test for the Slider component
17
+ test("renders correct number of slides", function () {
18
+ render(_jsxs(Slider, __assign({ visibleSlides: 1 }, { children: [_jsx("div", { children: "Slide 1" }), _jsx("div", { children: "Slide 2" }), _jsx("div", { children: "Slide 3" })] })));
19
+ // Selecting the slides by their text content
20
+ var slide1 = screen.getByText("Slide 1");
21
+ var slide2 = screen.getByText("Slide 2");
22
+ // Expect: Checking if the slides are present in the document
23
+ expect(slide1).toBeInTheDocument();
24
+ expect(slide2).toBeInTheDocument();
25
+ });
8
26
  });
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { SliderProps } from "../../types/Slider.types";
3
+ import SliderTrack from "./SliderTrack";
4
+ import SliderButton from "./SliderButton";
5
+ import SliderDots from "./SliderDots";
6
+ declare const Slider: React.FC<SliderProps> & {
7
+ Track: typeof SliderTrack;
8
+ Button: typeof SliderButton;
9
+ Dots: typeof SliderDots;
10
+ };
11
+ export default Slider;
@@ -0,0 +1,84 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useState, useCallback, useMemo, useEffect } from "react";
14
+ import { SliderContext } from "../../context/SliderContext";
15
+ import { SliderWrapper } from "./SliderStyles.styles";
16
+ import SliderTrack from "./SliderTrack";
17
+ import SliderButton from "./SliderButton";
18
+ import SliderDots from "./SliderDots";
19
+ var Slider = function (_a) {
20
+ var children = _a.children, _b = _a.visibleSlides, defaultVisibleSlides = _b === void 0 ? 1 : _b, _c = _a.direction, direction = _c === void 0 ? "horizontal" : _c, _d = _a.initialIndex, initialIndex = _d === void 0 ? 0 : _d, _e = _a.infinite, infinite = _e === void 0 ? false : _e, _f = _a.autoplay, autoplay = _f === void 0 ? false : _f, _g = _a.autoplaySpeed, autoplaySpeed = _g === void 0 ? 3000 : _g, _h = _a.gap, gap = _h === void 0 ? 0 : _h, breakpoints = _a.breakpoints;
21
+ var _j = useState(initialIndex), currentIndex = _j[0], setCurrentIndex = _j[1];
22
+ var _k = useState(defaultVisibleSlides), visibleSlides = _k[0], setVisibleSlides = _k[1];
23
+ var _l = useState(0), totalSlides = _l[0], setTotalSlides = _l[1];
24
+ // Handle responsive breakpoints
25
+ useEffect(function () {
26
+ var handleResize = function () {
27
+ var width = window.innerWidth;
28
+ var activeVisibleSlides = defaultVisibleSlides;
29
+ if (breakpoints) {
30
+ var sorted = Object.keys(breakpoints)
31
+ .map(Number)
32
+ .sort(function (a, b) { return a - b; });
33
+ for (var _i = 0, sorted_1 = sorted; _i < sorted_1.length; _i++) {
34
+ var b = sorted_1[_i];
35
+ if (width >= b)
36
+ activeVisibleSlides = breakpoints[b].visibleSlides;
37
+ }
38
+ }
39
+ setVisibleSlides(activeVisibleSlides);
40
+ };
41
+ handleResize();
42
+ window.addEventListener("resize", handleResize);
43
+ return function () { return window.removeEventListener("resize", handleResize); };
44
+ }, [breakpoints, defaultVisibleSlides]);
45
+ var maxIndex = useMemo(function () { return Math.max(0, totalSlides - visibleSlides); }, [totalSlides, visibleSlides]);
46
+ var goToNext = useCallback(function () {
47
+ setCurrentIndex(function (prev) {
48
+ return infinite
49
+ ? prev >= maxIndex
50
+ ? 0
51
+ : prev + 1
52
+ : Math.min(prev + 1, maxIndex);
53
+ });
54
+ }, [maxIndex, infinite]);
55
+ var goToPrev = useCallback(function () {
56
+ setCurrentIndex(function (prev) {
57
+ return infinite ? (prev <= 0 ? maxIndex : prev - 1) : Math.max(prev - 1, 0);
58
+ });
59
+ }, [maxIndex, infinite]);
60
+ var goToSlide = useCallback(function (index) { return setCurrentIndex(index); }, []);
61
+ // Autoplay effect
62
+ useEffect(function () {
63
+ var interval;
64
+ if (autoplay && totalSlides > visibleSlides)
65
+ interval = setInterval(goToNext, autoplaySpeed);
66
+ return function () { return clearInterval(interval); };
67
+ }, [autoplay, autoplaySpeed, goToNext, totalSlides, visibleSlides]);
68
+ return (_jsx(SliderContext.Provider, __assign({ value: {
69
+ currentIndex: currentIndex,
70
+ totalSlides: totalSlides,
71
+ setTotalSlides: setTotalSlides,
72
+ visibleSlides: visibleSlides,
73
+ direction: direction,
74
+ infinite: infinite,
75
+ gap: gap,
76
+ goToNext: goToNext,
77
+ goToPrev: goToPrev,
78
+ goToSlide: goToSlide,
79
+ } }, { children: _jsx(SliderWrapper, __assign({ direction: direction }, { children: children })) })));
80
+ };
81
+ Slider.Track = SliderTrack;
82
+ Slider.Button = SliderButton;
83
+ Slider.Dots = SliderDots;
84
+ export default Slider;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { ButtonProps } from "../../types/Slider.types";
3
+ declare const SliderButton: React.FC<ButtonProps>;
4
+ export default SliderButton;
@@ -0,0 +1,29 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useSlider } from "../../context/SliderContext";
14
+ import { Arrow } from "./SliderStyles.styles";
15
+ var SliderButton = function (_a) {
16
+ var type = _a.type, children = _a.children, _b = _a.style, style = _b === void 0 ? "minimal" : _b;
17
+ var _c = useSlider(), goToNext = _c.goToNext, goToPrev = _c.goToPrev, direction = _c.direction;
18
+ var isHorizontal = direction === "horizontal";
19
+ var handleClick = type === "next" ? goToNext : goToPrev;
20
+ var defaultIcon = type === "next" ? (isHorizontal ? ">" : "˅") : isHorizontal ? "<" : "˄";
21
+ return (_jsx(Arrow, __assign({ direction: type === "next"
22
+ ? isHorizontal
23
+ ? "right"
24
+ : "down"
25
+ : isHorizontal
26
+ ? "left"
27
+ : "up", arrowStyle: style, arrowColor: "black", onClick: handleClick }, { children: children || defaultIcon })));
28
+ };
29
+ export default SliderButton;
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import { DotsPosition } from "../../types/Slider.types";
3
+ declare const SliderDots: React.FC<{
4
+ position?: DotsPosition;
5
+ }>;
6
+ export default SliderDots;
@@ -0,0 +1,23 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useSlider } from "../../context/SliderContext";
14
+ import { DotsWrapper, Dot } from "./SliderStyles.styles";
15
+ var SliderDots = function (_a) {
16
+ var _b = _a.position, position = _b === void 0 ? "bottom" : _b;
17
+ var _c = useSlider(), totalSlides = _c.totalSlides, visibleSlides = _c.visibleSlides, currentIndex = _c.currentIndex, goToSlide = _c.goToSlide;
18
+ var numberOfDots = Math.max(0, totalSlides - visibleSlides + 1);
19
+ if (numberOfDots <= 1)
20
+ return null;
21
+ return (_jsx(DotsWrapper, __assign({ position: position }, { children: Array.from({ length: numberOfDots }).map(function (_, index) { return (_jsx(Dot, { active: index === currentIndex, onClick: function () { return goToSlide(index); } }, index)); }) })));
22
+ };
23
+ export default SliderDots;
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ export declare const SliderWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
3
+ direction: 'horizontal' | 'vertical';
4
+ }>> & string;
5
+ export declare const SlideTrack: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
6
+ export declare const Slide: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
7
+ visibleSlides: number;
8
+ }>> & string;
9
+ export declare const DotsWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
10
+ position: 'top' | 'bottom' | 'left' | 'right';
11
+ }>> & string;
12
+ export declare const Dot: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
13
+ active: boolean;
14
+ }>> & string;
15
+ export declare const Arrow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
16
+ direction: 'left' | 'right' | 'up' | 'down';
17
+ arrowStyle: 'minimal' | 'filled' | 'outlined' | 'plain';
18
+ arrowColor: 'black' | 'white';
19
+ }>> & string;
@@ -0,0 +1,60 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import styled from 'styled-components';
6
+ export var SliderWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative;\n width: 100%;\n overflow: hidden;\n height: ", ";\n\n ", "\n"], ["\n position: relative;\n width: 100%;\n overflow: hidden;\n height: ", ";\n\n ", "\n"])), function (_a) {
7
+ var direction = _a.direction;
8
+ return (direction === 'vertical' ? '100%' : 'auto');
9
+ }, function (_a) {
10
+ var direction = _a.direction;
11
+ return direction === 'vertical' && "\n display: flex;\n flex-direction: column;\n ";
12
+ });
13
+ export var SlideTrack = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n transition: transform 0.3s ease-in-out;\n /* Track width will be set dynamically via inline styles */\n"], ["\n display: flex;\n transition: transform 0.3s ease-in-out;\n /* Track width will be set dynamically via inline styles */\n"])));
14
+ export var Slide = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n box-sizing: border-box;\n flex-shrink: 0; /* Important: prevents slides from squeezing */\n width: 100%;\n height: 100%;\n"], ["\n box-sizing: border-box;\n flex-shrink: 0; /* Important: prevents slides from squeezing */\n width: 100%;\n height: 100%;\n"])));
15
+ export var DotsWrapper = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n position: absolute;\n display: flex;\n justify-content: center;\n z-index: 5;\n flex-direction: ", ";\n \n ", "\n ", "\n ", "\n ", "\n"], ["\n position: absolute;\n display: flex;\n justify-content: center;\n z-index: 5;\n flex-direction: ", ";\n \n ", "\n ", "\n ", "\n ", "\n"])), function (_a) {
16
+ var position = _a.position;
17
+ return (position === 'left' || position === 'right' ? 'column' : 'row');
18
+ }, function (_a) {
19
+ var position = _a.position;
20
+ return position === 'top' && "top: 10px; left: 50%; transform: translateX(-50%);";
21
+ }, function (_a) {
22
+ var position = _a.position;
23
+ return position === 'bottom' && "bottom: 10px; left: 50%; transform: translateX(-50%);";
24
+ }, function (_a) {
25
+ var position = _a.position;
26
+ return position === 'left' && "left: 10px; top: 50%; transform: translateY(-50%);";
27
+ }, function (_a) {
28
+ var position = _a.position;
29
+ return position === 'right' && "right: 10px; top: 50%; transform: translateY(-50%);";
30
+ });
31
+ export var Dot = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background-color: ", ";\n margin: 5px;\n cursor: pointer;\n transition: background-color 0.2s;\n"], ["\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background-color: ", ";\n margin: 5px;\n cursor: pointer;\n transition: background-color 0.2s;\n"])), function (_a) {
32
+ var active = _a.active;
33
+ return (active ? 'black' : 'lightgray');
34
+ });
35
+ export var Arrow = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n position: absolute;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n z-index: 10;\n user-select: none;\n transition: all 0.2s ease-in-out;\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n"], ["\n position: absolute;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n z-index: 10;\n user-select: none;\n transition: all 0.2s ease-in-out;\n\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n"])), function (_a) {
36
+ var direction = _a.direction;
37
+ return direction === 'left' && 'left: 15px; top: 50%; transform: translateY(-50%);';
38
+ }, function (_a) {
39
+ var direction = _a.direction;
40
+ return direction === 'right' && 'right: 15px; top: 50%; transform: translateY(-50%);';
41
+ }, function (_a) {
42
+ var direction = _a.direction;
43
+ return direction === 'up' && 'top: 15px; left: 50%; transform: translateX(-50%);';
44
+ }, function (_a) {
45
+ var direction = _a.direction;
46
+ return direction === 'down' && 'bottom: 15px; left: 50%; transform: translateX(-50%);';
47
+ }, function (_a) {
48
+ var arrowStyle = _a.arrowStyle;
49
+ return arrowStyle !== 'plain' && "\n width: 45px;\n height: 45px;\n border-radius: 50%;\n font-size: 20px;\n box-shadow: 0 4px 6px rgba(0,0,0,0.1);\n &:hover { transform: scale(1.1) ".concat(function (props) { return props.direction === 'left' || props.direction === 'right' ? 'translateY(-45%)' : 'translateX(-45%)'; }, "; }\n ");
50
+ }, function (_a) {
51
+ var arrowStyle = _a.arrowStyle, arrowColor = _a.arrowColor;
52
+ return arrowStyle === 'minimal' && "\n background-color: rgba(255, 255, 255, 0.8);\n backdrop-filter: blur(4px);\n color: ".concat(arrowColor === 'white' ? 'white' : '#333', ";\n ");
53
+ }, function (_a) {
54
+ var arrowStyle = _a.arrowStyle, arrowColor = _a.arrowColor;
55
+ return arrowStyle === 'filled' && "\n background-color: ".concat(arrowColor === 'white' ? '#fff' : '#222', ";\n color: ").concat(arrowColor === 'white' ? '#222' : '#fff', ";\n ");
56
+ }, function (_a) {
57
+ var arrowStyle = _a.arrowStyle, arrowColor = _a.arrowColor;
58
+ return arrowStyle === 'plain' && "\n background: none;\n font-size: 32px;\n font-weight: bold;\n color: ".concat(arrowColor === 'white' ? '#fff' : '#222', ";\n &:hover { opacity: 0.7; transform: scale(1.2) ").concat(function (props) { return props.direction === 'left' || props.direction === 'right' ? 'translateY(-42%)' : 'translateX(-42%)'; }, "; }\n ");
59
+ });
60
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ declare const SliderTrack: React.FC<{
3
+ children: React.ReactNode;
4
+ }>;
5
+ export default SliderTrack;
@@ -0,0 +1,45 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import React, { useEffect } from "react";
14
+ import { useSlider } from "../../context/SliderContext";
15
+ import { SlideTrack, Slide } from "./SliderStyles.styles";
16
+ var SliderTrack = function (_a) {
17
+ var children = _a.children;
18
+ var _b = useSlider(), currentIndex = _b.currentIndex, direction = _b.direction, visibleSlides = _b.visibleSlides, setTotalSlides = _b.setTotalSlides, gap = _b.gap;
19
+ var isHorizontal = direction === "horizontal";
20
+ var count = React.Children.count(children);
21
+ useEffect(function () {
22
+ setTotalSlides(count);
23
+ }, [count, setTotalSlides]);
24
+ if (count === 0)
25
+ return null;
26
+ var trackWidth = (count / visibleSlides) * 100;
27
+ var transformPercentage = (currentIndex / count) * 100;
28
+ var transformValue = isHorizontal
29
+ ? "translateX(-".concat(transformPercentage, "%)")
30
+ : "translateY(-".concat(transformPercentage, "%)");
31
+ return (_jsx("div", __assign({ style: {
32
+ overflow: "hidden",
33
+ width: "100%",
34
+ height: isHorizontal ? "auto" : "100%",
35
+ } }, { children: _jsx(SlideTrack, __assign({ style: {
36
+ transform: transformValue,
37
+ flexDirection: isHorizontal ? "row" : "column",
38
+ width: isHorizontal ? "".concat(trackWidth, "%") : "100%",
39
+ height: isHorizontal ? "auto" : "".concat(trackWidth, "%"),
40
+ } }, { children: React.Children.map(children, function (child, index) { return (_jsx(Slide, __assign({ visibleSlides: visibleSlides, style: {
41
+ flex: "0 0 ".concat(100 / count, "%"),
42
+ padding: isHorizontal ? "0 ".concat(gap / 2, "px") : "".concat(gap / 2, "px 0"),
43
+ } }, { children: child }), index)); }) })) })));
44
+ };
45
+ export default SliderTrack;
@@ -0,0 +1,4 @@
1
+ export { default as Slider } from "./Slider";
2
+ export { default as SliderTrack } from "./SliderTrack";
3
+ export { default as SliderButton } from "./SliderButton";
4
+ export { default as SliderDots } from "./SliderDots";
@@ -0,0 +1,4 @@
1
+ export { default as Slider } from "./Slider";
2
+ export { default as SliderTrack } from "./SliderTrack";
3
+ export { default as SliderButton } from "./SliderButton";
4
+ export { default as SliderDots } from "./SliderDots";
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { SliderContextProps } from "../types/Slider.types";
3
+ export declare const SliderContext: import("react").Context<SliderContextProps | undefined>;
4
+ export declare const useSlider: () => SliderContextProps;
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from "react";
2
+ export var SliderContext = createContext(undefined);
3
+ export var useSlider = function () {
4
+ var context = useContext(SliderContext);
5
+ if (!context) {
6
+ throw new Error("Slider sub-components must be used within a <Slider />");
7
+ }
8
+ return context;
9
+ };
@@ -0,0 +1,2 @@
1
+ export { Slider } from "./components/Slider";
2
+ export * from "./components/Slider";
package/dist/export.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Slider } from "./components/Slider";
2
+ export * from "./components/Slider";
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default as Slider } from './components/Slider';
1
+ import './index.css';
package/dist/index.js CHANGED
@@ -1 +1,12 @@
1
- export { default as Slider } from './components/Slider';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import ReactDOM from 'react-dom/client';
4
+ import './index.css';
5
+ import App from './App';
6
+ import reportWebVitals from './reportWebVitals';
7
+ var root = ReactDOM.createRoot(document.getElementById('root'));
8
+ root.render(_jsx(React.StrictMode, { children: _jsx(App, {}) }));
9
+ // If you want to start measuring performance in your app, pass a function
10
+ // to log results (for example: reportWebVitals(console.log))
11
+ // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
12
+ reportWebVitals();
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+ export type SliderDirection = "horizontal" | "vertical";
3
+ export type ArrowStyle = "minimal" | "filled" | "outlined" | "plain";
4
+ export type DotsPosition = "top" | "bottom" | "left" | "right";
5
+ export interface Breakpoints {
6
+ [key: number]: {
7
+ visibleSlides: number;
8
+ };
9
+ }
10
+ export interface SliderProps {
11
+ children: React.ReactNode;
12
+ visibleSlides?: number;
13
+ direction?: SliderDirection;
14
+ initialIndex?: number;
15
+ infinite?: boolean;
16
+ autoplay?: boolean;
17
+ autoplaySpeed?: number;
18
+ gap?: number;
19
+ breakpoints?: Breakpoints;
20
+ }
21
+ export interface SliderContextProps {
22
+ currentIndex: number;
23
+ totalSlides: number;
24
+ visibleSlides: number;
25
+ direction: SliderDirection;
26
+ infinite: boolean;
27
+ gap: number;
28
+ setTotalSlides: (count: number) => void;
29
+ goToNext: () => void;
30
+ goToPrev: () => void;
31
+ goToSlide: (index: number) => void;
32
+ }
33
+ export interface ButtonProps {
34
+ type: "prev" | "next";
35
+ children?: React.ReactNode;
36
+ style?: ArrowStyle;
37
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-styled-slider-component",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
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",
@@ -33,6 +33,17 @@
33
33
  "web-vitals": "^2.1.4"
34
34
  },
35
35
  "devDependencies": {
36
+ "@testing-library/jest-dom": "^6.9.1",
37
+ "@testing-library/react": "^16.3.2",
38
+ "@testing-library/user-event": "^14.6.1",
39
+ "@types/jest": "^30.0.0",
40
+ "@types/node": "^16.18.0",
41
+ "@types/react": "^18.2.0",
42
+ "@types/react-dom": "^18.2.0",
43
+ "@types/styled-components": "^5.1.0",
44
+ "react": "^18.2.0",
45
+ "react-dom": "^18.2.0",
46
+ "styled-components": "^6.1.1",
36
47
  "typescript": "^4.9.5"
37
48
  },
38
49
  "peerDependencies": {
@@ -57,5 +68,13 @@
57
68
  "last 1 firefox version",
58
69
  "last 1 safari version"
59
70
  ]
71
+ },
72
+ "overrides": {
73
+ "nth-check": "^2.0.1",
74
+ "postcss": "^8.4.31",
75
+ "serialize-javascript": "^7.0.3",
76
+ "webpack-dev-server": "^5.2.0",
77
+ "underscore": "^1.13.7",
78
+ "jsonpath": "^1.1.1"
60
79
  }
61
80
  }