@@ -21,18 +21,6 @@ function stopPropagation(e) {
21
21
}
22
22
}
23
23
24
- /**
25
- * Spreads `count` values equally between `min` and `max`.
26
- */
27
- function linspace ( min , max , count ) {
28
- const range = ( max - min ) / ( count - 1 ) ;
29
- const res = [ ] ;
30
- for ( let i = 0 ; i < count ; i += 1 ) {
31
- res . push ( min + range * i ) ;
32
- }
33
- return res ;
34
- }
35
-
36
24
function ensureArray ( x ) {
37
25
if ( x == null ) {
38
26
return [ ] ;
@@ -104,13 +92,11 @@ class ReactSlider extends React.Component {
104
92
minDistance : PropTypes . number ,
105
93
106
94
/**
107
- * Determines the initial positions of the thumbs and the number of thumbs if the
108
- * component has no children.
95
+ * Determines the initial positions of the thumbs and the number of thumbs.
109
96
*
110
97
* If a number is passed a slider with one thumb will be rendered.
111
98
* If an array is passed each value will determine the position of one thumb.
112
99
* The values in the array must be sorted.
113
- * If the component has children, the length of the array must match the number of children.
114
100
*/
115
101
defaultValue : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) ,
116
102
@@ -206,22 +192,6 @@ class ReactSlider extends React.Component {
206
192
// eslint-disable-next-line zillow/react/require-default-props
207
193
onSliderClick : PropTypes . func ,
208
194
209
- /**
210
- * Provide custom thumbs:
211
- *
212
- * <ReactSlider withTracks>
213
- * <div className="my-thumb">1</div>
214
- * <div className="my-thumb">2</div>
215
- * <div className="my-thumb">3</div>
216
- * </ReactSlider>
217
- *
218
- * Note: the children nodes must match the number of values provided
219
- * to `value` or `defaultValue`. To dynamically create custom thumb
220
- * content, use the `renderThumb` render prop.
221
- */
222
- // eslint-disable-next-line zillow/react/require-default-props
223
- children : PropTypes . node ,
224
-
225
195
/**
226
196
* aria-label for screen-readers to apply to the thumbs.
227
197
* Use an array for more than one thumb.
@@ -250,7 +220,6 @@ class ReactSlider extends React.Component {
250
220
251
221
/**
252
222
* Provide a custom render function for dynamic thumb content.
253
- * For static thumb content, you can use the `children` prop.
254
223
* The render function will be passed a single argument,
255
224
* an object with the following properties:
256
225
*
@@ -284,7 +253,10 @@ class ReactSlider extends React.Component {
284
253
constructor ( props ) {
285
254
super ( props ) ;
286
255
287
- const value = this . or ( ensureArray ( props . value ) , ensureArray ( props . defaultValue ) ) ;
256
+ let value = ensureArray ( props . value ) ;
257
+ if ( ! value . length ) {
258
+ value = ensureArray ( props . defaultValue ) ;
259
+ }
288
260
289
261
// reused throughout the component to store results of iterations over `value`
290
262
this . tempArray = value . slice ( ) ;
@@ -317,7 +289,11 @@ class ReactSlider extends React.Component {
317
289
// Keep the internal `value` consistent with an outside `value` if present.
318
290
// This basically allows the slider to be a controlled component.
319
291
componentWillReceiveProps ( newProps ) {
320
- const value = this . or ( ensureArray ( newProps . value ) , this . state . value ) ;
292
+ let value = ensureArray ( newProps . value ) ;
293
+ if ( ! value . length ) {
294
+ // eslint-disable-next-line prefer-destructuring
295
+ value = this . state . value ;
296
+ }
321
297
322
298
// ensure the array keeps the same size as `value`
323
299
this . tempArray = value . slice ( ) ;
@@ -638,35 +614,6 @@ class ReactSlider extends React.Component {
638
614
} while ( this . pendingResizeTimeouts . length ) ;
639
615
}
640
616
641
- // Check if the arity of `value` or `defaultValue` matches the number of children
642
- // (= number of custom thumbs).
643
- // If no custom thumbs are provided,
644
- // just returns `value` if present and `defaultValue` otherwise.
645
- // If custom thumbs are present but neither `value` nor `defaultValue` are applicable
646
- // the thumbs are spread out equally.
647
- // TODO: better name? better solution?
648
- or ( value , defaultValue ) {
649
- const count = React . Children . count ( this . props . children ) ;
650
- switch ( count ) {
651
- case 0 :
652
- return value . length > 0 ? value : defaultValue ;
653
- case value . length :
654
- return value ;
655
- case defaultValue . length :
656
- return defaultValue ;
657
- default :
658
- if ( value . length !== count || defaultValue . length !== count ) {
659
- // eslint-disable-next-line no-console
660
- console . warn (
661
- `${
662
- this . constructor . displayName
663
- } : Number of values does not match number of children.`
664
- ) ;
665
- }
666
- return linspace ( this . props . min , this . props . max , count ) ;
667
- }
668
- }
669
-
670
617
start ( i , position ) {
671
618
const activeEl = document . activeElement ;
672
619
const thumbRef = this [ `thumb${ i } ` ] ;
@@ -912,11 +859,7 @@ class ReactSlider extends React.Component {
912
859
}
913
860
914
861
const res = [ ] ;
915
- if ( React . Children . count ( this . props . children ) > 0 ) {
916
- React . Children . forEach ( this . props . children , ( child , i ) => {
917
- res [ i ] = this . renderThumb ( styles [ i ] , child , i ) ;
918
- } ) ;
919
- } else if ( this . props . renderThumb ) {
862
+ if ( this . props . renderThumb ) {
920
863
for ( let i = 0 ; i < length ; i += 1 ) {
921
864
const child = this . props . renderThumb ( {
922
865
index : i ,
0 commit comments