1.0.15 • Published 10 months ago

magic-motion v1.0.15

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

MagicMotion is a powerful and flexible code animation library that allows developers to easily create dynamic code animations. Whether you're building educational tools, showcasing code snippets, or creating interactive tutorials, MagicMotion makes it easy to animate code transitions with smooth and customizable effects.

Example on Stackblitz: https://stackblitz.com/edit/vitejs-vite-pgb6rr?file=src%2FApp.tsx

Installation

You can install MagicMotion via npm or yarn:

npm install magic-motion

Or with yarn:

yarn add magic-motion

Example with plain text

To use MagicMotion, simply import the library and pass the initial content to the MagicMotion component. On button click lets assign handler which will update the value of content which we want animate to. Component animates whenever the value of animateTo is changing.

Note: To prevent undesired behaviour, update the value of animateTo only when animation is finished. You could use onAnimationFinished callback to verify when animation is finished.

import { MagicMotion } from 'magic-motion';

const App = () => {
    const [animateTo, setAnimateTo] = useState();

    const buttonHandler = () => {
        setAnimateTo('Hello my friends');
    };

    return (
        <>
            <MagicMotion
                initialContent="Hello World!!!"
                animateTo={animateTo}
            />
            <button onClick={buttonHandler}>Animate</button>
        </>
    );
};

export default App;

Example with code

MagicMotion useses prismjs underhood for code highlighting, so you could use any theme provided by prismjs. Here is example list of themes which could be used.

So lets install these themes.

npm install prism-themes

Or with yarn:

yarn add prism-themes

Import styles.

import { MagicMotion } from 'magic-motion';
import 'prism-themes/themes/prism-one-dark.css';

const App = () => {
    const [animateTo, setAnimateTo] = useState();

    const buttonHandler = () => {
        setAnimateTo('const sum = (a, b) => a + b;');
    };

    return (
        <>
            <MagicMotion
                initialContent="const value = 5;"
                animateTo={animateTo}
                codeHighlight={{
                    languageName: 'javascript',
                }}
            />
            <button onClick={buttonHandler}>Animate</button>
        </>
    );
};

export default App;

Don't forget to define the languageName (e.g. javascript, css, html).

Configuration Options

MagicMotionConfig

The MagicMotionConfig interface provides a range of options to customize your code animations. Here's a breakdown of each property:

PropertyTypeDescription
initialContentstring, requiredThe initial code content to be displayed.
animateTostring, optionalThe target code content to animate to. If not provided, only the initial content will be displayed.
durationvery slow, slow, normal, fast, very fast, number, optionalThe duration of the animation. Specify the duration in seconds or milliseconds.
variantmove later, move instantly, optionalThe animation variant or style. Customize the transition effect between the initial and target content.
stylesany, optionalCustom CSS styles to apply to the animated code content.
fontSizenumber, optionalSet the font size of the code content.
codeHighlightCodeHighlight, optionalDefine syntax highlighting options for the code content.
childrenJSX.Element, optionalPass additional JSX elements to be rendered alongside the animated content.
onAnimationFinishedfunction, optionalA callback function triggered when the animation finishes.
onAnimationStartfunction, optionalA callback function triggered when the animation starts.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an issue if you have any ideas, improvements, or bugs to report.

License

MagicMotion is licensed under the MIT License. See the LICENSE file for more information.


This README provides a comprehensive overview of your library, including installation, usage, configuration options, and examples. You can further enhance it by adding more detailed documentation, links to live demos, or badges for things like build status or npm version.

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago