@wojtekmaj/react-daterange-picker
Advanced tools
Comparing version 4.0.0 to 4.1.0
"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,108 +8,61 @@ 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 _reactCalendar = _interopRequireDefault(require("react-calendar")); | ||
var _reactFit = _interopRequireDefault(require("react-fit")); | ||
var _DateInput = _interopRequireDefault(require("react-date-picker/dist/DateInput")); | ||
var _propTypes2 = require("./shared/propTypes"); | ||
var _excluded = ["calendarClassName", "className", "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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
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 baseClassName = 'react-daterange-picker'; | ||
var outsideActionEvents = ['mousedown', 'focusin', 'touchstart']; | ||
var allViews = ['century', 'decade', 'year', 'month']; | ||
var DateRangePicker = /*#__PURE__*/function (_PureComponent) { | ||
_inherits(DateRangePicker, _PureComponent); | ||
var _super = _createSuper(DateRangePicker); | ||
function DateRangePicker() { | ||
var _this; | ||
_classCallCheck(this, DateRangePicker); | ||
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), "calendarWrapper", /*#__PURE__*/(0, _react.createRef)()); | ||
_defineProperty(_assertThisInitialized(_this), "onOutsideAction", function (event) { | ||
var _assertThisInitialize = _assertThisInitialized(_this), | ||
wrapper = _assertThisInitialize.wrapper, | ||
calendarWrapper = _assertThisInitialize.calendarWrapper; // Try event.composedPath first to handle clicks inside a Shadow DOM. | ||
wrapper = _assertThisInitialize.wrapper, | ||
calendarWrapper = _assertThisInitialize.calendarWrapper; | ||
// 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) && (!calendarWrapper.current || !calendarWrapper.current.contains(target))) { | ||
@@ -120,11 +72,8 @@ _this.closeCalendar(); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChange", function (value) { | ||
var closeCalendar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this.props.closeCalendar; | ||
var onChange = _this.props.onChange; | ||
if (closeCalendar) { | ||
_this.closeCalendar(); | ||
} | ||
if (onChange) { | ||
@@ -134,38 +83,29 @@ onChange(value); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChangeFrom", function (valueFrom, closeCalendar) { | ||
var value = _this.props.value; | ||
var _concat = [].concat(value), | ||
_concat2 = _slicedToArray(_concat, 2), | ||
valueTo = _concat2[1]; | ||
_concat2 = _slicedToArray(_concat, 2), | ||
valueTo = _concat2[1]; | ||
_this.onChange([valueFrom, valueTo], closeCalendar); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onChangeTo", function (valueTo, closeCalendar) { | ||
var value = _this.props.value; | ||
var _concat3 = [].concat(value), | ||
_concat4 = _slicedToArray(_concat3, 1), | ||
valueFrom = _concat4[0]; | ||
_concat4 = _slicedToArray(_concat3, 1), | ||
valueFrom = _concat4[0]; | ||
_this.onChange([valueFrom, valueTo], closeCalendar); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onFocus", function (event) { | ||
var _this$props = _this.props, | ||
disabled = _this$props.disabled, | ||
onFocus = _this$props.onFocus, | ||
openCalendarOnFocus = _this$props.openCalendarOnFocus; | ||
disabled = _this$props.disabled, | ||
onFocus = _this$props.onFocus, | ||
openCalendarOnFocus = _this$props.openCalendarOnFocus; | ||
if (onFocus) { | ||
onFocus(event); | ||
} // Internet Explorer still fires onFocus on disabled elements | ||
} | ||
// Internet Explorer still fires onFocus on disabled elements | ||
if (disabled) { | ||
return; | ||
} | ||
if (openCalendarOnFocus) { | ||
@@ -175,7 +115,5 @@ if (event.target.dataset.select === 'true') { | ||
} | ||
_this.openCalendar(); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) { | ||
@@ -186,3 +124,2 @@ if (event.key === 'Escape') { | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "openCalendar", function () { | ||
@@ -193,3 +130,2 @@ _this.setState({ | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "closeCalendar", function () { | ||
@@ -200,3 +136,2 @@ _this.setState(function (prevState) { | ||
} | ||
return { | ||
@@ -207,3 +142,2 @@ isOpen: false | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "toggleCalendar", function () { | ||
@@ -216,14 +150,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(DateRangePicker, [{ | ||
@@ -239,5 +169,4 @@ key: "componentDidMount", | ||
var _this$props2 = this.props, | ||
onCalendarClose = _this$props2.onCalendarClose, | ||
onCalendarOpen = _this$props2.onCalendarOpen; | ||
onCalendarClose = _this$props2.onCalendarClose, | ||
onCalendarOpen = _this$props2.onCalendarOpen; | ||
if (isOpen !== prevState.isOpen) { | ||
@@ -263,3 +192,2 @@ this.handleOutsideActionListeners(); | ||
var _this2 = this; | ||
var isOpen = this.state.isOpen; | ||
@@ -277,33 +205,31 @@ var shouldListenWithFallback = typeof shouldListen !== 'undefined' ? shouldListen : isOpen; | ||
var _this$props3 = this.props, | ||
autoFocus = _this$props3.autoFocus, | ||
calendarAriaLabel = _this$props3.calendarAriaLabel, | ||
calendarIcon = _this$props3.calendarIcon, | ||
clearAriaLabel = _this$props3.clearAriaLabel, | ||
clearIcon = _this$props3.clearIcon, | ||
dayAriaLabel = _this$props3.dayAriaLabel, | ||
dayPlaceholder = _this$props3.dayPlaceholder, | ||
disableCalendar = _this$props3.disableCalendar, | ||
disabled = _this$props3.disabled, | ||
format = _this$props3.format, | ||
locale = _this$props3.locale, | ||
maxDate = _this$props3.maxDate, | ||
maxDetail = _this$props3.maxDetail, | ||
minDate = _this$props3.minDate, | ||
monthAriaLabel = _this$props3.monthAriaLabel, | ||
monthPlaceholder = _this$props3.monthPlaceholder, | ||
name = _this$props3.name, | ||
nativeInputAriaLabel = _this$props3.nativeInputAriaLabel, | ||
rangeDivider = _this$props3.rangeDivider, | ||
required = _this$props3.required, | ||
showLeadingZeros = _this$props3.showLeadingZeros, | ||
value = _this$props3.value, | ||
yearAriaLabel = _this$props3.yearAriaLabel, | ||
yearPlaceholder = _this$props3.yearPlaceholder; | ||
autoFocus = _this$props3.autoFocus, | ||
calendarAriaLabel = _this$props3.calendarAriaLabel, | ||
calendarIcon = _this$props3.calendarIcon, | ||
clearAriaLabel = _this$props3.clearAriaLabel, | ||
clearIcon = _this$props3.clearIcon, | ||
dayAriaLabel = _this$props3.dayAriaLabel, | ||
dayPlaceholder = _this$props3.dayPlaceholder, | ||
disableCalendar = _this$props3.disableCalendar, | ||
disabled = _this$props3.disabled, | ||
format = _this$props3.format, | ||
locale = _this$props3.locale, | ||
maxDate = _this$props3.maxDate, | ||
maxDetail = _this$props3.maxDetail, | ||
minDate = _this$props3.minDate, | ||
monthAriaLabel = _this$props3.monthAriaLabel, | ||
monthPlaceholder = _this$props3.monthPlaceholder, | ||
name = _this$props3.name, | ||
nativeInputAriaLabel = _this$props3.nativeInputAriaLabel, | ||
rangeDivider = _this$props3.rangeDivider, | ||
required = _this$props3.required, | ||
showLeadingZeros = _this$props3.showLeadingZeros, | ||
value = _this$props3.value, | ||
yearAriaLabel = _this$props3.yearAriaLabel, | ||
yearPlaceholder = _this$props3.yearPlaceholder; | ||
var isOpen = this.state.isOpen; | ||
var _concat5 = [].concat(value), | ||
_concat6 = _slicedToArray(_concat5, 2), | ||
valueFrom = _concat6[0], | ||
valueTo = _concat6[1]; | ||
_concat6 = _slicedToArray(_concat5, 2), | ||
valueFrom = _concat6[0], | ||
valueTo = _concat6[1]; | ||
var ariaLabelProps = { | ||
@@ -320,3 +246,2 @@ dayAriaLabel: dayAriaLabel, | ||
}; | ||
var commonProps = _objectSpread(_objectSpread(_objectSpread({}, ariaLabelProps), placeholderProps), {}, { | ||
@@ -334,3 +259,2 @@ className: "".concat(baseClassName, "__inputGroup"), | ||
}); | ||
return /*#__PURE__*/_react["default"].createElement("div", { | ||
@@ -373,21 +297,16 @@ className: "".concat(baseClassName, "__wrapper") | ||
var _this3 = this; | ||
var disableCalendar = this.props.disableCalendar; | ||
var isOpen = this.state.isOpen; | ||
if (isOpen === null || disableCalendar) { | ||
return null; | ||
} | ||
var _this$props4 = this.props, | ||
calendarClassName = _this$props4.calendarClassName, | ||
datePickerClassName = _this$props4.className, | ||
onChange = _this$props4.onChange, | ||
portalContainer = _this$props4.portalContainer, | ||
value = _this$props4.value, | ||
calendarProps = _objectWithoutProperties(_this$props4, _excluded); | ||
calendarClassName = _this$props4.calendarClassName, | ||
datePickerClassName = _this$props4.className, | ||
onChange = _this$props4.onChange, | ||
portalContainer = _this$props4.portalContainer, | ||
value = _this$props4.value, | ||
calendarProps = _objectWithoutProperties(_this$props4, _excluded); | ||
var className = "".concat(baseClassName, "__calendar"); | ||
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 calendar = /*#__PURE__*/_react["default"].createElement(_reactCalendar["default"], _extends({ | ||
@@ -401,3 +320,2 @@ className: calendarClassName, | ||
}, calendarProps)); | ||
return portalContainer ? /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react["default"].createElement("div", { | ||
@@ -420,11 +338,9 @@ ref: this.calendarWrapper, | ||
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, { | ||
@@ -444,10 +360,7 @@ onFocus: this.onFocus, | ||
} | ||
return null; | ||
} | ||
}]); | ||
return DateRangePicker; | ||
}(_react.PureComponent); | ||
exports["default"] = DateRangePicker; | ||
@@ -462,3 +375,2 @@ var iconProps = { | ||
}; | ||
var CalendarIcon = /*#__PURE__*/_react["default"].createElement("svg", _extends({}, iconProps, { | ||
@@ -483,3 +395,2 @@ className: "".concat(baseClassName, "__calendar-button__icon ").concat(baseClassName, "__button__icon") | ||
})); | ||
var ClearIcon = /*#__PURE__*/_react["default"].createElement("svg", _extends({}, iconProps, { | ||
@@ -498,3 +409,2 @@ className: "".concat(baseClassName, "__clear-button__icon ").concat(baseClassName, "__button__icon") | ||
})); | ||
DateRangePicker.defaultProps = { | ||
@@ -509,5 +419,3 @@ calendarIcon: CalendarIcon, | ||
}; | ||
var isValue = _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].instanceOf(Date)]); | ||
DateRangePicker.propTypes = { | ||
@@ -544,3 +452,2 @@ autoFocus: _propTypes["default"].bool, | ||
required: _propTypes["default"].bool, | ||
returnValue: _propTypes["default"].oneOf(['start', 'end', 'range']), | ||
showLeadingZeros: _propTypes["default"].bool, | ||
@@ -547,0 +454,0 @@ value: _propTypes["default"].oneOfType([isValue, _propTypes["default"].arrayOf(isValue)]), |
@@ -7,11 +7,6 @@ "use strict"; | ||
exports["default"] = void 0; | ||
require("react-calendar/dist/Calendar.css"); | ||
var _DateRangePicker = _interopRequireDefault(require("./DateRangePicker")); | ||
require("./DateRangePicker.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 _DateRangePicker = _interopRequireDefault(require("./DateRangePicker")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _default = _DateRangePicker["default"]; | ||
exports["default"] = _default; |
@@ -7,47 +7,32 @@ "use strict"; | ||
exports.isMinDate = exports.isMaxDate = void 0; | ||
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 isMinDate = function isMinDate(props, propName, componentName) { | ||
var minDate = props[propName]; | ||
if (!minDate) { | ||
return null; | ||
} | ||
if (!(minDate instanceof Date)) { | ||
return new Error("Invalid prop `".concat(propName, "` of type `").concat(_typeof(minDate), "` supplied to `").concat(componentName, "`, expected instance of `Date`.")); | ||
} | ||
var maxDate = props.maxDate; | ||
if (maxDate && minDate > maxDate) { | ||
return new Error("Invalid prop `".concat(propName, "` of type `").concat(_typeof(minDate), "` supplied to `").concat(componentName, "`, minDate cannot be larger than maxDate.")); | ||
} | ||
return null; | ||
}; | ||
exports.isMinDate = isMinDate; | ||
var isMaxDate = function isMaxDate(props, propName, componentName) { | ||
var maxDate = props[propName]; | ||
if (!maxDate) { | ||
return null; | ||
} | ||
if (!(maxDate instanceof Date)) { | ||
return new Error("Invalid prop `".concat(propName, "` of type `").concat(_typeof(maxDate), "` supplied to `").concat(componentName, "`, expected instance of `Date`.")); | ||
} | ||
var minDate = props.minDate; | ||
if (minDate && maxDate < minDate) { | ||
return new Error("Invalid prop `".concat(propName, "` of type `").concat(_typeof(maxDate), "` supplied to `").concat(componentName, "`, maxDate cannot be smaller than minDate.")); | ||
} | ||
return null; | ||
}; | ||
exports.isMaxDate = isMaxDate; |
{ | ||
"name": "@wojtekmaj/react-daterange-picker", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A date range 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" | ||
}, | ||
@@ -34,7 +35,7 @@ "keywords": [ | ||
"dependencies": { | ||
"clsx": "^1.2.1", | ||
"make-event-props": "^1.1.0", | ||
"merge-class-names": "^1.1.1", | ||
"prop-types": "^15.6.0", | ||
"react-calendar": "^3.7.0", | ||
"react-date-picker": "^9.0.0", | ||
"react-calendar": "^4.0.0", | ||
"react-date-picker": "^9.1.0", | ||
"react-fit": "^1.4.0" | ||
@@ -48,5 +49,5 @@ }, | ||
"@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", | ||
@@ -56,6 +57,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" | ||
@@ -62,0 +63,0 @@ }, |
@@ -113,2 +113,3 @@ [![npm](https://img.shields.io/npm/v/@wojtekmaj/react-daterange-picker.svg)](https://www.npmjs.com/package/@wojtekmaj/react-daterange-picker) ![downloads](https://img.shields.io/npm/dt/@wojtekmaj/react-daterange-picker.svg) [![CI](https://github.com/wojtekmaj/react-daterange-picker/workflows/CI/badge.svg)](https://github.com/wojtekmaj/react-daterange-picker/actions) ![dependencies](https://img.shields.io/david/wojtekmaj/react-daterange-picker.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/react-daterange-picker.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
| onChange | Function called when the user picks a valid date. If any of the fields were excluded using custom `format`, `new Date(y, 0, 1, 0, 0, 0)`, where `y` is the current year, is going to serve as a "base". | n/a | `(value) => alert('New date is: ', value)` | | ||
| onFocus | Function called when the focuses an input. | n/a | `(event) => alert('Focused input: ', event.target.name)` | | ||
| openCalendarOnFocus | Whether to open the calendar on input focus. | `true` | `false` | | ||
@@ -115,0 +116,0 @@ | portalContainer | Element to render the calendar in using portal. | n/a | `document.getElementById('my-div')` | |
@@ -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 Calendar from 'react-calendar'; | ||
@@ -281,3 +281,3 @@ import Fit from 'react-fit'; | ||
const className = `${baseClassName}__calendar`; | ||
const classNames = mergeClassNames(className, `${className}--${isOpen ? 'open' : 'closed'}`); | ||
const classNames = clsx(className, `${className}--${isOpen ? 'open' : 'closed'}`); | ||
@@ -326,3 +326,3 @@ const calendar = ( | ||
<div | ||
className={mergeClassNames( | ||
className={clsx( | ||
baseClassName, | ||
@@ -417,3 +417,2 @@ `${baseClassName}--${isOpen ? 'open' : 'closed'}`, | ||
required: PropTypes.bool, | ||
returnValue: PropTypes.oneOf(['start', 'end', 'range']), | ||
showLeadingZeros: PropTypes.bool, | ||
@@ -420,0 +419,0 @@ value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]), |
@@ -165,2 +165,10 @@ import React, { createRef } from 'react'; | ||
it('applies "--open" className to its wrapper when given isOpen flag', () => { | ||
const { container } = render(<DateRangePicker isOpen />); | ||
const wrapper = container.firstChild; | ||
expect(wrapper).toHaveClass('react-daterange-picker--open'); | ||
}); | ||
it('applies calendarClassName to the calendar when given a string', () => { | ||
@@ -167,0 +175,0 @@ const calendarClassName = 'testClassName'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87732
1361
145
+ Addedclsx@^1.2.1
+ Addedclsx@1.2.1(transitive)
- Removedmerge-class-names@^1.1.1
- Removedget-user-locale@1.5.1(transitive)
- Removedlodash.memoize@4.1.2(transitive)
- Removedmerge-class-names@1.4.2(transitive)
- Removedreact-calendar@3.9.0(transitive)
Updatedreact-calendar@^4.0.0
Updatedreact-date-picker@^9.1.0