npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magic-motion

v1.0.15

Published

Bring your code examples to life with the Magic Motion! This lightweight and customizable library allows you to effortlessly add stunning animations to your code snippets in React applications. Perfect for documentation, tutorials, or any project where yo

Downloads

164

Readme

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:

| Property | Type | Description | |-----------------------|------------------------------------------------|----------------------------------------------------------------------------------------------------------------| | initialContent | string, required | The initial code content to be displayed. | | animateTo | string, optional | The target code content to animate to. If not provided, only the initial content will be displayed. | | duration | very slow, slow, normal, fast, very fast, number, optional | The duration of the animation. Specify the duration in seconds or milliseconds. | | variant | move later, move instantly, optional | The animation variant or style. Customize the transition effect between the initial and target content. | | styles | any, optional | Custom CSS styles to apply to the animated code content. | | fontSize | number, optional | Set the font size of the code content. | | codeHighlight | CodeHighlight, optional | Define syntax highlighting options for the code content. | | children | JSX.Element, optional | Pass additional JSX elements to be rendered alongside the animated content. | | onAnimationFinished | function, optional | A callback function triggered when the animation finishes. | | onAnimationStart | function, optional | A 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.