react-magic-card 1.0.4 → 1.1.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/README.md CHANGED
@@ -50,7 +50,10 @@ function MyComponent() {
50
50
  | controller (required) | controller size is add to the size of the component |
51
51
  | delay | delay of the animation firing interval |
52
52
  | offsetIndex | add an offset to the index of the components and images |
53
- | reverseIndex | reverse index order the default true |
53
+ | reverseIndex | order the change the overlap of zindex default true |
54
+ | loading | loading attribute of img element in html |
55
+ | initialFadeRange | range of fade animation after page loaded |
56
+ | initialTransTime | transition time of fade animation after page loaded |
54
57
  | className | className of the component |
55
58
  | classImages | className of the images |
56
59
  | classImageSelect | className of the select image |
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { MagicCircleProps } from '../types';
3
- export declare const MagicCircle: ({ images, start, height, width, dynamic, scrollDirection, radius, 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, loading, initialFadeRange, initialTransTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicCircleProps) => React.JSX.Element;
@@ -31,7 +31,7 @@ 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, start, height, width, dynamic = true, scrollDirection = true, radius, 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, loading, initialFadeRange = 4, initialTransTime = 0.2, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
35
35
  // array out of range adjusting.
36
36
  start = Math.max(0, start);
37
37
  start = Math.min(start, images.length - 1);
@@ -267,13 +267,18 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
267
267
  e.key === 'Enter' && setHasPick(true);
268
268
  e.key === 'Escape' && setHasPick(false);
269
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
+ }, []);
270
275
  return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
271
276
  react_1.default.createElement("div", { className: className },
272
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: {
273
278
  zIndex: offsetIndex - 1,
274
279
  width: radius * 2 + controller + 'px',
275
280
  height: radius * 2 + controller + 'px'
276
- }, animate: { rotate: count }, transition: { duration: transition === null || transition === void 0 ? void 0 : transition.duration } },
281
+ }, animate: { rotate: count }, transition: transition },
277
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) => {
278
283
  const hasSelect = images[select] == images[index];
279
284
  const zIndex = reverseIndex
@@ -284,7 +289,7 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
284
289
  (hasSelect && classImageSelect) +
285
290
  ' ' +
286
291
  classImageUnique +
287
- 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: loading, animate: {
288
293
  rotate: -count,
289
294
  scale: hasSelect ? animate === null || animate === void 0 ? void 0 : animate.selectScale : animate === null || animate === void 0 ? void 0 : animate.scale,
290
295
  rotateY: hasSelect
@@ -316,7 +321,7 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
316
321
  opacity: hasSelect
317
322
  ? initial === null || initial === void 0 ? void 0 : initial.selectOpacity
318
323
  : initial === null || initial === void 0 ? void 0 : initial.opacity
319
- }, transition: transition, onMouseDown: () => setSelect(index), onClick: () => hasSelect && pickScale && !hasMove && setHasPick(true), style: {
324
+ }, transition: transition, onPointerDown: () => setSelect(index), onClick: () => hasSelect && pickScale && !hasMove && setHasPick(true), style: {
320
325
  zIndex: hasSelect ? frontImage : zIndex,
321
326
  width: width + 'px',
322
327
  height: height + 'px',
@@ -327,7 +332,11 @@ const MagicCircle = ({ images, start, height, width, dynamic = true, scrollDirec
327
332
  top: radius * Math.sin(index * angle) +
328
333
  radius -
329
334
  height / 2 +
330
- 'px'
335
+ 'px',
336
+ filter: isLoaded
337
+ ? 'blur(0)'
338
+ : `blur(${initialFadeRange}px)`,
339
+ transition: `filter ${initialTransTime}s ease-in-out`
331
340
  } }));
332
341
  }))),
333
342
  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, start, height, width, vertical, margin, selectOffsetX, selectOffsetY, 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, loading, initialFadeRange, initialTransTime, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale, pickProperty, pickTransition }: MagicStraightProps) => React.JSX.Element;
@@ -31,7 +31,7 @@ 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, start, height, width, vertical = true, margin = 0, selectOffsetX = 0, selectOffsetY = 0, 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, loading, initialFadeRange = 4, initialTransTime = 0.2, className, classImages, classImageSelect, classImageUnique, animate, initial, transition, pickScale = true, pickProperty, pickTransition }) => {
35
35
  // array out of range adjusting.
36
36
  start = Math.max(0, start);
37
37
  start = Math.min(start, images.length - 1);
@@ -40,6 +40,7 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
40
40
  const [initialX, setInitialX] = (0, react_1.useState)(0);
41
41
  const [initialY, setInitialY] = (0, react_1.useState)(0);
42
42
  const [isDragging, setIsDragging] = (0, react_1.useState)(false);
43
+ const [hasMove, setHasMove] = (0, react_1.useState)(false);
43
44
  const [hasShift, setHasShift] = (0, react_1.useState)(false);
44
45
  const [hasDelayed, setHasDelayed] = (0, react_1.useState)(true);
45
46
  const [select, setSelect] = (0, react_1.useState)(start);
@@ -113,10 +114,12 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
113
114
  if (!vertical ? deltaX > 0 : deltaY > 0)
114
115
  shiftRight();
115
116
  !vertical ? setInitialX(e.clientX) : setInitialY(e.clientY);
117
+ setHasMove(true);
116
118
  }
