Skip to content

Commit

Permalink
feat: add step support for marks
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Di Salvatore authored and stonebk committed Nov 3, 2020
1 parent 85060d2 commit 38f29d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/components/ReactSlider/ReactSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ class ReactSlider extends React.Component {
invert: PropTypes.bool,

/**
* Shows passed marks on the track, if true it shows all,
* if an array of numbers it shows just the passed marks
* Shows passed marks on the track, if true it shows all the marks,
* if an array of numbers it shows just the passed marks, if a number is passed
* it shows just the marks in that steps: like passing 3 shows the marks 3, 6, 9
*/
marks: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.bool]),
marks: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.number),
PropTypes.bool,
PropTypes.number,
]),

/**
* The css class set on the marks.
Expand Down Expand Up @@ -1025,9 +1030,14 @@ class ReactSlider extends React.Component {
renderMarks() {
let { marks } = this.props;

if (!Array.isArray(marks)) {
const range = this.props.max - this.props.min + 1;
const range = this.props.max - this.props.min + 1;

if (typeof marks === 'boolean') {
marks = Array.from({ length: range }).map((_, key) => key);
} else if (typeof marks === 'number') {
marks = Array.from({ length: range })
.map((_, key) => key)
.filter(key => key % marks === 0);
}

return marks
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReactSlider/ReactSlider.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Vertical slider with marks
invert
pearling
minDistance={1}
marks={[0, 3, 5, 8, 10]}
marks={3}
markClassName="example-mark"
/>
```
Expand Down

0 comments on commit 38f29d3

Please sign in to comment.