Skip to content

Commit da3a5bf

Browse files
Merge pull request #5 from rafaelklaessen/v1.1.0
v1.1.0
2 parents 1cdcc52 + f4c3189 commit da3a5bf

9 files changed

Lines changed: 93 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Version 1.1.0
2+
Released 2018-03-28
3+
4+
- Fixed dependency versions in `package.json`
5+
- Moved from `PureComponent` to `Component`
6+
- Added `onDragStart` and `onDragStop` callbacks
7+
- Updated README
8+
19
# Version 1.0.1
210
Released 2018-03-23
311

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export default class App extends Component {
5454
equalColor="blue"
5555
style={{ marginBottom: 40 }}
5656
onSlide={this.handleSlide}
57+
onDragStart={progress => console.log(`Started dragging: ${progress}%`)}
58+
onDragStop={progress => console.log(`Stopped dragging: ${progress}%`)}
5759
roundedCorners
5860
reversed
5961
/>
@@ -80,8 +82,10 @@ Prop | Description | Type | Default
8082
`slidableZoneSize` | Size of the zone in which sliders can be dragged | `number` or `string` | `7px`,
8183
`backgroundColor` | Background color of the slider | `string` | `#EEEEEE`
8284
`equalColor` | Color of all bars when their values are equal | `string` |
83-
`style` | Custom style for the slider | `object` or `function` | `{}`
84-
`onSlide*` | Callback that gets called when the progress is updated | `function` |
85+
`style` | Custom style for the slider <br> *Signature:* <br> `function(props: object) => object` | `object` or `function` | `{}`
86+
`onSlide` | Callback that is fired when the progress was set <br> *Signature:* <br> `function(progress: number) => void` | `function` |
87+
`onDragStart` | Callback function that is fired when the slider has begun to move <br> *Signature:* <br> `function(progress: number) => void` | `function` |
88+
`onDragStop`| Callback function that is fired when the slide has stopped moving <br> *Signature:* <br> `function(progress: number) => void` | `function` |
8589
`roundedCorners` | When set to `true`, the slider has rounded corners | `bool` | `false`
8690
`reversed` | When set to `true`, the slider is reversed | `bool` | `false`
8791
`readOnly` | When set to `true`, the slider can't be updated | `bool` | `false`
@@ -94,7 +98,7 @@ Prop | Description | Type | Default
9498
----- | ----------- | ---- | -------
9599
`color*` | Color of the progress bar | `string` |
96100
`progress*` | Progress of the progress bar | `number` |
97-
`style` | Custom style for the progress bar | `object` or `function` |
101+
`style` | Custom style for the progress bar <br> *Signature:* <br> `function(props: object) => object` | `object` or `function` |
98102
`children` | The slider dot (or any other children) | `node` |
99103

100104
All other props (not documented here) will be passed on to the root element.
@@ -106,8 +110,8 @@ Prop | Description | Type | Default
106110
`height` | Height of the dot | `number` or `string` | `50` when the dot has an icon, `28` if not
107111
`color` | Color of the dot | `string` |
108112
`icon` | URL of the image to use as dot icon | `string` |
109-
`style` | Custom style for the dot | `object` or `function` |
110-
`iconStyle` | Custom style for the dot icon | `object` or `function` |
113+
`style` | Custom style for the dot <br> *Signature:* <br> `function(props: object) => object` | `object` or `function` |
114+
`iconStyle` | Custom style for the dot icon <br> *Signature:* <br> `function(props: object) => object` | `object` or `function` |
111115
`children` | Children of the dot | `node` |
112116

113117
All other props (not documented here) will be passed on to the root element.

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-multi-bar-slider",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Slider component with multiple bars for React",
55
"repository": {
66
"type": "git",
@@ -19,11 +19,11 @@
1919
"react multi slider"
2020
],
2121
"peerDependencies": {
22-
"glamor": "^2.20.40",
23-
"glamorous": "^4.12.1",
24-
"prop-types": "^15.6.1",
25-
"react": "^15.3.0 || ^16.0.0",
26-
"react-dom": "^15.3.0 || ^16.0.0"
22+
"glamor": "^2.x",
23+
"glamorous": "^4.x",
24+
"prop-types": "^15.x",
25+
"react": "^15.3.x || ^16.x",
26+
"react-dom": "^15.3.x || ^16.x"
2727
},
2828
"scripts": {
2929
"build": "webpack --config webpack.config.babel.js",
@@ -37,6 +37,7 @@
3737
"babel-eslint": "^8.0.1",
3838
"babel-jest": "^22.1.0",
3939
"babel-loader": "^7.1.2",
40+
"babel-preset-env": "^1.6.1",
4041
"babel-preset-react": "^6.24.1",
4142
"babel-preset-stage-0": "^6.24.1",
4243
"clean-webpack-plugin": "^0.1.16",
@@ -53,8 +54,5 @@
5354
"react-dom": "^16.2.0",
5455
"react-test-renderer": "^16.2.0",
5556
"webpack": "^3.8.1"
56-
},
57-
"dependencies": {
58-
"babel-preset-env": "^1.6.1"
5957
}
6058
}

