react-magic-card 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.
- package/dist/MagicCircle/index.d.ts +51 -0
- package/dist/MagicCircle/index.js +132 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/license +21 -0
- package/package.json +32 -0
- package/readme.md +97 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './main.css';
|
|
3
|
+
type ImageProperty = {
|
|
4
|
+
src: string;
|
|
5
|
+
alt: string;
|
|
6
|
+
};
|
|
7
|
+
type AnimationProperty = {
|
|
8
|
+
scale?: number;
|
|
9
|
+
opacity?: number;
|
|
10
|
+
rotateY?: number;
|
|
11
|
+
rotateX?: number;
|
|
12
|
+
rotateZ?: number;
|
|
13
|
+
selectScale?: number;
|
|
14
|
+
selectOpacity?: number;
|
|
15
|
+
selectRotateY?: number;
|
|
16
|
+
selectRotateX?: number;
|
|
17
|
+
selectRotateZ?: number;
|
|
18
|
+
};
|
|
19
|
+
type TransitionProperty = {
|
|
20
|
+
duration?: number;
|
|
21
|
+
type: undefined;
|
|
22
|
+
ease: number[] | 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'circIn' | 'circOut' | 'circInOut' | 'backIn' | 'backOut' | 'backInOut' | 'anticipate';
|
|
23
|
+
} | {
|
|
24
|
+
duration?: number;
|
|
25
|
+
type?: 'spring';
|
|
26
|
+
bounce?: number;
|
|
27
|
+
damping?: number;
|
|
28
|
+
mass?: number;
|
|
29
|
+
stiffness?: number;
|
|
30
|
+
velocity?: number;
|
|
31
|
+
restSpeed?: number;
|
|
32
|
+
restDelta?: number;
|
|
33
|
+
};
|
|
34
|
+
type MagicCircleProps = {
|
|
35
|
+
data: ImageProperty[];
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
radius: number;
|
|
39
|
+
controller: number;
|
|
40
|
+
start: number;
|
|
41
|
+
dynamic: boolean;
|
|
42
|
+
wheelDelay: number;
|
|
43
|
+
animate?: AnimationProperty;
|
|
44
|
+
initial?: AnimationProperty;
|
|
45
|
+
transition?: TransitionProperty;
|
|
46
|
+
className?: string;
|
|
47
|
+
classImage?: string;
|
|
48
|
+
classImageUnique?: string;
|
|
49
|
+
};
|
|
50
|
+
export declare const MagicCircle: ({ data, width, height, radius, controller, start, dynamic, wheelDelay, animate, initial, transition, className, classImage, classImageUnique }: MagicCircleProps) => React.JSX.Element;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MagicCircle = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const framer_motion_1 = require("framer-motion");
|
|
29
|
+
require("./main.css");
|
|
30
|
+
const MagicCircle = ({ data, width, height, radius, controller, start, dynamic, wheelDelay, animate, initial, transition, className, classImage, classImageUnique }) => {
|
|
31
|
+
const [count, setCount] = (0, react_1.useState)(0);
|
|
32
|
+
const [hasDelayed, setHasDelayed] = (0, react_1.useState)(true);
|
|
33
|
+
const [images, setImages] = (0, react_1.useState)(data);
|
|
34
|
+
const [select, setSelect] = (0, react_1.useState)(start);
|
|
35
|
+
const ref = (0, react_1.useRef)(null);
|
|
36
|
+
const shiftRight = (0, react_1.useCallback)(() => {
|
|
37
|
+
setImages(arr => {
|
|
38
|
+
const lastElement = arr.pop();
|
|
39
|
+
arr.unshift(lastElement);
|
|
40
|
+
setSelect(select == images.length - 1 ? 0 : select + 1);
|
|
41
|
+
return arr;
|
|
42
|
+
});
|
|
43
|
+
}, [images.length, select]);
|
|
44
|
+
const shiftLeft = (0, react_1.useCallback)(() => {
|
|
45
|
+
setImages(arr => {
|
|
46
|
+
const firstElement = arr.shift();
|
|
47
|
+
arr.push(firstElement);
|
|
48
|
+
setSelect(select == 0 ? images.length - 1 : select - 1);
|
|
49
|
+
return arr;
|
|
50
|
+
});
|
|
51
|
+
}, [images.length, select]);
|
|
52
|
+
const centralAngle = ((2 * Math.PI) / images.length) * (180 / Math.PI);
|
|
53
|
+
const controlRotation = (0, react_1.useCallback)((e) => {
|
|
54
|
+
const delta = e.deltaY;
|
|
55
|
+
if (delta > 0) {
|
|
56
|
+
setHasDelayed(false);
|
|
57
|
+
for (let i = 0; i < images.length; i++)
|
|
58
|
+
shiftRight();
|
|
59
|
+
if (dynamic)
|
|
60
|
+
return setCount(count - centralAngle);
|
|
61
|
+
}
|
|
62
|
+
if (delta < 0) {
|
|
63
|
+
setHasDelayed(false);
|
|
64
|
+
for (let i = 0; i < images.length; i++)
|
|
65
|
+
shiftLeft();
|
|
66
|
+
if (dynamic)
|
|
67
|
+
return setCount(count + centralAngle);
|
|
68
|
+
}
|
|
69
|
+
}, [dynamic, count, centralAngle, images.length, shiftRight, shiftLeft]);
|
|
70
|
+
(0, react_1.useEffect)(() => {
|
|
71
|
+
const range = ref.current;
|
|
72
|
+
const timeId = setTimeout(() => {
|
|
73
|
+
setHasDelayed(true);
|
|
74
|
+
}, wheelDelay);
|
|
75
|
+
if (!range || !hasDelayed)
|
|
76
|
+
return;
|
|
77
|
+
range.addEventListener('wheel', controlRotation, { passive: false });
|
|
78
|
+
return () => {
|
|
79
|
+
range.removeEventListener('wheel', controlRotation);
|
|
80
|
+
clearTimeout(timeId);
|
|
81
|
+
};
|
|
82
|
+
}, [count, hasDelayed, controlRotation, wheelDelay]);
|
|
83
|
+
const enterControll = () => {
|
|
84
|
+
document.body.style.overflow = 'hidden';
|
|
85
|
+
};
|
|
86
|
+
const leaveControll = () => {
|
|
87
|
+
document.body.style.overflow = 'auto';
|
|
88
|
+
};
|
|
89
|
+
(0, react_1.useEffect)(() => {
|
|
90
|
+
const range = ref.current;
|
|
91
|
+
if (!range)
|
|
92
|
+
return;
|
|
93
|
+
range.addEventListener('mouseover', enterControll);
|
|
94
|
+
range.addEventListener('mouseout', leaveControll);
|
|
95
|
+
range.addEventListener('touchmove', leaveControll, { passive: false });
|
|
96
|
+
return () => {
|
|
97
|
+
range.removeEventListener('mouseover', enterControll);
|
|
98
|
+
range.removeEventListener('mouseout', leaveControll);
|
|
99
|
+
range.removeEventListener('touchmove', leaveControll);
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
// angle between images.
|
|
103
|
+
const angle = parseFloat((2 * Math.PI).toFixed(15)) / data.length;
|
|
104
|
+
return (react_1.default.createElement(framer_motion_1.m.div, { ref: ref, className: className + ' ' + 'outer', style: {
|
|
105
|
+
width: radius * 2 + controller + 'px',
|
|
106
|
+
height: radius * 2 + controller + 'px'
|
|
107
|
+
}, animate: { rotate: count }, transition: { duration: transition === null || transition === void 0 ? void 0 : transition.duration } },
|
|
108
|
+
react_1.default.createElement("div", { className: "inner", style: { width: radius * 2 + 'px', height: radius * 2 + 'px' } }, images.map((image, index) => {
|
|
109
|
+
const hasSelect = images[select] == images[index];
|
|
110
|
+
return (react_1.default.createElement(framer_motion_1.m.img, { key: index, animate: {
|
|
111
|
+
scale: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectScale : animate === null || animate === void 0 ? void 0 : animate.scale,
|
|
112
|
+
opacity: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectOpacity : animate === null || animate === void 0 ? void 0 : animate.opacity,
|
|
113
|
+
rotateX: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectRotateX : animate === null || animate === void 0 ? void 0 : animate.rotateX,
|
|
114
|
+
rotateY: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectRotateY : animate === null || animate === void 0 ? void 0 : animate.rotateY,
|
|
115
|
+
rotateZ: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectRotateZ : animate === null || animate === void 0 ? void 0 : animate.rotateZ,
|
|
116
|
+
rotate: -count
|
|
117
|
+
}, initial: {
|
|
118
|
+
scale: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectScale : initial === null || initial === void 0 ? void 0 : initial.scale,
|
|
119
|
+
opacity: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectOpacity : initial === null || initial === void 0 ? void 0 : initial.opacity,
|
|
120
|
+
rotateX: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectRotateX : initial === null || initial === void 0 ? void 0 : initial.rotateX,
|
|
121
|
+
rotateY: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectRotateY : initial === null || initial === void 0 ? void 0 : initial.rotateY,
|
|
122
|
+
rotateZ: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectRotateZ : initial === null || initial === void 0 ? void 0 : initial.rotateZ,
|
|
123
|
+
rotate: -count
|
|
124
|
+
}, transition: transition, onClick: () => setSelect(index), className: classImage + ' ' + classImageUnique + index, src: image.src, alt: image.alt, style: {
|
|
125
|
+
width: width + 'px',
|
|
126
|
+
height: height + 'px',
|
|
127
|
+
left: radius * Math.cos(index * angle) + radius - width / 2 + 'px',
|
|
128
|
+
top: radius * Math.sin(index * angle) + radius - height / 2 + 'px'
|
|
129
|
+
} }));
|
|
130
|
+
}))));
|
|
131
|
+
};
|
|
132
|
+
exports.MagicCircle = MagicCircle;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MagicCircle = void 0;
|
|
4
|
+
const MagicCircle_1 = require("./MagicCircle");
|
|
5
|
+
Object.defineProperty(exports, "MagicCircle", { enumerable: true, get: function () { return MagicCircle_1.MagicCircle; } });
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 S.Watanabe
|
|
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/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-magic-card",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "animation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/su-pull/react-magic-card",
|
|
10
|
+
"directory": "react-magic-card/src"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"tsc": "./node_modules/.bin/tsc",
|
|
14
|
+
"test": "test"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"illust",
|
|
19
|
+
"photograph",
|
|
20
|
+
"animation"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"framer-motion": "^10.12.16",
|
|
25
|
+
"react": "^18.2.0",
|
|
26
|
+
"react-dom": "^18.2.0",
|
|
27
|
+
"typescript": "^5.1.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^18.2.12"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# react-magic-card
|
|
2
|
+
|
|
3
|
+
[](https://github.com/su-pull/react-magic-card/releases/latest)
|
|
4
|
+
[](https://bundlephobia.com/package/react-magic-card)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
This is the framer motion component, that supports illust and photograph galleries.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install react-magic-card framer-motion
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { MagicCircle } from "react-magic-card";
|
|
19
|
+
|
|
20
|
+
function MyComponent() {
|
|
21
|
+
const images = [
|
|
22
|
+
{
|
|
23
|
+
src: "/1.jpeg",
|
|
24
|
+
alt: "1image",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
src: "/2.jpeg",
|
|
28
|
+
alt: "2image",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
src: "/3.jpeg",
|
|
32
|
+
alt: "3image",
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<MagicCircle
|
|
38
|
+
data={images}
|
|
39
|
+
width={120}
|
|
40
|
+
height={120}
|
|
41
|
+
radius={100}
|
|
42
|
+
controller={200}
|
|
43
|
+
start={1}
|
|
44
|
+
dynamic={true}
|
|
45
|
+
wheelDelay={100}
|
|
46
|
+
animate={{
|
|
47
|
+
scale: 0.8,
|
|
48
|
+
rotateX: 70,
|
|
49
|
+
rotateY: 40,
|
|
50
|
+
rotateZ: -50,
|
|
51
|
+
selectScale: 1.6,
|
|
52
|
+
selectRotateX: 40,
|
|
53
|
+
selectRotateY: 40,
|
|
54
|
+
selectRotateZ: -10,
|
|
55
|
+
}}
|
|
56
|
+
transition={{ duration: 0.2 }}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Properties
|
|
63
|
+
|
|
64
|
+
- data: An array a images property objects for src and alt.
|
|
65
|
+
- width: The width of single image.
|
|
66
|
+
- height: The height a single image.
|
|
67
|
+
- dynamic: A flag indicating whether dynamic rotation is allow.
|
|
68
|
+
- start: The Index number, start scale position
|
|
69
|
+
- radius: The radius of the circle.
|
|
70
|
+
- controller: The diameter plus the value of the controller is the size of the controller.
|
|
71
|
+
- className: The class name of the component.
|
|
72
|
+
- classImage: The class name of the images.
|
|
73
|
+
- classImageUnique: An index number is assigned to the end of the class name set for this.
|
|
74
|
+
- animate: An object in the animation property.
|
|
75
|
+
- initial: An object in the animation property.
|
|
76
|
+
- transition: An object in the transition property.
|
|
77
|
+
|
|
78
|
+
## Animation property
|
|
79
|
+
|
|
80
|
+
- scale
|
|
81
|
+
- opacity
|
|
82
|
+
- rotateX
|
|
83
|
+
- rotateY
|
|
84
|
+
- rotateZ
|
|
85
|
+
- selectScale
|
|
86
|
+
- selectOpacity
|
|
87
|
+
- selectRotateY
|
|
88
|
+
- selectRotateX
|
|
89
|
+
- selectRotateZ
|
|
90
|
+
|
|
91
|
+
## Transition property
|
|
92
|
+
|
|
93
|
+
It Inherits framer motion transition properties other than intera.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT License
|