react-magic-card 1.0.3 → 1.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 CHANGED
@@ -41,25 +41,27 @@ function MyComponent() {
41
41
 
42
42
  ## Common Properties
43
43
 
44
- | Property | Meaning |
45
- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
46
- | images (required) | array of images and objects containing the src and alt properties |
47
- | width (required) | width of the single image |
48
- | height (required) | height of the single image |
49
- | start (required) | index number of the array of starting scale position,An error is issued if a number outside the range of the array is entered |
50
- | controller (required) | controller size is add to the size of the component |
51
- | delay | delay of the animation firing interval |
52
- | offsetIndex | add an offset to the index of the components and images |
53
- | reverseIndex | reverse index order the default true |
54
- | className | className of the component |
55
- | classImages | className of the images |
56
- | classImageSelect | className of the select image |
57
- | classImageUnique | className of the index number is assigned to the end |
58
- | animate | object in the animation property |
59
- | initial | object in the animation property |
60
- | transition | object in the transition property |
61
- | pickTransition | object in the transition property |
62
- | pickProperty | object in the pick property |
44
+ | Property | Meaning |
45
+ | --------------------- | ----------------------------------------------------------------- |
46
+ | images (required) | array of images and objects containing the src and alt properties |
47
+ | start (required) | index number of the array of start scale position |
48
+ | width (required) | width of the single image |
49
+ | height (required) | height of the single image |
50
+ | controller (required) | controller size is add to the size of the component |
51
+ | delay | delay of the animation firing interval |
52
+ | offsetIndex | add an offset to the index of the components and images |
53
+ | reverseIndex | order the change the overlap of zindex default true |
54
+ | fadeRange | range of fade animation after page loaded |
55
+ | transTime | transition time of fade animation after page loaded |
56
+ | className | className of the component |
57
+ | classImages | className of the images |
58
+ | classImageSelect | className of the select image |
59
+ | classImageUnique | className of the index number is assigned to the end |
60
+ | animate | object in the animation property |
61
+ | initial | object in the animation property |
62
+ | transition | object in the transition property |
63
+ | pickTransition | object in the transition property |
64
+ | pickProperty | object in the pick property |
63
65
 
64
66
  ## MagicCircle Properties
65
67
 
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { MagicCircleProps } from '../types';
3
- export declare const MagicCircle: ({ images, height, width, dynamic, scrollDirection, radius, start, delay, controller, offsetIndex, reverseIndex, loading, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicCircleProps) => React.JSX.Element;
3
+ export declare const MagicCircle: ({ images, start, height, width, dynamic, scrollDirection, radius, delay, controller, offsetIndex, reverseIndex, fadeRange, transTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicCircleProps) => React.JSX.Element;
@@ -31,13 +31,17 @@ const react_1 = __importStar(require("react"));
31
31
  const framer_motion_1 = require("framer-motion");
32
32
  const styles_module_css_1 = __importDefault(require("./styles.module.css"));
33
33
  const PickImage_1 = __importDefault(require("../common/PickImage"));
34
- const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection = true, radius, start, delay = 100, controller, offsetIndex = 0, reverseIndex = true, loading, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
34
+ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirection = true, radius, delay = 100, controller, offsetIndex = 0, reverseIndex = true, fadeRange = 4, transTime = 0.2, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
35
+ // array out of range adjusting.
36
+ start = Math.max(0, start);
37
+ start = Math.min(start, images.length - 1);
35
38
  const [count, setCount] = (0, react_1.useState)(0);
36
39
  const [touchStartY, setTouchStartY] = (0, react_1.useState)(0);
37
40
  const [touchStartX, setTouchStartX] = (0, react_1.useState)(0);
38
41
  const [initialX, setInitialX] = (0, react_1.useState)(0);
39
42
  const [initialY, setInitialY] = (0, react_1.useState)(0);
40
43
  const [isDragging, setIsDragging] = (0, react_1.useState)(false);
44
+ const [hasMove, setHasMove] = (0, react_1.useState)(false);
41
45
  const [hasShift, setHasShift] = (0, react_1.useState)(false);
42
46
  const [hasDelayed, setHasDelayed] = (0, react_1.useState)(true);
43
47
  const [select, setSelect] = (0, react_1.useState)(start);
@@ -119,10 +123,12 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
119
123
  setTouchStartY(deltaY);
120
124
  }, [shiftLeft, shiftRight, touchStartX, touchStartY]);
121
125
  const handleMouseDown = (0, react_1.useCallback)((e) => {
126
+ if (hasPick)
127
+ return;
122
128
  setIsDragging(true);
123
129
  setInitialX(e.clientX);
124
130
  setInitialY(e.clientY);
125
- }, []);
131
+ }, [hasPick]);
126
132
  const handleMouseMove = (0, react_1.useCallback)((e) => {
127
133
  if (isDragging) {
128
134
  const outer = refOuter.current;
@@ -163,10 +169,12 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
163
169
  }
164
170
  setInitialX(e.clientX);
165
171
  setInitialY(e.clientY);
172
+ setHasMove(true);
166
173
  }
167
174
  }, [initialX, initialY, isDragging, shiftLeft, shiftRight]);
