Compare commits

...
5 Commits
Author SHA1 Message Date
simaQ a68a839515 update README.md 2015-08-24 14:07:38 +08:00
Emma e615ffb7b0 Merge pull request #20 from jljsj33/addAnimation
add slider animation
2015-08-24 13:59:45 +08:00
jljsj c643ae235e tipTransitionName is tag 2015-08-24 13:21:08 +08:00
jljsj 93c92f5f37 改名字 2015-08-24 13:12:46 +08:00
jljsj 35ba80d884 add slider animation 2015-08-24 11:56:37 +08:00
5 changed files with 91 additions and 14 deletions
+9 -3
View File
@@ -136,6 +136,12 @@ React.render(<Rcslider />, container);
<td>false</td> <td>false</td>
<td>If true the handles can't be moved.</td> <td>If true the handles can't be moved.</td>
</tr> </tr>
<tr>
<td>tipTransitionName</td>
<td>string</td>
<td>''</td>
<td>Set the animation for tooltip if it shows.</td>
</tr>
</tbody> </tbody>
</table> </table>
@@ -148,17 +154,17 @@ npm start
## Example ## Example
http://localhost:8000/examples/ http://localhost:8005/examples/
online example: http://react-component.github.io/slider/ online example: http://react-component.github.io/slider/
## Test Case ## Test Case
http://localhost:8000/tests/runner.html?coverage http://localhost:8005/tests/runner.html?coverage
## Coverage ## Coverage
http://localhost:8000/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8088/tests/runner.html?coverage http://localhost:8005/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8088/tests/runner.html?coverage
## License ## License
+62
View File
@@ -8,6 +8,8 @@
@tooltip-arrow-width: 4px; @tooltip-arrow-width: 4px;
@tooltip-distance: @tooltip-arrow-width+4; @tooltip-distance: @tooltip-arrow-width+4;
@tooltip-arrow-color: @tooltip-bg; @tooltip-arrow-color: @tooltip-bg;
@ease-out-quint : cubic-bezier(0.23, 1, 0.32, 1);
@ease-in-quint : cubic-bezier(0.755, 0.05, 0.855, 0.06);
* { * {
box-sizing: border-box; box-sizing: border-box;
@@ -174,4 +176,64 @@
border-top-color: @tooltip-arrow-color; border-top-color: @tooltip-arrow-color;
} }
} }
}
.motion-common() {
animation-duration: .3s;
animation-fill-mode: both;
display: block !important;
}
.make-motion(@className, @keyframeName) {
.@{className}-enter, .@{className}-appear {
.motion-common();
animation-play-state: paused;
}
.@{className}-leave {
.motion-common();
animation-play-state: paused;
}
.@{className}-enter.@{className}-enter-active, .@{className}-appear.@{className}-appear-active {
animation-name: ~"@{keyframeName}In";
animation-play-state: running;
}
.@{className}-leave.@{className}-leave-active {
animation-name: ~"@{keyframeName}Out";
animation-play-state: running;
}
}
.zoom-motion(@className, @keyframeName) {
.make-motion(@className, @keyframeName);
.@{className}-enter, .@{className}-appear {
transform: scale(0, 0); // need this by yiminghe
animation-timing-function: @ease-out-quint;
}
.@{className}-leave {
animation-timing-function: @ease-in-quint;
}
}
.zoom-motion(zoom-down, zoomDown);
@keyframes zoomDownIn {
0% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
}
100% {
transform-origin: 50% 100%;
transform: scale(1, 1);
}
}
@keyframes zoomDownOut {
0% {
transform-origin: 50% 100%;
transform: scale(1, 1);
}
100% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
}
} }
+1 -1
View File
@@ -11,4 +11,4 @@ function onChange(v){
// React.render(<div style={{width:400,margin:100}}><Slider marks={["一","二","三","四","五"]} defaultIndex={2} /></div>, document.getElementById('__react-content')); // React.render(<div style={{width:400,margin:100}}><Slider marks={["一","二","三","四","五"]} defaultIndex={2} /></div>, document.getElementById('__react-content'));
// React.render(<div style={{width:400,margin:100}}><Slider className='rc-slider' step={20}/></div>, document.getElementById('__react-content')); // React.render(<div style={{width:400,margin:100}}><Slider className='rc-slider' step={20}/></div>, document.getElementById('__react-content'));
React.render(<div style={{width:400,margin:100}}><Slider onChange={onChange}/></div>, document.getElementById('__react-content')); React.render(<div style={{width:400,margin:100}}><Slider onChange={onChange} tipTransitionName='zoom-down'/></div>, document.getElementById('__react-content'));
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "rc-slider", "name": "rc-slider",
"version": "1.4.3", "version": "1.4.4",
"description": "slider ui component for react", "description": "slider ui component for react",
"keywords": [ "keywords": [
"react", "react",
@@ -24,7 +24,7 @@
"licenses": "MIT", "licenses": "MIT",
"main": "./lib/index.js", "main": "./lib/index.js",
"config": { "config": {
"port": 8000 "port": 8005
}, },
"scripts": { "scripts": {
"build": "rc-tools run build", "build": "rc-tools run build",
+17 -8
View File
@@ -56,6 +56,7 @@ const Slider = React.createClass({
onBeforeChange: React.PropTypes.func, onBeforeChange: React.PropTypes.func,
onChange: React.PropTypes.func, onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func, onAfterChange: React.PropTypes.func,
tipTransitionName: React.PropTypes.string,
}, },
getDefaultProps() { getDefaultProps() {
@@ -70,6 +71,7 @@ const Slider = React.createClass({
prefixCls: 'rc-slider', prefixCls: 'rc-slider',
disabled: false, disabled: false,
defaultIndex: 0, defaultIndex: 0,
tipTransitionName: '',
}; };
}, },
@@ -103,8 +105,14 @@ const Slider = React.createClass({
} }
}, },
onMouseUp() { onMouseUp(e) {
this._end('mouse'); const m = e.target;
const handleDom = React.findDOMNode(this.refs.handle);
let showToolTip = false;
if (m === handleDom) {
showToolTip = true;
}
this._end('mouse', showToolTip);
}, },
onTouchUp() { onTouchUp() {
@@ -308,8 +316,8 @@ const Slider = React.createClass({
const handle = (<div className={className} const handle = (<div className={className}
{...events} {...events}
ref="handle" ref="handle"
style={onStyle}></div>); style={onStyle}></div>);
if (this.props.marks.length > 0) { if (this.props.marks.length > 0) {
return handle; return handle;
@@ -320,6 +328,7 @@ const Slider = React.createClass({
visible={tooltipVisible} visible={tooltipVisible}
overlay={<span>{this.state.value}</span>} overlay={<span>{this.state.value}</span>}
delay={0} delay={0}
transitionName={this.props.tipTransitionName}
prefixCls={prefixClsFn(prefixCls, 'tooltip')}> prefixCls={prefixClsFn(prefixCls, 'tooltip')}>
{handle} {handle}
</Tooltip> </Tooltip>
@@ -358,8 +367,8 @@ const Slider = React.createClass({
return ( return (
<div className={rcUtil.classSet(sliderClassName)} ref="slider" <div className={rcUtil.classSet(sliderClassName)} ref="slider"
onTouchStart={disabled ? noop : this.onTouchStart} onTouchStart={disabled ? noop : this.onTouchStart}
onMouseDown={disabled ? noop : this.onSliderMouseDown}> onMouseDown={disabled ? noop : this.onSliderMouseDown}>
{track} {track}
{ons} {ons}
{steps} {steps}
@@ -468,12 +477,12 @@ const Slider = React.createClass({
}); });
}, },
_end(type) { _end(type, showToolTip) {
this._removeEventons(type); this._removeEventons(type);
this._triggerEvents('onAfterChange'); this._triggerEvents('onAfterChange');
this.setState({ this.setState({
dragging: false, dragging: false,
showTooltip: false, showTooltip: !!showToolTip,
}); });
}, },
}); });