@wojtekmaj/react-daterange-picker
Advanced tools
Comparing version 4.1.0 to 4.2.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", { | ||
@@ -22,2 +21,3 @@ value: true | ||
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 _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); } | ||
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; } | ||
@@ -31,7 +31,7 @@ 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 _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 _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 = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) 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 _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, _toPropertyKey(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; } | ||
@@ -45,3 +45,5 @@ 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 _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 _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
var baseClassName = 'react-daterange-picker'; | ||
@@ -326,2 +328,3 @@ var outsideActionEvents = ['mousedown', 'focusin', 'touchstart']; | ||
className = _this$props5.className, | ||
dataTestid = _this$props5['data-testid'], | ||
disabled = _this$props5.disabled; | ||
@@ -332,3 +335,4 @@ var isOpen = this.state.isOpen; | ||
return /*#__PURE__*/_react["default"].createElement("div", _extends({ | ||
className: (0, _clsx["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), | ||
"data-testid": dataTestid | ||
}, eventPropsWithoutOnChange, { | ||
@@ -413,2 +417,3 @@ onFocus: this.onFocus, | ||
closeCalendar: _propTypes["default"].bool, | ||
'data-testid': _propTypes["default"].string, | ||
dayAriaLabel: _propTypes["default"].string, | ||
@@ -415,0 +420,0 @@ dayPlaceholder: _propTypes["default"].string, |
{ | ||
"name": "@wojtekmaj/react-daterange-picker", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A date range picker for your React app.", | ||
@@ -8,5 +8,4 @@ "main": "dist/entry.js", | ||
"scripts": { | ||
"build": "yarn build-js && yarn copy-styles && yarn build-styles", | ||
"build": "yarn build-js && yarn copy-styles", | ||
"build-js": "babel src -d dist --ignore \"**/*.spec.js,**/*.spec.jsx\"", | ||
"build-styles": "lessc ./dist/DateRangePicker.less ./dist/DateRangePicker.css", | ||
"clean": "rimraf dist", | ||
@@ -39,3 +38,3 @@ "copy-styles": "node ./copy-styles.js", | ||
"react-calendar": "^4.0.0", | ||
"react-date-picker": "^9.1.0", | ||
"react-date-picker": "^9.2.0", | ||
"react-fit": "^1.4.0" | ||
@@ -50,2 +49,3 @@ }, | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^14.4.0", | ||
"eslint": "^8.26.0", | ||
@@ -56,3 +56,2 @@ "eslint-config-wojtekmaj": "^0.7.1", | ||
"jest-environment-jsdom": "^29.0.0", | ||
"less": "^4.0.0", | ||
"prettier": "^2.7.0", | ||
@@ -59,0 +58,0 @@ "pretty-quick": "^3.1.0", |
@@ -95,2 +95,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) | ||
| closeCalendar | Whether to close the calendar on value selection. | `true` | `false` | | ||
| data-testid | `data-testid` attribute for the main React-DateRange-Picker `<div>` element. | n/a | `"date-picker"` | | ||
| dayAriaLabel | `aria-label` for the day input. | n/a | `"Day"` | | ||
@@ -97,0 +98,0 @@ | dayPlaceholder | `placeholder` for the day input. | `"--"` | `"dd"` | |
@@ -317,3 +317,3 @@ import React, { createRef, PureComponent } from 'react'; | ||
const { eventProps } = this; | ||
const { className, disabled } = this.props; | ||
const { className, 'data-testid': dataTestid, disabled } = this.props; | ||
const { isOpen } = this.state; | ||
@@ -331,2 +331,3 @@ | ||
)} | ||
data-testid={dataTestid} | ||
{...eventPropsWithoutOnChange} | ||
@@ -394,2 +395,3 @@ onFocus={this.onFocus} | ||
closeCalendar: PropTypes.bool, | ||
'data-testid': PropTypes.string, | ||
dayAriaLabel: PropTypes.string, | ||
@@ -396,0 +398,0 @@ dayPlaceholder: PropTypes.string, |
import React, { createRef } from 'react'; | ||
import { fireEvent, render, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import { act, fireEvent, render, waitFor, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import DateRangePicker from './DateRangePicker'; | ||
async function waitForElementToBeRemovedOrHidden(callback) { | ||
const element = callback(); | ||
if (element) { | ||
try { | ||
await waitFor(() => | ||
expect(element).toHaveAttribute('class', expect.stringContaining('--closed')), | ||
); | ||
} catch (error) { | ||
await waitForElementToBeRemoved(element); | ||
} | ||
} | ||
} | ||
describe('DateRangePicker', () => { | ||
@@ -336,3 +351,3 @@ it('passes default name to DateInput components', () => { | ||
it('closes Calendar component when clicked outside', () => { | ||
it('closes Calendar component when clicked outside', async () => { | ||
const root = document.createElement('div'); | ||
@@ -343,8 +358,10 @@ document.body.appendChild(root); | ||
fireEvent.mouseDown(document.body); | ||
userEvent.click(document.body); | ||
waitForElementToBeRemoved(() => container.querySelector('.react-calendar')); | ||
await waitForElementToBeRemovedOrHidden(() => | ||
container.querySelector('.react-daterange-picker__calendar'), | ||
); | ||
}); | ||
it('closes Calendar component when focused outside', () => { | ||
it('closes Calendar component when focused outside', async () => { | ||
const root = document.createElement('div'); | ||
@@ -357,6 +374,8 @@ document.body.appendChild(root); | ||
waitForElementToBeRemoved(() => container.querySelector('.react-calendar')); | ||
await waitForElementToBeRemovedOrHidden(() => | ||
container.querySelector('.react-daterange-picker__calendar'), | ||
); | ||
}); | ||
it('closes Calendar component when tapped outside', () => { | ||
it('closes Calendar component when tapped outside', async () => { | ||
const root = document.createElement('div'); | ||
@@ -369,3 +388,5 @@ document.body.appendChild(root); | ||
waitForElementToBeRemoved(() => container.querySelector('.react-calendar')); | ||
await waitForElementToBeRemovedOrHidden(() => | ||
container.querySelector('.react-daterange-picker__calendar'), | ||
); | ||
}); | ||
@@ -388,3 +409,3 @@ | ||
it('closes Calendar when calling internal onChange by default', () => { | ||
it('closes Calendar when calling internal onChange by default', async () => { | ||
const instance = createRef(); | ||
@@ -394,7 +415,11 @@ | ||
const { onChange } = instance.current; | ||
const { onChange: onChangeInternal } = instance.current; | ||
onChange(new Date()); | ||
act(() => { | ||
onChangeInternal(new Date()); | ||
}); | ||
waitForElementToBeRemoved(() => container.querySelector('.react-calendar')); | ||
await waitForElementToBeRemovedOrHidden(() => | ||
container.querySelector('.react-daterange-picker__calendar'), | ||
); | ||
}); | ||
@@ -407,5 +432,7 @@ | ||
const { onChange } = instance.current; | ||
const { onChange: onChangeInternal } = instance.current; | ||
onChange(new Date()); | ||
act(() => { | ||
onChangeInternal(new Date()); | ||
}); | ||
@@ -422,5 +449,7 @@ const calendar = container.querySelector('.react-calendar'); | ||
const { onChange } = instance.current; | ||
const { onChange: onChangeInternal } = instance.current; | ||
onChange(new Date(), false); | ||
act(() => { | ||
onChangeInternal(new Date(), false); | ||
}); | ||
@@ -441,3 +470,5 @@ const calendar = container.querySelector('.react-calendar'); | ||
onChangeInternal(nextValue); | ||
act(() => { | ||
onChangeInternal(nextValue); | ||
}); | ||
@@ -469,2 +500,3 @@ expect(onChange).toHaveBeenCalledWith(nextValue); | ||
const componentInstance = instance.current; | ||
const { onChangeFrom: onChangeFromInternal } = componentInstance; | ||
@@ -474,4 +506,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueFrom = new Date(); | ||
componentInstance.onChangeFrom(nextValueFrom); | ||
act(() => { | ||
onChangeFromInternal(nextValueFrom); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -488,2 +523,3 @@ expect(onChangeSpy).toHaveBeenCalledWith([nextValueFrom, undefined], undefined); | ||
const componentInstance = instance.current; | ||
const { onChangeFrom: onChangeFromInternal } = componentInstance; | ||
@@ -493,4 +529,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueFrom = new Date(); | ||
componentInstance.onChangeFrom(nextValueFrom); | ||
act(() => { | ||
onChangeFromInternal(nextValueFrom); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -509,2 +548,3 @@ expect(onChangeSpy).toHaveBeenCalledWith([nextValueFrom, undefined], undefined); | ||
const componentInstance = instance.current; | ||
const { onChangeFrom: onChangeFromInternal } = componentInstance; | ||
@@ -514,4 +554,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueFrom = new Date(); | ||
componentInstance.onChangeFrom(nextValueFrom); | ||
act(() => { | ||
onChangeFromInternal(nextValueFrom); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -529,2 +572,3 @@ expect(onChangeSpy).toHaveBeenCalledWith([nextValueFrom, valueTo], undefined); | ||
const componentInstance = instance.current; | ||
const { onChangeTo: onChangeToInternal } = componentInstance; | ||
@@ -534,4 +578,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueTo = new Date(); | ||
componentInstance.onChangeTo(nextValueTo); | ||
act(() => { | ||
onChangeToInternal(nextValueTo); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -548,2 +595,3 @@ expect(onChangeSpy).toHaveBeenCalledWith([undefined, nextValueTo], undefined); | ||
const componentInstance = instance.current; | ||
const { onChangeTo: onChangeToInternal } = componentInstance; | ||
@@ -553,4 +601,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueTo = new Date(); | ||
componentInstance.onChangeTo(nextValueTo); | ||
act(() => { | ||
onChangeToInternal(nextValueTo); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -569,2 +620,3 @@ expect(onChangeSpy).toHaveBeenCalledWith([value, nextValueTo], undefined); | ||
const componentInstance = instance.current; | ||
const { onChangeTo: onChangeToInternal } = componentInstance; | ||
@@ -574,4 +626,7 @@ const onChangeSpy = jest.spyOn(componentInstance, 'onChange'); | ||
const nextValueTo = new Date(); | ||
componentInstance.onChangeTo(nextValueTo); | ||
act(() => { | ||
onChangeToInternal(nextValueTo); | ||
}); | ||
expect(onChangeSpy).toHaveBeenCalled(); | ||
@@ -578,0 +633,0 @@ expect(onChangeSpy).toHaveBeenCalledWith([valueFrom, nextValueTo], undefined); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
88900
1518
146
14
Updatedreact-date-picker@^9.2.0