diff --git a/packages/react-daterange-picker/package.json b/packages/react-daterange-picker/package.json index fe326057..d862552e 100644 --- a/packages/react-daterange-picker/package.json +++ b/packages/react-daterange-picker/package.json @@ -51,7 +51,6 @@ "dependencies": { "clsx": "^2.0.0", "make-event-props": "^1.6.0", - "prop-types": "^15.6.0", "react-calendar": "^4.6.0", "react-date-picker": "^10.5.0", "react-fit": "^1.7.0" diff --git a/packages/react-daterange-picker/src/DateRangePicker.tsx b/packages/react-daterange-picker/src/DateRangePicker.tsx index 03cef899..45d4ed26 100644 --- a/packages/react-daterange-picker/src/DateRangePicker.tsx +++ b/packages/react-daterange-picker/src/DateRangePicker.tsx @@ -2,7 +2,6 @@ import { createElement, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; -import PropTypes from 'prop-types'; import makeEventProps from 'make-event-props'; import clsx from 'clsx'; import Calendar from 'react-calendar'; @@ -10,9 +9,6 @@ import Fit from 'react-fit'; import DateInput from 'react-date-picker/dist/esm/DateInput'; -import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes.js'; - -import type { ReactNodeArray } from 'prop-types'; import type { ClassName, CloseReason, @@ -22,11 +18,8 @@ import type { Value, } from './shared/types.js'; -const isBrowser = typeof document !== 'undefined'; - const baseClassName = 'react-daterange-picker'; const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'] as const; -const allViews = ['century', 'decade', 'year', 'month'] as const; const iconProps = { xmlns: 'http://www.w3.org/2000/svg', @@ -58,7 +51,9 @@ const ClearIcon = ( ); -type Icon = React.ReactElement | ReactNodeArray | null | string | number | boolean; +type ReactNodeLike = React.ReactNode | string | number | boolean | null | undefined; + +type Icon = ReactNodeLike | ReactNodeLike[]; type IconOrRenderFunction = Icon | React.ComponentType | React.ReactElement; @@ -686,50 +681,4 @@ const DateRangePicker: React.FC = function DateRangePicker ); }; -const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]); - -const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]); - -DateRangePicker.propTypes = { - autoFocus: PropTypes.bool, - calendarAriaLabel: PropTypes.string, - calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), - calendarIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), - className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), - clearAriaLabel: PropTypes.string, - clearIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), - closeCalendar: PropTypes.bool, - 'data-testid': PropTypes.string, - dayAriaLabel: PropTypes.string, - dayPlaceholder: PropTypes.string, - disableCalendar: PropTypes.bool, - disabled: PropTypes.bool, - format: PropTypes.string, - id: PropTypes.string, - isOpen: PropTypes.bool, - locale: PropTypes.string, - maxDate: isMaxDate, - maxDetail: PropTypes.oneOf(allViews), - minDate: isMinDate, - monthAriaLabel: PropTypes.string, - monthPlaceholder: PropTypes.string, - name: PropTypes.string, - nativeInputAriaLabel: PropTypes.string, - onCalendarClose: PropTypes.func, - onCalendarOpen: PropTypes.func, - onChange: PropTypes.func, - onFocus: PropTypes.func, - openCalendarOnFocus: PropTypes.bool, - rangeDivider: PropTypes.node, - required: PropTypes.bool, - showLeadingZeros: PropTypes.bool, - value: isValueOrValueArray, - yearAriaLabel: PropTypes.string, - yearPlaceholder: PropTypes.string, -}; - -if (isBrowser) { - DateRangePicker.propTypes.portalContainer = PropTypes.instanceOf(HTMLElement); -} - export default DateRangePicker; diff --git a/packages/react-daterange-picker/src/shared/propTypes.ts b/packages/react-daterange-picker/src/shared/propTypes.ts deleted file mode 100644 index 68037b1d..00000000 --- a/packages/react-daterange-picker/src/shared/propTypes.ts +++ /dev/null @@ -1,64 +0,0 @@ -import PropTypes from 'prop-types'; - -import type { Requireable, Validator } from 'prop-types'; -import type { Range } from './types.js'; - -export const isMinDate: Validator = function isMinDate( - props, - propName, - componentName, -) { - const { [propName]: minDate } = props; - - if (!minDate) { - return null; - } - - if (!(minDate instanceof Date)) { - return new Error( - `Invalid prop \`${propName}\` of type \`${typeof minDate}\` supplied to \`${componentName}\`, expected instance of \`Date\`.`, - ); - } - - const { maxDate } = props; - - if (maxDate && minDate > maxDate) { - return new Error( - `Invalid prop \`${propName}\` of type \`${typeof minDate}\` supplied to \`${componentName}\`, minDate cannot be larger than maxDate.`, - ); - } - - return null; -}; - -export const isMaxDate: Validator = function isMaxDate( - props, - propName, - componentName, -) { - const { [propName]: maxDate } = props; - - if (!maxDate) { - return null; - } - - if (!(maxDate instanceof Date)) { - return new Error( - `Invalid prop \`${propName}\` of type \`${typeof maxDate}\` supplied to \`${componentName}\`, expected instance of \`Date\`.`, - ); - } - - const { minDate } = props; - - if (minDate && maxDate < minDate) { - return new Error( - `Invalid prop \`${propName}\` of type \`${typeof maxDate}\` supplied to \`${componentName}\`, maxDate cannot be smaller than minDate.`, - ); - } - - return null; -}; - -export const rangeOf = (type: Requireable): Requireable> => { - return PropTypes.arrayOf(type) as Requireable>; -}; diff --git a/sample/package.json b/sample/package.json index cf8450f5..3120ef59 100644 --- a/sample/package.json +++ b/sample/package.json @@ -16,7 +16,6 @@ "license": "MIT", "dependencies": { "@wojtekmaj/react-daterange-picker": "latest", - "prop-types": "^15.6.0", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/yarn.lock b/yarn.lock index 653e39e8..09de4b8d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1221,7 +1221,6 @@ __metadata: make-event-props: "npm:^1.6.0" nodemon: "npm:^3.0.0" prettier: "npm:^3.2.0" - prop-types: "npm:^15.6.0" react: "npm:^18.2.0" react-calendar: "npm:^4.6.0" react-date-picker: "npm:^10.5.0"