CardAuth

A component of a bank card whit aniamtions.

Usage

logo

YourBank

John Doe

12/12

1234 5678 91 23 9876

PaypassMasterCard
Card design
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
69
70
71
72
73
74
75
76
77
78
79
80
81
"use client";
import { useState, useEffect } from "react";
import Image from "next/image";

const CardAuth = () => {
  const mockCardNumber = "1234 5678 9123 9876";
  const mockUserName = "John Doe";
  const mockExpirationDate = "12/12";

  const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
  const [isMounted, setIsMounted] = useState(false);

  useEffect(() => {
    setIsMounted(true);

    const handleMouseMove = (event: MouseEvent) => {
      setMousePosition({ x: event.clientX, y: event.clientY });
    };

    window.addEventListener("mousemove", handleMouseMove);

    return () => {
      window.removeEventListener("mousemove", handleMouseMove);
    };
  }, []);

  const rotationX = isMounted ? (mousePosition.y / window.innerHeight - 0.5) * 50 : 0;
  const rotationY = isMounted ? (mousePosition.x / window.innerWidth - 0.5) * -50 : 0;

  return (
    <div className="flex flex-col justify-center items-center">
      <div
        className="bank-card"
        style={{
          transform: `rotateX(${rotationX}deg) rotateY(${rotationY}deg)`,
        }}
      >
        <div className="bank-card_content">
          <Image src="/icons/logo_white.svg" width={30} height={30} alt="logo" />
          <h1 className="text-16 font-semibold text-white">YourBank</h1>

          <article className="flex flex-col gap-2">
            <div className="flex justify-between">
              <h1 className="text-12 font-semibold text-white">{mockUserName}</h1>
              <h2 className="text-12 font-semibold text-white">{mockExpirationDate}</h2>
            </div>
            <p className="text-14 font-semibold tracking-[1.1px] text-white">
              {mockCardNumber.slice(0, 4)} {mockCardNumber.slice(5, 9)} {mockCardNumber.slice(10, 12)} {mockCardNumber.slice(12)}
            </p>
          </article>
        </div>

        <div className="bank-card_icon">
          <Image 
            src="/icons/Paypass.svg"
            width={20}
            height={24}
            alt="Paypass"
          />
          <Image 
            src="/icons/mastercard.svg"
            width={45}
            height={32}
            alt="MasterCard"
            className="ml-5"
          />
        </div>

        <Image 
          src="/icons/Lines.svg"
          width={316}
          height={190}
          alt="Card design"
          className="absolute top-0 left-0"
        />
      </div>
    </div>
  );
};

export default CardAuth;