Skip to content

Commit 920d716

Browse files
authored
Feat/enable expressing overlap distance in step (ptomasroos#210)
* feat: Allow expressing overlap distance without re-computing stepLength * refactor: Suggest reducing number of ternary conditions
1 parent d0bf770 commit 920d716

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

MultiSlider.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ export default class MultiSlider extends React.Component {
4646
snapped: false,
4747
vertical: false,
4848
minMarkerOverlapDistance: 0,
49+
minMarkerOverlapStepDistance: 0,
4950
};
5051

5152
constructor(props) {
5253
super(props);
5354

55+
if(this.props.minMarkerOverlapDistance > 0 && this.props.minMarkerOverlapStepDistance > 0) {
56+
console.error('You should provide either "minMarkerOverlapDistance" or "minMarkerOverlapStepDistance", not both. Expect unreliable results.');
57+
}
58+
5459
this.optionsArray =
5560
this.props.optionsArray ||
5661
createArray(this.props.min, this.props.max, this.props.step);
@@ -161,7 +166,7 @@ export default class MultiSlider extends React.Component {
161166
? 0
162167
: this.props.minMarkerOverlapDistance > 0
163168
? this.props.minMarkerOverlapDistance
164-
: this.stepLength);
169+
: (this.props.minMarkerOverlapStepDistance || 1) * this.stepLength);
165170
var top =
166171
trueTop === 0
167172
? 0
@@ -233,7 +238,7 @@ export default class MultiSlider extends React.Component {
233238
? 0
234239
: this.props.minMarkerOverlapDistance > 0
235240
? this.props.minMarkerOverlapDistance
236-
: this.stepLength);
241+
: (this.props.minMarkerOverlapStepDistance || 1) * this.stepLength);
237242
var top = this.props.sliderLength - this.props.markerSize / 2;
238243
var confined =
239244
unconfined < bottom ? bottom : unconfined > top ? top : unconfined;

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ Feel free to contribute to this part of the documentation.
9999
| markerOffsetX | 0 | number | Offset the cursor(s) on the X axis |
100100
| markerOffsetY | 0 | number | Offset the cursor(s) on the Y axis |
101101
| markerSize | 0 | number | It determines the marker margin from the edges of the track, useful to avoid the markers to overflow out of the track. |
102-
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. |
102+
| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapDistance |
103+
| minMarkerOverlapStepDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in steps, not pixels). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapStepDistance |
103104
| imageBackgroundSource | undefined | string | Specifies the source as required by [ImageBackground](https://facebook.github.io/react-native/docs/imagebackground)|

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface MultiSliderProps {
7474
markerOffsetX?: number;
7575
markerOffsetY?: number;
7676
minMarkerOverlapDistance?: number;
77+
minMarkerOverlapStepDistance?: number;
7778
imageBackgroundSource?: string;
7879
enableLabel?: boolean;
7980
vertical?: boolean;

0 commit comments

Comments
 (0)