src/MultiSlider/Slider.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const Slider = ({
88
height,
99
backgroundColor,
1010
style,
11-
onSlide,
1211
onMouseMoveActivate,
1312
onMouseMoveDeactivate,
1413
onMouseMove,
@@ -30,7 +29,6 @@ const Slider = ({
3029
roundedCorners,
3130
readOnly
3231
})}
33-
onClick={onSlide}
3432
onMouseDown={onMouseMoveActivate}
3533
onMouseUp={onMouseMoveDeactivate}
3634
onMouseLeave={onMouseMoveDeactivate}
@@ -54,7 +52,6 @@ Slider.propTypes = {
5452
]).isRequired,
5553
backgroundColor: PropTypes.string.isRequired,
5654
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,
57-
onSlide: PropTypes.func.isRequired,
5855
onMouseMoveActivate: PropTypes.func.isRequired,
5956
onMouseMoveDeactivate: PropTypes.func.isRequired,
6057
onMouseMove: PropTypes.func.isRequired,

src/MultiSlider/__tests__/__snapshots__/Slider.test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exports[`Slider.js matches the snapshot 1`] = `
44
<div
55
className="css-975bpe"
6-
onClick={[Function]}
76
onMouseDown={[Function]}
87
onMouseLeave={[Function]}
98
onMouseMove={[Function]}

src/MultiSlider/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { PureComponent, Children } from 'react';
1+
import React, { Component, Children } from 'react';
22
import PropTypes from 'prop-types';
33
import getProgressFromMousePosition from '../utils/getProgressFromMousePosition';
44
import progressEqual from '../utils/progressEqual';
55
import sortProgress from '../utils/sortProgress';
66
import Slider from './Slider';
77
import SlidableZone from './SlidableZone';
88

9-
export default class MultiSlider extends PureComponent {
9+
export default class MultiSlider extends Component {
1010
static displayName = 'MultiSlider';
1111

1212
static propTypes = {
@@ -17,6 +17,8 @@ export default class MultiSlider extends PureComponent {
1717
equalColor: PropTypes.string,
1818
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
1919
onSlide: PropTypes.func,
20+
onDragStart: PropTypes.func,
21+
onDragStop: PropTypes.func,
2022
roundedCorners: PropTypes.bool,
2123
reversed: PropTypes.bool,
2224
readOnly: PropTypes.bool,
@@ -53,8 +55,29 @@ export default class MultiSlider extends PureComponent {
5355
onSlide(newProgress);
5456
};
5557

56-
handleMouseMoveActivate = () => this.setState({ mouseDown: true });
57-
handleMouseMoveDeactivate = () => this.setState({ mouseDown: false });
58+
handleMouseMoveActivate = (e) => {
59+
if (this.state.mouseDown) return;
60+
this.setState({ mouseDown: true });
61+
62+
const { onDragStart, reversed } = this.props;
63+
if (onDragStart) {
64+
const progress = getProgressFromMousePosition(e, reversed);
65+
onDragStart(progress);
66+
}
67+
};
68+
69+
handleMouseMoveDeactivate = (e) => {
70+
if (!this.state.mouseDown) return;
71+
this.setState({ mouseDown: false });
72+
73+
this.handleSlide(e);
74+
75+
const { onDragStop, reversed } = this.props;
76+
if (onDragStop) {
77+
const progress = getProgressFromMousePosition(e, reversed);
78+
onDragStop(progress);
79+
}
80+
};
5881

5982
handleMouseMove = (e) => {
6083
if (!this.state.mouseDown) return;
@@ -86,7 +109,6 @@ export default class MultiSlider extends PureComponent {
86109
height={height}
87110
backgroundColor={backgroundColor}
88111
style={style}
89-
onSlide={this.handleSlide}
90112
onMouseMoveActivate={this.handleMouseMoveActivate}
91113
onMouseMoveDeactivate={this.handleMouseMoveDeactivate}
92114
onMouseMove={this.handleMouseMove}

src/__tests__/MultiSlider.test.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ describe('MultiSlider.js', () => {
116116
<Child progress={4} />
117117
</MultiSlider>
118118
);
119-
multiSlider.find(Slider).prop('onSlide')({
119+
multiSlider.find(Slider).prop('onMouseMoveActivate')();
120+
multiSlider.find(Slider).prop('onMouseMoveDeactivate')({
120121
target: {
121122
classList: [],
122123
getBoundingClientRect: () => ({
@@ -149,14 +150,47 @@ describe('MultiSlider.js', () => {
149150
multiSlider.find(Slider).prop('onMouseMove')(fakeEvent);
150151
expect(onSlide.mock.calls.length).toBe(0);
151152

152-
multiSlider.find(Slider).prop('onMouseMoveActivate')();
153+
multiSlider.find(Slider).prop('onMouseMoveActivate')(fakeEvent);
153154
multiSlider.update();
154155
multiSlider.find(Slider).prop('onMouseMove')(fakeEvent);
155156
expect(onSlide.mock.calls[0][0]).toBe(89);
156157

157-
multiSlider.find(Slider).prop('onMouseMoveDeactivate')();
158+
multiSlider.find(Slider).prop('onMouseMoveDeactivate')(fakeEvent);
159+
expect(onSlide.mock.calls.length).toBe(2);
158160
multiSlider.update();
159161
multiSlider.find(Slider).prop('onMouseMove')(fakeEvent);
160-
expect(onSlide.mock.calls.length).toBe(1);
162+
expect(onSlide.mock.calls.length).toBe(2);
163+
});
164+
165+
it('calls onDragStart and onDragStop correctly', () => {
166+
const onDragStart = jest.fn();
167+
const onDragStop = jest.fn();
168+
const multiSlider = shallow(
169+
<MultiSlider
170+
{...multiSliderProps}
171+
onDragStart={onDragStart}
172+
onDragStop={onDragStop}
173+
>
174+
<Child progress={4} />
175+
</MultiSlider>
176+
);
177+
const fakeEvent = {
178+
target: {
179+
classList: [],
180+
getBoundingClientRect: () => ({
181+
left: 154,
182+
width: 876
183+
})
184+
},
185+
pageX: 933.64
186+
};
187+
multiSlider.instance().handleMouseMoveActivate(fakeEvent);
188+
expect(onDragStart.mock.calls.length).toBe(1);
189+
expect(onDragStop.mock.calls.length).toBe(0);
190+
expect(onDragStart.mock.calls[0][0]).toBe(89);
191+
multiSlider.instance().handleMouseMoveDeactivate(fakeEvent);
192+
expect(onDragStart.mock.calls.length).toBe(1);
193+
expect(onDragStop.mock.calls.length).toBe(1);
194+
expect(onDragStop.mock.calls[0][0]).toBe(89);
161195
});
162196
});

src/__tests__/__snapshots__/MultiSlider.test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exports[`MultiSlider.js matches the snapshot 1`] = `
44
<div
55
className="css-1i6y0pe"
6-
onClick={[Function]}
76
onMouseDown={[Function]}
87
onMouseLeave={[Function]}
98
onMouseMove={[Function]}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,8 +1339,8 @@ camelcase@^4.1.0:
13391339
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
13401340

13411341
caniuse-lite@^1.0.30000792:
1342-
version "1.0.30000819"
1343-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000819.tgz#aabee5fd15a080febab6ae5d30c9ea15f4c6d4e2"
1342+
version "1.0.30000821"
1343+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000821.tgz#0f3223f1e048ed96451c56ca6cf197058c42cb93"
13441344

13451345
caseless@~0.12.0:
13461346
version "0.12.0"
@@ -1849,8 +1849,8 @@ ecc-jsbn@~0.1.1:
18491849
jsbn "~0.1.0"
18501850

18511851
electron-to-chromium@^1.3.30:
1852-
version "1.3.40"
1853-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.40.tgz#1fbd6d97befd72b8a6f921dc38d22413d2f6fddf"
1852+
version "1.3.41"
1853+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.41.tgz#7e33643e00cd85edfd17e04194f6d00e73737235"
18541854

18551855
elliptic@^6.0.0:
18561856
version "6.4.0"

0 commit comments

Comments
 (0)