1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| import { useRef, useState } from 'react';
| import { useSpring, animated } from '@react-spring/web';
| import styles from '@/styles/panel.module.scss';
|
| const Panel = (props = {
| panelConfig: {},
| title: '',
| children: {},
| scale: 50
| }
| ) => {
| const cardRef = useRef(null);
| const config = {
| mass: 1,
| tension: 170,
| friction: 26,
| clamp: false,
| precision: 0.01,
| velocity: 0,
| ...props.panelConfig,
| };
|
| const calc = (x, y, rect) => [
| -(y - rect.top - rect.height / 2) / (props.scale || 50),
| (x - rect.left - rect.width / 2) / (props.scale || 50),
| 1.01,
| ];
|
| const trans = (x, y, s) => `perspective(600px) rotateX(${x}deg) rotateY(${y}deg) scale(${s})`;
|
| const [{ xys }, api] = useSpring(() => ({ xys: [0, 0, 1], config }), [config]);
|
| const handleMouseLeave = () =>
| api.start({
| xys: [0, 0, 1],
| });
|
| const handleMouseMove = (e) => {
| const rect = cardRef.current.getBoundingClientRect();
| api.start({
| xys: calc(e.clientX, e.clientY, rect),
| });
| };
|
| return (
| <div className="w-full mt-2" ref={cardRef}>
| {/* <BorderBox8 dur={12}> */}
| <div>
| <animated.div
| className={`border border-solid ${styles['animate-border-glow']} ${styles.card} `}
| style={{ transform: xys.to(trans) }}
| onMouseLeave={handleMouseLeave}
| onMouseMove={handleMouseMove}
| >
| {props.title && (
| <p className={`${styles.title} text-sm flex justify-between border-solid`}>
| {props.title} {props.right}
| </p>
| )}
| {props.children}
| </animated.div>
| </div>
| {/* </BorderBox8> */}
| </div>
| );
| }
|
| export default Panel;
|
|