-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlipCard.tsx
84 lines (74 loc) · 2.53 KB
/
FlipCard.tsx
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
82
83
84
import React, { useRef } from 'react'
import { Button, Card, Typography } from "antd"
import { CSSProperties, ReactElement, useState } from "react"
import { BsInfoCircle, BsInfoCircleFill } from "react-icons/bs"
import { cardStyles } from "../../utils/cardStyles";
const { Text } = Typography;
interface FlipCardProps {
title?:string|ReactElement
children:ReactElement | ReactElement[]
information?:ReactElement|string
}
/**
* Une card qui peux se retourner et afficher des informations a son verso
*/
const FlipCard: React.FC<FlipCardProps> = ({ title, information, children }) => {
const [flipped, setFlipped] = useState(false);
const toggleFlipped = () => setFlipped(!flipped);
const cardARef = useRef<HTMLDivElement>(null);
const height = cardARef.current ? cardARef.current.clientHeight : undefined; // Forcer la hauteur à celle de la card "Recto"
const FlipCardStyle: CSSProperties = {
position: "absolute",
transition: "transform 0.8s",
backfaceVisibility: "hidden",
width: "100%",
};
const titleElement: ReactElement = (
<span style={{ marginLeft: 5 }}>
{title}{" "}
{information && ( //Affichage du bouton "i" s'il y a une description
<Button
type="text"
onClick={toggleFlipped}
shape="circle"
style={{ position: "absolute", right: 0, top: 0 }}
aria-label="info"
>
{flipped ? <BsInfoCircleFill /> : <BsInfoCircle />}
</Button>
)}
</span>
);
return (
<div style={{ position: "relative", height: height }}>
<Card
title={titleElement}
style={{ transform: flipped ? "rotateY(180deg)" : "", ...FlipCardStyle }}
styles={cardStyles} //Default g2f-dashboard style (header & body)
ref={cardARef}
>
{children}
</Card>
<Card
title={titleElement}
style={{
transform: !flipped ? "rotateY(180deg)" : "",
height: height ,
overflow:"auto",
...FlipCardStyle}}
styles={cardStyles} //Default g2f-dashboard style (header & body)
>
{typeof information === "string" ? (
<div style={{ margin: 10 }}>
<Text italic type="secondary">
{information}
</Text>
</div>
) : (
<>{information}</>
)}
</Card>
</div>
);
};
export default FlipCard;