Skip to content

Commit

Permalink
implement typewriter animation and button animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohitha-pudu committed Jun 2, 2024
1 parent f74056e commit 0bc27fa
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 0 deletions.
68 changes: 68 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"axios": "^1.7.2",
"clsx": "^2.1.1",
"framer-motion": "^11.2.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.1",
"recoil": "^0.7.7",
"tailwind-merge": "^2.3.0",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/components/ui/MagicButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


const MagicButton = ({title}:{title:string}) => {
return (
<>
<button className="relative inline-flex h-12 overflow-hidden rounded-lg p-[1px] focus:outline-none ">
<span className="absolute inset-[-1000%] animate-[spin_2s_linear_infinite] bg-[conic-gradient(from_90deg_at_50%_50%,#E2CBFF_0%,#393BB2_50%,#E2CBFF_100%)]" />
<span className="inline-flex h-full w-full cursor-pointer items-center justify-center rounded-lg bg-slate-950 px-7 text-sm font-medium text-white backdrop-blur-3xl">
{title}
</span>
</button>
</>
)
}

export default MagicButton
187 changes: 187 additions & 0 deletions frontend/src/components/ui/TypeWriter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
"use client";

import { cn } from "../../utils/cn";
import { motion, stagger, useAnimate, useInView } from "framer-motion";
import { useEffect } from "react";

export const TypewriterEffect = ({
words,
className,
cursorClassName,
}: {
words: {
text: string;
className?: string;
}[];
className?: string;
cursorClassName?: string;
}) => {
// split text inside of words into array of characters
const wordsArray = words.map((word) => {
return {
...word,
text: word.text.split(""),
};
});

const [scope, animate] = useAnimate();
const isInView = useInView(scope);
useEffect(() => {
if (isInView) {
animate(
"span",
{
display: "inline-block",
opacity: 1,
width: "fit-content",
},
{
duration: 0.3,
delay: stagger(0.1),
ease: "easeInOut",
}
);
}
}, [isInView]);

const renderWords = () => {
return (
<motion.div ref={scope} className="inline">
{wordsArray.map((word, idx) => {
return (
<div key={`word-${idx}`} className="inline-block">
{word.text.map((char, index) => (
<motion.span
initial={{}}
key={`char-${index}`}
className={cn(
`dark:text-white text-black opacity-0 hidden`,
word.className
)}
>
{char}
</motion.span>
))}
&nbsp;
</div>
);
})}
</motion.div>
);
};
return (
<div
className={cn(
"text-base sm:text-xl md:text-3xl lg:text-5xl font-bold text-center",
className
)}
>
{renderWords()}
<motion.span
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
transition={{
duration: 0.8,
repeat: Infinity,
repeatType: "reverse",
}}
className={cn(
"inline-block rounded-sm w-[4px] h-4 md:h-6 lg:h-10 bg-blue-500",
cursorClassName
)}
></motion.span>
</div>
);
};

export const TypewriterEffectSmooth = ({
words,
className,
cursorClassName,
}: {
words: {
text: string;
className?: string;
}[];
className?: string;
cursorClassName?: string;
}) => {
// split text inside of words into array of characters
const wordsArray = words.map((word) => {
return {
...word,
text: word.text.split(""),
};
});
const renderWords = () => {
return (
<div>
{wordsArray.map((word, idx) => {
return (
<div key={`word-${idx}`} className="inline-block">
{word.text.map((char, index) => (
<span
key={`char-${index}`}
className={cn(`dark:text-white text-black `, word.className)}
>
{char}
</span>
))}
&nbsp;
</div>
);
})}
</div>
);
};

return (
<div className={cn("flex space-x-1 my-6", className)}>
<motion.div
className="overflow-hidden pb-2"
initial={{
width: "0%",
}}
whileInView={{
width: "fit-content",
}}
transition={{
duration: 2,
ease: "linear",
delay: 1,
}}
>
<div
className="text-xs sm:text-base md:text-xl lg:text:3xl xl:text-5xl font-bold"
style={{
whiteSpace: "nowrap",
}}
>
{renderWords()}{" "}
</div>{" "}
</motion.div>
<motion.span
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
transition={{
duration: 0.8,

repeat: Infinity,
repeatType: "reverse",
}}
className={cn(
"block rounded-sm w-[4px] h-4 sm:h-6 xl:h-12 bg-blue-500",
cursorClassName
)}
></motion.span>
</div>
);
};
6 changes: 6 additions & 0 deletions frontend/src/utils/cn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

0 comments on commit 0bc27fa

Please sign in to comment.