fade-in.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use client";
  2. import { motion } from "framer-motion";
  3. import { ReactNode } from "react";
  4. interface FadeInProps {
  5. children: ReactNode;
  6. delay?: number;
  7. className?: string;
  8. }
  9. export function FadeIn({ children, delay = 0, className = "" }: FadeInProps) {
  10. return (
  11. <motion.div
  12. initial={{ opacity: 0, y: 20 }}
  13. whileInView={{ opacity: 1, y: 0 }}
  14. viewport={{ once: true, margin: "-100px" }}
  15. transition={{ duration: 0.6, delay, ease: "easeOut" }}
  16. className={className}
  17. style={{ willChange: "opacity, transform" }}
  18. >
  19. {children}
  20. </motion.div>
  21. );
  22. }
  23. interface FadeInStaggerProps {
  24. children: ReactNode;
  25. className?: string;
  26. }
  27. export function FadeInStagger({ children, className = "" }: FadeInStaggerProps) {
  28. return (
  29. <motion.div
  30. initial="hidden"
  31. whileInView="visible"
  32. viewport={{ once: true, margin: "-100px" }}
  33. variants={{
  34. hidden: { opacity: 0 },
  35. visible: {
  36. opacity: 1,
  37. transition: {
  38. staggerChildren: 0.1,
  39. },
  40. },
  41. }}
  42. className={className}
  43. >
  44. {children}
  45. </motion.div>
  46. );
  47. }
  48. interface FadeInItemProps {
  49. children: ReactNode;
  50. className?: string;
  51. }
  52. export function FadeInItem({ children, className = "" }: FadeInItemProps) {
  53. return (
  54. <motion.div
  55. variants={{
  56. hidden: { opacity: 0, y: 20 },
  57. visible: { opacity: 1, y: 0 },
  58. }}
  59. transition={{ duration: 0.5, ease: "easeOut" }}
  60. className={className}
  61. style={{ willChange: "opacity, transform" }}
  62. >
  63. {children}
  64. </motion.div>
  65. );
  66. }