@douyinfe/semi-animation-react 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ > React animation library based on `@douyinfe/semi-animation`.
2
+
3
+ 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.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @douyinfe/semi-animation-react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Transition Component
14
+
15
+ It is used to realize the animation effect of the component [show and exit]. Examples are as follows:
16
+
17
+ ```jsx
18
+ import { Transition } from "@douyinfe/semi-animation-react";
19
+ import { useState } from "react";
20
+
21
+ export default function App() {
22
+ const [visible, setVisible] = useState(false);
23
+ return (
24
+ <div className="App">
25
+ <Transition
26
+ state={visible ? "enter" : "leave"}
27
+ from={{ opacity: 0, scale: 0}}
28
+ enter={{ opacity: 1, scale: 1 }}
29
+ leave={{ opacity: 0, scale: 0 }}
30
+ >
31
+ {({scale, opacity}: any) => (
32
+ <h2 style={{transform: `scale(${scale})`, opacity}}>
33
+ Toggle to see some animation happen!
34
+ </h2>
35
+ )}
36
+ </Transition>
37
+
38
+ <button onClick={() => {
39
+ setVisible((state) => !state)
40
+ }}>toggle</button>
41
+ </div>
42
+ );
43
+ }
44
+ ```
45
+
46
+ ### Props
47
+
48
+ |Name|Type|Required|Default|Description|
49
+ |--|--|--|--|--|
50
+ |from|Object|Y||Initial state|
51
+ |enter|Object|Y||Show the end state of the animation, but also the initial state of the exit animation|
52
+ |leave|Object|Y||Exit the termination state of the animation|
53
+ |state|Enum 'enter', 'leave'|N|''|Current state|
54
+ |willEnter|Function|N|()=> {}|The callback function before the enter animation starts|
55
+ |didEnter|Function|N|()=> {}|The callback function before the animation ends|
56
+ |willLeave|Function|N|()=> {}|The callback function before the exit animation starts |
57
+ |didLeave|Function|N|()=> {}|The callback function before the exit animation ends|
58
+ |onStart|Function|N|()=> {}|The callback function before animation starts,including enter and exit|
59
+ |onRest|Function|N|()=> {}|The callback function before animation ends,including enter and exit|
60
+ |config|ConfigType|N|{}|Additional animation parameters|
61
+
62
+ ### config
63
+
64
+ |Name|Type|Default|Description|
65
+ |--|--|--|--|
66
+ |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|
67
+ | 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 |
68
+ | tension | Number | 170 | Tension, used for spring easing function |
69
+ | friction | Number | 14 | Friction, used for spring easing function |
70
+
@@ -0,0 +1,6 @@
1
+ export { default as StyledAnimation } from './src/StyledAnimation';
2
+ export { default as StyledTransition } from './src/StyledTransition';
3
+ export { default as Animation } from './src/Animation';
4
+ export { default as KeyFrames } from './src/KeyFrames';
5
+ export { default as Transition } from './src/Transition';
6
+ export { interpolate, presets } from '@douyinfe/semi-animation';
@@ -0,0 +1,6 @@
1
+ export { default as StyledAnimation } from './src/StyledAnimation';
2
+ export { default as StyledTransition } from './src/StyledTransition';
3
+ export { default as Animation } from './src/Animation';
4
+ export { default as KeyFrames } from './src/KeyFrames';
5
+ export { default as Transition } from './src/Transition';
6
+ export { interpolate, presets } from '@douyinfe/semi-animation';
@@ -0,0 +1,70 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import noop from './utils/noop';
4
+ export interface AnimationProps {
5
+ onStart?: Function;
6
+ onFrame?: Function;
7
+ onPause?: Function;
8
+ onResume?: Function;
9
+ onStop?: Function;
10
+ onRest?: Function;
11
+ children?: React.ReactNode;
12
+ from?: Record<string, any>;
13
+ to?: Record<string, any>;
14
+ reverse?: boolean;
15
+ reset?: boolean;
16
+ force?: boolean;
17
+ config?: Record<string, any>;
18
+ autoStart?: boolean;
19
+ forwardInstance?: (value: any) => void;
20
+ immediate?: boolean;
21
+ }
22
+ export default class Animation extends PureComponent<AnimationProps> {
23
+ static propTypes: {
24
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
25
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
26
+ onPause: PropTypes.Requireable<(...args: any[]) => any>;
27
+ onResume: PropTypes.Requireable<(...args: any[]) => any>;
28
+ onStop: PropTypes.Requireable<(...args: any[]) => any>;
29
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
30
+ children: PropTypes.Requireable<any>;
31
+ from: PropTypes.Requireable<object>;
32
+ to: PropTypes.Requireable<object>;
33
+ reverse: PropTypes.Requireable<boolean>;
34
+ reset: PropTypes.Requireable<boolean>;
35
+ force: PropTypes.Requireable<boolean>;
36
+ config: PropTypes.Requireable<object>;
37
+ autoStart: PropTypes.Requireable<boolean>;
38
+ forwardInstance: PropTypes.Requireable<(...args: any[]) => any>;
39
+ immediate: PropTypes.Requireable<boolean>;
40
+ };
41
+ static defaultProps: {
42
+ autoStart: boolean;
43
+ force: boolean;
44
+ onStart: typeof noop;
45
+ onFrame: typeof noop;
46
+ onPause: typeof noop;
47
+ onResume: typeof noop;
48
+ onStop: typeof noop;
49
+ onRest: typeof noop;
50
+ };
51
+ _mounted: boolean;
52
+ _destroyed: boolean;
53
+ animation: any;
54
+ reverse: () => void;
55
+ destroy: () => void;
56
+ reset: () => void;
57
+ resume: () => void;
58
+ end: () => void;
59
+ stop: () => void;
60
+ pause: () => void;
61
+ start: () => void;
62
+ constructor(props?: {});
63
+ startOrNot(): void;
64
+ componentDidMount(): void;
65
+ componentWillUnmount(): void;
66
+ componentDidUpdate(prevProps?: AnimationProps): void;
67
+ initAnimation: (props?: AnimationProps) => void;
68
+ bindEvents: () => void;
69
+ render(): any;
70
+ }
@@ -0,0 +1,207 @@
1
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
2
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
3
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
4
+ import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
5
+
6
+ /* eslint-disable @typescript-eslint/ban-types */
7
+
8
+ /* eslint-disable react/destructuring-assignment */
9
+ import { PureComponent, isValidElement } from 'react';
10
+ import PropTypes from 'prop-types';
11
+ import { Animation as SemiAnimation, events } from '@douyinfe/semi-animation';
12
+ import noop from './utils/noop';
13
+ export default class Animation extends PureComponent {
14
+ constructor(props = {}) {
15
+ super(props);
16
+
17
+ this.initAnimation = props => {
18
+ // eslint-disable-next-line eqeqeq
19
+ props = props == null ? this.props : props; // eslint-disable-next-line prefer-const
20
+
21
+ let {
22
+ from,
23
+ to,
24
+ config,
25
+ reverse
26
+ } = props;
27
+
28
+ if (reverse) {
29
+ [from, to] = [to, from];
30
+ }
31
+
32
+ this.animation = new SemiAnimation({
33
+ from: _Object$assign({}, from),
34
+ to: _Object$assign({}, to)
35
+ }, _Object$assign({}, config));
36
+
37
+ _forEachInstanceProperty(events).call(events, event => {
38
+ const propName = "on".concat(event[0].toUpperCase() + _sliceInstanceProperty(event).call(event, 1)); // eslint-disable-next-line @typescript-eslint/no-shadow
39
+
40
+ this.animation.on(event, props => {
41
+ // avoid memory leak
42
+ if (this._mounted && !this._destroyed) {
43
+ this.setState({
44
+ currentStyle: _Object$assign({}, props)
45
+ });
46
+ this.props[propName](props);
47
+ }
48
+ });
49
+ });
50
+
51
+ this._destroyed = false;
52
+ };
53
+
54
+ this.bindEvents = () => {
55
+ this.startOrNot = () => {
56
+ const {
57
+ immediate,
58
+ autoStart
59
+ } = this.props;
60
+
61
+ if (immediate) {
62
+ this.end();
63
+ } else if (autoStart) {
64
+ this.start();
65
+ }
66
+ };
67
+
68
+ this.start = () => {
69
+ this.animation && this.animation.start();
70
+ };
71
+
72
+ this.pause = () => {
73
+ this.animation && this.animation.pause();
74
+ };
75
+
76
+ this.stop = () => {
77
+ this.animation && this.animation.stop();
78
+ };
79
+
80
+ this.end = () => {
81
+ this.animation && this.animation.end();
82
+ };
83
+
84
+ this.resume = () => {
85
+ this.animation && this.animation.resume();
86
+ };
87
+
88
+ this.reset = () => {
89
+ if (this.animation) {
90
+ this.animation.reset();
91
+ this.startOrNot();
92
+ }
93
+ };
94
+
95
+ this.reverse = () => {
96
+ if (this.animation) {
97
+ var _context;
98
+
99
+ _reverseInstanceProperty(_context = this.animation).call(_context);
100
+
101
+ this.startOrNot();
102
+ }
103
+ };
104
+
105
+ this.destroy = () => {
106
+ this._destroyed = true;
107
+ this.animation && this.animation.destroy();
108
+ };
109
+ };
110
+
111
+ this.state = {
112
+ currentStyle: {}
113
+ };
114
+ this._mounted = false;
115
+ this._destroyed = false;
116
+ this.initAnimation();
117
+ this.bindEvents();
118
+ }
119
+
120
+ startOrNot() {
121
+ throw new Error('Method not implemented.');
122
+ }
123
+
124
+ componentDidMount() {
125
+ this._mounted = true;
126
+ const {
127
+ forwardInstance
128
+ } = this.props;
129
+
130
+ if (typeof forwardInstance === 'function') {
131
+ forwardInstance(this.animation);
132
+ }
133
+
134
+ this.startOrNot();
135
+ }
136
+
137
+ componentWillUnmount() {
138
+ this._mounted = false;
139
+
140
+ if (this.animation) {
141
+ this.animation.destroy();
142
+ this.animation = null;
143
+ }
144
+ }
145
+
146
+ componentDidUpdate(prevProps = {}) {
147
+ if (this.props.reset) {
148
+ if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
149
+ this.destroy();
150
+ this.initAnimation();
151
+ this.startOrNot();
152
+ }
153
+ }
154
+
155
+ if (this.props.force) {
156
+ if (this.props.to !== prevProps.to) {
157
+ this.initAnimation(_Object$assign(_Object$assign({}, this.props), {
158
+ from: prevProps.to
159
+ }));
160
+ this.startOrNot();
161
+ }
162
+ }
163
+ }
164
+
165
+ render() {
166
+ const {
167
+ children
168
+ } = this.props;
169
+
170
+ if (typeof children === 'function') {
171
+ return children(this.animation.getCurrentStates());
172
+ } else if ( /*#__PURE__*/isValidElement(children)) {
173
+ return children;
174
+ } else {
175
+ return null;
176
+ }
177
+ }
178
+
179
+ }
180
+ Animation.propTypes = {
181
+ onStart: PropTypes.func,
182
+ onFrame: PropTypes.func,
183
+ onPause: PropTypes.func,
184
+ onResume: PropTypes.func,
185
+ onStop: PropTypes.func,
186
+ onRest: PropTypes.func,
187
+ children: PropTypes.any,
188
+ from: PropTypes.object,
189
+ to: PropTypes.object,
190
+ reverse: PropTypes.bool,
191
+ reset: PropTypes.bool,
192
+ force: PropTypes.bool,
193
+ config: PropTypes.object,
194
+ autoStart: PropTypes.bool,
195
+ forwardInstance: PropTypes.func,
196
+ immediate: PropTypes.bool
197
+ };
198
+ Animation.defaultProps = {
199
+ autoStart: true,
200
+ force: false,
201
+ onStart: noop,
202
+ onFrame: noop,
203
+ onPause: noop,
204
+ onResume: noop,
205
+ onStop: noop,
206
+ onRest: noop
207
+ };
@@ -0,0 +1,39 @@
1
+ import { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import noop from './utils/noop';
4
+ export interface KeyFramesProps {
5
+ frames?: any[];
6
+ loop?: boolean;
7
+ forwardInstance?: (value: any) => void;
8
+ onFrame?: (value: any) => void;
9
+ onKeyRest?: (value: Record<string, any>) => void;
10
+ onRest?: (value: Record<string, any>) => void;
11
+ }
12
+ export interface KeyFramesStates {
13
+ currentStyle: Record<string, any>;
14
+ frameIndex: number;
15
+ }
16
+ export default class KeyFrames extends Component<KeyFramesProps, KeyFramesStates> {
17
+ static propTypes: {
18
+ frames: PropTypes.Requireable<any[]>;
19
+ loop: PropTypes.Requireable<boolean>;
20
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
21
+ onKeyRest: PropTypes.Requireable<(...args: any[]) => any>;
22
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
23
+ };
24
+ static defaultProps: {
25
+ frames: any[];
26
+ loop: boolean;
27
+ onKeyRest: typeof noop;
28
+ onRest: typeof noop;
29
+ onFrame: typeof noop;
30
+ };
31
+ instance: any;
32
+ constructor(props?: {});
33
+ onFrame: (props?: {}) => void;
34
+ next: () => void;
35
+ forwardInstance: (instance: any) => void;
36
+ componentDidMount(): void;
37
+ componentWillUnmount(): void;
38
+ render(): JSX.Element;
39
+ }
@@ -0,0 +1,104 @@
1
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
2
+
3
+ /* eslint-disable react/destructuring-assignment */
4
+ import React, { Component } from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import noop from './utils/noop';
7
+ import Animation from './Animation';
8
+ export default class KeyFrames extends Component {
9
+ constructor(props = {}) {
10
+ super(props);
11
+
12
+ this.onFrame = (props = {}) => {
13
+ const currentStyle = _Object$assign({}, props);
14
+
15
+ this.props.onFrame(currentStyle);
16
+ this.setState({
17
+ currentStyle
18
+ });
19
+ };
20
+
21
+ this.next = () => {
22
+ let {
23
+ frameIndex
24
+ } = this.state;
25
+ const {
26
+ frames,
27
+ loop
28
+ } = this.props;
29
+ frameIndex++;
30
+
31
+ if (frameIndex < frames.length - 1) {
32
+ this.setState({
33
+ frameIndex
34
+ });
35
+ } else {
36
+ frameIndex = 0;
37
+ this.props.onRest(this.state.currentStyle);
38
+
39
+ if (loop) {
40
+ this.setState({
41
+ frameIndex
42
+ });
43
+ }
44
+ }
45
+
46
+ this.props.onKeyRest(this.state.currentStyle);
47
+ };
48
+
49
+ this.forwardInstance = instance => {
50
+ this.instance = instance;
51
+
52
+ if (typeof this.props.forwardInstance === 'function') {
53
+ this.props.forwardInstance(this.instance);
54
+ }
55
+ };
56
+
57
+ this.state = {
58
+ currentStyle: {},
59
+ frameIndex: 0
60
+ };
61
+ }
62
+
63
+ componentDidMount() {// this.props.forwardInstance(this.instance);
64
+ }
65
+
66
+ componentWillUnmount() {
67
+ this.instance && this.instance.destroy();
68
+ }
69
+
70
+ render() {
71
+ const {
72
+ children,
73
+ frames
74
+ } = this.props;
75
+ const {
76
+ frameIndex,
77
+ currentStyle
78
+ } = this.state;
79
+ const from = frames[frameIndex];
80
+ const to = frames[frameIndex + 1];
81
+ return /*#__PURE__*/React.createElement(Animation, _Object$assign({}, this.props, {
82
+ forwardInstance: this.forwardInstance,
83
+ from: from,
84
+ to: to,
85
+ onFrame: this.onFrame,
86
+ onRest: this.next
87
+ }), typeof children === 'function' ? children(currentStyle) : children);
88
+ }
89
+
90
+ }
91
+ KeyFrames.propTypes = {
92
+ frames: PropTypes.array,
93
+ loop: PropTypes.bool,
94
+ onFrame: PropTypes.func,
95
+ onKeyRest: PropTypes.func,
96
+ onRest: PropTypes.func
97
+ };
98
+ KeyFrames.defaultProps = {
99
+ frames: [],
100
+ loop: false,
101
+ onKeyRest: noop,
102
+ onRest: noop,
103
+ onFrame: noop
104
+ };
@@ -0,0 +1,57 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import '@douyinfe/semi-animation-styled';
4
+ import noop from './utils/noop';
5
+ export interface StyledAnimationProps {
6
+ className?: string;
7
+ type?: any;
8
+ style?: React.CSSProperties;
9
+ speed?: string | number;
10
+ delay?: string | number;
11
+ reverse?: boolean | string;
12
+ loop?: string | number;
13
+ children?: any;
14
+ onStart?: (value: any) => void;
15
+ onFrame?: (value: any) => void;
16
+ onRest?: (value: any) => void;
17
+ prefixCls?: string;
18
+ timing?: string;
19
+ duration?: string | number;
20
+ fillMode?: string;
21
+ }
22
+ export default class StyledAnimation extends PureComponent<StyledAnimationProps> {
23
+ static propTypes: {
24
+ className: PropTypes.Requireable<string>;
25
+ type: PropTypes.Requireable<any>;
26
+ speed: PropTypes.Requireable<string | number>;
27
+ delay: PropTypes.Requireable<string | number>;
28
+ reverse: PropTypes.Requireable<string | boolean>;
29
+ loop: PropTypes.Requireable<string | number>;
30
+ children: PropTypes.Requireable<any>;
31
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
32
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
33
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
34
+ prefixCls: PropTypes.Requireable<string>;
35
+ timing: PropTypes.Requireable<string>;
36
+ duration: PropTypes.Requireable<string | number>;
37
+ fillMode: PropTypes.Requireable<string>;
38
+ };
39
+ static defaultProps: {
40
+ prefixCls: string;
41
+ speed: string;
42
+ onFrame: typeof noop;
43
+ onStart: typeof noop;
44
+ onRest: typeof noop;
45
+ };
46
+ constructor(props?: {});
47
+ _generateAnimateEvents: (child: React.ReactElement, props?: StyledAnimationProps) => {
48
+ onAnimationIteration: (...args: any) => void;
49
+ onAnimationStart: (...args: any) => void;
50
+ onAnimationEnd: (...args: any) => void;
51
+ };
52
+ _hasSpeedClass: (speed?: string | number) => boolean;
53
+ _hasTypeClass: (type?: any) => any;
54
+ _hasDelayClass: (delay?: string | number) => boolean;
55
+ _hasLoopClass: (loop?: string | number) => boolean;
56
+ render(): any;
57
+ }
@@ -0,0 +1,131 @@
1
+ var _context;
2
+
3
+ import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
4
+ import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
5
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
6
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
7
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
8
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
9
+
10
+ /* eslint-disable react/destructuring-assignment */
11
+
12
+ /* eslint-disable prefer-const */
13
+
14
+ /* eslint-disable eqeqeq */
15
+
16
+ /* eslint-disable import/no-duplicates */
17
+
18
+ /* eslint-disable no-duplicate-imports */
19
+ import { PureComponent, isValidElement, cloneElement, Children } from 'react';
20
+ import PropTypes from 'prop-types';
21
+ import classnames from 'classnames';
22
+ import '@douyinfe/semi-animation-styled'; // eslint-disable-next-line @typescript-eslint/no-duplicate-imports
23
+
24
+ import { types as styledTypes, loops, delays, speeds } from '@douyinfe/semi-animation-styled';
25
+ import noop from './utils/noop';
26
+ import invokeFns from './utils/invokeFns';
27
+
28
+ const types = _reduceInstanceProperty(_context = _Object$values(styledTypes)).call(_context, (arr, cur) => [...arr, ...cur], []);
29
+
30
+ export default class StyledAnimation extends PureComponent {
31
+ constructor(props = {}) {
32
+ super(props);
33
+
34
+ this._generateAnimateEvents = (child, props = {}) => ({
35
+ onAnimationIteration: (...args) => invokeFns([child && child.props && child.props.onAnimationIteration, props.onFrame], args),
36
+ onAnimationStart: (...args) => invokeFns([child && child.props && child.props.onAnimationStart, props.onStart], args),
37
+ onAnimationEnd: (...args) => invokeFns([child && child.props && child.props.onAnimationEnd, props.onRest], args)
38
+ });
39
+
40
+ this._hasSpeedClass = (speed = this.props.speed) => speed != null && _includesInstanceProperty(speeds).call(speeds, speed);
41
+
42
+ this._hasTypeClass = (type = this.props.type) => type != null && _includesInstanceProperty(types).call(types, type);
43
+
44
+ this._hasDelayClass = (delay = this.props.delay) => delay != null && _includesInstanceProperty(delays).call(delays, delay);
45
+
46
+ this._hasLoopClass = (loop = this.props.loop) => loop != null && _includesInstanceProperty(loops).call(loops, loop);
47
+ }
48
+
49
+ render() {
50
+ var _context2, _context3, _context4, _context5;
51
+
52
+ let {
53
+ type,
54
+ speed,
55
+ duration,
56
+ delay,
57
+ loop,
58
+ reverse,
59
+ children,
60
+ prefixCls,
61
+ timing,
62
+ className,
63
+ fillMode
64
+ } = this.props;
65
+
66
+ const hasTypeClass = this._hasTypeClass();
67
+
68
+ const hasSpeedClass = this._hasSpeedClass();
69
+
70
+ const hasDelayClass = this._hasDelayClass();
71
+
72
+ const hasLoopClass = this._hasLoopClass();
73
+
74
+ const animateCls = className || classnames("".concat(prefixCls, "-animated"), {
75
+ [_concatInstanceProperty(_context2 = "".concat(prefixCls, "-")).call(_context2, type)]: Boolean(type),
76
+ [_concatInstanceProperty(_context3 = "".concat(prefixCls, "-speed-")).call(_context3, speed)]: hasSpeedClass,
77
+ [_concatInstanceProperty(_context4 = "".concat(prefixCls, "-delay-")).call(_context4, delay)]: hasDelayClass,
78
+ [_concatInstanceProperty(_context5 = "".concat(prefixCls, "-loop-")).call(_context5, loop)]: hasLoopClass
79
+ });
80
+ const animateStyle = {
81
+ animationTimingFunction: timing,
82
+ animationName: !hasTypeClass && type,
83
+ animationDuration: duration,
84
+ animationDelay: !hasDelayClass && delay,
85
+ animationIterationCount: !hasLoopClass && loop,
86
+ animationDirection: reverse ? 'alternate' : 'normal',
87
+ animationFillMode: fillMode
88
+ };
89
+
90
+ if ( /*#__PURE__*/isValidElement(children)) {
91
+ children = _mapInstanceProperty(Children).call(Children, children, child => {
92
+ const animateEvents = this._generateAnimateEvents(child, this.props);
93
+
94
+ return /*#__PURE__*/cloneElement(child, _Object$assign({
95
+ className: classnames(child.props.className, animateCls),
96
+ style: _Object$assign(_Object$assign({}, child.props.style), this.props.style)
97
+ }, animateEvents));
98
+ });
99
+ }
100
+
101
+ return typeof children === 'function' ? children({
102
+ animateCls,
103
+ animateStyle,
104
+ animateEvents: this._generateAnimateEvents(null, this.props)
105
+ }) : children;
106
+ }
107
+
108
+ }
109
+ StyledAnimation.propTypes = {
110
+ className: PropTypes.string,
111
+ type: PropTypes.oneOfType([PropTypes.string, PropTypes.any]),
112
+ speed: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
113
+ delay: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
114
+ reverse: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
115
+ loop: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
116
+ children: PropTypes.any,
117
+ onStart: PropTypes.func,
118
+ onFrame: PropTypes.func,
119
+ onRest: PropTypes.func,
120
+ prefixCls: PropTypes.string,
121
+ timing: PropTypes.string,
122
+ duration: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
123
+ fillMode: PropTypes.string
124
+ };
125
+ StyledAnimation.defaultProps = {
126
+ prefixCls: 'semi',
127
+ speed: 'faster',
128
+ onFrame: noop,
129
+ onStart: noop,
130
+ onRest: noop
131
+ };
@@ -0,0 +1,49 @@
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { StyledAnimationProps } from './StyledAnimation';
4
+ import noop from './utils/noop';
5
+ export interface StyledTransitionProps extends StyledAnimationProps {
6
+ state?: string | boolean;
7
+ enter?: string;
8
+ leave?: string;
9
+ children?: React.ReactNode;
10
+ willEnter?: (value: any) => void;
11
+ didEnter?: (value: any) => void;
12
+ willLeave?: (value: any) => void;
13
+ didLeave?: (value: any) => void;
14
+ onStart?: (value: any) => void;
15
+ onRest?: (value: any) => void;
16
+ }
17
+ export interface StyledTransitionState {
18
+ state: string | boolean;
19
+ lastChildren: React.ReactNode;
20
+ currentChildren: React.ReactNode;
21
+ }
22
+ export default class StyledTransition extends Component<StyledTransitionProps, StyledTransitionState> {
23
+ static propTypes: {
24
+ state: PropTypes.Requireable<string>;
25
+ enter: PropTypes.Requireable<string>;
26
+ leave: PropTypes.Requireable<string>;
27
+ children: PropTypes.Requireable<any>;
28
+ willEnter: PropTypes.Requireable<(...args: any[]) => any>;
29
+ didEnter: PropTypes.Requireable<(...args: any[]) => any>;
30
+ willLeave: PropTypes.Requireable<(...args: any[]) => any>;
31
+ didLeave: PropTypes.Requireable<(...args: any[]) => any>;
32
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
33
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
34
+ };
35
+ static defaultProps: {
36
+ willEnter: typeof noop;
37
+ didEnter: typeof noop;
38
+ willLeave: typeof noop;
39
+ didLeave: typeof noop;
40
+ onStart: typeof noop;
41
+ onRest: typeof noop;
42
+ };
43
+ constructor(props?: {});
44
+ static getDerivedStateFromProps(props: StyledTransitionProps, state: StyledTransitionState): Partial<StyledTransitionState>;
45
+ _isControlled: () => boolean;
46
+ onRest: (props: any) => void;
47
+ onStart: (props: any) => void;
48
+ render(): JSX.Element;
49
+ }
@@ -0,0 +1,161 @@
1
+ import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
4
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
5
+
6
+ var __rest = this && this.__rest || function (s, e) {
7
+ var t = {};
8
+
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && _indexOfInstanceProperty(e).call(e, p) < 0) t[p] = s[p];
10
+
11
+ if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
12
+ if (_indexOfInstanceProperty(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ };
16
+ /* eslint-disable eqeqeq */
17
+
18
+
19
+ import React, { Component } from 'react';
20
+ import PropTypes from 'prop-types';
21
+ import StyledAnimation from './StyledAnimation';
22
+ import noop from './utils/noop';
23
+ export default class StyledTransition extends Component {
24
+ constructor(props = {}) {
25
+ super(props);
26
+
27
+ this._isControlled = () => {
28
+ var _context;
29
+
30
+ return _includesInstanceProperty(_context = [true, false, 'enter', 'leave']).call(_context, this.props.state);
31
+ };
32
+
33
+ this.onRest = props => {
34
+ const {
35
+ state
36
+ } = this.state;
37
+
38
+ if (state === 'enter') {
39
+ this.props.didEnter(props);
40
+ } else if (state === 'leave') {
41
+ this.setState({
42
+ currentChildren: null,
43
+ lastChildren: null
44
+ });
45
+ this.props.didLeave(props);
46
+ }
47
+
48
+ this.props.onRest(props);
49
+ };
50
+
51
+ this.onStart = props => {
52
+ const {
53
+ state
54
+ } = this.state;
55
+
56
+ if (state === 'enter') {
57
+ this.props.willEnter(props);
58
+ } else if (state === 'leave') {
59
+ this.props.willLeave(props);
60
+ }
61
+
62
+ this.props.onStart(props);
63
+ };
64
+
65
+ this.state = {
66
+ state: '',
67
+ lastChildren: null,
68
+ currentChildren: null
69
+ };
70
+ }
71
+
72
+ static getDerivedStateFromProps(props, state) {
73
+ const willUpdateStates = {};
74
+
75
+ if (props.children !== state.currentChildren) {
76
+ willUpdateStates.lastChildren = state.currentChildren;
77
+ willUpdateStates.currentChildren = props.children;
78
+
79
+ if (props.children == null) {
80
+ willUpdateStates.state = 'leave';
81
+ } else {
82
+ willUpdateStates.state = 'enter';
83
+ }
84
+ }
85
+
86
+ if (props.state != null && props.state !== state.state) {
87
+ willUpdateStates.state = props.state;
88
+ }
89
+
90
+ return willUpdateStates;
91
+ }
92
+
93
+ render() {
94
+ const _a = this.props,
95
+ {
96
+ enter,
97
+ leave
98
+ } = _a,
99
+ restProps = __rest(_a, ["enter", "leave"]);
100
+
101
+ const {
102
+ currentChildren,
103
+ lastChildren
104
+ } = this.state;
105
+
106
+ const isControlled = this._isControlled();
107
+
108
+ let children, type;
109
+ let {
110
+ state
111
+ } = this.state;
112
+
113
+ if (isControlled) {
114
+ children = this.props.children;
115
+ state = this.props.state;
116
+ } else if (currentChildren == null && lastChildren == null) {
117
+ return null;
118
+ }
119
+
120
+ if (state === 'enter') {
121
+ type = enter;
122
+
123
+ if (!isControlled) {
124
+ children = currentChildren;
125
+ }
126
+ } else if (state === 'leave') {
127
+ type = leave;
128
+
129
+ if (!isControlled) {
130
+ children = lastChildren;
131
+ }
132
+ }
133
+
134
+ return /*#__PURE__*/React.createElement(StyledAnimation, _Object$assign({}, restProps, {
135
+ type: type,
136
+ onStart: this.onStart,
137
+ onRest: this.onRest
138
+ }), children);
139
+ }
140
+
141
+ }
142
+ StyledTransition.propTypes = {
143
+ state: PropTypes.string,
144
+ enter: PropTypes.string,
145
+ leave: PropTypes.string,
146
+ children: PropTypes.any,
147
+ willEnter: PropTypes.func,
148
+ didEnter: PropTypes.func,
149
+ willLeave: PropTypes.func,
150
+ didLeave: PropTypes.func,
151
+ onStart: PropTypes.func,
152
+ onRest: PropTypes.func
153
+ };
154
+ StyledTransition.defaultProps = {
155
+ willEnter: noop,
156
+ didEnter: noop,
157
+ willLeave: noop,
158
+ didLeave: noop,
159
+ onStart: noop,
160
+ onRest: noop
161
+ };
@@ -0,0 +1,52 @@
1
+ import { AnimationProps } from './Animation';
2
+ import PropTypes from 'prop-types';
3
+ import React, { Component } from 'react';
4
+ import noop from './utils/noop';
5
+ export interface TransitionProps extends AnimationProps {
6
+ children?: React.ReactNode;
7
+ from?: Record<string, any>;
8
+ enter?: Record<string, any>;
9
+ leave?: Record<string, any>;
10
+ state?: string | boolean;
11
+ willEnter?: (value: any) => void;
12
+ didEnter?: (value: any) => void;
13
+ willLeave?: (value: any) => void;
14
+ didLeave?: (value: any) => void;
15
+ onRest?: (value: any) => void;
16
+ onStart?: (value: any) => void;
17
+ }
18
+ export interface TransitionState {
19
+ state: string | boolean;
20
+ lastChildren: React.ReactNode;
21
+ currentChildren: React.ReactNode;
22
+ }
23
+ export default class Transition extends Component<TransitionProps, TransitionState> {
24
+ static propTypes: {
25
+ children: PropTypes.Requireable<any>;
26
+ from: PropTypes.Requireable<object>;
27
+ enter: PropTypes.Requireable<object>;
28
+ leave: PropTypes.Requireable<object>;
29
+ willEnter: PropTypes.Requireable<(...args: any[]) => any>;
30
+ didEnter: PropTypes.Requireable<(...args: any[]) => any>;
31
+ willLeave: PropTypes.Requireable<(...args: any[]) => any>;
32
+ didLeave: PropTypes.Requireable<(...args: any[]) => any>;
33
+ state: PropTypes.Requireable<string | boolean>;
34
+ };
35
+ static defaultProps: {
36
+ willEnter: typeof noop;
37
+ didEnter: typeof noop;
38
+ willLeave: typeof noop;
39
+ didLeave: typeof noop;
40
+ onStart: typeof noop;
41
+ onRest: typeof noop;
42
+ };
43
+ instance: any;
44
+ constructor(props?: {});
45
+ static getDerivedStateFromProps(props: TransitionProps, state: TransitionState): Partial<TransitionState>;
46
+ componentWillUnmount(): void;
47
+ _isControlled: () => boolean;
48
+ forwardInstance: (instance: any) => void;
49
+ onRest: (props: any) => void;
50
+ onStart: (props: any) => void;
51
+ render(): JSX.Element;
52
+ }
@@ -0,0 +1,178 @@
1
+ import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
4
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
5
+
6
+ var __rest = this && this.__rest || function (s, e) {
7
+ var t = {};
8
+
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && _indexOfInstanceProperty(e).call(e, p) < 0) t[p] = s[p];
10
+
11
+ if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
12
+ if (_indexOfInstanceProperty(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ };
16
+ /* eslint-disable eqeqeq */
17
+
18
+
19
+ import Animation from './Animation';
20
+ import PropTypes from 'prop-types';
21
+ import React, { Component, isValidElement } from 'react';
22
+ import noop from './utils/noop';
23
+ export default class Transition extends Component {
24
+ constructor(props = {}) {
25
+ super(props);
26
+
27
+ this._isControlled = () => {
28
+ var _context;
29
+
30
+ return _includesInstanceProperty(_context = [true, false, 'enter', 'leave']).call(_context, this.props.state);
31
+ };
32
+
33
+ this.forwardInstance = instance => {
34
+ this.instance = instance;
35
+ };
36
+
37
+ this.onRest = props => {
38
+ const {
39
+ state
40
+ } = this.state;
41
+
42
+ if (state === 'enter') {
43
+ this.props.didEnter(props);
44
+ } else if (state === 'leave') {
45
+ this.setState({
46
+ currentChildren: null,
47
+ lastChildren: null
48
+ });
49
+ this.props.didLeave(props);
50
+ }
51
+
52
+ this.props.onRest(props);
53
+ };
54
+
55
+ this.onStart = props => {
56
+ const {
57
+ state
58
+ } = this.state;
59
+
60
+ if (state === 'enter') {
61
+ this.props.willEnter(props);
62
+ } else if (state === 'leave') {
63
+ this.props.willLeave(props);
64
+ }
65
+
66
+ this.props.onStart(props);
67
+ };
68
+
69
+ this.state = {
70
+ state: '',
71
+ lastChildren: null,
72
+ currentChildren: null
73
+ };
74
+ }
75
+
76
+ static getDerivedStateFromProps(props, state) {
77
+ const willUpdateStates = {};
78
+
79
+ if (props.children !== state.currentChildren // && (props.children == null || state.currentChildren == null)
80
+ ) {
81
+ willUpdateStates.lastChildren = state.currentChildren;
82
+ willUpdateStates.currentChildren = props.children;
83
+
84
+ if (props.children == null) {
85
+ willUpdateStates.state = 'leave';
86
+ } else {
87
+ willUpdateStates.state = 'enter';
88
+ }
89
+ }
90
+
91
+ if (props.state != null) {
92
+ willUpdateStates.state = props.state;
93
+ }
94
+
95
+ return willUpdateStates;
96
+ }
97
+
98
+ componentWillUnmount() {
99
+ if (this.instance) {
100
+ this.instance.destroy();
101
+ this.instance = null;
102
+ }
103
+ }
104
+
105
+ render() {
106
+ const _a = this.props,
107
+ {
108
+ from: propsFrom,
109
+ enter,
110
+ leave
111
+ } = _a,
112
+ restProps = __rest(_a, ["from", "enter", "leave"]);
113
+
114
+ let children; // eslint-disable-next-line prefer-const
115
+
116
+ let {
117
+ currentChildren,
118
+ lastChildren,
119
+ state
120
+ } = this.state;
121
+ let from = {};
122
+ let to = {};
123
+
124
+ const isControlled = this._isControlled();
125
+
126
+ if (isControlled) {
127
+ children = this.props.children;
128
+ state = this.props.state;
129
+ } else if (currentChildren == null && lastChildren == null) {
130
+ return null;
131
+ }
132
+
133
+ if (state === 'enter') {
134
+ from = propsFrom;
135
+ to = enter;
136
+
137
+ if (!isControlled) {
138
+ children = currentChildren;
139
+ }
140
+ } else if (state === 'leave') {
141
+ from = enter;
142
+ to = leave;
143
+
144
+ if (!isControlled) {
145
+ children = lastChildren;
146
+ }
147
+ }
148
+
149
+ return /*#__PURE__*/React.createElement(Animation, _Object$assign({}, restProps, {
150
+ force: true,
151
+ from: from,
152
+ to: to,
153
+ onRest: this.onRest,
154
+ onStart: this.onStart
155
+ }), props => // eslint-disable-next-line no-nested-ternary
156
+ typeof children === 'function' ? children(props) : /*#__PURE__*/isValidElement(children) ? children : null);
157
+ }
158
+
159
+ }
160
+ Transition.propTypes = {
161
+ children: PropTypes.any,
162
+ from: PropTypes.object,
163
+ enter: PropTypes.object,
164
+ leave: PropTypes.object,
165
+ willEnter: PropTypes.func,
166
+ didEnter: PropTypes.func,
167
+ willLeave: PropTypes.func,
168
+ didLeave: PropTypes.func,
169
+ state: PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
170
+ };
171
+ Transition.defaultProps = {
172
+ willEnter: noop,
173
+ didEnter: noop,
174
+ willLeave: noop,
175
+ didLeave: noop,
176
+ onStart: noop,
177
+ onRest: noop
178
+ };
@@ -0,0 +1 @@
1
+ export default function invokeFns(fns: any[], args?: any[]): void;
@@ -0,0 +1,11 @@
1
+ import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
2
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
3
+ export default function invokeFns(fns, args = []) {
4
+ if (_Array$isArray(fns) && fns.length) {
5
+ _forEachInstanceProperty(fns).call(fns, fn => {
6
+ if (typeof fn === 'function') {
7
+ fn(...args);
8
+ }
9
+ });
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export default function noop(): void;
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2
+ export default function noop() {}
@@ -0,0 +1 @@
1
+
File without changes
@@ -0,0 +1,2 @@
1
+ export declare function upperCase(str: string, pos: number): string;
2
+ export declare function lowerCase(str: string, pos: number): string;
@@ -0,0 +1,25 @@
1
+ import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
2
+
3
+ /* eslint-disable eqeqeq */
4
+ export function upperCase(str, pos) {
5
+ if (typeof str === 'string') {
6
+ var _context;
7
+
8
+ return _reduceInstanceProperty(_context = str // eslint-disable-next-line @typescript-eslint/ban-ts-comment
9
+ // @ts-ignore
10
+ .split()).call(_context, (total, cur, index) => pos == null || pos === index ? total + cur.toUpperCase() : total + cur, '');
11
+ }
12
+
13
+ return str;
14
+ }
15
+ export function lowerCase(str, pos) {
16
+ if (typeof str === 'string') {
17
+ var _context2;
18
+
19
+ return _reduceInstanceProperty(_context2 = str // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
+ // @ts-ignore
21
+ .split()).call(_context2, (total, cur, index) => pos == null || pos === index ? total + cur.toLowerCase() : total + cur, '');
22
+ }
23
+
24
+ return str;
25
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@douyinfe/semi-animation-react",
3
+ "version": "2.0.0-alpha.0",
4
+ "description": "motion library for semi-ui-react",
5
+ "keywords": [
6
+ "motion",
7
+ "react",
8
+ "semi-ui"
9
+ ],
10
+ "files": [
11
+ "lib",
12
+ "README.md"
13
+ ],
14
+ "license": "MIT",
15
+ "main": "lib/es/index.js",
16
+ "module": "lib/es/index.js",
17
+ "typings": "lib/es/index.d.ts",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/DouyinFE/semi-design"
21
+ },
22
+ "scripts": {
23
+ "test": "echo \"Error: run tests from root\" && exit 1",
24
+ "build:lib": "node scripts/compileLib",
25
+ "prepublishOnly": "npm run build:lib"
26
+ },
27
+ "dependencies": {
28
+ "@babel/runtime-corejs3": "^7.15.4",
29
+ "@douyinfe/semi-animation": "2.0.0-alpha.0",
30
+ "@douyinfe/semi-animation-styled": "2.0.0-alpha.0",
31
+ "classnames": "^2.2.6"
32
+ },
33
+ "peerDependencies": {
34
+ "prop-types": "15.7.2",
35
+ "react": ">=16.0.0",
36
+ "react-dom": ">=16.0.1"
37
+ },
38
+ "devDependencies": {
39
+ "@babel/plugin-proposal-decorators": "^7.15.8",
40
+ "@babel/plugin-transform-runtime": "^7.15.8",
41
+ "@babel/preset-env": "^7.15.8",
42
+ "@babel/preset-react": "^7.14.5",
43
+ "@storybook/addon-knobs": "^6.3.1",
44
+ "@vx/gradient": "0.0.199",
45
+ "del": "^6.0.0",
46
+ "flubber": "^0.4.2",
47
+ "gulp": "^4.0.2",
48
+ "gulp-babel": "^8.0.0",
49
+ "gulp-typescript": "^6.0.0-alpha.1",
50
+ "merge2": "^1.4.1",
51
+ "prop-types": "15.7.2",
52
+ "react-storybook-addon-props-combinations": "^1.1.0"
53
+ },
54
+ "gitHead": "5344f767711f1677a6113bc7fc38d1853bcc7f5a"
55
+ }