react-time-picker
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -7,9 +7,5 @@ "use strict"; | ||
exports["default"] = Divider; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function Divider(_ref) { | ||
@@ -21,5 +17,4 @@ var children = _ref.children; | ||
} | ||
Divider.propTypes = { | ||
children: _propTypes["default"].node | ||
}; |
@@ -7,11 +7,6 @@ "use strict"; | ||
exports["default"] = void 0; | ||
require("react-clock/dist/Clock.css"); | ||
var _TimePicker = _interopRequireDefault(require("./TimePicker")); | ||
require("./TimePicker.css"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
// File is created during build phase and placed in dist directory | ||
@@ -18,0 +13,0 @@ // eslint-disable-next-line import/no-unresolved |
@@ -7,8 +7,5 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _TimePicker = _interopRequireDefault(require("./TimePicker")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _default = _TimePicker["default"]; | ||
exports["default"] = _default; |
@@ -8,45 +8,31 @@ "use strict"; | ||
exports.getNumberFormatter = getNumberFormatter; | ||
var _getUserLocale = _interopRequireDefault(require("get-user-locale")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var formatterCache = new Map(); | ||
function getFormatter(options) { | ||
return function (locale, date) { | ||
var localeWithDefault = locale || (0, _getUserLocale["default"])(); | ||
if (!formatterCache.has(localeWithDefault)) { | ||
formatterCache.set(localeWithDefault, new Map()); | ||
} | ||
var formatterCacheLocale = formatterCache.get(localeWithDefault); | ||
if (!formatterCacheLocale.has(options)) { | ||
formatterCacheLocale.set(options, new Intl.DateTimeFormat(localeWithDefault, options).format); | ||
} | ||
return formatterCacheLocale.get(options)(date); | ||
}; | ||
} | ||
var numberFormatterCache = new Map(); | ||
function getNumberFormatter(options) { | ||
return function (locale, date) { | ||
var localeWithDefault = locale || (0, _getUserLocale["default"])(); | ||
if (!numberFormatterCache.has(localeWithDefault)) { | ||
numberFormatterCache.set(localeWithDefault, new Map()); | ||
} | ||
var numberFormatterCacheLocale = numberFormatterCache.get(localeWithDefault); | ||
if (!numberFormatterCacheLocale.has(options)) { | ||
numberFormatterCacheLocale.set(options, new Intl.NumberFormat(localeWithDefault, options).format); | ||
} | ||
return numberFormatterCacheLocale.get(options)(date); | ||
}; | ||
} |
@@ -8,6 +8,4 @@ "use strict"; | ||
exports.convert24to12 = convert24to12; | ||
function convert12to24(hour12, amPm) { | ||
var hour24 = parseInt(hour12, 10); | ||
if (amPm === 'am' && hour24 === 12) { | ||
@@ -18,6 +16,4 @@ hour24 = 0; | ||
} | ||
return hour24; | ||
} | ||
function convert24to12(hour24) { | ||
@@ -24,0 +20,0 @@ var hour12 = hour24 % 12 || 12; |
@@ -7,16 +7,10 @@ "use strict"; | ||
exports.isValueType = exports.isTime = exports.isRef = void 0; | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var allViews = ['hour', 'minute', 'second']; | ||
var allValueTypes = [].concat(allViews); | ||
var hourOptionalSecondsRegExp = /^(([0-1])?[0-9]|2[0-3]):[0-5][0-9](:([0-5][0-9]))?$/; | ||
var isTime = function isTime(props, propName, componentName) { | ||
var time = props[propName]; | ||
if (time) { | ||
@@ -26,18 +20,13 @@ if (!hourOptionalSecondsRegExp.test(time)) { | ||
} | ||
} // Everything is fine | ||
} | ||
// Everything is fine | ||
return null; | ||
}; | ||
exports.isTime = isTime; | ||
var isValueType = _propTypes["default"].oneOf(allValueTypes); | ||
exports.isValueType = isValueType; | ||
var isRef = _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].shape({ | ||
current: _propTypes["default"].any | ||
})]); | ||
exports.isRef = isRef; |
@@ -9,25 +9,13 @@ "use strict"; | ||
exports.safeMin = safeMin; | ||
var _dateFormatter = require("./dateFormatter"); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var nines = ['9', '٩']; | ||
@@ -38,17 +26,13 @@ var ninesRegExp = new RegExp("[".concat(nines.join(''), "]")); | ||
}); | ||
function getAmPmLabels(locale) { | ||
var amString = amPmFormatter(locale, new Date(2017, 0, 1, 9)); | ||
var pmString = amPmFormatter(locale, new Date(2017, 0, 1, 21)); | ||
var _amString$split = amString.split(ninesRegExp), | ||
_amString$split2 = _slicedToArray(_amString$split, 2), | ||
am1 = _amString$split2[0], | ||
am2 = _amString$split2[1]; | ||
_amString$split2 = _slicedToArray(_amString$split, 2), | ||
am1 = _amString$split2[0], | ||
am2 = _amString$split2[1]; | ||
var _pmString$split = pmString.split(ninesRegExp), | ||
_pmString$split2 = _slicedToArray(_pmString$split, 2), | ||
pm1 = _pmString$split2[0], | ||
pm2 = _pmString$split2[1]; | ||
_pmString$split2 = _slicedToArray(_pmString$split, 2), | ||
pm1 = _pmString$split2[0], | ||
pm2 = _pmString$split2[1]; | ||
if (pm2 !== undefined) { | ||
@@ -61,3 +45,2 @@ // If pm2 is undefined, nine was not found in pmString - this locale is not using 12-hour time | ||
} | ||
if (am2 !== pm2) { | ||
@@ -68,12 +51,10 @@ return [am2, pm2].map(function (el) { | ||
} | ||
} // Fallback | ||
} | ||
// Fallback | ||
return ['AM', 'PM']; | ||
} | ||
function isValidNumber(num) { | ||
return num !== null && num !== false && !Number.isNaN(Number(num)); | ||
} | ||
function safeMin() { | ||
@@ -83,6 +64,4 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
return Math.min.apply(Math, _toConsumableArray(args.filter(isValidNumber))); | ||
} | ||
function safeMax() { | ||
@@ -92,4 +71,3 @@ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
} | ||
return Math.max.apply(Math, _toConsumableArray(args.filter(isValidNumber))); | ||
} |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,84 +8,43 @@ value: true | ||
exports["default"] = void 0; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _Divider = _interopRequireDefault(require("./Divider")); | ||
var _Hour12Input = _interopRequireDefault(require("./TimeInput/Hour12Input")); | ||
var _Hour24Input = _interopRequireDefault(require("./TimeInput/Hour24Input")); | ||
var _MinuteInput = _interopRequireDefault(require("./TimeInput/MinuteInput")); | ||
var _SecondInput = _interopRequireDefault(require("./TimeInput/SecondInput")); | ||
var _NativeInput = _interopRequireDefault(require("./TimeInput/NativeInput")); | ||
var _AmPm = _interopRequireDefault(require("./TimeInput/AmPm")); | ||
var _dateFormatter = require("./shared/dateFormatter"); | ||
var _dates = require("./shared/dates"); | ||
var _propTypes2 = require("./shared/propTypes"); | ||
var _utils = require("./shared/utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var getFormatterOptionsCache = {}; | ||
var allViews = ['hour', 'minute', 'second']; | ||
function hoursAreDifferent(date1, date2) { | ||
@@ -100,13 +58,9 @@ return date1 && !date2 || !date1 && date2 || date1 && date2 && date1 !== date2 // TODO: Compare 11:22:00 and 11:22 properly | ||
} | ||
function findInput(element, property) { | ||
var nextElement = element; | ||
do { | ||
nextElement = nextElement[property]; | ||
} while (nextElement && !isInternalInput(nextElement)); | ||
return nextElement; | ||
} | ||
function focus(element) { | ||
@@ -117,3 +71,2 @@ if (element) { | ||
} | ||
function _renderCustomInputs(placeholder, elementFunctions, allowMultipleInstances) { | ||
@@ -132,6 +85,4 @@ var usedFunctions = []; | ||
}, element); | ||
var res = [].concat(_toConsumableArray(arr), [divider]); | ||
var currentMatch = matches && matches[index]; | ||
if (currentMatch) { | ||
@@ -141,3 +92,2 @@ var renderFunction = elementFunctions[currentMatch] || elementFunctions[Object.keys(elementFunctions).find(function (elementFunction) { | ||
})]; | ||
if (!allowMultipleInstances && usedFunctions.includes(renderFunction)) { | ||
@@ -150,27 +100,18 @@ res.push(currentMatch); | ||
} | ||
return res; | ||
}, []); | ||
} | ||
var formatNumber = (0, _dateFormatter.getNumberFormatter)({ | ||
useGrouping: false | ||
}); | ||
var TimeInput = /*#__PURE__*/function (_PureComponent) { | ||
_inherits(TimeInput, _PureComponent); | ||
var _super = _createSuper(TimeInput); | ||
function TimeInput() { | ||
var _this; | ||
_classCallCheck(this, TimeInput); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
@@ -182,13 +123,7 @@ amPm: null, | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "amPmInput", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "hour12Input", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "hour24Input", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "minuteInput", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "secondInput", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "onClick", function (event) { | ||
@@ -201,3 +136,2 @@ if (event.target === event.currentTarget) { | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) { | ||
@@ -216,18 +150,15 @@ switch (event.key) { | ||
} | ||
default: | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onKeyUp", function (event) { | ||
var key = event.key, | ||
input = event.target; | ||
input = event.target; | ||
var isNumberKey = !isNaN(parseInt(key, 10)); | ||
if (!isNumberKey) { | ||
return; | ||
} | ||
var value = input.value; | ||
var max = input.getAttribute('max'); | ||
/** | ||
@@ -239,3 +170,2 @@ * Given 1, the smallest possible number the user could type by adding another digit is 10. | ||
*/ | ||
if (value * 10 > max || value.length >= max.length) { | ||
@@ -247,8 +177,6 @@ var property = 'nextElementSibling'; | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChange", function (event) { | ||
var _event$target = event.target, | ||
name = _event$target.name, | ||
value = _event$target.value; | ||
name = _event$target.name, | ||
value = _event$target.value; | ||
switch (name) { | ||
@@ -262,6 +190,4 @@ case 'hour12': | ||
}, _this.onChangeExternal); | ||
break; | ||
} | ||
case 'hour24': | ||
@@ -272,6 +198,4 @@ { | ||
}, _this.onChangeExternal); | ||
break; | ||
} | ||
default: | ||
@@ -283,11 +207,8 @@ { | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChangeNative", function (event) { | ||
var onChange = _this.props.onChange; | ||
var value = event.target.value; | ||
if (!onChange) { | ||
return; | ||
} | ||
var processedValue = function () { | ||
@@ -297,12 +218,8 @@ if (!value) { | ||
} | ||
return value; | ||
}(); | ||
onChange(processedValue, false); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChangeAmPm", function (event) { | ||
var value = event.target.value; | ||
_this.setState({ | ||
@@ -312,10 +229,7 @@ amPm: value | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChangeExternal", function () { | ||
var onChange = _this.props.onChange; | ||
if (!onChange) { | ||
return; | ||
} | ||
var formElements = [_this.amPmInput.current, _this.hour12Input.current, _this.hour24Input.current, _this.minuteInput.current, _this.secondInput.current].filter(Boolean); | ||
@@ -327,3 +241,2 @@ var formElementsWithoutSelect = formElements.slice(1); | ||
}); | ||
if (formElementsWithoutSelect.every(function (formElement) { | ||
@@ -339,15 +252,10 @@ return !formElement.value; | ||
var second = parseInt(values.second || 0, 10); | ||
var padStart = function padStart(num) { | ||
return "0".concat(num).slice(-2); | ||
}; | ||
var proposedValue = "".concat(padStart(hour), ":").concat(padStart(minute), ":").concat(padStart(second)); | ||
var processedValue = _this.getProcessedValue(proposedValue); | ||
onChange(processedValue, false); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderHour", function (currentMatch, index) { | ||
@@ -357,19 +265,15 @@ if (/h/.test(currentMatch)) { | ||
} | ||
return _this.renderHour24(currentMatch, index); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderHour12", function (currentMatch, index) { | ||
var _this$props = _this.props, | ||
autoFocus = _this$props.autoFocus, | ||
hourAriaLabel = _this$props.hourAriaLabel, | ||
hourPlaceholder = _this$props.hourPlaceholder; | ||
autoFocus = _this$props.autoFocus, | ||
hourAriaLabel = _this$props.hourAriaLabel, | ||
hourPlaceholder = _this$props.hourPlaceholder; | ||
var _this$state = _this.state, | ||
amPm = _this$state.amPm, | ||
hour = _this$state.hour; | ||
amPm = _this$state.amPm, | ||
hour = _this$state.hour; | ||
if (currentMatch && currentMatch.length > 2) { | ||
throw new Error("Unsupported token: ".concat(currentMatch)); | ||
} | ||
var showLeadingZeros = currentMatch && currentMatch.length === 2; | ||
@@ -380,3 +284,4 @@ return /*#__PURE__*/_react["default"].createElement(_Hour12Input["default"], _extends({ | ||
amPm: amPm, | ||
ariaLabel: hourAriaLabel // eslint-disable-next-line jsx-a11y/no-autofocus | ||
ariaLabel: hourAriaLabel | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
, | ||
@@ -390,14 +295,11 @@ autoFocus: index === 0 && autoFocus, | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderHour24", function (currentMatch, index) { | ||
var _this$props2 = _this.props, | ||
autoFocus = _this$props2.autoFocus, | ||
hourAriaLabel = _this$props2.hourAriaLabel, | ||
hourPlaceholder = _this$props2.hourPlaceholder; | ||
autoFocus = _this$props2.autoFocus, | ||
hourAriaLabel = _this$props2.hourAriaLabel, | ||
hourPlaceholder = _this$props2.hourPlaceholder; | ||
var hour = _this.state.hour; | ||
if (currentMatch && currentMatch.length > 2) { | ||
throw new Error("Unsupported token: ".concat(currentMatch)); | ||
} | ||
var showLeadingZeros = currentMatch && currentMatch.length === 2; | ||
@@ -407,3 +309,4 @@ return /*#__PURE__*/_react["default"].createElement(_Hour24Input["default"], _extends({ | ||
}, _this.commonInputProps, { | ||
ariaLabel: hourAriaLabel // eslint-disable-next-line jsx-a11y/no-autofocus | ||
ariaLabel: hourAriaLabel | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
, | ||
@@ -417,16 +320,13 @@ autoFocus: index === 0 && autoFocus, | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderMinute", function (currentMatch, index) { | ||
var _this$props3 = _this.props, | ||
autoFocus = _this$props3.autoFocus, | ||
minuteAriaLabel = _this$props3.minuteAriaLabel, | ||
minutePlaceholder = _this$props3.minutePlaceholder; | ||
autoFocus = _this$props3.autoFocus, | ||
minuteAriaLabel = _this$props3.minuteAriaLabel, | ||
minutePlaceholder = _this$props3.minutePlaceholder; | ||
var _this$state2 = _this.state, | ||
hour = _this$state2.hour, | ||
minute = _this$state2.minute; | ||
hour = _this$state2.hour, | ||
minute = _this$state2.minute; | ||
if (currentMatch && currentMatch.length > 2) { | ||
throw new Error("Unsupported token: ".concat(currentMatch)); | ||
} | ||
var showLeadingZeros = currentMatch && currentMatch.length === 2; | ||
@@ -436,3 +336,4 @@ return /*#__PURE__*/_react["default"].createElement(_MinuteInput["default"], _extends({ | ||
}, _this.commonInputProps, { | ||
ariaLabel: minuteAriaLabel // eslint-disable-next-line jsx-a11y/no-autofocus | ||
ariaLabel: minuteAriaLabel | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
, | ||
@@ -447,17 +348,14 @@ autoFocus: index === 0 && autoFocus, | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderSecond", function (currentMatch, index) { | ||
var _this$props4 = _this.props, | ||
autoFocus = _this$props4.autoFocus, | ||
secondAriaLabel = _this$props4.secondAriaLabel, | ||
secondPlaceholder = _this$props4.secondPlaceholder; | ||
autoFocus = _this$props4.autoFocus, | ||
secondAriaLabel = _this$props4.secondAriaLabel, | ||
secondPlaceholder = _this$props4.secondPlaceholder; | ||
var _this$state3 = _this.state, | ||
hour = _this$state3.hour, | ||
minute = _this$state3.minute, | ||
second = _this$state3.second; | ||
hour = _this$state3.hour, | ||
minute = _this$state3.minute, | ||
second = _this$state3.second; | ||
if (currentMatch && currentMatch.length > 2) { | ||
throw new Error("Unsupported token: ".concat(currentMatch)); | ||
} | ||
var showLeadingZeros = currentMatch ? currentMatch.length === 2 : true; | ||
@@ -467,3 +365,4 @@ return /*#__PURE__*/_react["default"].createElement(_SecondInput["default"], _extends({ | ||
}, _this.commonInputProps, { | ||
ariaLabel: secondAriaLabel // eslint-disable-next-line jsx-a11y/no-autofocus | ||
ariaLabel: secondAriaLabel | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
, | ||
@@ -479,8 +378,7 @@ autoFocus: index === 0 && autoFocus, | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "renderAmPm", function (currentMatch, index) { | ||
var _this$props5 = _this.props, | ||
amPmAriaLabel = _this$props5.amPmAriaLabel, | ||
autoFocus = _this$props5.autoFocus, | ||
locale = _this$props5.locale; | ||
amPmAriaLabel = _this$props5.amPmAriaLabel, | ||
autoFocus = _this$props5.autoFocus, | ||
locale = _this$props5.locale; | ||
var amPm = _this.state.amPm; | ||
@@ -490,3 +388,4 @@ return /*#__PURE__*/_react["default"].createElement(_AmPm["default"], _extends({ | ||
}, _this.commonInputProps, { | ||
ariaLabel: amPmAriaLabel // eslint-disable-next-line jsx-a11y/no-autofocus | ||
ariaLabel: amPmAriaLabel | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
, | ||
@@ -500,6 +399,4 @@ autoFocus: index === 0 && autoFocus, | ||
}); | ||
return _this; | ||
} | ||
_createClass(TimeInput, [{ | ||
@@ -510,3 +407,2 @@ key: "formatTime", | ||
var level = allViews.indexOf(maxDetail); | ||
var formatterOptions = getFormatterOptionsCache[level] || function () { | ||
@@ -516,15 +412,11 @@ var options = { | ||
}; | ||
if (level >= 1) { | ||
options.minute = 'numeric'; | ||
} | ||
if (level >= 2) { | ||
options.second = 'numeric'; | ||
} | ||
getFormatterOptionsCache[level] = options; | ||
return options; | ||
}(); | ||
return (0, _dateFormatter.getFormatter)(formatterOptions); | ||
@@ -537,6 +429,6 @@ } | ||
} | ||
/** | ||
* Gets current value in a desired format. | ||
*/ | ||
}, { | ||
@@ -546,3 +438,2 @@ key: "getProcessedValue", | ||
var _this2 = this; | ||
var processFunction = function () { | ||
@@ -553,6 +444,4 @@ switch (_this2.valueType) { | ||
return _dateUtils.getHoursMinutes; | ||
case 'second': | ||
return _dateUtils.getHoursMinutesSeconds; | ||
default: | ||
@@ -562,9 +451,8 @@ throw new Error('Invalid valueType.'); | ||
}(); | ||
return processFunction(value); | ||
} | ||
/** | ||
* Returns value type that can be returned with currently applied settings. | ||
*/ | ||
}, { | ||
@@ -586,9 +474,7 @@ key: "valueType", | ||
var _this$props6 = this.props, | ||
format = _this$props6.format, | ||
locale = _this$props6.locale; | ||
format = _this$props6.format, | ||
locale = _this$props6.locale; | ||
if (format) { | ||
return format; | ||
} | ||
var hour24 = 21; | ||
@@ -605,8 +491,8 @@ var hour12 = 9; | ||
var _this$props7 = this.props, | ||
className = _this$props7.className, | ||
disabled = _this$props7.disabled, | ||
isClockOpen = _this$props7.isClockOpen, | ||
maxTime = _this$props7.maxTime, | ||
minTime = _this$props7.minTime, | ||
required = _this$props7.required; | ||
className = _this$props7.className, | ||
disabled = _this$props7.disabled, | ||
isClockOpen = _this$props7.isClockOpen, | ||
maxTime = _this$props7.maxTime, | ||
minTime = _this$props7.minTime, | ||
required = _this$props7.required; | ||
return { | ||
@@ -644,9 +530,9 @@ className: className, | ||
var _this$props8 = this.props, | ||
disabled = _this$props8.disabled, | ||
maxTime = _this$props8.maxTime, | ||
minTime = _this$props8.minTime, | ||
name = _this$props8.name, | ||
nativeInputAriaLabel = _this$props8.nativeInputAriaLabel, | ||
required = _this$props8.required, | ||
value = _this$props8.value; | ||
disabled = _this$props8.disabled, | ||
maxTime = _this$props8.maxTime, | ||
minTime = _this$props8.minTime, | ||
name = _this$props8.name, | ||
nativeInputAriaLabel = _this$props8.nativeInputAriaLabel, | ||
required = _this$props8.required, | ||
value = _this$props8.value; | ||
return /*#__PURE__*/_react["default"].createElement(_NativeInput["default"], { | ||
@@ -682,2 +568,3 @@ key: "time", | ||
var nextState = {}; | ||
/** | ||
@@ -687,6 +574,6 @@ * If isClockOpen flag has changed, we have to update it. | ||
*/ | ||
if (nextProps.isClockOpen !== prevState.isClockOpen) { | ||
nextState.isClockOpen = nextProps.isClockOpen; | ||
} | ||
/** | ||
@@ -697,14 +584,11 @@ * If the next value is different from the current one (with an exception of situation in | ||
*/ | ||
var nextValue = nextProps.value; | ||
if ( // Toggling calendar visibility resets values | ||
nextState.isClockOpen || // Flag was toggled | ||
if ( | ||
// Toggling calendar visibility resets values | ||
nextState.isClockOpen || | ||
// Flag was toggled | ||
hoursAreDifferent(nextValue, prevState.value)) { | ||
if (nextValue) { | ||
var _convert24to = (0, _dates.convert24to12)((0, _dateUtils.getHours)(nextValue)); | ||
var _convert24to2 = _slicedToArray(_convert24to, 2); | ||
nextState.amPm = _convert24to2[1]; | ||
@@ -720,13 +604,9 @@ nextState.hour = (0, _dateUtils.getHours)(nextValue).toString(); | ||
} | ||
nextState.value = nextValue; | ||
} | ||
return nextState; | ||
} | ||
}]); | ||
return TimeInput; | ||
}(_react.PureComponent); | ||
exports["default"] = TimeInput; | ||
@@ -733,0 +613,0 @@ TimeInput.defaultProps = { |
@@ -7,55 +7,38 @@ "use strict"; | ||
exports["default"] = AmPm; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _mergeClassNames = _interopRequireDefault(require("merge-class-names")); | ||
var _clsx = _interopRequireDefault(require("clsx")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _dates = require("../shared/dates"); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
var _utils = require("../shared/utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function AmPm(_ref) { | ||
var ariaLabel = _ref.ariaLabel, | ||
className = _ref.className, | ||
disabled = _ref.disabled, | ||
inputRef = _ref.inputRef, | ||
locale = _ref.locale, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
onChange = _ref.onChange, | ||
onKeyDown = _ref.onKeyDown, | ||
required = _ref.required, | ||
value = _ref.value; | ||
className = _ref.className, | ||
disabled = _ref.disabled, | ||
inputRef = _ref.inputRef, | ||
locale = _ref.locale, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
onChange = _ref.onChange, | ||
onKeyDown = _ref.onKeyDown, | ||
required = _ref.required, | ||
value = _ref.value; | ||
var amDisabled = minTime && (0, _dates.convert24to12)((0, _dateUtils.getHours)(minTime))[1] === 'pm'; | ||
var pmDisabled = maxTime && (0, _dates.convert24to12)((0, _dateUtils.getHours)(maxTime))[1] === 'am'; | ||
var name = 'amPm'; | ||
var _getAmPmLabels = (0, _utils.getAmPmLabels)(locale), | ||
_getAmPmLabels2 = _slicedToArray(_getAmPmLabels, 2), | ||
amLabel = _getAmPmLabels2[0], | ||
pmLabel = _getAmPmLabels2[1]; | ||
_getAmPmLabels2 = _slicedToArray(_getAmPmLabels, 2), | ||
amLabel = _getAmPmLabels2[0], | ||
pmLabel = _getAmPmLabels2[1]; | ||
return /*#__PURE__*/_react["default"].createElement("select", { | ||
"aria-label": ariaLabel, | ||
className: (0, _mergeClassNames["default"])("".concat(className, "__input"), "".concat(className, "__").concat(name)), | ||
className: (0, _clsx["default"])("".concat(className, "__input"), "".concat(className, "__").concat(name)), | ||
"data-input": "true", | ||
@@ -80,3 +63,2 @@ "data-select": "true", | ||
} | ||
AmPm.propTypes = { | ||
@@ -83,0 +65,0 @@ ariaLabel: _propTypes["default"].string, |
@@ -7,53 +7,32 @@ "use strict"; | ||
exports["default"] = Hour12Input; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _Input = _interopRequireDefault(require("./Input")); | ||
var _dates = require("../shared/dates"); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
var _utils = require("../shared/utils"); | ||
var _excluded = ["amPm", "hour", "maxTime", "minTime", "value"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function Hour12Input(_ref) { | ||
var amPm = _ref.amPm, | ||
hour = _ref.hour, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
value = _ref.value, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
hour = _ref.hour, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
value = _ref.value, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
var maxHour = (0, _utils.safeMin)(12, maxTime && function () { | ||
var _convert24to = (0, _dates.convert24to12)((0, _dateUtils.getHours)(maxTime)), | ||
_convert24to2 = _slicedToArray(_convert24to, 2), | ||
maxHourResult = _convert24to2[0], | ||
maxAmPm = _convert24to2[1]; | ||
_convert24to2 = _slicedToArray(_convert24to, 2), | ||
maxHourResult = _convert24to2[0], | ||
maxAmPm = _convert24to2[1]; | ||
if (maxAmPm !== amPm) { | ||
@@ -63,3 +42,2 @@ // pm is always after am, so we should ignore validation | ||
} | ||
return maxHourResult; | ||
@@ -69,12 +47,12 @@ }()); | ||
var _convert24to3 = (0, _dates.convert24to12)((0, _dateUtils.getHours)(minTime)), | ||
_convert24to4 = _slicedToArray(_convert24to3, 2), | ||
minHourResult = _convert24to4[0], | ||
minAmPm = _convert24to4[1]; | ||
if ( // pm is always after am, so we should ignore validation | ||
minAmPm !== amPm || // If minHour is 12 am/pm, user should be able to enter 12, 1, ..., 11. | ||
_convert24to4 = _slicedToArray(_convert24to3, 2), | ||
minHourResult = _convert24to4[0], | ||
minAmPm = _convert24to4[1]; | ||
if ( | ||
// pm is always after am, so we should ignore validation | ||
minAmPm !== amPm || | ||
// If minHour is 12 am/pm, user should be able to enter 12, 1, ..., 11. | ||
minHourResult === 12) { | ||
return null; | ||
} | ||
return minHourResult; | ||
@@ -91,3 +69,2 @@ }()); | ||
} | ||
Hour12Input.propTypes = { | ||
@@ -94,0 +71,0 @@ amPm: _propTypes["default"].string, |
@@ -7,31 +7,18 @@ "use strict"; | ||
exports["default"] = Hour24Input; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _Input = _interopRequireDefault(require("./Input")); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
var _utils = require("../shared/utils"); | ||
var _excluded = ["hour", "maxTime", "minTime"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function Hour24Input(_ref) { | ||
var hour = _ref.hour, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
var maxHour = (0, _utils.safeMin)(23, maxTime && (0, _dateUtils.getHours)(maxTime)); | ||
@@ -46,3 +33,2 @@ var minHour = (0, _utils.safeMax)(0, minTime && (0, _dateUtils.getHours)(minTime)); | ||
} | ||
Hour24Input.propTypes = { | ||
@@ -49,0 +35,0 @@ ariaLabel: _propTypes["default"].string, |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,26 +8,16 @@ value: true | ||
exports["default"] = Input; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _mergeClassNames = _interopRequireDefault(require("merge-class-names")); | ||
var _clsx = _interopRequireDefault(require("clsx")); | ||
var _updateInputWidth = _interopRequireWildcard(require("update-input-width")); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/* eslint-disable jsx-a11y/no-autofocus */ | ||
/* eslint-disable jsx-a11y/no-autofocus */ | ||
var isIEOrEdgeLegacy = typeof window !== 'undefined' && /(MSIE|Trident\/|Edge\/)/.test(window.navigator.userAgent); | ||
var isFirefox = typeof window !== 'undefined' && /Firefox/.test(window.navigator.userAgent); | ||
function onFocus(event) { | ||
var target = event.target; | ||
if (isIEOrEdgeLegacy) { | ||
@@ -42,3 +31,2 @@ requestAnimationFrame(function () { | ||
} | ||
function updateInputWidthOnLoad(element) { | ||
@@ -48,10 +36,7 @@ if (document.readyState === 'complete') { | ||
} | ||
function onLoad() { | ||
(0, _updateInputWidth["default"])(element); | ||
} | ||
window.addEventListener('load', onLoad); | ||
} | ||
function updateInputWidthOnFontLoad(element) { | ||
@@ -61,22 +46,15 @@ if (!document.fonts) { | ||
} | ||
var font = (0, _updateInputWidth.getFontShorthand)(element); | ||
if (!font) { | ||
return; | ||
} | ||
var isFontLoaded = document.fonts.check(font); | ||
if (isFontLoaded) { | ||
return; | ||
} | ||
function onLoadingDone() { | ||
(0, _updateInputWidth["default"])(element); | ||
} | ||
document.fonts.addEventListener('loadingdone', onLoadingDone); | ||
} | ||
function getSelectionString(input) { | ||
@@ -90,10 +68,7 @@ /** | ||
} | ||
if ('getSelection' in window) { | ||
return window.getSelection().toString(); | ||
} | ||
return null; | ||
} | ||
function makeOnKeyPress(maxLength) { | ||
@@ -109,9 +84,7 @@ /** | ||
} | ||
var key = event.key, | ||
input = event.target; | ||
input = event.target; | ||
var value = input.value; | ||
var isNumberKey = key.length === 1 && /\d/.test(key); | ||
var selection = getSelectionString(input); | ||
if (!isNumberKey || !(selection || value.length < maxLength)) { | ||
@@ -122,22 +95,21 @@ event.preventDefault(); | ||
} | ||
function Input(_ref) { | ||
var ariaLabel = _ref.ariaLabel, | ||
autoFocus = _ref.autoFocus, | ||
className = _ref.className, | ||
disabled = _ref.disabled, | ||
inputRef = _ref.inputRef, | ||
max = _ref.max, | ||
min = _ref.min, | ||
name = _ref.name, | ||
nameForClass = _ref.nameForClass, | ||
onChange = _ref.onChange, | ||
onKeyDown = _ref.onKeyDown, | ||
_onKeyUp = _ref.onKeyUp, | ||
_ref$placeholder = _ref.placeholder, | ||
placeholder = _ref$placeholder === void 0 ? '--' : _ref$placeholder, | ||
required = _ref.required, | ||
showLeadingZeros = _ref.showLeadingZeros, | ||
step = _ref.step, | ||
value = _ref.value; | ||
autoFocus = _ref.autoFocus, | ||
className = _ref.className, | ||
disabled = _ref.disabled, | ||
inputRef = _ref.inputRef, | ||
max = _ref.max, | ||
min = _ref.min, | ||
name = _ref.name, | ||
nameForClass = _ref.nameForClass, | ||
onChange = _ref.onChange, | ||
onKeyDown = _ref.onKeyDown, | ||
_onKeyUp = _ref.onKeyUp, | ||
_ref$placeholder = _ref.placeholder, | ||
placeholder = _ref$placeholder === void 0 ? '--' : _ref$placeholder, | ||
required = _ref.required, | ||
showLeadingZeros = _ref.showLeadingZeros, | ||
step = _ref.step, | ||
value = _ref.value; | ||
(0, _react.useLayoutEffect)(function () { | ||
@@ -147,3 +119,2 @@ if (!inputRef || !inputRef.current) { | ||
} | ||
(0, _updateInputWidth["default"])(inputRef.current); | ||
@@ -163,3 +134,3 @@ updateInputWidthOnLoad(inputRef.current); | ||
autoFocus: autoFocus, | ||
className: (0, _mergeClassNames["default"])("".concat(className, "__input"), "".concat(className, "__").concat(nameForClass || name), hasLeadingZero && "".concat(className, "__input--hasLeadingZero")), | ||
className: (0, _clsx["default"])("".concat(className, "__input"), "".concat(className, "__").concat(nameForClass || name), hasLeadingZero && "".concat(className, "__input--hasLeadingZero")), | ||
"data-input": "true", | ||
@@ -177,3 +148,2 @@ disabled: disabled, | ||
(0, _updateInputWidth["default"])(event.target); | ||
if (_onKeyUp) { | ||
@@ -191,3 +161,2 @@ _onKeyUp(event); | ||
} | ||
Input.propTypes = { | ||
@@ -194,0 +163,0 @@ ariaLabel: _propTypes["default"].string, |
@@ -7,37 +7,23 @@ "use strict"; | ||
exports["default"] = MinuteInput; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _Input = _interopRequireDefault(require("./Input")); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
var _utils = require("../shared/utils"); | ||
var _excluded = ["hour", "maxTime", "minTime", "showLeadingZeros"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function MinuteInput(_ref) { | ||
var hour = _ref.hour, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
_ref$showLeadingZeros = _ref.showLeadingZeros, | ||
showLeadingZeros = _ref$showLeadingZeros === void 0 ? true : _ref$showLeadingZeros, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
_ref$showLeadingZeros = _ref.showLeadingZeros, | ||
showLeadingZeros = _ref$showLeadingZeros === void 0 ? true : _ref$showLeadingZeros, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
function isSameHour(date) { | ||
return date && hour === (0, _dateUtils.getHours)(date).toString(); | ||
} | ||
var maxMinute = (0, _utils.safeMin)(59, isSameHour(maxTime) && (0, _dateUtils.getMinutes)(maxTime)); | ||
@@ -52,3 +38,2 @@ var minMinute = (0, _utils.safeMax)(0, isSameHour(minTime) && (0, _dateUtils.getMinutes)(minTime)); | ||
} | ||
MinuteInput.propTypes = { | ||
@@ -55,0 +40,0 @@ ariaLabel: _propTypes["default"].string, |
@@ -7,24 +7,17 @@ "use strict"; | ||
exports["default"] = NativeInput; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function NativeInput(_ref) { | ||
var ariaLabel = _ref.ariaLabel, | ||
disabled = _ref.disabled, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
name = _ref.name, | ||
onChange = _ref.onChange, | ||
required = _ref.required, | ||
value = _ref.value, | ||
valueType = _ref.valueType; | ||
disabled = _ref.disabled, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
name = _ref.name, | ||
onChange = _ref.onChange, | ||
required = _ref.required, | ||
value = _ref.value, | ||
valueType = _ref.valueType; | ||
var nativeValueParser = function () { | ||
@@ -36,9 +29,6 @@ switch (valueType) { | ||
}; | ||
case 'minute': | ||
return _dateUtils.getHoursMinutes; | ||
case 'second': | ||
return _dateUtils.getHoursMinutesSeconds; | ||
default: | ||
@@ -48,3 +38,2 @@ throw new Error('Invalid valueType.'); | ||
}(); | ||
var step = function () { | ||
@@ -54,9 +43,6 @@ switch (valueType) { | ||
return 3600; | ||
case 'minute': | ||
return 60; | ||
case 'second': | ||
return 1; | ||
default: | ||
@@ -66,7 +52,5 @@ throw new Error('Invalid valueType.'); | ||
}(); | ||
function stopPropagation(event) { | ||
event.stopPropagation(); | ||
} | ||
return /*#__PURE__*/_react["default"].createElement("input", { | ||
@@ -91,3 +75,2 @@ "aria-label": ariaLabel, | ||
} | ||
NativeInput.propTypes = { | ||
@@ -94,0 +77,0 @@ ariaLabel: _propTypes["default"].string, |
@@ -7,38 +7,24 @@ "use strict"; | ||
exports["default"] = SecondInput; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _dateUtils = require("@wojtekmaj/date-utils"); | ||
var _Input = _interopRequireDefault(require("./Input")); | ||
var _propTypes2 = require("../shared/propTypes"); | ||
var _utils = require("../shared/utils"); | ||
var _excluded = ["hour", "maxTime", "minTime", "minute", "showLeadingZeros"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function SecondInput(_ref) { | ||
var hour = _ref.hour, | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
minute = _ref.minute, | ||
_ref$showLeadingZeros = _ref.showLeadingZeros, | ||
showLeadingZeros = _ref$showLeadingZeros === void 0 ? true : _ref$showLeadingZeros, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
maxTime = _ref.maxTime, | ||
minTime = _ref.minTime, | ||
minute = _ref.minute, | ||
_ref$showLeadingZeros = _ref.showLeadingZeros, | ||
showLeadingZeros = _ref$showLeadingZeros === void 0 ? true : _ref$showLeadingZeros, | ||
otherProps = _objectWithoutProperties(_ref, _excluded); | ||
function isSameMinute(date) { | ||
return date && hour === (0, _dateUtils.getHours)(date).toString() && minute === (0, _dateUtils.getMinutes)(date).toString(); | ||
} | ||
var maxSecond = (0, _utils.safeMin)(59, isSameMinute(maxTime) && (0, _dateUtils.getSeconds)(maxTime)); | ||
@@ -53,3 +39,2 @@ var minSecond = (0, _utils.safeMax)(0, isSameMinute(minTime) && (0, _dateUtils.getSeconds)(minTime)); | ||
} | ||
SecondInput.propTypes = { | ||
@@ -56,0 +41,0 @@ ariaLabel: _propTypes["default"].string, |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,104 +8,59 @@ value: true | ||
exports["default"] = void 0; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _reactDom = require("react-dom"); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _makeEventProps = _interopRequireDefault(require("make-event-props")); | ||
var _mergeClassNames = _interopRequireDefault(require("merge-class-names")); | ||
var _clsx = _interopRequireDefault(require("clsx")); | ||
var _reactFit = _interopRequireDefault(require("react-fit")); | ||
var _reactClock = _interopRequireDefault(require("react-clock")); | ||
var _TimeInput = _interopRequireDefault(require("./TimeInput")); | ||
var _propTypes2 = require("./shared/propTypes"); | ||
var _excluded = ["clockClassName", "className", "maxDetail", "onChange", "portalContainer", "value"], | ||
_excluded2 = ["onChange"]; | ||
_excluded2 = ["onChange"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var allViews = ['hour', 'minute', 'second']; | ||
var baseClassName = 'react-time-picker'; | ||
var outsideActionEvents = ['mousedown', 'focusin', 'touchstart']; | ||
var TimePicker = /*#__PURE__*/function (_PureComponent) { | ||
_inherits(TimePicker, _PureComponent); | ||
var _super = _createSuper(TimePicker); | ||
function TimePicker() { | ||
var _this; | ||
_classCallCheck(this, TimePicker); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "state", {}); | ||
_defineProperty(_assertThisInitialized(_this), "wrapper", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "clockWrapper", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "onOutsideAction", function (event) { | ||
var _assertThisInitialize = _assertThisInitialized(_this), | ||
wrapper = _assertThisInitialize.wrapper, | ||
clockWrapper = _assertThisInitialize.clockWrapper; // Try event.composedPath first to handle clicks inside a Shadow DOM. | ||
wrapper = _assertThisInitialize.wrapper, | ||
clockWrapper = _assertThisInitialize.clockWrapper; | ||
// Try event.composedPath first to handle clicks inside a Shadow DOM. | ||
var target = 'composedPath' in event ? event.composedPath()[0] : event.target; | ||
if (wrapper.current && !wrapper.current.contains(target) && (!clockWrapper.current || !clockWrapper.current.contains(target))) { | ||
@@ -116,11 +70,8 @@ _this.closeClock(); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChange", function (value) { | ||
var closeClock = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this.props.closeClock; | ||
var onChange = _this.props.onChange; | ||
if (closeClock) { | ||
_this.closeClock(); | ||
} | ||
if (onChange) { | ||
@@ -130,18 +81,15 @@ onChange(value); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onFocus", function (event) { | ||
var _this$props = _this.props, | ||
disabled = _this$props.disabled, | ||
onFocus = _this$props.onFocus, | ||
openClockOnFocus = _this$props.openClockOnFocus; | ||
disabled = _this$props.disabled, | ||
onFocus = _this$props.onFocus, | ||
openClockOnFocus = _this$props.openClockOnFocus; | ||
if (onFocus) { | ||
onFocus(event); | ||
} // Internet Explorer still fires onFocus on disabled elements | ||
} | ||
// Internet Explorer still fires onFocus on disabled elements | ||
if (disabled) { | ||
return; | ||
} | ||
if (openClockOnFocus) { | ||
@@ -151,7 +99,5 @@ if (event.target.dataset.select === 'true') { | ||
} | ||
_this.openClock(); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) { | ||
@@ -162,3 +108,2 @@ if (event.key === 'Escape') { | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "openClock", function () { | ||
@@ -169,3 +114,2 @@ _this.setState({ | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "closeClock", function () { | ||
@@ -176,3 +120,2 @@ _this.setState(function (prevState) { | ||
} | ||
return { | ||
@@ -183,3 +126,2 @@ isOpen: false | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "toggleClock", function () { | ||
@@ -192,14 +134,10 @@ _this.setState(function (prevState) { | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "stopPropagation", function (event) { | ||
return event.stopPropagation(); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "clear", function () { | ||
return _this.onChange(null); | ||
}); | ||
return _this; | ||
} | ||
_createClass(TimePicker, [{ | ||
@@ -215,5 +153,4 @@ key: "componentDidMount", | ||
var _this$props2 = this.props, | ||
onClockClose = _this$props2.onClockClose, | ||
onClockOpen = _this$props2.onClockOpen; | ||
onClockClose = _this$props2.onClockClose, | ||
onClockOpen = _this$props2.onClockOpen; | ||
if (isOpen !== prevState.isOpen) { | ||
@@ -239,3 +176,2 @@ this.handleOutsideActionListeners(); | ||
var _this2 = this; | ||
var isOpen = this.state.isOpen; | ||
@@ -253,31 +189,29 @@ var shouldListenWithFallback = typeof shouldListen !== 'undefined' ? shouldListen : isOpen; | ||
var _this$props3 = this.props, | ||
amPmAriaLabel = _this$props3.amPmAriaLabel, | ||
autoFocus = _this$props3.autoFocus, | ||
clearAriaLabel = _this$props3.clearAriaLabel, | ||
clearIcon = _this$props3.clearIcon, | ||
clockAriaLabel = _this$props3.clockAriaLabel, | ||
clockIcon = _this$props3.clockIcon, | ||
disableClock = _this$props3.disableClock, | ||
disabled = _this$props3.disabled, | ||
format = _this$props3.format, | ||
hourAriaLabel = _this$props3.hourAriaLabel, | ||
hourPlaceholder = _this$props3.hourPlaceholder, | ||
isOpen = _this$props3.isOpen, | ||
locale = _this$props3.locale, | ||
maxDetail = _this$props3.maxDetail, | ||
maxTime = _this$props3.maxTime, | ||
minTime = _this$props3.minTime, | ||
minuteAriaLabel = _this$props3.minuteAriaLabel, | ||
minutePlaceholder = _this$props3.minutePlaceholder, | ||
name = _this$props3.name, | ||
nativeInputAriaLabel = _this$props3.nativeInputAriaLabel, | ||
required = _this$props3.required, | ||
secondAriaLabel = _this$props3.secondAriaLabel, | ||
secondPlaceholder = _this$props3.secondPlaceholder, | ||
value = _this$props3.value; | ||
amPmAriaLabel = _this$props3.amPmAriaLabel, | ||
autoFocus = _this$props3.autoFocus, | ||
clearAriaLabel = _this$props3.clearAriaLabel, | ||
clearIcon = _this$props3.clearIcon, | ||
clockAriaLabel = _this$props3.clockAriaLabel, | ||
clockIcon = _this$props3.clockIcon, | ||
disableClock = _this$props3.disableClock, | ||
disabled = _this$props3.disabled, | ||
format = _this$props3.format, | ||
hourAriaLabel = _this$props3.hourAriaLabel, | ||
hourPlaceholder = _this$props3.hourPlaceholder, | ||
isOpen = _this$props3.isOpen, | ||
locale = _this$props3.locale, | ||
maxDetail = _this$props3.maxDetail, | ||
maxTime = _this$props3.maxTime, | ||
minTime = _this$props3.minTime, | ||
minuteAriaLabel = _this$props3.minuteAriaLabel, | ||
minutePlaceholder = _this$props3.minutePlaceholder, | ||
name = _this$props3.name, | ||
nativeInputAriaLabel = _this$props3.nativeInputAriaLabel, | ||
required = _this$props3.required, | ||
secondAriaLabel = _this$props3.secondAriaLabel, | ||
secondPlaceholder = _this$props3.secondPlaceholder, | ||
value = _this$props3.value; | ||
var _concat = [].concat(value), | ||
_concat2 = _slicedToArray(_concat, 1), | ||
valueFrom = _concat2[0]; | ||
_concat2 = _slicedToArray(_concat, 1), | ||
valueFrom = _concat2[0]; | ||
var ariaLabelProps = { | ||
@@ -335,25 +269,19 @@ amPmAriaLabel: amPmAriaLabel, | ||
var isOpen = this.state.isOpen; | ||
if (isOpen === null || disableClock) { | ||
return null; | ||
} | ||
var _this$props4 = this.props, | ||
clockClassName = _this$props4.clockClassName, | ||
timePickerClassName = _this$props4.className, | ||
maxDetail = _this$props4.maxDetail, | ||
onChange = _this$props4.onChange, | ||
portalContainer = _this$props4.portalContainer, | ||
value = _this$props4.value, | ||
clockProps = _objectWithoutProperties(_this$props4, _excluded); | ||
clockClassName = _this$props4.clockClassName, | ||
timePickerClassName = _this$props4.className, | ||
maxDetail = _this$props4.maxDetail, | ||
onChange = _this$props4.onChange, | ||
portalContainer = _this$props4.portalContainer, | ||
value = _this$props4.value, | ||
clockProps = _objectWithoutProperties(_this$props4, _excluded); | ||
var className = "".concat(baseClassName, "__clock"); | ||
var classNames = (0, _mergeClassNames["default"])(className, "".concat(className, "--").concat(isOpen ? 'open' : 'closed')); | ||
var classNames = (0, _clsx["default"])(className, "".concat(className, "--").concat(isOpen ? 'open' : 'closed')); | ||
var _concat3 = [].concat(value), | ||
_concat4 = _slicedToArray(_concat3, 1), | ||
valueFrom = _concat4[0]; | ||
_concat4 = _slicedToArray(_concat3, 1), | ||
valueFrom = _concat4[0]; | ||
var maxDetailIndex = allViews.indexOf(maxDetail); | ||
var clock = /*#__PURE__*/_react["default"].createElement(_reactClock["default"], _extends({ | ||
@@ -365,3 +293,2 @@ className: clockClassName, | ||
}, clockProps)); | ||
return portalContainer ? /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react["default"].createElement("div", { | ||
@@ -384,11 +311,9 @@ ref: this.clockWrapper, | ||
var _this$props5 = this.props, | ||
className = _this$props5.className, | ||
disabled = _this$props5.disabled; | ||
className = _this$props5.className, | ||
disabled = _this$props5.disabled; | ||
var isOpen = this.state.isOpen; | ||
var onChange = eventProps.onChange, | ||
eventPropsWithoutOnChange = _objectWithoutProperties(eventProps, _excluded2); | ||
eventPropsWithoutOnChange = _objectWithoutProperties(eventProps, _excluded2); | ||
return /*#__PURE__*/_react["default"].createElement("div", _extends({ | ||
className: (0, _mergeClassNames["default"])(baseClassName, "".concat(baseClassName, "--").concat(isOpen ? 'open' : 'closed'), "".concat(baseClassName, "--").concat(disabled ? 'disabled' : 'enabled'), className) | ||
className: (0, _clsx["default"])(baseClassName, "".concat(baseClassName, "--").concat(isOpen ? 'open' : 'closed'), "".concat(baseClassName, "--").concat(disabled ? 'disabled' : 'enabled'), className) | ||
}, eventPropsWithoutOnChange, { | ||
@@ -408,10 +333,7 @@ onFocus: this.onFocus, | ||
} | ||
return null; | ||
} | ||
}]); | ||
return TimePicker; | ||
}(_react.PureComponent); | ||
exports["default"] = TimePicker; | ||
@@ -426,3 +348,2 @@ var iconProps = { | ||
}; | ||
var ClockIcon = /*#__PURE__*/_react["default"].createElement("svg", _extends({}, iconProps, { | ||
@@ -438,3 +359,2 @@ className: "".concat(baseClassName, "__clock-button__icon ").concat(baseClassName, "__button__icon"), | ||
})); | ||
var ClearIcon = /*#__PURE__*/_react["default"].createElement("svg", _extends({}, iconProps, { | ||
@@ -453,3 +373,2 @@ className: "".concat(baseClassName, "__clear-button__icon ").concat(baseClassName, "__button__icon") | ||
})); | ||
TimePicker.defaultProps = { | ||
@@ -463,5 +382,3 @@ clearIcon: ClearIcon, | ||
}; | ||
var isValue = _propTypes["default"].oneOfType([_propTypes2.isTime, _propTypes["default"].instanceOf(Date)]); | ||
TimePicker.propTypes = { | ||
@@ -468,0 +385,0 @@ amPmAriaLabel: _propTypes["default"].string, |
{ | ||
"name": "react-time-picker", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "A time picker for your React app.", | ||
@@ -14,5 +14,6 @@ "main": "dist/entry.js", | ||
"jest": "jest", | ||
"lint": "eslint sample/ src/ test/ --ext .jsx,.js", | ||
"lint": "eslint sample src test --ext .jsx,.js", | ||
"prepack": "yarn clean && yarn build", | ||
"test": "yarn lint && yarn jest" | ||
"prettier": "prettier --check . --cache", | ||
"test": "yarn lint && yarn prettier && yarn jest" | ||
}, | ||
@@ -31,7 +32,7 @@ "keywords": [ | ||
"@wojtekmaj/date-utils": "^1.0.0", | ||
"clsx": "^1.2.1", | ||
"get-user-locale": "^1.2.0", | ||
"make-event-props": "^1.1.0", | ||
"merge-class-names": "^1.1.1", | ||
"prop-types": "^15.6.0", | ||
"react-clock": "^3.1.0", | ||
"react-clock": "^4.0.0", | ||
"react-fit": "^1.4.0", | ||
@@ -46,5 +47,5 @@ "update-input-width": "^1.2.2" | ||
"@testing-library/jest-dom": "^5.15.0", | ||
"@testing-library/react": "^12.1.0", | ||
"eslint": "^8.5.0", | ||
"eslint-config-wojtekmaj": "^0.6.5", | ||
"@testing-library/react": "^13.4.0", | ||
"eslint": "^8.26.0", | ||
"eslint-config-wojtekmaj": "^0.7.1", | ||
"husky": "^8.0.0", | ||
@@ -54,6 +55,6 @@ "jest": "^29.0.0", | ||
"less": "^4.0.0", | ||
"prettier": "^2.5.0", | ||
"prettier": "^2.7.0", | ||
"pretty-quick": "^3.1.0", | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "^3.0.0" | ||
@@ -60,0 +61,0 @@ }, |
@@ -110,2 +110,3 @@ [![npm](https://img.shields.io/npm/v/react-time-picker.svg)](https://www.npmjs.com/package/react-time-picker) ![downloads](https://img.shields.io/npm/dt/react-time-picker.svg) [![CI](https://github.com/wojtekmaj/react-time-picker/workflows/CI/badge.svg)](https://github.com/wojtekmaj/react-time-picker/actions) ![dependencies](https://img.shields.io/david/wojtekmaj/react-time-picker.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/react-time-picker.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
| onClockOpen | Function called when the clock opens. | n/a | `() => alert('Clock opened')` | | ||
| onFocus | Function called when the focuses an input. | n/a | `(event) => alert('Focused input: ', event.target.name)` | | ||
| openClockOnFocus | Whether to open the clock on input focus. | `true` | `false` | | ||
@@ -112,0 +113,0 @@ | portalContainer | Element to render the clock in using portal. | n/a | `document.getElementById('my-div')` | |
@@ -21,6 +21,6 @@ import React from 'react'; | ||
const keyCodes = { | ||
ArrowLeft: 37, | ||
ArrowUp: 38, | ||
ArrowRight: 39, | ||
ArrowDown: 40, | ||
'ArrowLeft': 37, | ||
'ArrowUp': 38, | ||
'ArrowRight': 39, | ||
'ArrowDown': 40, | ||
'-': 189, | ||
@@ -320,5 +320,3 @@ '.': 190, | ||
it('jumps to the next field when right arrow is pressed', () => { | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />, { | ||
attachTo: container, | ||
}); | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />); | ||
@@ -340,5 +338,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it('jumps to the next field when separator key is pressed', () => { | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />, { | ||
attachTo: container, | ||
}); | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />); | ||
@@ -362,5 +358,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it('does not jump to the next field when right arrow is pressed when the last input is focused', () => { | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />, { | ||
attachTo: container, | ||
}); | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />); | ||
@@ -379,5 +373,3 @@ const select = container.querySelector('select'); | ||
it('jumps to the previous field when left arrow is pressed', () => { | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />, { | ||
attachTo: container, | ||
}); | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />); | ||
@@ -399,5 +391,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it('does not jump to the previous field when left arrow is pressed when the first input is focused', () => { | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />, { | ||
attachTo: container, | ||
}); | ||
const { container } = render(<TimeInput {...defaultProps} maxDetail="second" />); | ||
@@ -418,3 +408,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it("jumps to the next field when a value which can't be extended to another valid value is entered", () => { | ||
const { container } = render(<TimeInput {...defaultProps} />, { attachTo: container }); | ||
const { container } = render(<TimeInput {...defaultProps} />); | ||
@@ -434,3 +424,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it('jumps to the next field when a value as long as the length of maximum value is entered', () => { | ||
const { container } = render(<TimeInput {...defaultProps} />, { attachTo: container }); | ||
const { container } = render(<TimeInput {...defaultProps} />); | ||
@@ -450,3 +440,3 @@ const customInputs = container.querySelectorAll('input[data-input]'); | ||
it('does not jump the next field when a value which can be extended to another valid value is entered', () => { | ||
const { container } = render(<TimeInput {...defaultProps} />, { attachTo: container }); | ||
const { container } = render(<TimeInput {...defaultProps} />); | ||
@@ -453,0 +443,0 @@ const customInputs = container.querySelectorAll('input[data-input]'); |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import mergeClassNames from 'merge-class-names'; | ||
import clsx from 'clsx'; | ||
import { getHours } from '@wojtekmaj/date-utils'; | ||
@@ -32,3 +32,3 @@ | ||
aria-label={ariaLabel} | ||
className={mergeClassNames(`${className}__input`, `${className}__${name}`)} | ||
className={clsx(`${className}__input`, `${className}__${name}`)} | ||
data-input="true" | ||
@@ -35,0 +35,0 @@ data-select="true" |
import React, { useLayoutEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import mergeClassNames from 'merge-class-names'; | ||
import clsx from 'clsx'; | ||
import updateInputWidth, { getFontShorthand } from 'update-input-width'; | ||
@@ -144,3 +144,3 @@ | ||
autoFocus={autoFocus} | ||
className={mergeClassNames( | ||
className={clsx( | ||
`${className}__input`, | ||
@@ -147,0 +147,0 @@ `${className}__${nameForClass || name}`, |
@@ -5,3 +5,3 @@ import React, { createRef, PureComponent } from 'react'; | ||
import makeEventProps from 'make-event-props'; | ||
import mergeClassNames from 'merge-class-names'; | ||
import clsx from 'clsx'; | ||
import Fit from 'react-fit'; | ||
@@ -258,3 +258,3 @@ | ||
const className = `${baseClassName}__clock`; | ||
const classNames = mergeClassNames(className, `${className}--${isOpen ? 'open' : 'closed'}`); | ||
const classNames = clsx(className, `${className}--${isOpen ? 'open' : 'closed'}`); | ||
@@ -307,3 +307,3 @@ const [valueFrom] = [].concat(value); | ||
<div | ||
className={mergeClassNames( | ||
className={clsx( | ||
baseClassName, | ||
@@ -310,0 +310,0 @@ `${baseClassName}--${isOpen ? 'open' : 'closed'}`, |
@@ -137,2 +137,10 @@ import React, { createRef } from 'react'; | ||
it('applies "--open" className to its wrapper when given isOpen flag', () => { | ||
const { container } = render(<TimePicker isOpen />); | ||
const wrapper = container.firstChild; | ||
expect(wrapper).toHaveClass('react-time-picker--open'); | ||
}); | ||
it('applies clockClassName to the clock when given a string', () => { | ||
@@ -139,0 +147,0 @@ const clockClassName = 'testClassName'; |
4768
140
224832
+ Addedclsx@^1.2.1
+ Addedclsx@1.2.12.1.1(transitive)
+ Addedget-user-locale@2.3.2(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@8.1.1(transitive)
+ Addedmimic-fn@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedreact-clock@4.6.0(transitive)
- Removedmerge-class-names@^1.1.1
- Removedmerge-class-names@1.4.2(transitive)
- Removedreact-clock@3.1.0(transitive)
Updatedreact-clock@^4.0.0