@@ -21,15 +21,7 @@ function _isMultiple(slider, isFixedWidth) {
21
21
}
22
22
23
23
function LowerSlider ( props ) {
24
- const {
25
- hasTip,
26
- value,
27
- tipRender,
28
- slider,
29
- tooltipVisible,
30
- onTooltipVisibleChange,
31
- tooltipAnimation,
32
- } = props ;
24
+ const { hasTip, value, tipRender, slider, tooltipVisible, onTooltipVisibleChange, tooltipAnimation } = props ;
33
25
34
26
if ( _isMultiple ( slider ) ) {
35
27
return hasTip ? (
@@ -58,25 +50,14 @@ LowerSlider.propTypes = {
58
50
tooltipVisible : PropTypes . bool ,
59
51
onTooltipVisibleChange : PropTypes . func ,
60
52
tooltipAnimation : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . object ] ) ,
61
- value : PropTypes . oneOfType ( [
62
- PropTypes . number ,
63
- PropTypes . arrayOf ( PropTypes . number ) ,
64
- ] ) ,
53
+ value : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
65
54
tipRender : PropTypes . func ,
66
55
slider : PropTypes . oneOf ( [ 'single' , 'double' ] ) ,
67
56
} ;
68
57
69
58
function UpperSlider ( props ) {
70
59
const newprop = Object . assign ( { } , props ) ;
71
- const {
72
- hasTip,
73
- value,
74
- tipRender,
75
- slider,
76
- tooltipVisible,
77
- onTooltipVisibleChange,
78
- tooltipAnimation,
79
- } = newprop ;
60
+ const { hasTip, value, tipRender, slider, tooltipVisible, onTooltipVisibleChange, tooltipAnimation } = newprop ;
80
61
if ( _isMultiple ( slider ) ) {
81
62
delete newprop . onKeyDown ;
82
63
return hasTip ? (
@@ -125,10 +106,7 @@ UpperSlider.propTypes = {
125
106
tooltipVisible : PropTypes . bool ,
126
107
onTooltipVisibleChange : PropTypes . func ,
127
108
tooltipAnimation : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . object ] ) ,
128
- value : PropTypes . oneOfType ( [
129
- PropTypes . number ,
130
- PropTypes . arrayOf ( PropTypes . number ) ,
131
- ] ) ,
109
+ value : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
132
110
tipRender : PropTypes . func ,
133
111
slider : PropTypes . oneOf ( [ 'single' , 'double' ] ) ,
134
112
} ;
@@ -176,21 +154,12 @@ class Range extends React.Component {
176
154
/**
177
155
* 设置当前取值。当 `slider` 为 `single` 时,使用 `Number`,否则用 `[Number, Number]`
178
156
*/
179
- value : PropTypes . oneOfType ( [
180
- PropTypes . number ,
181
- PropTypes . arrayOf ( PropTypes . number ) ,
182
- ] ) ,
183
- tempValue : PropTypes . oneOfType ( [
184
- PropTypes . number ,
185
- PropTypes . arrayOf ( PropTypes . number ) ,
186
- ] ) ,
157
+ value : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
158
+ tempValue : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
187
159
/**
188
160
* 设置初始取值。当 `slider` 为 `single` 时,使用 `Number`,否则用 `[Number, Number]`
189
161
*/
190
- defaultValue : PropTypes . oneOfType ( [
191
- PropTypes . number ,
192
- PropTypes . arrayOf ( PropTypes . number ) ,
193
- ] ) ,
162
+ defaultValue : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
194
163
/**
195
164
* 刻度数值显示逻辑(false 代表不显示,array 枚举显示的值,number 代表按 number 平分,object 表示按 key 划分,value 值显示)
196
165
*/
@@ -285,8 +254,7 @@ class Range extends React.Component {
285
254
super ( props ) ;
286
255
const { min } = props ;
287
256
const initialValue = _isMultiple ( props . slider ) ? [ min , min ] : min ;
288
- const defaultValue =
289
- 'defaultValue' in props ? props . defaultValue : initialValue ;
257
+ const defaultValue = 'defaultValue' in props ? props . defaultValue : initialValue ;
290
258
const value = props . value !== undefined ? props . value : defaultValue ;
291
259
292
260
this . state = {
@@ -298,11 +266,7 @@ class Range extends React.Component {
298
266
tooltipAnimation : true ,
299
267
} ;
300
268
301
- bindCtx ( this , [
302
- 'handleLowerTooltipVisibleChange' ,
303
- 'handleUpperTooltipVisibleChange' ,
304
- 'onKeyDown' ,
305
- ] ) ;
269
+ bindCtx ( this , [ 'handleLowerTooltipVisibleChange' , 'handleUpperTooltipVisibleChange' , 'onKeyDown' ] ) ;
306
270
}
307
271
308
272
static getDerivedStateFromProps ( props , state ) {
@@ -409,10 +373,7 @@ class Range extends React.Component {
409
373
onKeyDown ( e ) {
410
374
if ( this . props . disabled ) return ;
411
375
412
- if (
413
- e . keyCode === KEYCODE . LEFT_ARROW ||
414
- e . keyCode === KEYCODE . RIGHT_ARROW
415
- ) {
376
+ if ( e . keyCode === KEYCODE . LEFT_ARROW || e . keyCode === KEYCODE . RIGHT_ARROW ) {
416
377
e . stopPropagation ( ) ;
417
378
e . preventDefault ( ) ;
418
379
let newValue ;
@@ -495,8 +456,7 @@ class Range extends React.Component {
495
456
}
496
457
497
458
_move ( e ) {
498
- const position =
499
- e . type === 'mousemove' ? e . pageX : e . targetTouches [ 0 ] . pageX ;
459
+ const position = e . type === 'mousemove' ? e . pageX : e . targetTouches [ 0 ] . pageX ;
500
460
this . _onProcess ( position ) ;
501
461
}
502
462
@@ -521,18 +481,12 @@ class Range extends React.Component {
521
481
upperTooltipVisible : this . _moving . dragging === 'upper' ,
522
482
tooltipAnimation : false ,
523
483
} ) ;
524
- } else if (
525
- this . oldDragging === 'lower' &&
526
- this . _moving . dragging === 'upper'
527
- ) {
484
+ } else if ( this . oldDragging === 'lower' && this . _moving . dragging === 'upper' ) {
528
485
this . setState ( {
529
486
upperTooltipVisible : true ,
530
487
lowerTooltipVisible : false ,
531
488
} ) ;
532
- } else if (
533
- this . oldDragging === 'upper' &&
534
- this . _moving . dragging === 'lower'
535
- ) {
489
+ } else if ( this . oldDragging === 'upper' && this . _moving . dragging === 'lower' ) {
536
490
this . setState ( {
537
491
upperTooltipVisible : false ,
538
492
lowerTooltipVisible : true ,
@@ -541,12 +495,7 @@ class Range extends React.Component {
541
495
542
496
this . oldDragging = this . _moving . dragging ;
543
497
544
- const nextValue = this . _currentToValue (
545
- current ,
546
- tempValue ,
547
- this . lastPosition ,
548
- this . isFixedWidth
549
- ) ; //计算range的新value,可能是数组,可能是单个值
498
+ const nextValue = this . _currentToValue ( current , tempValue , this . lastPosition , this . isFixedWidth ) ; //计算range的新value,可能是数组,可能是单个值
550
499
this . lastPosition = current ;
551
500
552
501
if ( ! isEqual ( nextValue , tempValue ) ) {
@@ -558,29 +507,13 @@ class Range extends React.Component {
558
507
}
559
508
560
509
_addDocumentMouseEvents ( ) {
561
- this . _onMouseMoveListener = events . on (
562
- document ,
563
- 'mousemove' ,
564
- this . _move . bind ( this )
565
- ) ;
566
- this . _onMouseUpListener = events . on (
567
- document ,
568
- 'mouseup' ,
569
- this . _end . bind ( this )
570
- ) ;
510
+ this . _onMouseMoveListener = events . on ( document , 'mousemove' , this . _move . bind ( this ) ) ;
511
+ this . _onMouseUpListener = events . on ( document , 'mouseup' , this . _end . bind ( this ) ) ;
571
512
}
572
513
573
514
_addDocumentTouchEvents ( ) {
574
- this . _onTouchMoveListener = events . on (
575
- document ,
576
- 'touchmove' ,
577
- this . _move . bind ( this )
578
- ) ;
579
- this . _onTouchEndListener = events . on (
580
- document ,
581
- 'touchend' ,
582
- this . _end . bind ( this )
583
- ) ;
515
+ this . _onTouchMoveListener = events . on ( document , 'touchmove' , this . _move . bind ( this ) ) ;
516
+ this . _onTouchEndListener = events . on ( document , 'touchend' , this . _end . bind ( this ) ) ;
584
517
}
585
518
586
519
_removeDocumentEvents ( ) {
@@ -619,12 +552,11 @@ class Range extends React.Component {
619
552
percent = rtl ? 100 - percent : percent ;
620
553
// reset by step
621
554
const newValue = parseFloat (
622
- ( Math . round ( ( ( percent / 100 ) * ( max - min ) ) / step ) * step ) . toFixed (
623
- getPrecision ( step )
624
- )
555
+ ( Math . round ( ( ( percent / 100 ) * ( max - min ) ) / step ) * step ) . toFixed ( getPrecision ( step ) )
625
556
) ;
557
+ const currentValue = ( min + newValue ) . toFixed ( getPrecision ( step ) ) ;
626
558
627
- return min + newValue ;
559
+ return Number ( currentValue ) ;
628
560
}
629
561
630
562
_currentToValue ( current , preValue , lastPosition , isFixedWidth ) {
@@ -641,12 +573,8 @@ class Range extends React.Component {
641
573
const newLeft = + ( + preValue [ 0 ] + diff ) . toFixed ( precision ) ;
642
574
const newRight = + ( + preValue [ 1 ] + diff ) . toFixed ( precision ) ;
643
575
644
- const newMaxLeft = + ( max - preValue [ 1 ] + preValue [ 0 ] ) . toFixed (
645
- precision
646
- ) ;
647
- const newMinRight = + ( min + preValue [ 1 ] - preValue [ 0 ] ) . toFixed (
648
- precision
649
- ) ;
576
+ const newMaxLeft = + ( max - preValue [ 1 ] + preValue [ 0 ] ) . toFixed ( precision ) ;
577
+ const newMinRight = + ( min + preValue [ 1 ] - preValue [ 0 ] ) . toFixed ( precision ) ;
650
578
651
579
if ( isFixedWidth ) {
652
580
if ( newLeft < min ) {
@@ -754,36 +682,21 @@ class Range extends React.Component {
754
682
} ;
755
683
756
684
this . isFixedWidth =
757
- fixedWidth &&
758
- ( value
759
- ? Array . isArray ( value )
760
- : defaultValue
761
- ? Array . isArray ( defaultValue )
762
- : false ) ;
685
+ fixedWidth && ( value ? Array . isArray ( value ) : defaultValue ? Array . isArray ( defaultValue ) : false ) ;
763
686
764
687
if ( isPreview ) {
765
688
const previewCls = classNames ( className , `${ prefix } form-preview` ) ;
766
689
767
690
if ( 'renderPreview' in this . props ) {
768
691
return (
769
- < div
770
- id = { id }
771
- dir = { rtl ? 'rtl' : 'ltr' }
772
- { ...others }
773
- className = { previewCls }
774
- >
692
+ < div id = { id } dir = { rtl ? 'rtl' : 'ltr' } { ...others } className = { previewCls } >
775
693
{ renderPreview ( value , this . props ) }
776
694
</ div >
777
695
) ;
778
696
}
779
697
780
698
return (
781
- < p
782
- id = { id }
783
- dir = { rtl ? 'rtl' : 'ltr' }
784
- { ...others }
785
- className = { previewCls }
786
- >
699
+ < p id = { id } dir = { rtl ? 'rtl' : 'ltr' } { ...others } className = { previewCls } >
787
700
{ Array . isArray ( value ) ? value . join ( '~' ) : value }
788
701
</ p >
789
702
) ;
@@ -816,17 +729,10 @@ class Range extends React.Component {
816
729
< LowerSlider
817
730
{ ...commonProps }
818
731
hasMovingClass = {
819
- this . state . hasMovingClass &&
820
- this . _moving &&
821
- this . _moving . dragging === 'lower'
822
- }
823
- tooltipVisible = {
824
- tooltipVisible ||
825
- this . state . lowerTooltipVisible
826
- }
827
- onTooltipVisibleChange = {
828
- this . handleLowerTooltipVisibleChange
732
+ this . state . hasMovingClass && this . _moving && this . _moving . dragging === 'lower'
829
733
}
734
+ tooltipVisible = { tooltipVisible || this . state . lowerTooltipVisible }
735
+ onTooltipVisibleChange = { this . handleLowerTooltipVisibleChange }
830
736
tooltipAnimation = {
831
737
this . state . tooltipAnimation
832
738
? {
@@ -840,17 +746,10 @@ class Range extends React.Component {
840
746
{ ...commonProps }
841
747
onKeyDown = { this . onKeyDown }
842
748
hasMovingClass = {
843
- this . state . hasMovingClass &&
844
- this . _moving &&
845
- this . _moving . dragging === 'upper'
846
- }
847
- tooltipVisible = {
848
- tooltipVisible ||
849
- this . state . upperTooltipVisible
850
- }
851
- onTooltipVisibleChange = {
852
- this . handleUpperTooltipVisibleChange
749
+ this . state . hasMovingClass && this . _moving && this . _moving . dragging === 'upper'
853
750
}
751
+ tooltipVisible = { tooltipVisible || this . state . upperTooltipVisible }
752
+ onTooltipVisibleChange = { this . handleUpperTooltipVisibleChange }
854
753
tooltipAnimation = {
855
754
this . state . tooltipAnimation
856
755
? {
0 commit comments