Skip to content

Display Slider Labels #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var TimeRangeSlider = require('react-time-range-slider')
import React from 'react';
import { render} from 'react-dom';
import TimeRangeSlider from 'react-time-range-slider';
import 'react-time-range-slider/dist/styles.css';

class App extends React.Component{
constructor(props) {
super(props);
Expand Down Expand Up @@ -63,7 +65,8 @@ class App extends React.Component{
onChangeComplete={this.changeCompleteHandler}
onChange={this.timeChangeHandler}
step={15}
value={this.state.value}/>
value={this.state.value}
formatLabel={(value) => {`${value}`}}/>
</div>);
}
};
Expand Down Expand Up @@ -108,6 +111,9 @@ The amount of time, in minutes, increment/decrement when time range change.
#### value: Range
Set the current value for your component

#### formatLabel: Function(Value, Type): void
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.

## Defaults
* disabled: `false`
* draggableTrack: `false`
Expand All @@ -116,4 +122,4 @@ Set the current value for your component
* minValue: `00:00`
* name: ` `
* step: `15`
* value: `{start: "00:00", end: "23:59"}`
* value: `{start: "00:00", end: "23:59"}`
37 changes: 19 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
'use strict';
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

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; }; }();

var _react = require('react');
var _react = require("react");

var _react2 = _interopRequireDefault(_react);

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

var _reactInputRange2 = _interopRequireDefault(_reactInputRange);

require('./styles.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

_createClass(TimeRangeSlider, [{
key: 'componentDidMount',
key: "componentDidMount",
value: function componentDidMount() {}
}, {
key: 'componentWillUnmount',
key: "componentWillUnmount",
value: function componentWillUnmount() {}
}, {
key: 'minuteToTime',
key: "minuteToTime",
value: function minuteToTime(value) {
value = value > 1439 ? 1439 : value;
var hours = Math.floor(value / 60),
minutes = value - hours * 60,
ampm = null;

if (hours.length == 1) hours = '0' + hours;
if (minutes.length == 1) minutes = '0' + minutes;
if (minutes == 0) minutes = '00';
if (hours.length == 1) hours = "0" + hours;
if (minutes.length == 1) minutes = "0" + minutes;
if (minutes == 0) minutes = "00";
if (this.props.format == 12) {
ampm = "AM";
if (hours >= 12) {
Expand All @@ -75,7 +73,7 @@ var TimeRangeSlider = function (_Component) {
return { hours: hours, minutes: minutes, am_pm: ampm };
}
}, {
key: 'timeToMinute',
key: "timeToMinute",
value: function timeToMinute(time) {
var rMinutes = 1439;
if (this.props.format == 24) {
Expand Down Expand Up @@ -111,7 +109,7 @@ var TimeRangeSlider = function (_Component) {
return rMinutes > 1439 ? 1439 : rMinutes;
}
}, {
key: 'onChange',
key: "onChange",
value: function onChange(value) {
var start = this.minuteToTime(value.min);
var end = this.minuteToTime(value.max);
Expand All @@ -127,7 +125,7 @@ var TimeRangeSlider = function (_Component) {
});
}
}, {
key: 'onChangeComplete',
key: "onChangeComplete",
value: function onChangeComplete(value) {
var start = this.minuteToTime(value.min),
end = this.minuteToTime(value.max);
Expand All @@ -137,7 +135,7 @@ var TimeRangeSlider = function (_Component) {
});
}
}, {
key: 'onChangeStart',
key: "onChangeStart",
value: function onChangeStart(value) {
var start = this.minuteToTime(value.min),
end = this.minuteToTime(value.max);
Expand All @@ -147,7 +145,7 @@ var TimeRangeSlider = function (_Component) {
});
}
}, {
key: 'render',
key: "render",
value: function render() {
var _props$value = this.props.value,
start = _props$value.start,
Expand All @@ -163,8 +161,10 @@ var TimeRangeSlider = function (_Component) {
onChangeStart: this.onChangeStart.bind(this),
onChange: this.onChange.bind(this),
onChangeComplete: this.onChangeComplete.bind(this),
step: 15,
value: { min: min, max: max } });
formatLabel: this.props.formatLabel,
step: this.props.step,
value: { min: min, max: max }
});
}
}]);

Expand All @@ -180,6 +180,7 @@ TimeRangeSlider.defaultProps = {
onChange: function onChange() {},
onChangeComplete: function onChangeComplete() {},
onChangeStart: function onChangeStart() {},
formatLabel: function formatLabel() {},
step: 15,
value: {
start: "00:00",
Expand Down
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import React from 'react';
import { render} from 'react-dom';
import TimeRangeSlider from '../src';
import '../src/styles.css';

class App extends React.Component{
constructor(props) {
super(props);
Expand Down
Loading