@@ -48,12 +48,12 @@ class Rating extends Component {
48
48
allowHalf : PropTypes . bool ,
49
49
/**
50
50
* 用户点击评分时触发的回调
51
- * @param {String } value 评分值
51
+ * @param {Number } value 评分值
52
52
*/
53
53
onChange : PropTypes . func ,
54
54
/**
55
55
* 用户hover评分时触发的回调
56
- * @param {String } value 评分值
56
+ * @param {Number } value 评分值
57
57
*/
58
58
onHoverChange : PropTypes . func ,
59
59
/**
@@ -127,12 +127,7 @@ class Rating extends Component {
127
127
} ;
128
128
this . timer = null ;
129
129
130
- bindCtx ( this , [
131
- 'handleClick' ,
132
- 'handleHover' ,
133
- 'handleLeave' ,
134
- 'onKeyDown' ,
135
- ] ) ;
130
+ bindCtx ( this , [ 'handleClick' , 'handleHover' , 'handleLeave' , 'onKeyDown' ] ) ;
136
131
}
137
132
138
133
static getDerivedStateFromProps ( nextProps , prevState ) {
@@ -148,9 +143,7 @@ class Rating extends Component {
148
143
'renderPreview' in nextProps
149
144
) {
150
145
state . disabled =
151
- nextProps . disabled ||
152
- nextProps . readOnly ||
153
- ( nextProps . isPreview && ! ( 'renderPreview' in nextProps ) ) ;
146
+ nextProps . disabled || nextProps . readOnly || ( nextProps . isPreview && ! ( 'renderPreview' in nextProps ) ) ;
154
147
}
155
148
156
149
return state ;
@@ -179,9 +172,7 @@ class Rating extends Component {
179
172
180
173
if ( icon && this . underlayNode ) {
181
174
const newIconSize = icon . offsetWidth ;
182
- const newIconSpace =
183
- ( this . underlayNode . offsetWidth - count * newIconSize ) /
184
- ( count + 1 ) ;
175
+ const newIconSpace = ( this . underlayNode . offsetWidth - count * newIconSize ) / ( count + 1 ) ;
185
176
186
177
if ( newIconSize !== iconSize || newIconSpace !== iconSpace ) {
187
178
this . setState ( {
@@ -201,23 +192,16 @@ class Rating extends Component {
201
192
202
193
const pos = e . pageX - this . underlayNode . getBoundingClientRect ( ) . left ;
203
194
const fullNum = Math . floor ( pos / ( iconSpace + iconSize ) ) ;
204
- const surplusNum =
205
- ( pos - fullNum * ( iconSpace + iconSize ) - iconSpace ) / iconSize ;
195
+ const surplusNum = ( pos - fullNum * ( iconSpace + iconSize ) - iconSpace ) / iconSize ;
206
196
let value = Number ( fullNum ) + Number ( surplusNum . toFixed ( 1 ) ) ;
207
197
if ( value >= count ) {
208
198
value = count ;
209
199
} else if ( allowHalf ) {
210
200
const floorValue = Math . floor ( value ) ;
211
201
if ( rtl ) {
212
- value =
213
- value - 0.5 >= floorValue
214
- ? floorValue + 1.5
215
- : floorValue + 1 ;
202
+ value = value - 0.5 >= floorValue ? floorValue + 1.5 : floorValue + 1 ;
216
203
} else {
217
- value =
218
- value - 0.5 >= floorValue
219
- ? floorValue + 1
220
- : floorValue + 0.5 ;
204
+ value = value - 0.5 >= floorValue ? floorValue + 1 : floorValue + 0.5 ;
221
205
}
222
206
} else {
223
207
value = Math . floor ( value ) + 1 ;
@@ -337,12 +321,7 @@ class Rating extends Component {
337
321
return 'auto' ;
338
322
}
339
323
340
- const value = Rating . currentValue (
341
- 0 ,
342
- this . props . count ,
343
- hoverValue ,
344
- this . state . value
345
- ) ;
324
+ const value = Rating . currentValue ( 0 , this . props . count , hoverValue , this . state . value ) ;
346
325
347
326
const floorValue = Math . floor ( value ) ;
348
327
@@ -387,12 +366,7 @@ class Rating extends Component {
387
366
const enableA11y = ! ! id ;
388
367
389
368
// 获得Value
390
- const value = Rating . currentValue (
391
- 0 ,
392
- count ,
393
- hoverValue ,
394
- this . state . value
395
- ) ;
369
+ const value = Rating . currentValue ( 0 , count , hoverValue , this . state . value ) ;
396
370
397
371
// icon的sizeMap
398
372
const sizeMap = ICON_SIZE_MAP [ size ] ;
@@ -407,23 +381,15 @@ class Rating extends Component {
407
381
const iconNode = iconType ? (
408
382
< Icon type = { iconType } size = { sizeMap } className = { iconCls } />
409
383
) : (
410
- < Icon
411
- type = "favorites-filling"
412
- size = { sizeMap }
413
- className = { iconCls }
414
- />
384
+ < Icon type = "favorites-filling" size = { sizeMap } className = { iconCls } />
415
385
) ;
416
386
417
387
const saveRefs = ref => {
418
388
this . saveRef ( ref , i ) ;
419
389
} ;
420
390
421
391
underlay . push (
422
- < span
423
- ref = { saveRefs }
424
- key = { `underlay-${ i } ` }
425
- className = { `${ prefix } rating-icon` }
426
- >
392
+ < span ref = { saveRefs } key = { `underlay-${ i } ` } className = { `${ prefix } rating-icon` } >
427
393
{ iconNode }
428
394
</ span >
429
395
) ;
@@ -449,11 +415,7 @@ class Rating extends Component {
449
415
className = { `${ prefix } rating-icon` }
450
416
>
451
417
{ iconNode }
452
- { enableA11y ? (
453
- < span className = { `${ prefix } sr-only` } >
454
- { readAs ( i + 1 ) }
455
- </ span >
456
- ) : null }
418
+ { enableA11y ? < span className = { `${ prefix } sr-only` } > { readAs ( i + 1 ) } </ span > : null }
457
419
</ label >
458
420
) ;
459
421
}
@@ -518,17 +480,10 @@ class Rating extends Component {
518
480
aria-label = { locale . description }
519
481
>
520
482
< div className = { baseCls } { ...finalProps } >
521
- < div
522
- className = { `${ prefix } rating-underlay` }
523
- ref = { n => ( this . underlayNode = n ) }
524
- aria-hidden
525
- >
483
+ < div className = { `${ prefix } rating-underlay` } ref = { n => ( this . underlayNode = n ) } aria-hidden >
526
484
{ underlay }
527
485
</ div >
528
- < div
529
- className = { `${ prefix } rating-overlay` }
530
- style = { overlayStyle }
531
- >
486
+ < div className = { `${ prefix } rating-overlay` } style = { overlayStyle } >
532
487
{ overlay }
533
488
</ div >
534
489
</ div >
0 commit comments