From 38d96ee1250714d497928e73f091d449131aa676 Mon Sep 17 00:00:00 2001 From: doong-jo Date: Fri, 21 Aug 2020 03:10:10 +0900 Subject: [PATCH 1/2] feat: add distanceBetweenHandles --- examples/range.jsx | 4 ++++ src/Range.tsx | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/range.jsx b/examples/range.jsx index 704bbe6ac..a2953cd50 100644 --- a/examples/range.jsx +++ b/examples/range.jsx @@ -235,5 +235,9 @@ export default () => (

Range as child component

+
+

Set Distance between handles

+ +
); diff --git a/src/Range.tsx b/src/Range.tsx index 36a7286e9..464af3c6d 100644 --- a/src/Range.tsx +++ b/src/Range.tsx @@ -40,6 +40,7 @@ export interface RangeProps { max?: number; allowCross?: boolean; pushable: boolean; + distanceBetweenHandles?: number; onChange?: (value: number[]) => void; onBeforeChange?: (value: number[]) => void; onAfterChange?: (value: number[]) => void; @@ -194,7 +195,24 @@ class Range extends React.Component { } const data = { ...this.state, ...state }; - const changedValue = data.bounds; + let changedValue = data.bounds; + const { distanceBetweenHandles } = this.props; + + if (distanceBetweenHandles) { + const [beforeFirst, beforeSecond] = this.state.bounds; + const [afterFirst, afterSecond] = changedValue; + + if (afterSecond - afterFirst < distanceBetweenHandles) { + if (beforeFirst < afterFirst) { + changedValue = [afterSecond - distanceBetweenHandles, afterSecond]; + } else if (afterSecond < beforeSecond) { + changedValue = [afterFirst, afterFirst + distanceBetweenHandles]; + } + } + this.setState({ + bounds: changedValue, + }); + } props.onChange(changedValue); } From 33a49d64dd0a33045d37e88402ef71337cda09fe Mon Sep 17 00:00:00 2001 From: doong-jo Date: Fri, 21 Aug 2020 03:33:50 +0900 Subject: [PATCH 2/2] fix: eslint error by disable code --- src/Range.tsx | 2 ++ src/Slider.tsx | 1 + src/common/createSlider.tsx | 5 +++-- src/utils.ts | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Range.tsx b/src/Range.tsx index 464af3c6d..5af1d1dcf 100644 --- a/src/Range.tsx +++ b/src/Range.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import classNames from 'classnames'; import shallowEqual from 'shallowequal'; @@ -106,6 +107,7 @@ class Range extends React.Component { internalPointsCache: { marks: RangeProps['marks']; step: number; points: number[] }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any handlesRefs: Record; constructor(props: RangeProps) { diff --git a/src/Slider.tsx b/src/Slider.tsx index b1742ded1..209a33439 100644 --- a/src/Slider.tsx +++ b/src/Slider.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import warning from 'rc-util/lib/warning'; import Track from './common/Track'; diff --git a/src/common/createSlider.tsx b/src/common/createSlider.tsx index 2477f5a0f..f075c6302 100644 --- a/src/common/createSlider.tsx +++ b/src/common/createSlider.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ +/* eslint-disable no-unused-expressions */ import React from 'react'; import addEventListener from 'rc-util/lib/Dom/addEventListener'; import classNames from 'classnames'; @@ -163,6 +165,7 @@ export default function createSlider(Component) { onClickMarkLabel = (e, value) => { e.stopPropagation(); this.onChange({ value }); + // eslint-disable-next-line react/no-unused-state this.setState({ value }, () => this.onEnd(true)); }; @@ -198,13 +201,11 @@ export default function createSlider(Component) { } removeDocumentEvents() { - /* eslint-disable no-unused-expressions */ this.onTouchMoveListener && this.onTouchMoveListener.remove(); this.onTouchUpListener && this.onTouchUpListener.remove(); this.onMouseMoveListener && this.onMouseMoveListener.remove(); this.onMouseUpListener && this.onMouseUpListener.remove(); - /* eslint-enable no-unused-expressions */ } focus() { diff --git a/src/utils.ts b/src/utils.ts index b3710e739..abbfb05ed 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,4 @@ +/* eslint-disable react/no-find-dom-node */ import { findDOMNode } from 'react-dom'; import keyCode from 'rc-util/lib/KeyCode';