react-magic-motion

A library that magically animates your React components.

README

react-magic-motion


react-magic-motion.com


react-magic-motion is a react.js library that ✨ magically animates your components.


⭐️ Getting Started


📦 Install


  1. ```bash
  2. npm i react-magic-motion
  3. ```

🔎 Simple Example


🎥 Demo


https://github.com/Etesam913/react-magic-motion/assets/55665282/dfc56ad5-5012-4f5e-90cc-8ec372527320

🧑‍💻 Code


  1. ```jsx
  2. import { useState } from "react";
  3. import { MagicMotion } from "react-magic-motion";

  4. function ListItem({ children }: { children: string }) {
  5.   return (
  6.     <li
  7.       style={{
  8.         backgroundColor: "#4d4d4dff",
  9.         width: "20rem",
  10.         padding: "0.5rem",
  11.       }}
  12.     >
  13.       {children}
  14.     </li>
  15.   );
  16. }

  17. export default function App() {
  18.   const [areGoalsShowing, setAreGoalsShowing] = useState(true);
  19.   return (
  20.     <MagicMotion>
  21.       <div
  22.         style={{
  23.           margin: "0.75rem auto 0",
  24.           width: "20rem",
  25.           display: "flex",
  26.           flexDirection: "column",
  27.           gap: "1rem",
  28.           overflow: "hidden",
  29.         }}
  30.       >
  31.         <h1
  32.           style={{
  33.             fontWeight: "bold",
  34.             margin: "0.25rem",
  35.           }}
  36.         >
  37.           My Goals
  38.         </h1>
  39.         {areGoalsShowing && (
  40.           <ul
  41.             style={{
  42.               display: "flex",
  43.               flexDirection: "column",
  44.               gap: "0.75rem",
  45.               listStyle: "none",
  46.               paddingLeft: "0.5rem",
  47.               margin: 0,
  48.             }}
  49.           >
  50.             <ListItem> Make 10 three pointers in a row</ListItem>
  51.             <ListItem> Bench press 225 lbs</ListItem>
  52.             <ListItem> Run a 5k in under 20 minutes</ListItem>
  53.           </ul>
  54.         )}
  55.         <button
  56.           style={{
  57.             width: "fit-content",
  58.             whiteSpace: "nowrap",
  59.             padding: "0.5rem 1rem",
  60.             backgroundColor: "#5a70ed",
  61.             color: "#ffffff",
  62.             border: 0,
  63.             cursor: "pointer",
  64.             fontFamily: "inherit",
  65.           }}
  66.           onClick={() => setAreGoalsShowing(!areGoalsShowing)}
  67.         >
  68.           {areGoalsShowing ? "Hide" : "Show"} my goals
  69.         </button>
  70.       </div>
  71.     </MagicMotion>
  72.   );
  73. }
  74. ```

💫 Examples



📓 Docs


- For a full understanding of react-magic-motion visit the docs here

❓ Want to Contribute


- Visit the contributing.md