2.0.4 • Published 10 months ago

next-app-router-transitions v2.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Next App Router Transitions 🚀

Elevate your Next.js App Router projects with silky-smooth page transitions! This package provides an easy-to-use component that adds fluid animations between route changes, enhancing the overall user experience of your Next.js applications.

Features

  • 🎭 Multiple transition effects (block, multiBlock, blinds)
  • 🔧 Fully customizable (duration, ease, colors)
  • 📱 Responsive and accessible
  • 🧩 Seamless integration with Next.js App Router
  • 🪶 Lightweight with minimal setup

Installation

npm install next-app-router-transitions framer-motion

Important: This package requires framer-motion as a peer dependency. Make sure to install it alongside the package.

Usage

To use Next App Router Transitions in your project, follow these steps:

  1. Create a new client component in your app directory, e.g., app/TransitionLayout.tsx:
"use client";

import { TransitionWrapper } from "next-app-router-transitions";

export default function TransitionLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <TransitionWrapper
      transitionType="block"
      duration={0.5}
      backgroundColor="#000">
      {children}
    </TransitionWrapper>
  );
}
  1. Use this component in your root layout (app/layout.tsx):
import TransitionLayout from "./TransitionLayout";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <TransitionLayout>{children}</TransitionLayout>
      </body>
    </html>
  );
}

This setup ensures that the transition effects are applied consistently across your entire application.

API

The TransitionWrapper component accepts the following props:

PropTypeDefaultDescription
transitionTypestring'block'Type of transition effect ('block', 'multiBlock', 'blinds')
durationnumber0.75Duration of the transition in seconds
backgroundColorstring'black'Background color of the transition element
easestring | number[]'easeInOut'Easing function for the transition
zIndexnumber50z-index of the transition element

Examples

Block Transition

<TransitionWrapper transitionType="block" duration={0.5} backgroundColor="#000">
  {children}
</TransitionWrapper>

MultiBlock Transition

<TransitionWrapper
  transitionType="multiBlock"
  duration={0.7}
  backgroundColor="#fff">
  {children}
</TransitionWrapper>

Blinds Transition

<TransitionWrapper
  transitionType="blinds"
  duration={0.6}
  backgroundColor="#333">
  {children}
</TransitionWrapper>

Troubleshooting

If you encounter any issues, ensure that:

  1. You have installed framer-motion as a peer dependency.
  2. You're using the TransitionWrapper in a client component (with the "use client" directive).
  3. The TransitionWrapper is placed as high as possible in your component tree, ideally in the root layout.
  4. You have the correct peer dependencies installed (react, react-dom, next, framer-motion).

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

MIT © Theogene Junior | @theogenejr


Happy coding! If you enjoy smooth transitions in your Next.js App Router projects, don't forget to give us a star on GitHub! ⭐

2.0.4

10 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago