react-styled-slider-component 0.1.0
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 +74 -0
- package/dist/App.d.ts +3 -0
- package/dist/App.js +17 -0
- package/dist/App.test.d.ts +1 -0
- package/dist/App.test.js +8 -0
- package/dist/components/Slider.d.ts +14 -0
- package/dist/components/Slider.js +59 -0
- package/dist/components/SliderStyles.styles.d.ts +19 -0
- package/dist/components/SliderStyles.styles.js +57 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/reportWebVitals.d.ts +3 -0
- package/dist/reportWebVitals.js +13 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +5 -0
- package/package.json +66 -0
- package/src/App.css +0 -0
- package/src/App.test.tsx +9 -0
- package/src/App.tsx +29 -0
- package/src/components/Slider.tsx +139 -0
- package/src/components/SliderStyles.styles.ts +89 -0
- package/src/index.css +13 -0
- package/src/index.tsx +1 -0
- package/src/logo.svg +1 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/setupTests.ts +5 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# React Styled Slider Component
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the package, use npm or yarn:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install react-styled-slider-component
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Here's how to use the slider component in your React application:
|
|
16
|
+
|
|
17
|
+
```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;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Props
|
|
50
|
+
|
|
51
|
+
The `Slider` component accepts the following props:
|
|
52
|
+
|
|
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. |
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## Customization
|
|
67
|
+
|
|
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.
|
|
69
|
+
|
|
70
|
+
## Contributing
|
|
71
|
+
|
|
72
|
+
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
|
|
73
|
+
|
|
74
|
+
|
package/dist/App.d.ts
ADDED
package/dist/App.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 Slider from './components/Slider';
|
|
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" }))] })) }));
|
|
16
|
+
};
|
|
17
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/App.test.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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();
|
|
8
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface SliderProps {
|
|
3
|
+
children: React.ReactNode[];
|
|
4
|
+
visibleSlides?: number;
|
|
5
|
+
showDots?: boolean;
|
|
6
|
+
showArrows?: boolean;
|
|
7
|
+
dotsPosition?: "top" | "bottom" | "left" | "right";
|
|
8
|
+
slideStep?: number;
|
|
9
|
+
direction?: "horizontal" | "vertical";
|
|
10
|
+
arrowStyle?: "minimal" | "filled" | "outlined";
|
|
11
|
+
arrowColor?: "black" | "white";
|
|
12
|
+
}
|
|
13
|
+
declare const Slider: React.FC<SliderProps>;
|
|
14
|
+
export default Slider;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { useState } from "react";
|
|
14
|
+
import { SliderWrapper, SlideTrack, Slide, DotsWrapper, Dot, Arrow, } from "./SliderStyles.styles";
|
|
15
|
+
var Slider = function (_a) {
|
|
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
|
+
var _k = useState(0), currentIndex = _k[0], setCurrentIndex = _k[1];
|
|
18
|
+
var totalSlides = children.length;
|
|
19
|
+
// Maximum index value, preventing overflow when navigating through slides.
|
|
20
|
+
var maxIndex = totalSlides - visibleSlides;
|
|
21
|
+
// Calculate the number of dots based on the total number of slides and the number of visible slides.
|
|
22
|
+
var numberOfDots = Math.ceil((totalSlides - visibleSlides + 1) / slideStep);
|
|
23
|
+
var isHorizontal = direction === "horizontal";
|
|
24
|
+
var goToNext = function () {
|
|
25
|
+
setCurrentIndex(function (prevIndex) { return Math.min(prevIndex + slideStep, maxIndex); });
|
|
26
|
+
};
|
|
27
|
+
var goToPrev = function () {
|
|
28
|
+
setCurrentIndex(function (prevIndex) { return Math.max(prevIndex - slideStep, 0); });
|
|
29
|
+
};
|
|
30
|
+
var goToSlide = function (index) {
|
|
31
|
+
setCurrentIndex(index);
|
|
32
|
+
};
|
|
33
|
+
var slidePercentage = isHorizontal
|
|
34
|
+
? 100 / visibleSlides
|
|
35
|
+
: 100 / totalSlides;
|
|
36
|
+
return (_jsxs(SliderWrapper, __assign({ direction: direction, style: {
|
|
37
|
+
height: isHorizontal ? "auto" : "".concat(visibleSlides * 200, "px"),
|
|
38
|
+
display: isHorizontal ? "block" : "flex",
|
|
39
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
40
|
+
} }, { children: [showArrows && (_jsx(Arrow, __assign({ direction: isHorizontal ? "left" : "up", arrowStyle: arrowStyle, arrowColor: arrowColor, onClick: goToPrev }, { children: isHorizontal ? "<" : "˄" }))), _jsx(SlideTrack, __assign({ style: {
|
|
41
|
+
transform: isHorizontal
|
|
42
|
+
? "translateX(-".concat(currentIndex * slidePercentage, "%)")
|
|
43
|
+
: "translateY(-".concat((currentIndex * slideStep * 100) / totalSlides, "%)"),
|
|
44
|
+
display: "flex",
|
|
45
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
46
|
+
width: isHorizontal ? "100%" : "100%",
|
|
47
|
+
height: isHorizontal ? "auto" : "".concat(totalSlides * 100, "%"),
|
|
48
|
+
transition: "transform 0.3s ease-in-out",
|
|
49
|
+
boxSizing: "border-box",
|
|
50
|
+
} }, { children: children.map(function (child, index) { return (_jsx(Slide, __assign({ visibleSlides: visibleSlides, style: {
|
|
51
|
+
flex: isHorizontal ? "0 0 ".concat(slidePercentage, "%") : "1",
|
|
52
|
+
width: isHorizontal ? "".concat(slidePercentage, "%") : "100%",
|
|
53
|
+
height: isHorizontal ? "auto" : "".concat(100 / totalSlides, "%"),
|
|
54
|
+
boxSizing: "border-box",
|
|
55
|
+
margin: "0",
|
|
56
|
+
padding: "0",
|
|
57
|
+
} }, { children: child }), index)); }) })), showArrows && (_jsx(Arrow, __assign({ direction: isHorizontal ? "right" : "down", arrowStyle: arrowStyle, arrowColor: arrowColor, onClick: goToNext }, { children: isHorizontal ? ">" : "˅" }))), showDots && (_jsx(DotsWrapper, __assign({ position: dotsPosition }, { children: Array.from({ length: numberOfDots }).map(function (_, index) { return (_jsx(Dot, { active: index * slideStep === currentIndex, onClick: function () { return goToSlide(index * slideStep); } }, index)); }) })))] })));
|
|
58
|
+
};
|
|
59
|
+
export default Slider;
|
|
@@ -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';
|
|
18
|
+
arrowColor: 'black' | 'white';
|
|
19
|
+
}>> & string;
|
|
@@ -0,0 +1,57 @@
|
|
|
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: ", "; // Ensure full height for vertical sliders\n\n ", "\n"], ["\n position: relative;\n width: 100%;\n overflow: hidden;\n height: ", "; // Ensure full height for vertical sliders\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"], ["\n display: flex;\n transition: transform 0.3s ease-in-out;\n"])));
|
|
14
|
+
export var Slide = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n margin: 0; \n padding: 0; \n"], ["\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n margin: 0; \n padding: 0; \n"])));
|
|
15
|
+
export var DotsWrapper = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n justify-content: center;\n flex-direction: ", ";\n margin-top: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n margin-right: ", ";\n"], ["\n display: flex;\n justify-content: center;\n flex-direction: ", ";\n margin-top: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n margin-right: ", ";\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' ? '10px' : '0');
|
|
21
|
+
}, function (_a) {
|
|
22
|
+
var position = _a.position;
|
|
23
|
+
return (position === 'bottom' ? '10px' : '0');
|
|
24
|
+
}, function (_a) {
|
|
25
|
+
var position = _a.position;
|
|
26
|
+
return (position === 'left' ? '10px' : '0');
|
|
27
|
+
}, function (_a) {
|
|
28
|
+
var position = _a.position;
|
|
29
|
+
return (position === 'right' ? '10px' : '0');
|
|
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: 0 5px;\n cursor: pointer;\n"], ["\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background-color: ", ";\n margin: 0 5px;\n cursor: pointer;\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 width: 40px;\n height: 40px;\n border-radius: 50%;\n font-size: 24px;\n cursor: pointer;\n z-index: 1;\n user-select: none;\n\n // Horizontal arrows\n ", "\n ", "\n\n // Vertical arrows\n ", "\n ", "\n\n // Minimal style: no background or border\n ", "\n\n // Filled style: solid background and white arrow\n ", "\n\n // Outlined style: transparent background with colored border and arrow\n ", "\n"], ["\n position: absolute;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n border-radius: 50%;\n font-size: 24px;\n cursor: pointer;\n z-index: 1;\n user-select: none;\n\n // Horizontal arrows\n ", "\n ", "\n\n // Vertical arrows\n ", "\n ", "\n\n // Minimal style: no background or border\n ", "\n\n // Filled style: solid background and white arrow\n ", "\n\n // Outlined style: transparent background with colored border and arrow\n ", "\n"])), function (_a) {
|
|
36
|
+
var direction = _a.direction;
|
|
37
|
+
return direction === 'left' && 'left: 10px; top: 50%; transform: translateY(-50%);';
|
|
38
|
+
}, function (_a) {
|
|
39
|
+
var direction = _a.direction;
|
|
40
|
+
return direction === 'right' && 'right: 10px; top: 50%; transform: translateY(-50%);';
|
|
41
|
+
}, function (_a) {
|
|
42
|
+
var direction = _a.direction;
|
|
43
|
+
return direction === 'up' && 'top: 10px; left: 50%; transform: translateX(-50%);';
|
|
44
|
+
}, function (_a) {
|
|
45
|
+
var direction = _a.direction;
|
|
46
|
+
return direction === 'down' && 'bottom: 10px; left: 50%; transform: translateX(-50%);';
|
|
47
|
+
}, function (_a) {
|
|
48
|
+
var arrowStyle = _a.arrowStyle;
|
|
49
|
+
return arrowStyle === 'minimal' && "\n background-color: transparent;\n border: none;\n ";
|
|
50
|
+
}, function (_a) {
|
|
51
|
+
var arrowStyle = _a.arrowStyle, arrowColor = _a.arrowColor;
|
|
52
|
+
return arrowStyle === 'filled' && "\n background-color: ".concat(arrowColor === 'white' ? 'white' : 'black', ";\n color: ").concat(arrowColor === 'white' ? 'black' : 'white', ";\n ");
|
|
53
|
+
}, function (_a) {
|
|
54
|
+
var arrowStyle = _a.arrowStyle, arrowColor = _a.arrowColor;
|
|
55
|
+
return arrowStyle === 'outlined' && "\n background-color: transparent;\n border: 2px solid ".concat(arrowColor === 'white' ? 'white' : 'black', ";\n color: ").concat(arrowColor === 'white' ? 'white' : 'black', ";\n ");
|
|
56
|
+
});
|
|
57
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Slider } from '../src/components/Slider';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Slider } from '../src/components/Slider';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var reportWebVitals = function (onPerfEntry) {
|
|
2
|
+
if (onPerfEntry && onPerfEntry instanceof Function) {
|
|
3
|
+
import('web-vitals').then(function (_a) {
|
|
4
|
+
var getCLS = _a.getCLS, getFID = _a.getFID, getFCP = _a.getFCP, getLCP = _a.getLCP, getTTFB = _a.getTTFB;
|
|
5
|
+
getCLS(onPerfEntry);
|
|
6
|
+
getFID(onPerfEntry);
|
|
7
|
+
getFCP(onPerfEntry);
|
|
8
|
+
getLCP(onPerfEntry);
|
|
9
|
+
getTTFB(onPerfEntry);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default reportWebVitals;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-styled-slider-component",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A customizable React slider component built with react ts and styled-components.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "react-scripts start",
|
|
8
|
+
"build": "react-scripts build",
|
|
9
|
+
"test": "react-scripts test",
|
|
10
|
+
"eject": "react-scripts eject",
|
|
11
|
+
"prepublishOnly": "npm run build && tsc"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"slider",
|
|
16
|
+
"styled-components",
|
|
17
|
+
"typescript",
|
|
18
|
+
"component"
|
|
19
|
+
],
|
|
20
|
+
"author": "Ceyda Ulubas",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/ceydaulubas/slider.git"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
32
|
+
"@testing-library/react": "^13.4.0",
|
|
33
|
+
"@testing-library/user-event": "^13.5.0",
|
|
34
|
+
"@types/jest": "^27.5.2",
|
|
35
|
+
"@types/node": "^16.18.107",
|
|
36
|
+
"@types/react": "^18.3.5",
|
|
37
|
+
"@types/react-dom": "^18.3.0",
|
|
38
|
+
"react": "^18.3.1",
|
|
39
|
+
"react-dom": "^18.3.1",
|
|
40
|
+
"react-scripts": "5.0.1",
|
|
41
|
+
"styled-components": "^6.1.13",
|
|
42
|
+
"typescript": "^4.9.5",
|
|
43
|
+
"web-vitals": "^2.1.4"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"typescript": "^4.9.5"
|
|
47
|
+
},
|
|
48
|
+
"eslintConfig": {
|
|
49
|
+
"extends": [
|
|
50
|
+
"react-app",
|
|
51
|
+
"react-app/jest"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"browserslist": {
|
|
55
|
+
"production": [
|
|
56
|
+
">0.2%",
|
|
57
|
+
"not dead",
|
|
58
|
+
"not op_mini all"
|
|
59
|
+
],
|
|
60
|
+
"development": [
|
|
61
|
+
"last 1 chrome version",
|
|
62
|
+
"last 1 firefox version",
|
|
63
|
+
"last 1 safari version"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/App.css
ADDED
|
File without changes
|
package/src/App.test.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -0,0 +1,139 @@
|
|
|
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;
|
|
@@ -0,0 +1,89 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Slider } from '../src/components/Slider';
|
package/src/logo.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
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>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="react-scripts" />
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|