-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFloatingButton.tsx
More file actions
63 lines (59 loc) · 1.5 KB
/
FloatingButton.tsx
File metadata and controls
63 lines (59 loc) · 1.5 KB
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
import React from "react";
interface FloatingButtonProps {
onClick: () => void;
children: React.ReactNode;
position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
offset?: { x: number; y: number };
backgroundColor?: string;
color?: string;
zIndex?: number;
}
const FloatingButton: React.FC<FloatingButtonProps> = ({
onClick,
children,
position = "top-right",
offset = { x: 20, y: 20 },
backgroundColor = "oklch(40% 0.2 250)",
color = "white",
zIndex = 1000,
}) => {
const getPositionStyles = () => {
switch (position) {
case "top-left":
return { top: offset.y, left: offset.x };
case "bottom-right":
return { bottom: offset.y, right: offset.x };
case "bottom-left":
return { bottom: offset.y, left: offset.x };
default:
return { top: offset.y, right: offset.x };
}
};
return (
<button
onClick={onClick}
style={{
position: "fixed",
...getPositionStyles(),
zIndex,
padding: "8px 16px",
background: backgroundColor,
color,
border: "none",
borderRadius: "4px",
cursor: "pointer",
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.3)",
transition: "all 0.2s ease",
}}
onMouseEnter={(e) => {
e.currentTarget.style.transform = "scale(1.05)";
}}
onMouseLeave={(e) => {
e.currentTarget.style.transform = "scale(1)";
}}
>
{children}
</button>
);
};
export default FloatingButton;