168
175
  const handleMouseUp = (0, react_1.useCallback)(() => {
169
176
  setIsDragging(false);
177
+ setHasMove(false);
170
178
  }, []);
171
179
  // Main functional, exit function if ref and hasDelayed does not exist.
172
180
  (0, react_1.useEffect)(() => {
@@ -259,13 +267,18 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
259
267
  e.key === 'Enter' && setHasPick(true);
260
268
  e.key === 'Escape' && setHasPick(false);
261
269
  };
270
+ // has after Lazy loading fade transition.
271
+ const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
272
+ (0, react_1.useEffect)(() => {
273
+ setIsLoaded(true);
274
+ }, []);
262
275
  return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
263
276
  react_1.default.createElement("div", { className: className },
264
277
  react_1.default.createElement(framer_motion_1.m.div, { className: styles_module_css_1.default.outer, ref: refOuter, tabIndex: offsetIndex <= 0 ? 0 : offsetIndex - 1, onKeyDown: handleKeyPress, style: {
265
278
  zIndex: offsetIndex - 1,
266
279
  width: radius * 2 + controller + 'px',
267
280
  height: radius * 2 + controller + 'px'
268
- }, animate: { rotate: count }, transition: { duration: transition === null || transition === void 0 ? void 0 : transition.duration } },
281
+ }, animate: { rotate: count }, transition: transition },
269
282
  react_1.default.createElement("div", { className: styles_module_css_1.default.inner, style: { width: radius * 2 + 'px', height: radius * 2 + 'px' } }, images.map((image, index) => {
270
283
  const hasSelect = images[select] == images[index];
271
284
  const zIndex = reverseIndex
@@ -276,7 +289,7 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
276
289
  (hasSelect && classImageSelect) +
277
290
  ' ' +
278
291
  classImageUnique +
279
- zIndex, src: image.src, alt: image.alt, role: "button", draggable: false, loading: loading, animate: {
292
+ zIndex, role: 'button', src: image.src, alt: image.alt, draggable: false, loading: 'lazy', animate: {
280
293
  rotate: -count,
281
294
  scale: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectScale : animate === null || animate === void 0 ? void 0 : animate.scale,
282
295
  rotateY: hasSelect
@@ -308,10 +321,7 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
308
321
  opacity: hasSelect
309
322
  ? initial === null || initial === void 0 ? void 0 : initial.selectOpacity
310
323
  : initial === null || initial === void 0 ? void 0 : initial.opacity
311
- }, transition: transition, onMouseDown: () => {
312
- setSelect(index);
313
- hasSelect && pickScale && !isDragging && setHasPick(true);
314
- }, style: {
324
+ }, transition: transition, onMouseDown: () => setSelect(index), onPointerDown: () => setSelect(index), onClick: () => hasSelect && pickScale && !hasMove && setHasPick(true), style: {
315
325
  zIndex: hasSelect ? frontImage : zIndex,
316
326
  width: width + 'px',
317
327
  height: height + 'px',
@@ -322,7 +332,9 @@ const MagicCircle = ({ images, height, width, dynamic = true, scrollDirection =
322
332
  top: radius * Math.sin(index * angle) +
323
333
  radius -
324
334
  height / 2 +
325
- 'px'
335
+ 'px',
336
+ filter: isLoaded ? 'blur(0)' : `blur(${fadeRange}px)`,
337
+ transition: `filter ${transTime}s ease-in-out`
326
338
  } }));
327
339
  }))),
