-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
import {Component} from 'react'; | ||
import * as React from 'react'; | ||
import {IBaseComponent} from '../template/component'; | ||
import {Transition} from 'react-transition-group'; | ||
|
||
export interface IScaleProps extends IBaseComponent { | ||
/** | ||
* 动画时间 ms | ||
*/ | ||
timeout: number; | ||
/** | ||
* 激活状态 | ||
*/ | ||
active: boolean; | ||
} | ||
|
||
export interface IScaleState { | ||
|
||
} | ||
|
||
/** | ||
* **组件中文名称**-组件描述。 | ||
*/ | ||
export class Scale extends Component<IScaleProps, IScaleState> { | ||
refChild: HTMLElement; | ||
|
||
static defaultProps = { | ||
}; | ||
|
||
render() { | ||
const { | ||
active, timeout, children, | ||
} = this.props; | ||
|
||
const transition = { | ||
exit: 'scale(0)', | ||
enter: 'scale(1)', | ||
}; | ||
|
||
return ( | ||
<Transition | ||
timeout={timeout} | ||
in={active} | ||
mountOnEnter | ||
unmountOnExit | ||
appear | ||
onEnter={() => { | ||
this.refChild.style.transform = transition.exit; | ||
this.refChild.style.opacity = '0'; | ||
this.refChild.style.display = null; | ||
}} | ||
onEntering={() => { | ||
setTimeout(() => { | ||
this.refChild.style.transform = transition.enter; | ||
this.refChild.style.opacity = '1'; | ||
}, 0); | ||
}} | ||
onEntered={() => { | ||
this.refChild.style.transform = null; | ||
this.refChild.style.opacity = null; | ||
}} | ||
onExit={() => { | ||
this.refChild.style.transform = transition.enter; | ||
this.refChild.style.opacity = '1'; | ||
}} | ||
onExiting={() => { | ||
setTimeout(() => { | ||
this.refChild.style.transform = transition.exit; | ||
this.refChild.style.opacity = '0'; | ||
}, 0); | ||
}} | ||
onExited={() => { | ||
this.refChild.style.transform = null; | ||
this.refChild.style.opacity = null; | ||
this.refChild.style.display = 'none'; | ||
}} | ||
> | ||
{ | ||
() => { | ||
const child = React.Children.only(children); | ||
return React.cloneElement(child, { | ||
style: { | ||
...child.props.style, | ||
transition: `all ${timeout / 1000}s cubic-bezier(.645,.045,.355,1)`, | ||
}, | ||
ref: (v: HTMLElement) => { | ||
if (v) { | ||
this.refChild = v; | ||
} | ||
if (child.props.ref) { | ||
child.props.ref(); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
</Transition> | ||
); | ||
} | ||
} | ||
|
||
export default Scale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import Expand from './Expand'; | ||
import Slide from './Slide'; | ||
import Scale from './Scale'; | ||
|
||
const Transitions = { | ||
Expand, | ||
Slide, | ||
Scale, | ||
}; | ||
|
||
export default Transitions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#### Scale 放缩 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as React from 'react'; | ||
import { Transitions, Switch } from '../../../../components/'; | ||
import './index.less'; | ||
|
||
const {Scale} = Transitions; | ||
|
||
export default class App extends React.Component { | ||
state = { | ||
active: true, | ||
} | ||
|
||
onScale = (checked: boolean) => { | ||
this.setState({ | ||
active: checked, | ||
}); | ||
} | ||
|
||
render () { | ||
const height = 200; | ||
const {active} = this.state; | ||
const style: React.CSSProperties = { | ||
height, | ||
lineHeight: `${height}px`, | ||
}; | ||
return ( | ||
<div style={{height: 300}}> | ||
<Switch checked={active} onChange={this.onScale}>开/关</Switch> | ||
<Scale | ||
timeout={300} | ||
active={active} | ||
> | ||
<div | ||
className='transitions-expand-demo-box' | ||
style={style} | ||
> | ||
放缩 | ||
</div> | ||
</Scale> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters