代强 c18ab9cee4 Merge pull request #1109 from DouyinFE/chore-removeCoreJs %!s(int64=3) %!d(string=hai) anos
..
__tests__ f76bd5879d feat: init %!s(int64=4) %!d(string=hai) anos
_story 93f5b9fbd3 fix: correct the misspelling of some internal logic function names (#1008) %!s(int64=3) %!d(string=hai) anos
scripts f76bd5879d feat: init %!s(int64=4) %!d(string=hai) anos
src e5b24a4133 Fix react18 strict mode error (#843) %!s(int64=3) %!d(string=hai) anos
README.md e2fe505c2c docs: udpate readme %!s(int64=3) %!d(string=hai) anos
getBabelConfig.js 65f16ab439 chore: remove babel config of animation %!s(int64=3) %!d(string=hai) anos
gulpfile.js 626c4b9f9e Feat/support next (#245) %!s(int64=3) %!d(string=hai) anos
index.ts f76bd5879d feat: init %!s(int64=4) %!d(string=hai) anos
package.json c18ab9cee4 Merge pull request #1109 from DouyinFE/chore-removeCoreJs %!s(int64=3) %!d(string=hai) anos
tsconfig.json f76bd5879d feat: init %!s(int64=4) %!d(string=hai) anos

README.md

React animation library based on @douyinfe/semi-animation.

The transition animation effects of all components in @douyinfe/semi-ui are implemented based on this animation library, such as: Modal, Tooltip, Collapse and other component content display and exit effects.

Install

npm install @douyinfe/semi-animation-react

Usage

Transition Component

It is used to realize the animation effect of the component [show and exit]. Examples are as follows:

import { Transition } from "@douyinfe/semi-animation-react";
import { useState } from "react";

export default function App() {
  const [visible, setVisible] = useState(false);
  return (
    <div className="App">
      <Transition
        state={visible ? "enter" : "leave"}
        from={{ opacity: 0, scale: 0}}
        enter={{ opacity: 1, scale: 1 }}
        leave={{ opacity: 0, scale: 0 }}
      >
        {({ scale, opacity }: any) => (
          <h2 style={{transform: `scale(${scale})`, opacity}}>
            Toggle to see some animation happen!
          </h2>
        )}
      </Transition>

      <button onClick={() => {
        setVisible((state) => !state)
      }}>toggle</button>
    </div>
  );
}

Props

|Name|Type|Required|Default|Description| |--|--|--|--|--| |from|Object|Y||Initial state| |enter|Object|Y||Show the end state of the animation, but also the initial state of the exit animation| |leave|Object|Y||Exit the termination state of the animation| |state|Enum 'enter', 'leave'|N|''|Current state| |willEnter|Function|N|()=> {}|The callback function before the enter animation starts| |didEnter|Function|N|()=> {}|The callback function before the animation ends| |willLeave|Function|N|()=> {}|The callback function before the exit animation starts | |didLeave|Function|N|()=> {}|The callback function before the exit animation ends| |onStart|Function|N|()=> {}|The callback function before animation starts,including enter and exit| |onRest|Function|N|()=> {}|The callback function before animation ends,including enter and exit| |config|ConfigType|N|{}|Additional animation parameters|

config

|Name|Type|Default|Description| |--|--|--|--| |duration|Number|1000|Animation duration.If this parameter is passed in, the easing function of the animation will use easing or linear function,unit: ms| | easing | Function|String | | Easing function for animation. If duration is not passed, the spring easing function is used by default. If the duration parameter is passed in, the linear easing function will be used by default.For example, incoming "cubic-bezier(.17,.67,.83,.67)" will cause the animation frame update performed according to this easing function | | tension | Number | 170 | Tension, used for spring easing function | | friction | Number | 14 | Friction, used for spring easing function |