117
119
  }, [initialX, initialY, isDragging, shiftLeft, shiftRight, vertical]);
118
120
  const handleMouseUp = (0, react_1.useCallback)(() => {
119
121
  setIsDragging(false);
122
+ setHasMove(false);
120
123
  }, []);
121
124
  // Main functional, exit function if ref and hasDelayed does not exist.
122
125
  (0, react_1.useEffect)(() => {
@@ -211,6 +214,11 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
211
214
  e.key === 'Enter' && setHasPick(true);
212
215
  e.key === 'Escape' && setHasPick(false);
213
216
  };
217
+ // has after Lazy loading fade transition.
218
+ const [isLoaded, setIsLoaded] = (0, react_1.useState)(false);
219
+ (0, react_1.useEffect)(() => {
220
+ setIsLoaded(true);
221
+ }, []);
214
222
  return (react_1.default.createElement(framer_motion_1.LazyMotion, { features: framer_motion_1.domAnimation },
215
223
  react_1.default.createElement("div", { className: className },
216
224
  react_1.default.createElement("div", { className: styles_module_css_1.default.outer, ref: refOuter, tabIndex: offsetIndex <= 0 ? 0 : offsetIndex - 1, onKeyDown: handleKeyPress, style: {
@@ -232,7 +240,7 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
232
240
  (hasSelect && classImageSelect) +
233
241
  ' ' +
234
242
  classImageUnique +
235
- index, src: image.src, alt: image.alt, role: "button", draggable: false, loading: loading, animate: {
243
+ index, src: image.src, alt: image.alt, role: 'button', draggable: false, loading: loading, animate: {
236
244
  y: hasSelect
237
245
  ? vertical
238
246
  ? (average - index) * height +
@@ -276,12 +284,16 @@ const MagicStraight = ({ images, start, height, width, vertical = true, margin =
276
284
  opacity: hasSelect ? initial === null || initial === void 0 ? void 0 : initial.selectOpacity : initial === null || initial === void 0 ? void 0 : initial.opacity
277
285
  }, transition: transition, onClick: () => {
278
286
  setSelect(index);
279
- hasSelect && pickScale && !isDragging && setHasPick(true);
287
+ hasSelect && pickScale && !hasMove && setHasPick(true);
280
288
  }, style: {
281
289
  zIndex: hasSelect ? frontImage : zIndex,
282
290
  width: width + 'px',
283
291
  height: height + 'px',
284
- margin: vertical ? margin + 'px' + ' 0' : '0 ' + margin + 'px'
292
+ margin: vertical
293
+ ? margin + 'px' + ' 0'
294
+ : '0 ' + margin + 'px',
295
+ filter: isLoaded ? 'blur(0)' : `blur(${initialFadeRange}px)`,
296
+ transition: `filter ${initialTransTime}s ease-in-out`
285
297
  } }));
286
298
  })),
287
299
  react_1.default.createElement(PickImage_1.default, { classPick: pickProperty === null || pickProperty === void 0 ? void 0 : pickProperty.classPick, argRef: refPicker, onClick: () => {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const framer_motion_1 = require("framer-motion");
8
8
  const styles_module_css_1 = __importDefault(require("./styles.module.css"));
9
- const PickImage = ({ onClick, classPick, hasPick, hasShift, argRef, argKey, src, alt, width, height, zIndex, white = true, alpha = 0.4, blur = 4, scale = 2, offset = 200, transition }) => {
9
+ const PickImage = ({ onClick, classPick, hasPick, hasShift, argRef, argKey, src, alt, width, height, zIndex, white = true, alpha = 0.4, blur = 4, scale = 2, offset = 0, transition }) => {
10
10
  const backdropFilter = hasPick ? `blur(${blur}px)` : undefined;
11
11
  const background = hasPick
12
12
  ? white
package/dist/types.d.ts CHANGED
@@ -41,13 +41,15 @@ type PickProperty = {
41
41
  type CommonProperty = {
42
42
  images: ImageProperty[];
43
43
  start: number;
44
+ loading?: 'eager' | 'lazy';
44
45
  height: number;
45
46
  width: number;
46
47
  controller: number;
47
48
  delay: number;
48
49
  offsetIndex?: number;
49
50
  reverseIndex?: boolean;
50
- loading?: 'eager' | 'lazy';
51
+ initialFadeRange: number;
52
+ initialTransTime: number;
51
53
  className?: string;
52
54
  classImages?: string;
53
55
  classImageSelect?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-magic-card",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
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",