UNPKG

fk-react-ui-components

Version:

Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should

65 lines (46 loc) 3.31 kB
'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 _propTypes = require('prop-types'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var HumanReadableTime = function (_Component) { _inherits(HumanReadableTime, _Component); function HumanReadableTime() { var _ref; var _temp, _this, _ret; _classCallCheck(this, HumanReadableTime); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = HumanReadableTime.__proto__ || Object.getPrototypeOf(HumanReadableTime)).call.apply(_ref, [this].concat(args))), _this), _this.render = function () { return HumanReadableTime.getReadableTime(parseInt(_this.props.millisec)); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(HumanReadableTime, null, [{ key: 'getReadableTime', value: function getReadableTime(millisec) { var seconds = (millisec / 1000).toFixed(0); var minutes = (millisec / (1000 * 60)).toFixed(0); var hours = (millisec / (1000 * 60 * 60)).toFixed(0); var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(0); if (seconds < 60) { return 'Now'; } else if (minutes < 60) { return minutes + ' ' + (minutes <= 1 ? 'min' : 'mins'); } else if (hours < 24) { return hours + ' ' + (hours <= 1 ? 'hr' : 'hrs'); } return days + ' ' + (days <= 1 ? 'day' : 'days'); } }]); return HumanReadableTime; }(_react.Component); HumanReadableTime.propTypes = { millisec: _propTypes.PropTypes.number.isRequired }; exports.default = HumanReadableTime;