Skip to content

Commit 98545e5

Browse files
committed
✨ added Eco Mode Button
1 parent 559387f commit 98545e5

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const metadata = {
2+
title: 'Eco Mode Button',
3+
description:
4+
'A button that toggles between eco mode on and off. Built with Framer Motion and Tailwind CSS for projects using React or Next.js.',
5+
}
6+
7+
<BackButton href="/components/button" />
8+
9+
<ComponentPreview path="components/button/EcoModeButton" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use client'
2+
3+
import { motion, useAnimation } from 'framer-motion'
4+
import { Leaf } from 'lucide-react'
5+
import { useState } from 'react'
6+
7+
const EcoModeButton = () => {
8+
const [isActivated, setIsActivated] = useState(false)
9+
const leafControls = useAnimation()
10+
11+
const handleClick = async () => {
12+
setIsActivated(!isActivated)
13+
await leafControls.start({
14+
scale: [1, 1.2, 1],
15+
rotate: [0, 10, -10, 0],
16+
transition: { duration: 0.5 },
17+
})
18+
}
19+
20+
return (
21+
<motion.button
22+
className="relative overflow-hidden rounded-full bg-red-500 px-4 py-3 text-sm font-medium text-white"
23+
onClick={handleClick}
24+
whileTap={{ scale: 0.95 }}
25+
>
26+
<motion.div
27+
className="absolute inset-0 bg-green-600"
28+
initial={{ scaleX: 0 }}
29+
animate={{ scaleX: isActivated ? 1 : 0 }}
30+
transition={{ duration: 0.5 }}
31+
style={{ transformOrigin: 'left' }}
32+
/>
33+
<motion.div className="relative z-10 flex items-center justify-center space-x-1">
34+
<Leaf size={16} />
35+
<span>{isActivated ? 'Eco Mode On' : 'Eco Mode Off'}</span>
36+
</motion.div>
37+
{isActivated && (
38+
<motion.div
39+
className="absolute inset-0 flex items-center justify-center"
40+
initial={{ opacity: 0 }}
41+
animate={{ opacity: 1 }}
42+
transition={{ delay: 0.2 }}
43+
>
44+
{[...Array(20)].map((_, i) => (
45+
<motion.div
46+
key={i}
47+
className="absolute h-1 w-1 rounded-full bg-green-200"
48+
style={{
49+
top: Math.random() * 100 + '%',
50+
left: Math.random() * 100 + '%',
51+
}}
52+
animate={{
53+
y: [0, -20, 0],
54+
opacity: [0, 1, 0],
55+
}}
56+
transition={{
57+
duration: Math.random() * 2 + 1,
58+
repeat: Infinity,
59+
delay: Math.random() * 2,
60+
}}
61+
/>
62+
))}
63+
</motion.div>
64+
)}
65+
</motion.button>
66+
)
67+
}
68+
69+
export default EcoModeButton

src/showcase/ui-group/ButtonCards.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import MagneticButton from '../components/button/MagneticButton'
1212
import StarWarsButton from '../components/button/StarWarsButton'
1313
import TextRevealButton from '../components/button/TextRevealButton'
1414
import Card from './Card'
15-
import RotatingCompleteButton from '@/showcase/components/button/3DButton'
15+
import RotatingCompleteButton from '@/showcase/components/button/RotatingCompleteButton'
16+
import EcoModeButton from '../components/button/EcoModeButton'
1617

1718
const data = [
1819
{
@@ -61,6 +62,11 @@ const data = [
6162
link: '/components/button/rotating-complete-button',
6263
component: <RotatingCompleteButton />,
6364
},
65+
{
66+
title: 'Eco Mode',
67+
link: '/components/button/eco-mode-button',
68+
component: <EcoModeButton />,
69+
},
6470
{
6571
title: 'Bounce',
6672
link: '/components/button/bounce-button',

0 commit comments

Comments
 (0)