Introducing Magic UI Pro - 50+ blocks and templates to build beautiful landing pages in minutes.


Docs
Separate Away

Separate Away

Vertical separation of words

Separate

Away

Installation

Copy and paste the following code into your project.

components/magicui/separate-away.tsx
"use client";
 
import { cn } from "@/lib/utils";
import { motion } from "framer-motion";
 
interface SeparateAwayProps {
  upper_text: string;
  lower_text: string;
  duration?: number;
  hidden_opacity?: number;
  visible_opacity?: number;
  className?: string;
}
 
export function SeparateAway({
  upper_text,
  lower_text,
  duration = 1.5,
  hidden_opacity = 0,
  visible_opacity = 1,
  className,
}: SeparateAwayProps) {
  const separate = {
    hidden: { opacity: hidden_opacity, y: 0 },
    visible: (custom: number) => ({
      opacity: visible_opacity,
      y: custom * 5,
      transition: { duration: duration },
    }),
  };
 
  return (
    <div>
      <motion.h1
        custom={-1}
        variants={separate}
        initial="hidden"
        animate="visible"
        className={cn(className)}
      >
        {upper_text}
      </motion.h1>
      <motion.h1
        custom={1}
        variants={separate}
        initial="hidden"
        animate="visible"
        className={cn(className)}
      >
        {lower_text}
      </motion.h1>
    </div>
  );
}

Props

PropTypeDescriptionDefault
classNamestringThe class name to be applied to the component
upperTextstringThe words to be separated upwards"
lowerTextstringThe words to be separated downwards"
durationnumberDuration of the separation animation1.5
hiddenOpacitynumberOpacity of the text when it's hidden0
visibleOpacitynumberOpacity of the text when it's visible1