Compare commits

...
17 Commits
Author SHA1 Message Date
Benjy Cui ebf27cc9ba Merge pull request #24 from react-component/step-marks-fix
Step marks fix
2015-10-15 11:26:49 +08:00
SimaQ 314fc59d15 updata version. 2015-10-15 11:01:21 +08:00
SimaQ 7bd951072f fix: fix disabled style. 2015-10-15 11:01:21 +08:00
SimaQ d6779510f9 test: update test case. 2015-10-15 11:01:15 +08:00
SimaQ 2588a2b919 fix: fix#23. 2015-10-15 10:44:58 +08:00
yiminghe dd0a63dee3 change anim name 2015-10-14 23:08:51 +08:00
yiminghe 8b414d510b update travis 2015-10-14 23:06:24 +08:00
yiminghe 2c41239d90 fix style. fixes #19 2015-10-14 23:03:46 +08:00
simaQ 19f1183634 update version 2015-08-29 10:58:26 +08:00
simaQ 200d0810ce Merge pull request #21 from danioso/master
Sending new value to _start while dragging
2015-08-29 10:57:19 +08:00
Daniel Osorio e7007fbe8e Sending new value to _start while dragging 2015-08-27 19:23:57 -05:00
yiminghe 8f490c80be up 2015-08-25 21:45:26 +08:00
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
7 changed files with 164 additions and 59 deletions
+6 -2
View File
@@ -7,7 +7,7 @@ notifications:
- yiminghe@gmail.com
node_js:
- 0.12
- 4.0.0
before_install:
- |
@@ -16,7 +16,6 @@ before_install:
echo "Only docs were updated, stopping build process."
exit
fi
npm install mocha-phantomjs -g
phantomjs --version
script:
@@ -36,3 +35,8 @@ env:
global:
- secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU=
- secure: EBEDg8k///IlEsnx0AE8X3mbFl0QE5+xGKbG4AxXlGZda12uTIPUSMKJzdZQ2hVbZXduTzf1cQl9rcu9nGoSnkL/DWnIax9cvHi+1orx5+YPlxPHNWAwWByTnHosBn2MJhfy1s5paJfHC9cUzmmEL6x4fYthWxjsPUo+irEZH6E=
matrix:
allow_failures:
- env: "TEST_TYPE=saucelabs"
+15 -3
View File
@@ -136,6 +136,18 @@ React.render(<Rcslider />, container);
<td>false</td>
<td>If true the handles can't be moved.</td>
</tr>
<tr>
<td>tipTransitionName</td>
<td>string</td>
<td>''</td>
<td>Set the animation for tooltip if it shows.</td>
</tr>
<tr>
<td>withDots</td>
<td>bool</td>
<td>false</td>
<td>For linear slider, when the `step` value is greater than 1, you can set the `withDots` to `true` if you want to render the slider bar with dots.</td>
</tr>
</tbody>
</table>
@@ -148,17 +160,17 @@ npm start
## Example
http://localhost:8000/examples/
http://localhost:8005/examples/
online example: http://react-component.github.io/slider/
## Test Case
http://localhost:8000/tests/runner.html?coverage
http://localhost:8005/tests/runner.html?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
+74 -8
View File
@@ -8,15 +8,17 @@
@tooltip-arrow-width: 4px;
@tooltip-distance: @tooltip-arrow-width+4;
@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);
* {
.borderBox() {
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove tap highlight color for mobile safari
}
*:before,
*:after {
box-sizing: border-box;
* {
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove tap highlight color for mobile safari
}
}
.@{prefixClass} {
@@ -26,6 +28,8 @@
border-radius: @border-radius-base;
background-color: #e9e9e9;
.borderBox();
&-track {
position: absolute;
left: 0;
@@ -117,13 +121,13 @@
background-color: @disabledColor;
}
.@{prefixClass}-handle {
.@{prefixClass}-handle, .@{prefixClass}-dot {
border-color: @disabledColor;
background-color: #fff;
cursor: not-allowed;
}
.@{prefixClass}-mark-text, .dot {
.@{prefixClass}-mark-text, .@{prefixClass}-dot {
cursor: not-allowed!important;
}
}
@@ -136,6 +140,8 @@
z-index: 4;
visibility: visible;
.borderBox();
&-hidden {
display: none;
}
@@ -174,4 +180,64 @@
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(rc-slider-tooltip-zoom-down, rcSliderTooltipZoomDown);
@keyframes rcSliderTooltipZoomDownIn {
0% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
}
100% {
transform-origin: 50% 100%;
transform: scale(1, 1);
}
}
@keyframes rcSliderTooltipZoomDownOut {
0% {
transform-origin: 50% 100%;
transform: scale(1, 1);
}
100% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
}
}
+2 -1
View File
@@ -10,5 +10,6 @@ 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 withDots 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='rc-slider-tooltip-zoom-down'/></div>, document.getElementById('__react-content'));
+6 -7
View File
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "1.4.3",
"version": "1.5.1",
"description": "slider ui component for react",
"keywords": [
"react",
@@ -24,18 +24,18 @@
"licenses": "MIT",
"main": "./lib/index.js",
"config": {
"port": 8000
"port": 8005
},
"scripts": {
"build": "rc-tools run build",
"gh-pages": "rc-tools run gh-pages",
"start": "node --harmony node_modules/.bin/rc-server",
"start": "rc-server",
"pub": "rc-tools run pub",
"lint": "rc-tools run lint",
"karma": "rc-tools run karma",
"saucelabs": "node --harmony node_modules/.bin/rc-tools run saucelabs",
"browser-test": "node --harmony node_modules/.bin/rc-tools run browser-test",
"browser-test-cover": "node --harmony node_modules/.bin/rc-tools run browser-test-cover"
"saucelabs": "rc-tools run saucelabs",
"browser-test": "rc-tools run browser-test",
"browser-test-cover": "rc-tools run browser-test-cover"
},
"devDependencies": {
"expect.js": "0.3.x",
@@ -43,7 +43,6 @@
"rc-server": "3.x",
"rc-tools": "4.x",
"react": "^0.13.x",
"node-dev": "2.x",
"jquery": "^1.11.2"
},
"precommit": [
+52 -35
View File
@@ -56,6 +56,8 @@ const Slider = React.createClass({
onBeforeChange: React.PropTypes.func,
onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,
tipTransitionName: React.PropTypes.string,
withDots: React.PropTypes.bool,
},
getDefaultProps() {
@@ -70,6 +72,8 @@ const Slider = React.createClass({
prefixCls: 'rc-slider',
disabled: false,
defaultIndex: 0,
tipTransitionName: '',
withDots: false,
};
},
@@ -103,8 +107,14 @@ const Slider = React.createClass({
}
},
onMouseUp() {
this._end('mouse');
onMouseUp(e) {
const m = e.target;
const handleDom = React.findDOMNode(this.refs.handle);
let showToolTip = false;
if (m === handleDom) {
showToolTip = true;
}
this._end('mouse', showToolTip);
},
onTouchUp() {
@@ -156,7 +166,7 @@ const Slider = React.createClass({
const position = this._getTouchPosition(e);
const value = this._calValueByPos(position);
this._triggerEvents('onChange', value);
this._start(position);
this._start(position, value);
this._addDocumentEvents('touch');
pauseEvent(e);
},
@@ -165,7 +175,7 @@ const Slider = React.createClass({
const position = e.pageX || (e.clientX + document.documentElement.scrollLeft); // to compat ie8
const value = this._calValueByPos(position);
this._triggerEvents('onChange', value);
this._start(position);
this._start(position, value);
this._addDocumentEvents('mouse');
pauseEvent(e);
},
@@ -200,37 +210,43 @@ const Slider = React.createClass({
renderSteps() {
const props = this.props;
const marksLen = props.marks.length;
const stepNum = marksLen > 0 ? marksLen : Math.floor((props.max - props.min) / props.step) + 1;
const unit = 100 / (stepNum - 1);
const withDots = props.withDots;
const prefixCls = props.prefixCls;
const stepClassName = prefixClsFn(prefixCls, 'step');
if (marksLen || withDots) {
const stepNum = marksLen ? marksLen : Math.floor((props.max - props.min) / props.step) + 1;
const unit = 100 / (stepNum - 1);
const elements = [];
for (let i = 0; i < stepNum; i++) {
const offset = unit * i + '%';
const style = {
left: offset,
};
let className = prefixClsFn(prefixCls, 'dot');
if (props.isIncluded) {
if (i <= this.getIndex()) {
className = prefixClsFn(prefixCls, 'dot', 'dot-active');
const prefixCls = props.prefixCls;
const stepClassName = prefixClsFn(prefixCls, 'step');
const elements = [];
for (let i = 0; i < stepNum; i++) {
const offset = unit * i + '%';
const style = {
left: offset,
};
let className = prefixClsFn(prefixCls, 'dot');
if (props.isIncluded) {
if (i <= this.getIndex()) {
className = prefixClsFn(prefixCls, 'dot', 'dot-active');
}
} else {
className = (i === this.getIndex()) ? prefixClsFn(prefixCls, 'dot', 'dot-active') : className;
}
} else {
className = (i === this.getIndex()) ? prefixClsFn(prefixCls, 'dot', 'dot-active') : className;
elements[i] = (
<span className={className} style={style} ref={'step' + i} key={'step' + i}></span>
);
}
elements[i] = (
<span className={className} style={style} ref={'step' + i} key={'step' + i}></span>
return (
<div className={stepClassName}>
{elements}
</div>
);
}
return (
<div className={stepClassName}>
{elements}
</div>
);
return null;
},
renderMark(i) {
@@ -308,8 +324,8 @@ const Slider = React.createClass({
const handle = (<div className={className}
{...events}
ref="handle"
style={onStyle}></div>);
ref="handle"
style={onStyle}></div>);
if (this.props.marks.length > 0) {
return handle;
@@ -320,6 +336,7 @@ const Slider = React.createClass({
visible={tooltipVisible}
overlay={<span>{this.state.value}</span>}
delay={0}
transitionName={this.props.tipTransitionName}
prefixCls={prefixClsFn(prefixCls, 'tooltip')}>
{handle}
</Tooltip>
@@ -358,8 +375,8 @@ const Slider = React.createClass({
return (
<div className={rcUtil.classSet(sliderClassName)} ref="slider"
onTouchStart={disabled ? noop : this.onTouchStart}
onMouseDown={disabled ? noop : this.onSliderMouseDown}>
onTouchStart={disabled ? noop : this.onTouchStart}
onMouseDown={disabled ? noop : this.onSliderMouseDown}>
{track}
{ons}
{steps}
@@ -459,21 +476,21 @@ const Slider = React.createClass({
}
},
_start(position) {
_start(position, value) {
this._triggerEvents('onBeforeChange');
this.startValue = this.state.value;
this.startValue = value;
this.startPosition = position;
this.setState({
dragging: true,
});
},
_end(type) {
_end(type, showToolTip) {
this._removeEventons(type);
this._triggerEvents('onAfterChange');
this.setState({
dragging: false,
showTooltip: false,
showTooltip: !!showToolTip,
});
},
});
+9 -3
View File
@@ -1,7 +1,7 @@
var expect = require('expect.js');
var Slider = require('../index.js');
var React = require('react');
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var Simulate = TestUtils.Simulate;
var $ = require('jquery');
@@ -39,8 +39,14 @@ describe('rc-slider', function () {
expect(node.find('.rc-slider').length).to.be(1);
expect(node.find('.rc-slider-handle').length).to.be(1);
expect(node.find('.rc-slider-track').length).to.be(1);
expect(node.find('.rc-slider-dot').length).to.be(6);
expect(slider.state.value).to.be(0);
var sliderWithDots = React.render(
<Slider className='rc-slider' step={20} withDots/>,
div
);
var node1 = $(div);
expect(node1.find('.rc-slider-dot').length).to.be(6);
});
it('should render a slider with marks correctly!', function () {
@@ -64,7 +70,7 @@ describe('rc-slider', function () {
// div
// );
// var selectedStep = slider.refs.step3.getDOMNode();
// Simulate.mouseDown(selectedStep);
// setTimeout( function() {