All Projects → fakundo → preact-transitioning

fakundo / preact-transitioning

Licence: MIT license
Preact components for easily implementing basic CSS animations and transitions

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to preact-transitioning

Preact Redux Example
🔁 Preact + Redux Example Project
Stars: ✭ 199 (+468.57%)
Mutual labels:  preact
Rex Tils
Type safe utils for redux actions, epics, effects, react/preact default props, various type guards and TypeScript utils, React util components
Stars: ✭ 245 (+600%)
Mutual labels:  preact
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+974.29%)
Mutual labels:  preact
Preact Devtools
Browser extension for inspection Preact applications
Stars: ✭ 204 (+482.86%)
Mutual labels:  preact
Facebook Political Ads
Monitoring Facebook Political Ads
Stars: ✭ 215 (+514.29%)
Mutual labels:  preact
react-router-v4-transition
React Router V4 Transition
Stars: ✭ 40 (+14.29%)
Mutual labels:  transition
Bolt
The Bolt Design System provides robust Twig and Web Component-powered UI components, reusable visual styles, and powerful tooling to help developers, designers, and content authors build, maintain, and scale best of class digital experiences.
Stars: ✭ 186 (+431.43%)
Mutual labels:  preact
use-spring
Hooke's law hook
Stars: ✭ 53 (+51.43%)
Mutual labels:  transition
React
MOVED TO https://github.com/myitcv/x/blob/master/react/_doc/README.md
Stars: ✭ 234 (+568.57%)
Mutual labels:  preact
blurhash-as
Blurhash implementation in AssemblyScript
Stars: ✭ 26 (-25.71%)
Mutual labels:  preact
Styled Loaders
Loaders Built with Preact and Styled Components
Stars: ✭ 212 (+505.71%)
Mutual labels:  preact
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+517.14%)
Mutual labels:  preact
preact-cli-sw-precache
Preact cli plugin for configuring sw-precache
Stars: ✭ 19 (-45.71%)
Mutual labels:  preact
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (+482.86%)
Mutual labels:  preact
minimal-player
This is a minimal, clean audio/music/mp3 player with spinning cover images, built with jQuery, TweenMax.js and SVG images.
Stars: ✭ 48 (+37.14%)
Mutual labels:  transition
Recal
A minimal, accessible React/Preact calendar component using modern CSS.
Stars: ✭ 191 (+445.71%)
Mutual labels:  preact
Prefresh
Hot Module Reloading for Preact
Stars: ✭ 247 (+605.71%)
Mutual labels:  preact
preact-route-async
Easy asynchronous loading for your router components. For 440B.
Stars: ✭ 36 (+2.86%)
Mutual labels:  preact
hyperapp-example
hyperapp example
Stars: ✭ 14 (-60%)
Mutual labels:  preact
jazzer
Add some visual smooth jazz to your page
Stars: ✭ 19 (-45.71%)
Mutual labels:  transition

preact-transitioning

npm

Exposes Preact components for easily implementing basic CSS animations and transitions.

Lightweight and fast implementation. Inspired by react-transition-group and has almost the same API. Take a look how it works.

Installation

npm i preact-transitioning

Demo

Demo / Source

Usage

import { Transition } from 'preact-transitioning'

...

<Transition
  in={!hidden}
  appear
  exit={false}
>
  {(transitionState) => (
    <pre>
      {JSON.stringify(transitionState)}
    </pre>
  )}
</Transition>

import { CSSTransition } from 'preact-transitioning'

...

<CSSTransition
  in={!hidden}
  classNames="fade"
>
  <div>
    Animated element
  </div>
</CSSTransition>

import { StyleTransition } from 'preact-transitioning'

...

<StyleTransition
  in={!hidden}
  duration={300}
  styles={{
    enter: { opacity: 0 },
    enterActive: { opacity: 1 },
  }}
>
  <div style={{ transition: 'opacity 300ms' }}>
    Animated element
  </div>
</StyleTransition>

import { TransitionGroup } from 'preact-transitioning'

...

<TransitionGroup duration={300}>
  {items.map((item) => (
    <CSSTransition
      key={item.key}
      classNames="fade"
    >
      <div>
        {renderItem(item)}
      </div>
    </CSSTransition>
  ))}
</TransitionGroup>

Detecting transition end:

<CSSTransition
  in={!hidden}
  classNames="fade"
  addEndListener={(node, done) => {
    node.addEventListener('transitionend', done, { once: true, capture: false })
  }}
>
  <div>
    Animated element
  </div>
</CSSTransition>

Using event callbacks to animate height:

<CSSTransition
  in={!hidden}
  classNames="fade"
  onEnter={(node) => {
    node.style.height = `${node.scrollHeight}px`
  }}
  onEntered={(node) => {
    node.style.height = ''
  }}
  onExit={(node) => {
    node.style.height = `${node.scrollHeight}px`
    // force reflow
    node.clientHeight
  }}
>
  <div>
    Animated element
  </div>
</CSSTransition>

API

Transition props

type TransitionProps = {
  children: (transitionState: TransitionState, activePhase: Phase) => any
  in?: boolean = false
  appear?: boolean = false
  enter?: boolean = true
  exit?: boolean = true
  duration?: number = 500
  alwaysMounted?: boolean = false
  onEnter?: (node: Element) => void
  onEntering?: (node: Element) => void
  onEntered?: (node: Element) => void
  onExit?: (node: Element) => void
  onExiting?: (node: Element) => void
  onExited?: (node: Element) => void
  addEndListener?: (node: Element, done: () => void) => void
}

TransitionState passed to the children function has the following structure

type TransitionState = {
  appear: boolean
  appearActive: boolean
  appearDone: boolean
  enter: boolean
  enterActive: boolean
  enterDone: boolean
  exit: boolean
  exitActive: boolean
  exitDone: boolean
}

CSSTransition props

type CSSTransitionProps = TransitionProps & {
  children: VNode<any>
  classNames: string | {
    appear?: string
    appearActive?: string
    appearDone?: string
    enter?: string
    enterActive?: string
    enterDone?: string
    exit?: string
    exitActive?: string
    exitDone?: string
  }
}

If classNames is a string, then computed className will be suffixed according to the current transition state. For example, if you pass the string fade as classNames, then fade-appear-active className will be applied during the appearActive phase.

If classNames is an object, then final className will be taken from that object according to the current transition state. For example, when the element enters, enterActive className will be applied.

StyleTransition props

type StyleTransitionProps = TransitionProps & {
  children: VNode<any>
  styles: {
    appear?: object
    appearActive?: object
    appearDone?: object
    enter?: object
    enterActive?: object
    enterDone?: object
    exit?: object
    exitActive?: object
    exitDone?: object
  }
}

The styles prop used to compute inline styles of the element according to the current transition state. For example, when the element enters, enterActive styles will be applied.

TransitionGroup props

type TransitionGroupProps = {
  children: any
  appear?: boolean
  enter?: boolean
  exit?: boolean
  duration?: number
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].