Compare commits

...
12 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
7 changed files with 78 additions and 50 deletions
+6 -2
View File
@@ -7,7 +7,7 @@ notifications:
- yiminghe@gmail.com - yiminghe@gmail.com
node_js: node_js:
- 0.12 - 4.0.0
before_install: before_install:
- | - |
@@ -16,7 +16,6 @@ before_install:
echo "Only docs were updated, stopping build process." echo "Only docs were updated, stopping build process."
exit exit
fi fi
npm install mocha-phantomjs -g
phantomjs --version phantomjs --version
script: script:
@@ -36,3 +35,8 @@ env:
global: global:
- secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU= - secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU=
- secure: EBEDg8k///IlEsnx0AE8X3mbFl0QE5+xGKbG4AxXlGZda12uTIPUSMKJzdZQ2hVbZXduTzf1cQl9rcu9nGoSnkL/DWnIax9cvHi+1orx5+YPlxPHNWAwWByTnHosBn2MJhfy1s5paJfHC9cUzmmEL6x4fYthWxjsPUo+irEZH6E= - secure: EBEDg8k///IlEsnx0AE8X3mbFl0QE5+xGKbG4AxXlGZda12uTIPUSMKJzdZQ2hVbZXduTzf1cQl9rcu9nGoSnkL/DWnIax9cvHi+1orx5+YPlxPHNWAwWByTnHosBn2MJhfy1s5paJfHC9cUzmmEL6x4fYthWxjsPUo+irEZH6E=
matrix:
allow_failures:
- env: "TEST_TYPE=saucelabs"
+6
View File
@@ -142,6 +142,12 @@ React.render(<Rcslider />, container);
<td>''</td> <td>''</td>
<td>Set the animation for tooltip if it shows.</td> <td>Set the animation for tooltip if it shows.</td>
</tr> </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> </tbody>
</table> </table>
+14 -10
View File
@@ -11,14 +11,14 @@
@ease-out-quint : cubic-bezier(0.23, 1, 0.32, 1); @ease-out-quint : cubic-bezier(0.23, 1, 0.32, 1);
@ease-in-quint : cubic-bezier(0.755, 0.05, 0.855, 0.06); @ease-in-quint : cubic-bezier(0.755, 0.05, 0.855, 0.06);
* { .borderBox() {
box-sizing: border-box; box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove tap highlight color for mobile safari -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} { .@{prefixClass} {
@@ -28,6 +28,8 @@
border-radius: @border-radius-base; border-radius: @border-radius-base;
background-color: #e9e9e9; background-color: #e9e9e9;
.borderBox();
&-track { &-track {
position: absolute; position: absolute;
left: 0; left: 0;
@@ -119,13 +121,13 @@
background-color: @disabledColor; background-color: @disabledColor;
} }
.@{prefixClass}-handle { .@{prefixClass}-handle, .@{prefixClass}-dot {
border-color: @disabledColor; border-color: @disabledColor;
background-color: #fff; background-color: #fff;
cursor: not-allowed; cursor: not-allowed;
} }
.@{prefixClass}-mark-text, .dot { .@{prefixClass}-mark-text, .@{prefixClass}-dot {
cursor: not-allowed!important; cursor: not-allowed!important;
} }
} }
@@ -138,6 +140,8 @@
z-index: 4; z-index: 4;
visibility: visible; visibility: visible;
.borderBox();
&-hidden { &-hidden {
display: none; display: none;
} }
@@ -212,9 +216,9 @@
animation-timing-function: @ease-in-quint; animation-timing-function: @ease-in-quint;
} }
} }
.zoom-motion(zoom-down, zoomDown); .zoom-motion(rc-slider-tooltip-zoom-down, rcSliderTooltipZoomDown);
@keyframes zoomDownIn { @keyframes rcSliderTooltipZoomDownIn {
0% { 0% {
opacity: 0; opacity: 0;
transform-origin: 50% 100%; transform-origin: 50% 100%;
@@ -226,7 +230,7 @@
} }
} }
@keyframes zoomDownOut { @keyframes rcSliderTooltipZoomDownOut {
0% { 0% {
transform-origin: 50% 100%; transform-origin: 50% 100%;
transform: scale(1, 1); transform: scale(1, 1);
+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 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 className='rc-slider' step={20}/></div>, document.getElementById('__react-content'));
React.render(<div style={{width:400,margin:100}}><Slider onChange={onChange} tipTransitionName='zoom-down'/></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'));
+5 -6
View File
@@ -1,6 +1,6 @@
{ {
"name": "rc-slider", "name": "rc-slider",
"version": "1.4.4", "version": "1.5.1",
"description": "slider ui component for react", "description": "slider ui component for react",
"keywords": [ "keywords": [
"react", "react",
@@ -29,13 +29,13 @@
"scripts": { "scripts": {
"build": "rc-tools run build", "build": "rc-tools run build",
"gh-pages": "rc-tools run gh-pages", "gh-pages": "rc-tools run gh-pages",
"start": "node --harmony node_modules/.bin/rc-server", "start": "rc-server",
"pub": "rc-tools run pub", "pub": "rc-tools run pub",
"lint": "rc-tools run lint", "lint": "rc-tools run lint",
"karma": "rc-tools run karma", "karma": "rc-tools run karma",
"saucelabs": "node --harmony node_modules/.bin/rc-tools run saucelabs", "saucelabs": "rc-tools run saucelabs",
"browser-test": "node --harmony node_modules/.bin/rc-tools run browser-test", "browser-test": "rc-tools run browser-test",
"browser-test-cover": "node --harmony node_modules/.bin/rc-tools run browser-test-cover" "browser-test-cover": "rc-tools run browser-test-cover"
}, },
"devDependencies": { "devDependencies": {
"expect.js": "0.3.x", "expect.js": "0.3.x",
@@ -43,7 +43,6 @@
"rc-server": "3.x", "rc-server": "3.x",
"rc-tools": "4.x", "rc-tools": "4.x",
"react": "^0.13.x", "react": "^0.13.x",
"node-dev": "2.x",
"jquery": "^1.11.2" "jquery": "^1.11.2"
}, },
"precommit": [ "precommit": [
+35 -27
View File
@@ -57,6 +57,7 @@ const Slider = React.createClass({
onChange: React.PropTypes.func, onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func, onAfterChange: React.PropTypes.func,
tipTransitionName: React.PropTypes.string, tipTransitionName: React.PropTypes.string,
withDots: React.PropTypes.bool,
}, },
getDefaultProps() { getDefaultProps() {
@@ -72,6 +73,7 @@ const Slider = React.createClass({
disabled: false, disabled: false,
defaultIndex: 0, defaultIndex: 0,
tipTransitionName: '', tipTransitionName: '',
withDots: false,
}; };
}, },
@@ -164,7 +166,7 @@ const Slider = React.createClass({
const position = this._getTouchPosition(e); const position = this._getTouchPosition(e);
const value = this._calValueByPos(position); const value = this._calValueByPos(position);
this._triggerEvents('onChange', value); this._triggerEvents('onChange', value);
this._start(position); this._start(position, value);
this._addDocumentEvents('touch'); this._addDocumentEvents('touch');
pauseEvent(e); pauseEvent(e);
}, },
@@ -173,7 +175,7 @@ const Slider = React.createClass({
const position = e.pageX || (e.clientX + document.documentElement.scrollLeft); // to compat ie8 const position = e.pageX || (e.clientX + document.documentElement.scrollLeft); // to compat ie8
const value = this._calValueByPos(position); const value = this._calValueByPos(position);
this._triggerEvents('onChange', value); this._triggerEvents('onChange', value);
this._start(position); this._start(position, value);
this._addDocumentEvents('mouse'); this._addDocumentEvents('mouse');
pauseEvent(e); pauseEvent(e);
}, },
@@ -208,37 +210,43 @@ const Slider = React.createClass({
renderSteps() { renderSteps() {
const props = this.props; const props = this.props;
const marksLen = props.marks.length; const marksLen = props.marks.length;
const stepNum = marksLen > 0 ? marksLen : Math.floor((props.max - props.min) / props.step) + 1; const withDots = props.withDots;
const unit = 100 / (stepNum - 1);
const prefixCls = props.prefixCls; if (marksLen || withDots) {
const stepClassName = prefixClsFn(prefixCls, 'step'); const stepNum = marksLen ? marksLen : Math.floor((props.max - props.min) / props.step) + 1;
const unit = 100 / (stepNum - 1);
const elements = []; const prefixCls = props.prefixCls;
for (let i = 0; i < stepNum; i++) { const stepClassName = prefixClsFn(prefixCls, 'step');
const offset = unit * i + '%';
const style = { const elements = [];
left: offset, for (let i = 0; i < stepNum; i++) {
}; const offset = unit * i + '%';
let className = prefixClsFn(prefixCls, 'dot'); const style = {
if (props.isIncluded) { left: offset,
if (i <= this.getIndex()) { };
className = prefixClsFn(prefixCls, 'dot', 'dot-active'); 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] = ( return (
<span className={className} style={style} ref={'step' + i} key={'step' + i}></span> <div className={stepClassName}>
{elements}
</div>
); );
} }
return ( return null;
<div className={stepClassName}>
{elements}
</div>
);
}, },
renderMark(i) { renderMark(i) {
@@ -468,9 +476,9 @@ const Slider = React.createClass({
} }
}, },
_start(position) { _start(position, value) {
this._triggerEvents('onBeforeChange'); this._triggerEvents('onBeforeChange');
this.startValue = this.state.value; this.startValue = value;
this.startPosition = position; this.startPosition = position;
this.setState({ this.setState({
dragging: true, dragging: true,
+8 -2
View File
@@ -1,7 +1,7 @@
var expect = require('expect.js'); var expect = require('expect.js');
var Slider = require('../index.js'); var Slider = require('../index.js');
var React = require('react'); var React = require('react/addons');
var TestUtils = React.addons.TestUtils; var TestUtils = React.addons.TestUtils;
var Simulate = TestUtils.Simulate; var Simulate = TestUtils.Simulate;
var $ = require('jquery'); 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').length).to.be(1);
expect(node.find('.rc-slider-handle').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-track').length).to.be(1);
expect(node.find('.rc-slider-dot').length).to.be(6);
expect(slider.state.value).to.be(0); 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 () { it('should render a slider with marks correctly!', function () {