Skip to content

Commit 5f7c7df

Browse files
author
Jonny Pillar
committed
Display Slider Labels
1 parent ce760a2 commit 5f7c7df

File tree

5 files changed

+114
-88
lines changed

5 files changed

+114
-88
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var TimeRangeSlider = require('react-time-range-slider')
2222
import React from 'react';
2323
import { render} from 'react-dom';
2424
import TimeRangeSlider from 'react-time-range-slider';
25+
import 'react-time-range-slider/dist/styles.css';
26+
2527
class App extends React.Component{
2628
constructor(props) {
2729
super(props);
@@ -63,7 +65,8 @@ class App extends React.Component{
6365
onChangeComplete={this.changeCompleteHandler}
6466
onChange={this.timeChangeHandler}
6567
step={15}
66-
value={this.state.value}/>
68+
value={this.state.value}
69+
formatLabel={(value) => {`${value}`}}/>
6770
</div>);
6871
}
6972
};
@@ -108,6 +111,9 @@ The amount of time, in minutes, increment/decrement when time range change.
108111
#### value: Range
109112
Set the current value for your component
110113

114+
#### formatLabel: Function(Value, Type): void
115+
By default, value labels are displayed as plain numbers. If you want to change the display, you can do so by passing in a function. The function can return something different, i.e.: append a unit, reduce the precision of a number.
116+
111117
## Defaults
112118
* disabled: `false`
113119
* draggableTrack: `false`
@@ -116,4 +122,4 @@ Set the current value for your component
116122
* minValue: `00:00`
117123
* name: ` `
118124
* step: `15`
119-
* value: `{start: "00:00", end: "23:59"}`
125+
* value: `{start: "00:00", end: "23:59"}`

dist/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
'use strict';
1+
"use strict";
22

33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66

77
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
88

9-
var _react = require('react');
9+
var _react = require("react");
1010

1111
var _react2 = _interopRequireDefault(_react);
1212

13-
var _reactInputRange = require('react-input-range');
13+
var _reactInputRange = require("react-input-range");
1414

1515
var _reactInputRange2 = _interopRequireDefault(_reactInputRange);
1616

17-
require('./styles.css');
18-
1917
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2018

2119
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -38,22 +36,22 @@ var TimeRangeSlider = function (_Component) {
3836
}
3937

4038
_createClass(TimeRangeSlider, [{
41-
key: 'componentDidMount',
39+
key: "componentDidMount",
4240
value: function componentDidMount() {}
4341
}, {
44-
key: 'componentWillUnmount',
42+
key: "componentWillUnmount",
4543
value: function componentWillUnmount() {}
4644
}, {
47-
key: 'minuteToTime',
45+
key: "minuteToTime",
4846
value: function minuteToTime(value) {
4947
value = value > 1439 ? 1439 : value;
5048
var hours = Math.floor(value / 60),
5149
minutes = value - hours * 60,
5250
ampm = null;
5351

54-
if (hours.length == 1) hours = '0' + hours;
55-
if (minutes.length == 1) minutes = '0' + minutes;
56-
if (minutes == 0) minutes = '00';
52+
if (hours.length == 1) hours = "0" + hours;
53+
if (minutes.length == 1) minutes = "0" + minutes;
54+
if (minutes == 0) minutes = "00";
5755
if (this.props.format == 12) {
5856
ampm = "AM";
5957
if (hours >= 12) {
@@ -75,7 +73,7 @@ var TimeRangeSlider = function (_Component) {
7573
return { hours: hours, minutes: minutes, am_pm: ampm };
7674
}
7775
}, {
78-
key: 'timeToMinute',
76+
key: "timeToMinute",
7977
value: function timeToMinute(time) {
8078
var rMinutes = 1439;
8179
if (this.props.format == 24) {
@@ -111,7 +109,7 @@ var TimeRangeSlider = function (_Component) {
111109
return rMinutes > 1439 ? 1439 : rMinutes;
112110
}
113111
}, {
114-
key: 'onChange',
112+
key: "onChange",
115113
value: function onChange(value) {
116114
var start = this.minuteToTime(value.min);
117115
var end = this.minuteToTime(value.max);
@@ -127,7 +125,7 @@ var TimeRangeSlider = function (_Component) {
127125
});
128126
}
129127
}, {
130-
key: 'onChangeComplete',
128+
key: "onChangeComplete",
131129
value: function onChangeComplete(value) {
132130
var start = this.minuteToTime(value.min),
133131
end = this.minuteToTime(value.max);
@@ -137,7 +135,7 @@ var TimeRangeSlider = function (_Component) {
137135
});
138136
}
139137
}, {
140-
key: 'onChangeStart',
138+
key: "onChangeStart",
141139
value: function onChangeStart(value) {
142140
var start = this.minuteToTime(value.min),
143141
end = this.minuteToTime(value.max);
@@ -147,7 +145,7 @@ var TimeRangeSlider = function (_Component) {
147145
});
148146
}
149147
}, {
150-
key: 'render',
148+
key: "render",
151149
value: function render() {
152150
var _props$value = this.props.value,
153151
start = _props$value.start,
@@ -163,8 +161,10 @@ var TimeRangeSlider = function (_Component) {
163161
onChangeStart: this.onChangeStart.bind(this),
164162
onChange: this.onChange.bind(this),
165163
onChangeComplete: this.onChangeComplete.bind(this),
166-
step: 15,
167-
value: { min: min, max: max } });
164+
formatLabel: this.props.formatLabel,
165+
step: this.props.step,
166+
value: { min: min, max: max }
167+
});
168168
}
169169
}]);
170170

@@ -180,6 +180,7 @@ TimeRangeSlider.defaultProps = {
180180
onChange: function onChange() {},
181181
onChangeComplete: function onChangeComplete() {},
182182
onChangeStart: function onChangeStart() {},
183+
formatLabel: function formatLabel() {},
183184
step: 15,
184185
value: {
185186
start: "00:00",

examples/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import React from 'react';
33
import { render} from 'react-dom';
44
import TimeRangeSlider from '../src';
5+
import '../src/styles.css';
6+
57
class App extends React.Component{
68
constructor(props) {
79
super(props);

0 commit comments

Comments
 (0)