-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolbar.tsx
More file actions
89 lines (84 loc) · 2.56 KB
/
Toolbar.tsx
File metadata and controls
89 lines (84 loc) · 2.56 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"use client";
import { useState } from "react";
import { motion } from "framer-motion";
import classNames from "classnames";
import { MENU_OPTIONS } from "./constants";
const ACTIVE_BUTTON_CLASSES = "text-black dark:text-white";
const BUTTON_CLASSES =
"h-10 px-3.5 py-1.5 text-xs md:text-sm relative dark:text-white";
const SPRING_ANIMATION_TRANSITION = {
type: "spring",
stiffness: 300,
damping: 35,
};
const TWEEN_ANIMATION_TRANSITION = {
type: "tween",
duration: 0.1,
};
export const Toolbar = () => {
const [activeIndex, setActiveIndex] = useState(0);
return (
<div className="relative flex gap-2">
{MENU_OPTIONS.map((item, index) => (
<motion.button
key={item}
className={classNames(
BUTTON_CLASSES,
"relative z-10",
activeIndex === index ? ACTIVE_BUTTON_CLASSES : ""
)}
onClick={() => setActiveIndex(index)}
>
{item}
{activeIndex === index && (
<motion.div
layoutId="activeBackground"
className="absolute inset-0 bg-gray-800/10 dark:bg-white/10 rounded-md z-0"
initial={false}
transition={SPRING_ANIMATION_TRANSITION}
/>
)}
</motion.button>
))}
</div>
);
};
export const Toolbar2 = () => {
const [activeIndex, setActiveIndex] = useState(0);
const [hoveredIndex, setHoveredIndex] = useState(-1);
return (
<div className="relative flex gap-2">
{MENU_OPTIONS.map((item, index) => (
<motion.button
key={index}
className={classNames(
BUTTON_CLASSES,
"relative z-10",
hoveredIndex === index ? ACTIVE_BUTTON_CLASSES : ""
)}
onMouseEnter={() => setHoveredIndex(index)}
onMouseLeave={() => setHoveredIndex(-1)}
onClick={() => setActiveIndex(index)}
>
{item}
{hoveredIndex === index && (
<motion.div
layoutId="hoveredBg"
className="absolute inset-0 bg-gray-800/10 dark:bg-white/10 rounded-md z-0"
initial={false}
transition={SPRING_ANIMATION_TRANSITION}
/>
)}
{activeIndex === index && (
<motion.div
layoutId="activeBg"
className="absolute bottom-0 left-0 right-0 h-0.5 bg-gray-950 dark:bg-white rounded-md"
initial={false}
transition={TWEEN_ANIMATION_TRANSITION}
></motion.div>
)}
</motion.button>
))}
</div>
);
};