From d920022ddefcdf25869e9e68d9655d3c7907831b Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Fri, 26 Apr 2024 13:32:19 +0200 Subject: [PATCH] Remove propTypes --- packages/react-calendar/package.json | 1 - packages/react-calendar/src/Calendar.tsx | 75 -------- packages/react-calendar/src/CenturyView.tsx | 9 - packages/react-calendar/src/DecadeView.tsx | 9 - packages/react-calendar/src/MonthView.tsx | 16 -- packages/react-calendar/src/YearView.tsx | 6 - .../react-calendar/src/shared/propTypes.ts | 161 ------------------ sample/package.json | 1 - yarn.lock | 3 +- 9 files changed, 1 insertion(+), 280 deletions(-) delete mode 100644 packages/react-calendar/src/shared/propTypes.ts diff --git a/packages/react-calendar/package.json b/packages/react-calendar/package.json index 1e2e4ca9..7c2e840a 100644 --- a/packages/react-calendar/package.json +++ b/packages/react-calendar/package.json @@ -49,7 +49,6 @@ "@wojtekmaj/date-utils": "^1.1.3", "clsx": "^2.0.0", "get-user-locale": "^2.2.1", - "prop-types": "^15.6.0", "warning": "^4.0.0" }, "devDependencies": { diff --git a/packages/react-calendar/src/Calendar.tsx b/packages/react-calendar/src/Calendar.tsx index f7e7503c..498e99f1 100644 --- a/packages/react-calendar/src/Calendar.tsx +++ b/packages/react-calendar/src/Calendar.tsx @@ -1,7 +1,6 @@ 'use client'; import { forwardRef, useCallback, useImperativeHandle, useState } from 'react'; -import PropTypes from 'prop-types'; import clsx from 'clsx'; import Navigation from './Calendar/Navigation.js'; @@ -11,15 +10,6 @@ import YearView from './YearView.js'; import MonthView from './MonthView.js'; import { getBegin, getBeginNext, getEnd, getValueRange } from './shared/dates.js'; -import { - isCalendarType, - isClassName, - isMaxDate, - isMinDate, - isRef, - isView, - rangeOf, -} from './shared/propTypes.js'; import { between } from './shared/utils.js'; import type { @@ -1144,69 +1134,4 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { ); }); -const isActiveStartDate = PropTypes.instanceOf(Date); - -const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]); - -const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]); - -Calendar.propTypes = { - activeStartDate: isActiveStartDate, - allowPartialRange: PropTypes.bool, - calendarType: isCalendarType, - className: isClassName, - defaultActiveStartDate: isActiveStartDate, - defaultValue: isValueOrValueArray, - defaultView: isView, - formatDay: PropTypes.func, - formatLongDate: PropTypes.func, - formatMonth: PropTypes.func, - formatMonthYear: PropTypes.func, - formatShortWeekday: PropTypes.func, - formatWeekday: PropTypes.func, - formatYear: PropTypes.func, - goToRangeStartOnSelect: PropTypes.bool, - inputRef: isRef, - locale: PropTypes.string, - maxDate: isMaxDate, - maxDetail: PropTypes.oneOf(allViews), - minDate: isMinDate, - minDetail: PropTypes.oneOf(allViews), - navigationAriaLabel: PropTypes.string, - navigationAriaLive: PropTypes.oneOf(['off', 'polite', 'assertive'] as const), - navigationLabel: PropTypes.func, - next2AriaLabel: PropTypes.string, - next2Label: PropTypes.node, - nextAriaLabel: PropTypes.string, - nextLabel: PropTypes.node, - onActiveStartDateChange: PropTypes.func, - onChange: PropTypes.func, - onClickDay: PropTypes.func, - onClickDecade: PropTypes.func, - onClickMonth: PropTypes.func, - onClickWeekNumber: PropTypes.func, - onClickYear: PropTypes.func, - onDrillDown: PropTypes.func, - onDrillUp: PropTypes.func, - onViewChange: PropTypes.func, - prev2AriaLabel: PropTypes.string, - prev2Label: PropTypes.node, - prevAriaLabel: PropTypes.string, - prevLabel: PropTypes.node, - returnValue: PropTypes.oneOf(['start', 'end', 'range'] as const), - selectRange: PropTypes.bool, - showDoubleView: PropTypes.bool, - showFixedNumberOfWeeks: PropTypes.bool, - showNavigation: PropTypes.bool, - showNeighboringCentury: PropTypes.bool, - showNeighboringDecade: PropTypes.bool, - showNeighboringMonth: PropTypes.bool, - showWeekNumbers: PropTypes.bool, - tileClassName: PropTypes.oneOfType([PropTypes.func, isClassName]), - tileContent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), - tileDisabled: PropTypes.func, - value: isValueOrValueArray, - view: isView, -}; - export default Calendar; diff --git a/packages/react-calendar/src/CenturyView.tsx b/packages/react-calendar/src/CenturyView.tsx index 150e3d34..208aea1e 100644 --- a/packages/react-calendar/src/CenturyView.tsx +++ b/packages/react-calendar/src/CenturyView.tsx @@ -1,9 +1,5 @@ -import PropTypes from 'prop-types'; - import Decades from './CenturyView/Decades.js'; -import { tileGroupProps } from './shared/propTypes.js'; - type CenturyViewProps = React.ComponentProps; /** @@ -17,9 +13,4 @@ const CenturyView: React.FC = function CenturyView(props) { return
{renderDecades()}
; }; -CenturyView.propTypes = { - ...tileGroupProps, - showNeighboringCentury: PropTypes.bool, -}; - export default CenturyView; diff --git a/packages/react-calendar/src/DecadeView.tsx b/packages/react-calendar/src/DecadeView.tsx index ffdb3cc0..59602e45 100644 --- a/packages/react-calendar/src/DecadeView.tsx +++ b/packages/react-calendar/src/DecadeView.tsx @@ -1,9 +1,5 @@ -import PropTypes from 'prop-types'; - import Years from './DecadeView/Years.js'; -import { tileGroupProps } from './shared/propTypes.js'; - type DecadeViewProps = React.ComponentProps; /** @@ -17,9 +13,4 @@ const DecadeView: React.FC = function DecadeView(props) { return
{renderYears()}
; }; -DecadeView.propTypes = { - ...tileGroupProps, - showNeighboringDecade: PropTypes.bool, -}; - export default DecadeView; diff --git a/packages/react-calendar/src/MonthView.tsx b/packages/react-calendar/src/MonthView.tsx index a903ec47..53d7e88c 100644 --- a/packages/react-calendar/src/MonthView.tsx +++ b/packages/react-calendar/src/MonthView.tsx @@ -1,4 +1,3 @@ -import PropTypes from 'prop-types'; import clsx from 'clsx'; import Days from './MonthView/Days.js'; @@ -6,7 +5,6 @@ import Weekdays from './MonthView/Weekdays.js'; import WeekNumbers from './MonthView/WeekNumbers.js'; import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const.js'; -import { isCalendarType, tileGroupProps } from './shared/propTypes.js'; import type { CalendarType, DeprecatedCalendarType } from './shared/types.js'; @@ -114,18 +112,4 @@ const MonthView: React.FC = function MonthView(props) { ); }; -MonthView.propTypes = { - ...tileGroupProps, - calendarType: isCalendarType, - formatDay: PropTypes.func, - formatLongDate: PropTypes.func, - formatShortWeekday: PropTypes.func, - formatWeekday: PropTypes.func, - onClickWeekNumber: PropTypes.func, - onMouseLeave: PropTypes.func, - showFixedNumberOfWeeks: PropTypes.bool, - showNeighboringMonth: PropTypes.bool, - showWeekNumbers: PropTypes.bool, -}; - export default MonthView; diff --git a/packages/react-calendar/src/YearView.tsx b/packages/react-calendar/src/YearView.tsx index fb2d3a64..48fdea87 100644 --- a/packages/react-calendar/src/YearView.tsx +++ b/packages/react-calendar/src/YearView.tsx @@ -1,7 +1,5 @@ import Months from './YearView/Months.js'; -import { tileGroupProps } from './shared/propTypes.js'; - type YearViewProps = React.ComponentProps; /** @@ -15,8 +13,4 @@ const YearView: React.FC = function YearView(props) { return
{renderMonths()}
; }; -YearView.propTypes = { - ...tileGroupProps, -}; - export default YearView; diff --git a/packages/react-calendar/src/shared/propTypes.ts b/packages/react-calendar/src/shared/propTypes.ts deleted file mode 100644 index 87a15a85..00000000 --- a/packages/react-calendar/src/shared/propTypes.ts +++ /dev/null @@ -1,161 +0,0 @@ -import PropTypes from 'prop-types'; - -import { CALENDAR_TYPES, DEPRECATED_CALENDAR_TYPES } from './const.js'; - -import type { Requireable, Validator } from 'prop-types'; -import type { Range, View } from './types.js'; - -const calendarTypes = Object.values(CALENDAR_TYPES); -const deprecatedCalendarTypes = Object.values(DEPRECATED_CALENDAR_TYPES); -const allViews = ['century', 'decade', 'year', 'month']; - -export const isCalendarType = PropTypes.oneOf([ - ...calendarTypes, - ...deprecatedCalendarTypes, -] as const); - -export const isClassName = PropTypes.oneOfType([ - PropTypes.string, - PropTypes.arrayOf(PropTypes.string), -]); - -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 isRef = PropTypes.oneOfType([ - PropTypes.func, - PropTypes.exact({ - current: PropTypes.any, - }), -]); - -const isRange = PropTypes.arrayOf( - PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.oneOf([null])]).isRequired, -) as Requireable>; - -export const isValue = PropTypes.oneOfType([ - PropTypes.instanceOf(Date), - PropTypes.oneOf([null]), - isRange, -]); - -export const isViews = PropTypes.arrayOf(PropTypes.oneOf(allViews)); - -export const isView: Requireable = function isView(props, propName, componentName) { - const { [propName]: view } = props; - - if (view !== undefined && (typeof view !== 'string' || allViews.indexOf(view) === -1)) { - return new Error( - `Invalid prop \`${propName}\` of value \`${view}\` supplied to \`${componentName}\`, expected one of [${allViews - .map((a) => `"${a}"`) - .join(', ')}].`, - ); - } - - // Everything is fine - return null; -}; - -isView.isRequired = function isViewIsRequired( - props, - propName, - componentName, - location, - propFullName, -) { - const { [propName]: view } = props; - - if (!view) { - return new Error( - `The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is \`${view}\`.`, - ); - } - - return isView(props, propName, componentName, location, propFullName); -}; - -export const rangeOf = (type: Requireable): Requireable> => { - return PropTypes.arrayOf(type) as Requireable>; -}; - -export const tileGroupProps = { - activeStartDate: PropTypes.instanceOf(Date).isRequired, - hover: PropTypes.instanceOf(Date), - locale: PropTypes.string, - maxDate: isMaxDate, - minDate: isMinDate, - onClick: PropTypes.func, - onMouseOver: PropTypes.func, - tileClassName: PropTypes.oneOfType([PropTypes.func, isClassName]), - tileContent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), - value: isValue, - valueType: PropTypes.oneOf(['century', 'decade', 'year', 'month', 'day'] as const).isRequired, -}; - -export const tileProps = { - activeStartDate: PropTypes.instanceOf(Date).isRequired, - classes: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired, - date: PropTypes.instanceOf(Date).isRequired, - locale: PropTypes.string, - maxDate: isMaxDate, - minDate: isMinDate, - onClick: PropTypes.func, - onMouseOver: PropTypes.func, - style: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), - tileClassName: PropTypes.oneOfType([PropTypes.func, isClassName]), - tileContent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), - tileDisabled: PropTypes.func, -}; diff --git a/sample/package.json b/sample/package.json index 9cd23e92..306a90dd 100644 --- a/sample/package.json +++ b/sample/package.json @@ -15,7 +15,6 @@ }, "license": "MIT", "dependencies": { - "prop-types": "^15.6.2", "react": "^18.2.0", "react-calendar": "latest", "react-dom": "^18.2.0" diff --git a/yarn.lock b/yarn.lock index 14d0625f..811889b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4045,7 +4045,7 @@ __metadata: languageName: node linkType: hard -"prop-types@npm:^15.6.0, prop-types@npm:^15.8.1": +"prop-types@npm:^15.8.1": version: 15.8.1 resolution: "prop-types@npm:15.8.1" dependencies: @@ -4112,7 +4112,6 @@ __metadata: happy-dom: "npm:^12.6.0" nodemon: "npm:^3.0.0" prettier: "npm:^3.2.0" - prop-types: "npm:^15.6.0" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" rimraf: "npm:^3.0.0"