Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Animate): Technical Upgrade #4719

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions components/animate/__docs__/demo/basic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import ReactDOM from 'react-dom';
import { Animate } from '@alifd/next';

class Demo extends React.Component {
constructor(props) {
super(props);
this.state = { visible: true };
this.handleToggle = this.handleToggle.bind(this);
}
state = { visible: true };

handleToggle() {
handleToggle = () => {
this.setState({
visible: !this.state.visible,
});
}
};

render() {
return (
Expand Down
49 changes: 18 additions & 31 deletions components/animate/__docs__/demo/expand/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,40 @@ import ReactDOM from 'react-dom';
import { Animate } from '@alifd/next';

class Demo extends React.Component {
constructor(props) {
super(props);
this.state = { expand: true };
[
'beforeEnter',
'onEnter',
'afterEnter',
'beforeLeave',
'onLeave',
'afterLeave',
'handleToggle',
].forEach(method => {
this[method] = this[method].bind(this);
});
}
state = { expand: true };
height: number | null;

handleToggle() {
handleToggle = () => {
this.setState({
expand: !this.state.expand,
});
}
};

beforeEnter(node) {
beforeEnter = (node: HTMLElement) => {
this.height = node.offsetHeight;
node.style.height = '0px';
}
};

onEnter(node) {
onEnter = (node: HTMLElement) => {
node.style.height = `${this.height}px`;
}
};

afterEnter(node) {
afterEnter = (node: HTMLElement) => {
this.height = null;
node.style.height = null;
}
node.style.setProperty('height', null);
};

beforeLeave(node) {
beforeLeave = (node: HTMLElement) => {
node.style.height = `${this.height}px`;
}
};

onLeave(node) {
onLeave = (node: HTMLElement) => {
node.style.height = '0px';
}
};

afterLeave(node) {
node.style.height = null;
}
afterLeave = (node: HTMLElement) => {
node.style.setProperty('height', null);
};

render() {
return (
Expand Down
13 changes: 5 additions & 8 deletions components/animate/__docs__/demo/multiple/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import ReactDOM from 'react-dom';
import { Animate } from '@alifd/next';

class TodoList extends React.Component {
constructor(props) {
super(props);
this.state = { items: ['hello', 'world', 'click', 'me'] };
}
state = { items: ['hello', 'world', 'click', 'me'] };

handleAdd() {
this.setState({
items: [
...this.state.items,
// eslint-disable-next-line
prompt('Enter some text'),
// eslint-disable-next-line no-alert
window.prompt('Enter some text'),
],
});
}

handleRemove(i) {
handleRemove(i: number) {
const newItems = this.state.items.slice();
newItems.splice(i, 1);
this.setState({ items: newItems });
Expand All @@ -42,7 +39,7 @@ class TodoList extends React.Component {
onLeave={() => console.log('leave')}
afterLeave={() => console.log('after leave')}
>
{this.state.items.map((item, i) => (
{this.state.items.map((item: string, i: number) => (
<div key={item}>
{item}
<button onClick={() => this.handleRemove(i)}>&times;</button>
Expand Down
90 changes: 63 additions & 27 deletions components/animate/__docs__/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,69 @@ Need to customize animation.

### Animate

| Param | Descripiton | Type | Default Value |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | -------- |
| animation | animation class names | String/Object | - |
| animationAppear | whether the child elements performs animation when it is first mounted | Boolean | true |
| component | component wrapped child element | any | 'div' |
| singleMode | whether there is only a single child element, if there is more than one child element, set it to false | Boolean | true |
| children | child elements | ReactElement/Array&lt;ReactElement> | - |
| beforeAppear | triggered before performing the first mount animation<br><br>**signatures**:<br>Function() => void | Function | () => {} |
| onAppear | triggered after adding the xxx-appear-active class name<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| afterAppear | triggered after performing the first mount animation<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| beforeEnter | triggered before performing the enter animation<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| onEnter | triggered after adding the xxx-enter-active class name<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| afterEnter | triggered after performing the enter animation<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| beforeLeave | triggered before performing the leave animation<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| onLeave | triggered after adding the xxx-leave-active class name<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| afterLeave | triggered after performing the leave animation<br><br>**signatures**:<br>Function(node: HTMLElement) => void<br>**params**:<br>_node_: {HTMLElement} animated dom element | Function | () => {} |
| Param | Description | Type | Default Value | Required |
| --------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------- | -------- |
| animation | The animation className | string \| Partial<Record<'appear' \| 'enter' \| 'leave', string>> | - | |
| animationAppear | Whether to execute animation on the first mount | boolean | true | |
| component | The tag of the wrapper | React.ElementType | 'div' | |
| singleMode | Whether to only have a single child | boolean | true | |
| beforeAppear | Callback fired before the "entering" status of the first mount is applied | (node: HTMLElement) => void | - | |
| onAppear | Callback fired after the "entering" status of the first mount is applied | (node: HTMLElement) => void | - | |
| afterAppear | Callback fired after the "entered" status of the first mount is applied | (node: HTMLElement) => void | - | |
| beforeEnter | Callback fired before the "entering" status is applied | (node: HTMLElement) => void | - | |
| onEnter | Callback fired after the "entering" status is applied | (node: HTMLElement) => void | - | |
| afterEnter | Callback fired after the "entered" status is applied | (node: HTMLElement) => void | - | |
| beforeLeave | Callback fired before the "exiting" status is applied | (node: HTMLElement) => void | - | |
| onLeave | Callback fired after the leave stage | (node: HTMLElement) => void | - | |
| afterLeave | Callback fired after the leave stage | (node: HTMLElement) => void | - | |

### Animate.Expand

| Param | Description | Type | Default Value | Required |
| ----------- | ------------------------------------------------------ | ----------------------------------------------------------------- | ------------- | -------- |
| animation | The animation className | string \| Partial<Record<'appear' \| 'enter' \| 'leave', string>> | - | |
| beforeEnter | Callback fired before the "entering" status is applied | (node: HTMLElement) => void | - | |
| onEnter | Callback fired after the "entering" status is applied | (node: HTMLElement) => void | - | |
| afterEnter | Callback fired after the "entered" status is applied | (node: HTMLElement) => void | - | |
| beforeLeave | Callback fired before the "exiting" status is applied | (node: HTMLElement) => void | - | |
| onLeave | Callback fired after the "exiting" status is applied | (node: HTMLElement) => void | - | |
| afterLeave | Callback fired after the "exited" status is applied | (node: HTMLElement) => void | - | |

### Animate.OverlayAnimate

| Param | Description | Type | Default Value | Required |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- | ------------- | -------- |
| animation | The animation className | string \| false \| Record<'in' \| 'out', string> | - | |
| visible | Show the component; triggers the enter or exit states | boolean | - | |
| children | The element to be wrapped | ReactElement | - | yes |
| timeout | The duration of the transition. | \| number<br/> \| { appear?: number \| undefined; enter?: number \| undefined; exit?: number \| undefined } | - | |
| style | The style of the child element | React.CSSProperties | - | |
| mountOnEnter | "lazy mount" the component on the first `in={true}` | boolean | false | |
| unmountOnExit | "lazy unmount" the component on the first `in={false}` | boolean | false | |
| onEnter | Callback fired before the "entering" status is applied.<br/><br/>**signature**:<br/>**params**:<br/>_isAppearing_: IsAppearing | (node: HTMLElement, isAppearing: boolean) => void | - | |
| onEntering | Callback fired after the "entering" status is applied.<br/><br/>**signature**:<br/>**params**:<br/>_isAppearing_: IsAppearing | (node: HTMLElement, isAppearing: boolean) => void | - | |
| onEntered | Callback fired after the "entered" status is applied.<br/><br/>**signature**:<br/>**params**:<br/>_isAppearing_: IsAppearing | (node: HTMLElement, isAppearing: boolean) => void | - | |
| onExit | Callback fired before the "exiting" status is applied. | (node: HTMLElement) => void | - | |
| onExiting | Callback fired after the "exiting" status is applied. | (node: HTMLElement) => void | - | |
| onExited | Callback fired after the "exited" status is applied. | (node: HTMLElement) => void | - | |
| appear | Transition on the first mount. | boolean | - | |
| enter | Enable or disable enter transitions. | boolean | - | |
| exit | Enable or disable exit transitions. | boolean | - | |

## Animation List

| In | Out |
| ------------- | ------------------- |
| fadeIn | fadeOut |
| fadeInDown | fadeOutDown |
| fadeInLeft | fadeOutLeft |
| fadeInRight | fadeOutRight |
| fadeInUp | fadeOutUp |
| zoomIn | zoomOut |
| expandInDown | expandOutUp |
| expandInUp | expandOutDown |
| pulse | |
| In | Out |
| ------------ | ------------- |
| fadeIn | fadeOut |
| fadeInDown | fadeOutDown |
| fadeInLeft | fadeOutLeft |
| fadeInRight | fadeOutRight |
| fadeInUp | fadeOutUp |
| slideInDown | slideOutUp |
| slideInLeft | slideOutLeft |
| slideInRight | slideOutRight |
| slideInUp | slideOutDown |
| zoomIn | zoomOut |
| expandInDown | expandOutUp |
| expandInUp | expandOutDown |
| pulse | |
Loading
Loading