react-fancy-circular-carousel 0.0.1

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.
@@ -0,0 +1,58 @@
1
+ .fancy-carousel-wrapper-element {
2
+ background-color: transparent;
3
+ }
4
+
5
+ .fancy-carousel-border {
6
+ background-color: transparent;
7
+ z-index: 5;
8
+ }
9
+
10
+ .fancy-carousel {
11
+ position: relative;
12
+ width: 800px;
13
+ height: 800px;
14
+ border-radius: 50%;
15
+ transition: 0.5s;
16
+ transform-origin: center center;
17
+ background-color: transparent;
18
+ }
19
+
20
+ .fancy-carousel-navigators {
21
+ z-index: 1;
22
+ display: flex;
23
+ bottom: 0;
24
+ left: 0;
25
+ background: transparent;
26
+ }
27
+
28
+ .fancy-carousel-navigation-button {
29
+ color: white;
30
+ border-radius: 50%;
31
+ outline: none;
32
+ border: none;
33
+ }
34
+
35
+ .fancy-carousel-navigation-button:hover {
36
+ outline: none;
37
+ border: none;
38
+ cursor: pointer;
39
+ }
40
+
41
+ .fancy-carousel-element {
42
+ position: absolute;
43
+ background: transparent;
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
+ margin: 2px;
48
+ bottom: 0;
49
+ transition: 0.5s;
50
+ }
51
+
52
+ .fancy-carousel-image, .fancy-carousel-central-image, .fancy-carousel-element {
53
+ border-radius: 50%;
54
+ }
55
+
56
+ .invisible {
57
+ display: none;
58
+ }
@@ -0,0 +1,24 @@
1
+ import { FC, CSSProperties } from 'react';
2
+ interface CarouselInfo {
3
+ images?: string[];
4
+ setFocusElement?: Function;
5
+ offsetAngle?: number;
6
+ carouselRadius?: number;
7
+ centralImageRadius?: number;
8
+ centralImageBoxShadow?: string;
9
+ peripheralImageRadius?: number;
10
+ peripheralImageBoxShadow?: string;
11
+ focusElementStyling?: CSSProperties;
12
+ border?: boolean;
13
+ borderWidth?: number;
14
+ borderHexColor?: string;
15
+ autoRotateTime?: number;
16
+ transitionTime?: number;
17
+ navigationTextSize?: number;
18
+ navigationButtonRadius?: number;
19
+ navigationButtonBgColor?: string;
20
+ navigationButtonColor?: string;
21
+ navigationButtonStyling?: CSSProperties;
22
+ }
23
+ export declare const FancyCarousel: FC<CarouselInfo>;
24
+ export {};
@@ -0,0 +1,91 @@
1
+ import React, { useState } from 'react';
2
+ //importing images
3
+ import image1 from './assets/greatwall.webp';
4
+ import image2 from './assets/pyramid.webp';
5
+ import image3 from './assets/petra.webp';
6
+ import image4 from './assets/machupicchu.webp';
7
+ import image5 from './assets/christ.webp';
8
+ import image6 from './assets/colosseum.webp';
9
+ import image7 from './assets/tajmahal.webp';
10
+ export const FancyCarousel = ({ images = [image1, image2, image3, image4, image5, image6, image7], setFocusElement = () => { }, offsetAngle = 0, carouselRadius = 400, centralImageRadius = 125, centralImageBoxShadow = '5px 10px 18px #888888', peripheralImageRadius = 75, peripheralImageBoxShadow = '5px 10px 18px #888888', focusElementStyling = {}, border = true, borderWidth = 5, borderHexColor = 'CB786C', autoRotateTime = 0, transitionTime = 1.5, navigationTextSize = 2, navigationButtonRadius = 32.5, navigationButtonBgColor = 'CB786C', navigationButtonColor = 'FFFFFF', navigationButtonStyling = {} }) => {
11
+ const [carousel, setCarousel] = useState({
12
+ carouselOrietation: 0,
13
+ elementOrientation: 0,
14
+ focusElement: 0
15
+ });
16
+ setFocusElement(carousel.focusElement);
17
+ if (autoRotateTime) {
18
+ setTimeout(() => {
19
+ rotateRight();
20
+ }, autoRotateTime * 1000);
21
+ }
22
+ const noOfImages = images.length;
23
+ const theta = 360 / noOfImages;
24
+ const borderElement = (border) ? `url("data:image/svg+xml,%3csvg width=\'100%25\' height=\'100%25\' xmlns=\'http://www.w3.org/2000/svg\'%3e%3crect width=\'100%25\' height=\'100%25\' fill=\'none\' rx=\'${carouselRadius * 2}\' ry=\'${carouselRadius * 2}\' stroke=\'%23${borderHexColor}FF\' stroke-width=\'${borderWidth}\' stroke-dasharray=\'6%2c 24\' stroke-dashoffset=\'0\' stroke-linecap=\'square\'/%3e%3c/svg%3e")` : '';
25
+ const rotateRight = () => {
26
+ setCarousel({
27
+ carouselOrietation: carousel.carouselOrietation + theta,
28
+ elementOrientation: carousel.elementOrientation - theta,
29
+ focusElement: (carousel.focusElement < (noOfImages - 1)) ? carousel.focusElement + 1 : 0
30
+ });
31
+ };
32
+ const rotateLeft = () => {
33
+ setCarousel({
34
+ carouselOrietation: carousel.carouselOrietation - theta,
35
+ elementOrientation: carousel.elementOrientation + theta,
36
+ focusElement: (carousel.focusElement > 0) ? carousel.focusElement - 1 : noOfImages - 1
37
+ });
38
+ };
39
+ var newCoordinates = [];
40
+ images.forEach((item, index) => {
41
+ newCoordinates.push([carouselRadius - peripheralImageRadius + carouselRadius * Math.cos(2 * Math.PI * index / noOfImages), carouselRadius - peripheralImageRadius + carouselRadius * Math.sin(2 * Math.PI * index / noOfImages)]);
42
+ });
43
+ // rotate point around (carouselRadius-peripheralRadius, carouselRadius-peripheralRadius) by (offset+90) deg
44
+ const totalDeviation = offsetAngle * Math.PI / 180 + Math.PI / 2;
45
+ var rotatedCoordinates = [];
46
+ const centerCoordinate = carouselRadius - peripheralImageRadius;
47
+ newCoordinates.forEach((item, index) => {
48
+ rotatedCoordinates.push([centerCoordinate + (item[0] - centerCoordinate) * Math.cos(totalDeviation) - (item[1] - centerCoordinate) * Math.sin(totalDeviation), centerCoordinate + (item[0] - centerCoordinate) * Math.sin(totalDeviation) + (item[1] - centerCoordinate) * Math.cos(totalDeviation)]);
49
+ });
50
+ return (React.createElement("div", { className: "fancy-carousel-wrapper-element" },
51
+ React.createElement("div", { className: "fancy-carousel-border", style: { backgroundImage: borderElement, height: `${carouselRadius * 2}px`, width: `${carouselRadius * 2}px`, transition: `${transitionTime}` } },
52
+ React.createElement("div", { className: "fancy-carousel", style: {
53
+ transform: `rotate(${carousel.carouselOrietation}deg)`,
54
+ height: `${carouselRadius * 2}px`, width: `${carouselRadius * 2}px`
55
+ } },
56
+ images.map((item, index) => ((index !== carousel.focusElement) ?
57
+ React.createElement("div", { className: "fancy-carousel-element", key: index, style: {
58
+ transform: `rotate(${carousel.elementOrientation}deg)`, width: `${peripheralImageRadius * 2}px`, height: `${peripheralImageRadius * 2}px`,
59
+ left: `${rotatedCoordinates[index][0]}px`,
60
+ bottom: `${rotatedCoordinates[index][1]}px`,
61
+ boxShadow: `${peripheralImageBoxShadow}`,
62
+ transition: `${transitionTime}`
63
+ } },
64
+ React.createElement("img", { className: "fancy-carousel-image", src: item, style: { width: `${peripheralImageRadius * 2}px`, height: `${peripheralImageRadius * 2}px` } })) :
65
+ React.createElement("div", { className: "fancy-carousel-element", key: index, style: Object.assign({
66
+ transform: `rotate(${carousel.elementOrientation}deg)`, width: `${peripheralImageRadius * 2}px`, height: `${peripheralImageRadius * 2}px`,
67
+ left: `${rotatedCoordinates[index][0]}px`,
68
+ bottom: `${rotatedCoordinates[index][1]}px`,
69
+ boxShadow: `${peripheralImageBoxShadow}`,
70
+ transition: `${transitionTime}`
71
+ }, focusElementStyling) },
72
+ React.createElement("img", { className: "fancy-carousel-image", src: item, style: { width: `${peripheralImageRadius * 2}px`, height: `${peripheralImageRadius * 2}px`, transition: `${transitionTime}` } })))),
73
+ React.createElement("div", { className: "fancy-carousel-element central-img", key: noOfImages, style: {
74
+ transform: `rotate(${carousel.elementOrientation}deg)`, width: `${centralImageRadius * 2}px`, height: `${centralImageRadius * 2}px`,
75
+ left: `${carouselRadius - centralImageRadius - 10}px`, bottom: `${carouselRadius - centralImageRadius - 10}px`,
76
+ boxShadow: `${centralImageBoxShadow}`,
77
+ transition: `${transitionTime}`
78
+ } },
79
+ React.createElement("img", { className: "fancy-carousel-central-image", src: images[carousel.focusElement], style: { width: `${centralImageRadius * 2}px`, height: `${centralImageRadius * 2}px`, transition: `${transitionTime}` } })))),
80
+ React.createElement("div", { className: "fancy-carousel-navigators " + ((autoRotateTime) ? "invisible" : ""), style: { gap: `${carouselRadius * 2}px`, marginLeft: `-${navigationButtonRadius * 1.8}px` } },
81
+ React.createElement("button", { className: "fancy-carousel-navigation-button", onClick: rotateLeft, style: Object.assign({
82
+ width: `${navigationButtonRadius * 2}px`, height: `${navigationButtonRadius * 2}px`,
83
+ backgroundColor: `#${navigationButtonBgColor}`, color: `#${navigationButtonColor}`,
84
+ fontSize: `${navigationTextSize}rem`
85
+ }, navigationButtonStyling) }, "\u2193"),
86
+ React.createElement("button", { className: "fancy-carousel-navigation-button", onClick: rotateRight, style: Object.assign({
87
+ width: `${navigationButtonRadius * 2}px`, height: `${navigationButtonRadius * 2}px`,
88
+ backgroundColor: `#${navigationButtonBgColor}`, color: `#${navigationButtonColor}`,
89
+ fontSize: `${navigationTextSize}rem`
90
+ }, navigationButtonStyling) }, "\u2193"))));
91
+ };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Ninad Sutrave
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ <div align="center"><p align="center"><a href="https://www.npmjs.com/package/react-fancy-circular-carousel"><img src="./assets/React.webp" alt="React Logo - Carousel UI Component" width="140px" /></a></p></div>
2
+
3
+ <h1 align="center">React Fancy Image Carousel</h1>
4
+
5
+ ## Features
6
+
7
+ - Circular image carousel
8
+ - Everything you see is customisable
9
+ - Get focus element to add in your own components
10
+ - Smooth, easy to implement, fantastic UI
11
+
12
+ ## Install
13
+
14
+ $ npm install react-fancy-circular-carousel
15
+
16
+ Include the styles by importing node_modules/react-fancy-circular-carousel/FancyCarousel.css
17
+
18
+ ```jsx
19
+ import '../node_modules/react-fancy-circular-carousel/FancyCarousel.css';
20
+ ```
21
+
22
+ ## Quickstart
23
+
24
+ #### Parameters
25
+
26
+ | **Parameter** | **Type** | **Description** |
27
+ |:---|:---|:---|
28
+ | images | String[] | `optional` List of image sources |
29
+ | setFocusElement | Function | `optional` SetState method to get focus element in parent component |
30
+ | offsetAngle | Number | `optional` Angle in degrees to offset the carousel elements |
31
+ | carouselRadius | Number | `optional` Carousel radius in px |
32
+ | centralImageRadius | Number | `optional` Central image radius in px |
33
+ | centralImageBoxShadow | String | `optional` Central image box shadow property |
34
+ | peripheralImageRadius | Number | `optional` Peripheral Image radius in px |
35
+ | peripheralImageBoxShadow | String | `optional` Peripheral image box shadow property |
36
+ | focusElementStyling | React.CSSProperties | `optional` Custom styling for the element in focus |
37
+ | border | Boolean | `optional` Enable/disable bordering |
38
+ | borderWidth | Number | `optional` Border stroke width property in px |
39
+ | borderHexColor | String | `optional` Border hex color as a string excluding the '#' |
40
+ | autoRotateTime | Number | `optional` Time in seconds for an auto rotating carousel |
41
+ | transitionTime | Number | `optional` Time in seconds for the rotating transition |
42
+ | navigationTextSize | Number | `optional` ↓ Arrow font size in rem |
43
+ | navigationButtonRadius | Number | `optional` Navigation button radius in px |
44
+ | navigationButtonColor | String | `optional` ↓ Arrow hex color as a string excluding the '#' |
45
+ | navigationButtonBgColor | String | `optional` Navigation button hex color as a string excluding the '#' |
46
+ | navigationButtonStyling | React.CSSProperties | `optional` Custom styling for navigation buttons |
47
+
48
+
49
+ ```jsx
50
+ import React from "react";
51
+
52
+ import FancyCarousel from "react-fancy-circular-carousel";
53
+ import '../node_modules/react-fancy-circular-carousel/FancyCarousel.css';
54
+
55
+ import image1 from './assets/image1.png';
56
+ import image2 from './assets/image2.png';
57
+ import image3 from './assets/image3.png';
58
+ import image4 from './assets/image4.png';
59
+
60
+
61
+ const YourComponent = () => (
62
+
63
+ const imageSourcesUrl = [image1, image2, image3, image4];
64
+
65
+ return <div className="carousel">
66
+ <FancyCarousel images={imageSourcesUrl} />
67
+ </div>
68
+ );
69
+
70
+ export default YourComponent;
71
+ ```
72
+
73
+ #### Retrieve focus element
74
+
75
+ Utility using which one can know which element is currently at focus and may add relevant components around it.
76
+ For eg. if the carousel portrays images of cities, this feature may help you update the description in the information box along side the carousel.
77
+
78
+ ```jsx
79
+ import React, { useState } from "react";
80
+
81
+ import FancyCarousel from "react-fancy-circular-carousel";
82
+ import '../node_modules/react-fancy-circular-carousel/FancyCarousel.css';
83
+
84
+ import image1 from './assets/image1.png';
85
+ import image2 from './assets/image2.png';
86
+ import image3 from './assets/image3.png';
87
+ import image4 from './assets/image4.png';
88
+
89
+ const YourComponent = () => (
90
+
91
+ // the focus element would be the array index of the currently image at focus
92
+ const [focusElement, setFocusElement] = useState(0);
93
+
94
+ const imageSourcesUrl = [image1, image2, image3, image4];
95
+ const info = ['Delhi', 'Mumbai', 'Bengaluru', 'Kolkata'];
96
+
97
+ return <div className="carousel">
98
+ <FancyCarousel images={imageSourcesUrl} />
99
+ <div className="info-box-wrapper">
100
+ <p> {info[focusElement]} </p>
101
+ </div>
102
+ <div>
103
+ );
104
+
105
+ export default YourComponent;
106
+ ```
107
+
108
+ #### Customisations
109
+
110
+ Customise the carousel to your needs such as modifying the carousel size, image size, adding styling such as drop shadow, adding auto rotate, etc
111
+ The focusElementStyling and navigationButtonStyling props are of type React.CSSProperties, which is essentially a JavaScript object containing camelcased CSS properties and their corresponding values.
112
+
113
+ To know more check the official documentation [here](https://legacy.reactjs.org/docs/dom-elements.html#style).
114
+
115
+ ```jsx
116
+ import React from "react";
117
+
118
+ import FancyCarousel from "react-fancy-circular-carousel";
119
+ import '../node_modules/react-fancy-circular-carousel/FancyCarousel.css';
120
+
121
+ import image1 from './assets/image1.png';
122
+ import image2 from './assets/image2.png';
123
+ import image3 from './assets/image3.png';
124
+ import image4 from './assets/image4.png';
125
+
126
+ const YourComponent = () => (
127
+
128
+ const imageSourcesUrl = [image1, image2, image3, image4];
129
+
130
+ return <div className="carousel">
131
+ <FancyCarousel
132
+ images={imageSourcesUrl}
133
+ carouselRadius={400}
134
+ peripheralImageRadius={100}
135
+ centralImageRadius={200}
136
+ focusElementStyling={{border: '2px solid #ba4949'}}
137
+ autoRotateTime={3}
138
+ borderWidth={4}
139
+ borderHexColor={'1c364f'}
140
+ />
141
+ </div>
142
+ );
143
+
144
+ export default YourComponent;
145
+ ```
146
+
147
+ ## Preview
148
+
149
+ ![Preview Image](assets/preview1.png)
150
+
151
+ ![Preview Gif](assets/preview2.gif)
152
+
153
+ ## NPM Module
154
+
155
+ [Npm Page](https://www.npmjs.com/package/react-fancy-circular-carousel)
156
+ Try it out for yourselves and ⭐ this repo if you like it!
157
+
158
+ ## License
159
+
160
+ MIT © [Ninad Sutrave](https://ninadsutrave.in)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { FancyCarousel } from './FancyCarousel';
2
+ export default FancyCarousel;
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { FancyCarousel } from './FancyCarousel';
2
+ export default FancyCarousel;
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "react-fancy-circular-carousel",
3
+ "version": "0.0.1",
4
+ "description": "Interactive circular carousel with image elements highly customisable as per the developer's needs",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "clean": "rm -rf dist",
8
+ "build": "npm run clean && tsc && cp package.json README.md ./dist"
9
+ },
10
+ "keywords": ["react", "slider", "carousel", "image-slider"],
11
+ "author": {
12
+ "name": "Ninad Sutrave",
13
+ "email": "ninadsutrave@gmail.com",
14
+ "url": "https://ninadsutrave.in"
15
+ },
16
+ "repo": "https://github.com/ninadsutrave/react-fancy-circular-carousel",
17
+ "license": "MIT",
18
+ "devDependencies": {
19
+ "@types/react": "^18.0.28",
20
+ "react": "^18.2.0",
21
+ "react-dom": "^18.2.0",
22
+ "typescript": "^5.0.2"
23
+ }
24
+ }