react-styled-slider-component 0.1.2 → 0.1.4

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 (
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,15 +1,15 @@
1
1
  {
2
2
  "name": "react-styled-slider-component",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A customizable React slider component built with react ts and styled-components.",
5
- "main": "dist/index.js",
5
+ "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "start": "react-scripts start",
9
- "build": "react-scripts build",
9
+ "build": "tsc",
10
10
  "test": "react-scripts test",
11
11
  "eject": "react-scripts eject",
12
- "prepublishOnly": "tsc"
12
+ "prepublishOnly": "npm run build"
13
13
  },
14
14
  "keywords": [
15
15
  "react",
@@ -25,8 +25,7 @@
25
25
  "url": "https://github.com/ceydaulubas/slider.git"
26
26
  },
27
27
  "files": [
28
- "dist",
29
- "src"
28
+ "dist"
30
29
  ],
31
30
  "dependencies": {
32
31
  "@testing-library/jest-dom": "^5.17.0",
package/src/App.css DELETED
File without changes
package/src/App.test.tsx DELETED
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import App from './App';
4
-
5
- test('renders learn react link', () => {
6
- render(<App />);
7
- const linkElement = screen.getByText(/learn react/i);
8
- expect(linkElement).toBeInTheDocument();
9
- });
package/src/App.tsx DELETED
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import Slider from './components/Slider';
3
-
4
- const App: React.FC = () => {
5
- return (
6
- <div>
7
- <Slider
8
- visibleSlides={2}
9
- showDots={true}
10
- showArrows={true}
11
- dotsPosition="bottom"
12
- slideStep={1}
13
- direction="horizontal"
14
- arrowStyle="minimal"
15
- >
16
- <div style={{ backgroundColor: 'red', height: '200px' }}>Slide 1</div>
17
- <div style={{ backgroundColor: 'blue', height: '200px' }}>Slide 2</div>
18
- <div style={{ backgroundColor: 'green', height: '200px' }}>Slide 3</div>
19
- <div style={{ backgroundColor: 'yellow', height: '200px' }}>Slide 4</div>
20
- <div style={{ backgroundColor: 'red', height: '200px' }}>Slide 5</div>
21
- <div style={{ backgroundColor: 'blue', height: '200px' }}>Slide 6</div>
22
- <div style={{ backgroundColor: 'green', height: '200px' }}>Slide 7</div>
23
- <div style={{ backgroundColor: 'yellow', height: '200px' }}>Slide 8</div>
24
- </Slider>
25
- </div>
26
- );
27
- };
28
-
29
- export default App;
@@ -1,139 +0,0 @@
1
- import React, { useState } from "react";
2
- import {
3
- SliderWrapper,
4
- SlideTrack,
5
- Slide,
6
- DotsWrapper,
7
- Dot,
8
- Arrow,
9
- } from "./SliderStyles.styles";
10
-
11
- interface SliderProps {
12
- children: React.ReactNode[];
13
- visibleSlides?: number;
14
- showDots?: boolean;
15
- showArrows?: boolean;
16
- dotsPosition?: "top" | "bottom" | "left" | "right";
17
- slideStep?: number;
18
- direction?: "horizontal" | "vertical";
19
- arrowStyle?: "minimal" | "filled" | "outlined";
20
- arrowColor?: "black" | "white";
21
- }
22
-
23
- const Slider: React.FC<SliderProps> = ({
24
- children,
25
- visibleSlides = 1,
26
- showDots = true,
27
- showArrows = true,
28
- dotsPosition = "bottom",
29
- slideStep = 1,
30
- direction = "horizontal",
31
- arrowStyle = "minimal",
32
- arrowColor = "black",
33
- }) => {
34
- const [currentIndex, setCurrentIndex] = useState(0);
35
-
36
- const totalSlides = children.length;
37
-
38
- // Maximum index value, preventing overflow when navigating through slides.
39
- const maxIndex = totalSlides - visibleSlides;
40
-
41
- // Calculate the number of dots based on the total number of slides and the number of visible slides.
42
- const numberOfDots = Math.ceil((totalSlides - visibleSlides + 1) / slideStep);
43
-
44
- const isHorizontal = direction === "horizontal";
45
-
46
- const goToNext = () => {
47
- setCurrentIndex((prevIndex) => Math.min(prevIndex + slideStep, maxIndex));
48
- };
49
-
50
- const goToPrev = () => {
51
- setCurrentIndex((prevIndex) => Math.max(prevIndex - slideStep, 0));
52
- };
53
-
54
- const goToSlide = (index: number) => {
55
- setCurrentIndex(index);
56
- };
57
-
58
- const slidePercentage = isHorizontal
59
- ? 100 / visibleSlides
60
- : 100 / totalSlides;
61
-
62
- return (
63
- <SliderWrapper
64
- direction={direction}
65
- style={{
66
- height: isHorizontal ? "auto" : `${visibleSlides * 200}px`,
67
- display: isHorizontal ? "block" : "flex",
68
- flexDirection: isHorizontal ? "row" : "column",
69
- }}
70
- >
71
- {showArrows && (
72
- <Arrow
73
- direction={isHorizontal ? "left" : "up"}
74
- arrowStyle={arrowStyle}
75
- arrowColor={arrowColor}
76
- onClick={goToPrev}
77
- >
78
- {isHorizontal ? "<" : "˄"}
79
- </Arrow>
80
- )}
81
-
82
- <SlideTrack
83
- style={{
84
- transform: isHorizontal
85
- ? `translateX(-${currentIndex * slidePercentage}%)`
86
- : `translateY(-${(currentIndex * slideStep * 100) / totalSlides}%)`,
87
- display: "flex",
88
- flexDirection: isHorizontal ? "row" : "column",
89
- width: isHorizontal ? "100%" : "100%",
90
- height: isHorizontal ? "auto" : `${totalSlides * 100}%`,
91
- transition: "transform 0.3s ease-in-out",
92
- boxSizing: "border-box",
93
- }}
94
- >
95
- {children.map((child, index) => (
96
- <Slide
97
- key={index}
98
- visibleSlides={visibleSlides}
99
- style={{
100
- flex: isHorizontal ? `0 0 ${slidePercentage}%` : "1", // Remove flex-basis for vertical slides
101
- width: isHorizontal ? `${slidePercentage}%` : "100%",
102
- height: isHorizontal ? "auto" : `${100 / totalSlides}%`,
103
- boxSizing: "border-box",
104
- margin: "0",
105
- padding: "0",
106
- }}
107
- >
108
- {child}
109
- </Slide>
110
- ))}
111
- </SlideTrack>
112
-
113
- {showArrows && (
114
- <Arrow
115
- direction={isHorizontal ? "right" : "down"}
116
- arrowStyle={arrowStyle}
117
- arrowColor={arrowColor}
118
- onClick={goToNext}
119
- >
120
- {isHorizontal ? ">" : "˅"}
121
- </Arrow>
122
- )}
123
-
124
- {showDots && (
125
- <DotsWrapper position={dotsPosition}>
126
- {Array.from({ length: numberOfDots }).map((_, index) => (
127
- <Dot
128
- key={index}
129
- active={index * slideStep === currentIndex}
130
- onClick={() => goToSlide(index * slideStep)}
131
- />
132
- ))}
133
- </DotsWrapper>
134
- )}
135
- </SliderWrapper>
136
- );
137
- };
138
-
139
- export default Slider;
@@ -1,89 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- export const SliderWrapper = styled.div<{ direction: 'horizontal' | 'vertical' }>`
4
- position: relative;
5
- width: 100%;
6
- overflow: hidden;
7
- height: ${({ direction }) => (direction === 'vertical' ? '100%' : 'auto')}; // Ensure full height for vertical sliders
8
-
9
- ${({ direction }) => direction === 'vertical' && `
10
- display: flex;
11
- flex-direction: column;
12
- `}
13
- `;
14
-
15
-
16
- export const SlideTrack = styled.div`
17
- display: flex;
18
- transition: transform 0.3s ease-in-out;
19
- `;
20
-
21
-
22
- export const Slide = styled.div<{ visibleSlides: number }>`
23
- width: 100%;
24
- height: 100%;
25
- box-sizing: border-box;
26
- margin: 0;
27
- padding: 0;
28
- `;
29
-
30
-
31
-
32
- export const DotsWrapper = styled.div<{ position: 'top' | 'bottom' | 'left' | 'right' }>`
33
- display: flex;
34
- justify-content: center;
35
- flex-direction: ${({ position }) => (position === 'left' || position === 'right' ? 'column' : 'row')};
36
- margin-top: ${({ position }) => (position === 'top' ? '10px' : '0')};
37
- margin-bottom: ${({ position }) => (position === 'bottom' ? '10px' : '0')};
38
- margin-left: ${({ position }) => (position === 'left' ? '10px' : '0')};
39
- margin-right: ${({ position }) => (position === 'right' ? '10px' : '0')};
40
- `;
41
-
42
- export const Dot = styled.div<{ active: boolean }>`
43
- width: 10px;
44
- height: 10px;
45
- border-radius: 50%;
46
- background-color: ${({ active }) => (active ? 'black' : 'lightgray')};
47
- margin: 0 5px;
48
- cursor: pointer;
49
- `;
50
- export const Arrow = styled.div<{ direction: 'left' | 'right' | 'up' | 'down', arrowStyle: 'minimal' | 'filled' | 'outlined', arrowColor: 'black' | 'white' }>`
51
- position: absolute;
52
- display: flex;
53
- align-items: center;
54
- justify-content: center;
55
- width: 40px;
56
- height: 40px;
57
- border-radius: 50%;
58
- font-size: 24px;
59
- cursor: pointer;
60
- z-index: 1;
61
- user-select: none;
62
-
63
- // Horizontal arrows
64
- ${({ direction }) => direction === 'left' && 'left: 10px; top: 50%; transform: translateY(-50%);'}
65
- ${({ direction }) => direction === 'right' && 'right: 10px; top: 50%; transform: translateY(-50%);'}
66
-
67
- // Vertical arrows
68
- ${({ direction }) => direction === 'up' && 'top: 10px; left: 50%; transform: translateX(-50%);'}
69
- ${({ direction }) => direction === 'down' && 'bottom: 10px; left: 50%; transform: translateX(-50%);'}
70
-
71
- // Minimal style: no background or border
72
- ${({ arrowStyle }) => arrowStyle === 'minimal' && `
73
- background-color: transparent;
74
- border: none;
75
- `}
76
-
77
- // Filled style: solid background and white arrow
78
- ${({ arrowStyle, arrowColor }) => arrowStyle === 'filled' && `
79
- background-color: ${arrowColor === 'white' ? 'white' : 'black'};
80
- color: ${arrowColor === 'white' ? 'black' : 'white'};
81
- `}
82
-
83
- // Outlined style: transparent background with colored border and arrow
84
- ${({ arrowStyle, arrowColor }) => arrowStyle === 'outlined' && `
85
- background-color: transparent;
86
- border: 2px solid ${arrowColor === 'white' ? 'white' : 'black'};
87
- color: ${arrowColor === 'white' ? 'white' : 'black'};
88
- `}
89
- `;
package/src/index.css DELETED
@@ -1,13 +0,0 @@
1
- body {
2
- margin: 0;
3
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
- sans-serif;
6
- -webkit-font-smoothing: antialiased;
7
- -moz-osx-font-smoothing: grayscale;
8
- }
9
-
10
- code {
11
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
- monospace;
13
- }
package/src/index.tsx DELETED
@@ -1 +0,0 @@
1
- export { default as Slider } from '../src/components/Slider';
package/src/logo.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
@@ -1 +0,0 @@
1
- /// <reference types="react-scripts" />
@@ -1,15 +0,0 @@
1
- import { ReportHandler } from 'web-vitals';
2
-
3
- const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4
- if (onPerfEntry && onPerfEntry instanceof Function) {
5
- import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6
- getCLS(onPerfEntry);
7
- getFID(onPerfEntry);
8
- getFCP(onPerfEntry);
9
- getLCP(onPerfEntry);
10
- getTTFB(onPerfEntry);
11
- });
12
- }
13
- };
14
-
15
- export default reportWebVitals;
package/src/setupTests.ts DELETED
@@ -1,5 +0,0 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom';