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

react-transition-preset

v2.0.0

Published

Lightweight, zero-dependency transition component for React with common preset transition

Downloads

360

Readme

react-transition-preset

轻量零依赖的 React 过渡组件,预设了常见过渡效果

English Docs

在线演示

例子

安装

npm install react-transition-preset

使用

import { Transition } from 'react-transition-preset'

function Demo({ opened }: { opened: boolean }) {
  return (
    <Transition
      mounted={opened}
      transition='fade'
      duration={400}
      timingFunction='ease'
    >
      <div>Hello, World!</div>
    </Transition>
  )
}

如果你的组件有样式属性,你可以使用渲染函数

import { Transition } from 'react-transition-preset'

function Demo({ opened }: { opened: boolean }) {
  return (
    <Transition mounted={opened}>
      {(styles) => <div style={{
        ...styles,
        // 自定义样式
      }}>Hello, World!</div>}
    </Transition>
  )
}

Viewport 视窗过渡

mounted 选项支持 whileInView,当元素进入或离开视窗时,开始过渡动画

import { Transition } from 'react-transition-preset'

function Demo() {
  return (
    <Transition mounted='whileInView'>
      <div>Hello, World!</div>
    </Transition>
  )
}

全局配置

import { setGlobalConfig } from 'react-transition-preset'

setGlobalConfig({
  duration: 150,
  timingFunction: 'linear',
  transition: 'fade-up'
})

API

interface TransitionProps {
  /** 确定组件是否应该挂载到 DOM */
  mounted: boolean | 'whileInView'
  
  /** 如果设置了,当元素隐藏时不会从 DOM 中卸载,而是应用 `display: none` 样式 */
  keepMounted?: boolean

  /** 如果 mounted 是 `whileInView`,此选项透传 useInView */ 
  viewport?: UseInViewOptions

  /** 过渡名称或对象 */
  transition?: PresetTransition

  /** 在初始化时设置过渡 */
  initial?: boolean

  /** 过渡持续时间(毫秒),默认 `150` */
  duration?: number

  /** 退出过渡持续时间(毫秒),默认与 `duration` 相同 */
  exitDuration?: number

  /** 过渡时间函数,默认 `theme.transitionTimingFunction` */
  timingFunction?: string

  /** 带有过渡样式参数的渲染函数 */
  children: JSX.Element | ((styles: React.CSSProperties) => JSX.Element)

  /** 是否减少动画 */
  reduceMotion?: boolean

  /** 当退出过渡结束时调用 */
  onExited?: () => void

  /** 当退出过渡开始时调用 */
  onExit?: () => void

  /** 当进入过渡开始时调用 */
  onEnter?: () => void

  /** 当进入过渡结束时调用 */
  onEntered?: () => void

  /** 进入过渡开始前的延迟时间(毫秒) */
  enterDelay?: number

  /** 退出过渡开始前的延迟时间(毫秒) */
  exitDelay?: number

  /** 自定义元素类型,默认 `div` */
  as?: React.ElementType

  /** 根元素的 attributes */
  elementAttributes?: React.HTMLAttributes<React.ElementType>
}