Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Add DashSlider conditional in componentWillReceiveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
wbrgss committed Jun 12, 2019
1 parent e6f8026 commit 224ec57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/components/RangeSlider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export default class RangeSlider extends Component {
constructor(props) {
super(props);
this.propsToState = this.propsToState.bind(this);
this.DashSlider = props.tooltip
? createSliderWithTooltip(Range)
: Range;
}

propsToState(newProps) {
this.setState({value: newProps.value});
}

componentWillReceiveProps(newProps) {
if (newProps.tooltip !== this.props.tooltip) {
this.DashSlider = newProps.tooltip
? createSliderWithTooltip(Range)
: Range;
}
this.propsToState(newProps);
}

Expand All @@ -37,8 +45,6 @@ export default class RangeSlider extends Component {
} = this.props;
const value = this.state.value;

const DashSlider = tooltip ? createSliderWithTooltip(Range) : Range;

let tipProps;
if (tooltip && tooltip.always_visible) {
/**
Expand All @@ -47,8 +53,8 @@ export default class RangeSlider extends Component {
* assigns the new (renamed) key to the old key and deletes the old key
*/
tipProps = Object.assign(tooltip, {
visible: tooltip.always_visible
})
visible: tooltip.always_visible,
});
delete tipProps.always_visible;
} else {
tipProps = tooltip;
Expand All @@ -63,7 +69,7 @@ export default class RangeSlider extends Component {
className={className}
style={vertical ? {height: '100%'} : {}}
>
<DashSlider
<this.DashSlider
onChange={value => {
if (updatemode === 'drag') {
setProps({value});
Expand Down
18 changes: 11 additions & 7 deletions src/components/Slider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export default class Slider extends Component {
constructor(props) {
super(props);
this.propsToState = this.propsToState.bind(this);
this.DashSlider = props.tooltip
? createSliderWithTooltip(ReactSlider)
: ReactSlider;
}

propsToState(newProps) {
this.setState({value: newProps.value});
}

componentWillReceiveProps(newProps) {
if (newProps.tooltip !== this.props.tooltip) {
this.DashSlider = newProps.tooltip
? createSliderWithTooltip(ReactSlider)
: ReactSlider;
}
this.propsToState(newProps);
}

Expand All @@ -37,10 +45,6 @@ export default class Slider extends Component {
} = this.props;
const value = this.state.value;

const DashSlider = tooltip
? createSliderWithTooltip(ReactSlider)
: ReactSlider;

let tipProps;
if (tooltip && tooltip.always_visible) {
/**
Expand All @@ -49,8 +53,8 @@ export default class Slider extends Component {
* assigns the new (renamed) key to the old key and deletes the old key
*/
tipProps = Object.assign(tooltip, {
visible: tooltip.always_visible
})
visible: tooltip.always_visible,
});
delete tipProps.always_visible;
} else {
tipProps = tooltip;
Expand All @@ -65,7 +69,7 @@ export default class Slider extends Component {
className={className}
style={vertical ? {height: '100%'} : {}}
>
<DashSlider
<this.DashSlider
onChange={value => {
if (updatemode === 'drag') {
setProps({value});
Expand Down

0 comments on commit 224ec57

Please sign in to comment.