328
340
  react_1.default.createElement(PickImage_1.default, { onClick: () => {
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { MagicStraightProps } from '../types';
3
- export declare const MagicStraight: ({ images, height, width, vertical, margin, selectOffsetX, selectOffsetY, start, controller, delay, offsetIndex, reverseIndex, loading, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicStraightProps) => React.JSX.Element;
3
+ export declare const MagicStraight: ({ images, start, height, width, vertical, margin, selectOffsetX, selectOffsetY, controller, delay, offsetIndex, reverseIndex, fadeRange, transTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicStraightProps) => React.JSX.Element;
@@ -31,7 +31,10 @@ const react_1 = __importStar(require("react"));
31
31
  const framer_motion_1 = require("framer-motion");
32
32
  const styles_module_css_1 = __importDefault(require("./styles.module.css"));
33
33
  const PickImage_1 = __importDefault(require("../common/PickImage"));
34
- const MagicStraight = ({ images, height, width, vertical = true, margin = 0, selectOffsetX = 0, selectOffsetY = 0, start, controller, delay = 20, offsetIndex = 0, reverseIndex = true, loading, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
34
+ const MagicStraight = ({ images, start, height, width, vertical = true, margin = 0, selectOffsetX = 0, selectOffsetY = 0, controller, delay = 20, offsetIndex = 0, reverseIndex = true, fadeRange = 4, transTime = 0.2, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
35
+ // array out of range adjusting.
36
+ start = Math.max(0, start);
37
+ start = Math.min(start, images.length - 1);
35
38
  const [touchStartY, setTouchStartY] = (0, react_1.useState)(0);
36
39
  const [touchStartX, setTouchStartX] = (0, react_1.useState)(0);
37
40
  const [initialX, setInitialX] = (0, react_1.useState)(0);
@@ -208,6 +211,11 @@ const MagicStraight = ({ images, height, width, vertical = true, margin = 0, sel
208
211
  e.key === 'Enter' && setHasPick(true);
209
212
  e.key === 'Escape' && setHasPick(false);
210
213
  };
214
+ // has after Lazy loading fade transition.
215
+ const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
216
+ (0, react_1.useEffect)(() => {
217
+ setIsLoaded(true);
218
+ }, []);
211
219
  return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
212
220
  react_1.default.createElement("div", { className: className },
213
221
  react_1.default.createElement("div", { className: styles_module_css_1.default.outer, ref: refOuter, tabIndex: offsetIndex <= 0 ? 0 : offsetIndex - 1, onKeyDown: handleKeyPress, style: {
@@ -229,7 +237,7 @@ const MagicStraight = ({ images, height, width, vertical = true, margin = 0, sel
229
237
  (hasSelect && classImageSelect) +
230
238
  ' ' +
231
239
  classImageUnique +
232
- index, src: image.src, alt: image.alt, role: "button", draggable: false, loading: loading, animate: {
240
+ index, src: image.src, alt: image.alt, role: 'button', draggable: false, loading: 'lazy', animate: {
233
241
  y: hasSelect
234
242
  ? vertical
235
243
  ? (average - index) * height +
@@ -278,7 +286,11 @@ const MagicStraight = ({ images, height, width, vertical = true, margin = 0, sel
278
286
  zIndex: hasSelect ? frontImage : zIndex,
279
287
  width: width + 'px',
280
288
  height: height + 'px',
281
- margin: vertical ? margin + 'px' + ' 0' : '0 ' + margin + 'px'
289
+ margin: vertical
290
+ ? margin + 'px' + ' 0'
291
+ : '0 ' + margin + 'px',
292
+ filter: isLoaded ? 'blur(0)' : `blur(${fadeRange}px)`,
293
+ transition: `filter ${transTime}s ease-in-out`
282
294
  } }));
283
295
  })),
284
296
  react_1.default.createElement(PickImage_1.default, { classPick: pickProperty === null || pickProperty === void 0 ? void 0 : pickProperty.classPick, argRef: refPicker, onClick: () => {
package/dist/types.d.ts CHANGED
@@ -40,14 +40,15 @@ type PickProperty = {
40
40
  };
41
41
  type CommonProperty = {
42
42
  images: ImageProperty[];
43
+ start: number;
43
44
  height: number;
44
45
  width: number;
45
- start: number;
46
46
  controller: number;
47
47
  delay: number;
48
48
  offsetIndex?: number;
49
49
  reverseIndex?: boolean;
50
- loading?: 'eager' | 'lazy';
50
+ fadeRange: number;
51
+ transTime: number;
51
52
  className?: string;
52
53
  classImages?: string;
53
54
  classImageSelect?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-magic-card",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "React Component library for images gallery using the framer motion animation.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",