-
Notifications
You must be signed in to change notification settings - Fork 95
/
keyboard.json
21 lines (21 loc) · 2.4 KB
/
keyboard.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"name": "keyboard",
"type": "registry:ui",
"registryDependencies": [],
"dependencies": [
"motion"
],
"devDependencies": [],
"tailwind": {},
"cssVars": {
"light": {},
"dark": {}
},
"files": [
{
"path": "keyboard.tsx",
"content": "'use client';\n\nimport { AnimatePresence, motion, useAnimation } from 'motion/react';\nimport { useEffect, useState } from 'react';\n\nconst keyboardPaths = [\n { id: 'key1', d: 'M10 8h.01' },\n { id: 'key2', d: 'M12 12h.01' },\n { id: 'key3', d: 'M14 8h.01' },\n { id: 'key4', d: 'M16 12h.01' },\n { id: 'key5', d: 'M18 8h.01' },\n { id: 'key6', d: 'M6 8h.01' },\n { id: 'key7', d: 'M7 16h10' },\n { id: 'key8', d: 'M8 12h.01' },\n];\n\nconst KeyboardIcon = () => {\n const [isHovered, setIsHovered] = useState(false);\n const controls = useAnimation();\n\n useEffect(() => {\n const animateKeys = async () => {\n if (isHovered) {\n await controls.start((i) => ({\n opacity: [1, 0.2, 1],\n transition: {\n duration: 1.5,\n times: [0, 0.5, 1],\n delay: i * 0.2 * Math.random(),\n repeat: Infinity,\n repeatType: 'reverse',\n },\n }));\n } else {\n controls.stop();\n controls.set({ opacity: 1 });\n }\n };\n\n animateKeys();\n }, [isHovered, controls]);\n\n return (\n <motion.div\n className=\"cursor-pointer select-none p-2 hover:bg-accent rounded-md transition-colors duration-200 flex items-center justify-center\"\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"28\"\n height=\"28\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <rect width=\"20\" height=\"16\" x=\"2\" y=\"4\" rx=\"2\" />\n <AnimatePresence>\n {keyboardPaths.map((path, index) => (\n <motion.path\n key={path.id}\n d={path.d}\n initial={{ opacity: 1 }}\n animate={controls}\n custom={index}\n />\n ))}\n </AnimatePresence>\n </svg>\n </motion.div>\n );\n};\n\nexport { KeyboardIcon };\n",
"type": "registry:ui"
}
]
}