This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Omit marks that are outside of range specified by min and max. (#695)
* Omit marks that are outside of range specified by min and max. * Handle case in which marks prop is not defined. * Add test for out-of-range numbers. * Use pickBy. * Add mark at point below minimum value. * Also omit out-of-range marks for slider. * Add test for slider. * Add padding to Slider and RangeSlider containers. * Update test for persistence. With the new padding values, the '0' selection is no longer at the very edge of the container div. * Change test for always visible rangeslider. * Only add top padding if there are always-visible tooltips on the top. * Preserve whitespace in marks. * Add optional verticalHeight prop for vertical sliders. * Update slider stylesheet. * Update coordinates to reflect new padding. * Remove file. * Use fixed-width slider for rangeslider test. * Fix persistence test. * Memoize computation of style and move function to utils. * Simplify style code. * Fix eslint errors. * Modify style object directly. * Update CHANGELOG.
- Loading branch information
Shammamah Hossain
authored and
Ryan Patrick Kyle
committed
Dec 12, 2019
1 parent
ef4fd53
commit a115d5e
Showing
7 changed files
with
143 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React, {Component} from 'react'; | ||
import ReactSlider, {createSliderWithTooltip} from 'rc-slider'; | ||
import PropTypes from 'prop-types'; | ||
import {assoc, omit} from 'ramda'; | ||
import {assoc, omit, pickBy} from 'ramda'; | ||
import './css/[email protected]'; | ||
import computeSliderStyle from '../utils/computeSliderStyle'; | ||
|
||
/** | ||
* A slider component with a single handle. | ||
|
@@ -14,6 +15,7 @@ export default class Slider extends Component { | |
this.DashSlider = props.tooltip | ||
? createSliderWithTooltip(ReactSlider) | ||
: ReactSlider; | ||
this._computeStyle = computeSliderStyle(); | ||
} | ||
|
||
propsToState(newProps) { | ||
|
@@ -42,6 +44,7 @@ export default class Slider extends Component { | |
tooltip, | ||
updatemode, | ||
vertical, | ||
verticalHeight, | ||
} = this.props; | ||
const value = this.state.value; | ||
|
||
|
@@ -58,14 +61,21 @@ export default class Slider extends Component { | |
tipProps = tooltip; | ||
} | ||
|
||
const truncatedMarks = this.props.marks | ||
? pickBy( | ||
(k, mark) => mark >= this.props.min && mark <= this.props.max, | ||
this.props.marks | ||
) | ||
: this.props.marks; | ||
|
||
return ( | ||
<div | ||
id={id} | ||
data-dash-is-loading={ | ||
(loading_state && loading_state.is_loading) || undefined | ||
} | ||
className={className} | ||
style={vertical ? {height: '100%'} : {}} | ||
style={this._computeStyle(vertical, verticalHeight, tooltip)} | ||
> | ||
<this.DashSlider | ||
onChange={value => { | ||
|
@@ -82,8 +92,16 @@ export default class Slider extends Component { | |
}} | ||
tipProps={tipProps} | ||
value={value} | ||
marks={truncatedMarks} | ||
{...omit( | ||
['className', 'setProps', 'updatemode', 'value'], | ||
[ | ||
'className', | ||
'setProps', | ||
'updatemode', | ||
'value', | ||
'marks', | ||
'verticalHeight', | ||
], | ||
this.props | ||
)} | ||
/> | ||
|
@@ -194,6 +212,11 @@ Slider.propTypes = { | |
*/ | ||
vertical: PropTypes.bool, | ||
|
||
/** | ||
* The height, in px, of the slider if it is vertical. | ||
*/ | ||
verticalHeight: PropTypes.number, | ||
|
||
/** | ||
* Determines when the component should update | ||
* its value. If `mouseup`, then the slider | ||
|
@@ -262,4 +285,5 @@ Slider.defaultProps = { | |
updatemode: 'mouseup', | ||
persisted_props: ['value'], | ||
persistence_type: 'local', | ||
verticalHeight: 400, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {memoizeWith, identity, contains} from 'ramda'; | ||
|
||
export default () => { | ||
return memoizeWith(identity, (vertical, verticalHeight, tooltip) => { | ||
const style = { | ||
padding: '25px', | ||
}; | ||
|
||
if (vertical) { | ||
style.height = verticalHeight + 'px'; | ||
|
||
if ( | ||
!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, [ | ||
'left', | ||
'topRight', | ||
'bottomRight', | ||
]) | ||
) { | ||
style.paddingLeft = '0px'; | ||
} | ||
} else { | ||
if ( | ||
!tooltip || | ||
!tooltip.always_visible || | ||
!contains(tooltip.placement, ['top', 'topLeft', 'topRight']) | ||
) { | ||
style.paddingTop = '0px'; | ||
} | ||
} | ||
|
||
return style; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters