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

solid-motionone

v1.0.2

Published

A tiny, performant animation library for SolidJS

Downloads

20,695

Readme

Solid MotionOne

pnpm npm downloads

A tiny, performant animation library for SolidJS. Powered by Motion One.

Introduction

Motion One for Solid is a 5.8kb animation library for SolidJS. It takes advantage of Solid's excellent performance and simple declarative syntax. This package supplies springs, independent transforms, and hardware accelerated animations.

Installation

Motion One for Solid can be installed via npm:

npm install solid-motionone
# or
pnpm add solid-motionone
# or
yarn add solid-motionone

Create an animation

Import the Motion component and use it anywhere in your Solid components:

import {Motion} from "solid-motionone"

function MyComponent() {
  return <Motion>Hello world</Motion>
}

The Motion component can be used to create an animatable HTML or SVG element. By default, it will render a div element:

import {Motion} from "solid-motionone"

function App() {
  return (
    <Motion.div
      animate={{opacity: [0, 1]}}
      transition={{duration: 1, easing: "ease-in-out"}}
    />
  )
}

But any HTML or SVG element can be rendered, by defining it like this: <Motion.button>

Or like this: <Motion tag="button">

Transition options

We can change the type of animation used by passing a transition prop.

<Motion
  animate={{rotate: 90, backgroundColor: "yellow"}}
  transition={{duration: 1, easing: "ease-in-out"}}
/>

By default transition options are applied to all values, but we can also override on a per-value basis:

<Motion
  animate={{rotate: 90, backgroundColor: "yellow"}}
  transition={{
    duration: 1,
    rotate: {duration: 2},
  }}
/>

Taking advantage of Solid's reactivity is just as easy. Simply provide any of the Motion properties as accessors to have them change reactively:

const [bg, setBg] = createSignal("red")

return (
  <Motion.button
    onClick={() => setBg("blue")}
    animate={{backgroundColor: bg()}}
    transition={{duration: 3}}
  >
    Click Me
  </Motion.button>
)

The result is a button that begins red and upon being pressed transitions to blue. animate doesn't accept an accessor function. For reactive properties simply place signals in the object similar to using style prop.

Keyframes

Values can also be set as arrays, to define a series of keyframes.

<Motion animate={{x: [0, 100, 50]}} />

By default, keyframes are spaced evenly throughout duration, but this can be adjusted by providing progress values to offset:

<Motion animate={{x: [0, 100, 50]}} transition={{x: {offset: [0, 0.25, 1]}}} />

Enter animations

Elements will automatically animate to the values defined in animate when they're created.

This can be disabled by setting the initial prop to false. The styles defined in animate will be applied immediately when the element is first created.

<Motion initial={false} animate={{x: 100}} />

Exit animations

When an element is removed with <Show> it can be animated out with the Presence component and the exit prop:

import {createSignal, Show} from "solid-js"
import {Motion, Presence} from "solid-motionone"

function App() {
  const [isShown, setShow] = createSignal(true)

  return (
    <div>
      <Presence exitBeforeEnter>
        <Show when={isShown()}>
          <Motion
            initial={{opacity: 0, scale: 0.6}}
            animate={{opacity: 1, scale: 1}}
            exit={{opacity: 0, scale: 0.6}}
            transition={{duration: 0.3}}
          />
        </Show>
      </Presence>
      <button onClick={() => setShow(p => !p)}>Toggle</button>
    </div>
  )
}

exit can be provided a transition of its own, that override the component's transition:

<Presence>
  <Show when={isShown()}>
    <Motion
      animate={{opacity: 1}}
      exit={{opacity: 0, transition: {duration: 0.8}}}
    />
  </Show>
</Presence>