UNPKG

2.67 kBJavaScriptView Raw
1import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
2import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
3import _inherits from 'babel-runtime/helpers/inherits';
4
5var _class, _temp;
6
7import classNames from 'classnames';
8import React from 'react';
9import PropTypes from 'prop-types';
10import { inRange, getPercent } from '../utils';
11
12var Scale = (_temp = _class = function (_React$Component) {
13 _inherits(Scale, _React$Component);
14
15 function Scale() {
16 _classCallCheck(this, Scale);
17
18 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
19 }
20
21 Scale.prototype._renderItems = function _renderItems() {
22 var _props = this.props,
23 min = _props.min,
24 max = _props.max,
25 value = _props.value,
26 prefix = _props.prefix,
27 scales = _props.scales,
28 rtl = _props.rtl;
29
30 var items = [];
31
32 scales.forEach(function (scale, i) {
33 var _classNames;
34
35 var classes = classNames((_classNames = {}, _classNames[prefix + 'range-scale-item'] = true, _classNames.activated = inRange(scale, value, min), _classNames));
36 var style = void 0;
37 if (rtl) {
38 style = {
39 right: getPercent(min, max, scale) + '%',
40 left: 'auto'
41 };
42 } else {
43 style = {
44 left: getPercent(min, max, scale) + '%',
45 right: 'auto'
46 };
47 }
48
49 items.push(
50 // "key" is for https://fb.me/react-warning-keys
51 React.createElement('span', { className: classes, style: style, key: i }));
52 });
53
54 return items;
55 };
56
57 Scale.prototype.render = function render() {
58 var _classNames2;
59
60 var prefix = this.props.prefix;
61
62 var classes = classNames((_classNames2 = {}, _classNames2[prefix + 'range-scale'] = true, _classNames2));
63 var items = this._renderItems();
64
65 return React.createElement(
66 'div',
67 { className: classes },
68 items
69 );
70 };
71
72 return Scale;
73}(React.Component), _class.propTypes = {
74 min: PropTypes.number,
75 max: PropTypes.number,
76 value: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
77 prefix: PropTypes.string,
78 scales: PropTypes.arrayOf(PropTypes.number),
79 rtl: PropTypes.bool
80}, _class.defaultProps = {
81 prefix: 'next-',
82 min: 0,
83 max: 100,
84 value: 0,
85 rtl: false
86}, _temp);
87Scale.displayName = 'Scale';
88export { Scale as default };
\No newline at end of file