Skip to content

Commit

Permalink
feat(ui): upgrade react-datepicker dependency from 6.2.0 to 7.5.0 (pa…
Browse files Browse the repository at this point in the history
…yloadcms#9654)

The new version comes with included types (we can uninstall
`@types/react-datepicker`!), removes 1 dependency and adds official
support for React 19
  • Loading branch information
AlessioGr authored Dec 2, 2024
1 parent 0b445c8 commit 9d72408
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/payload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"@types/minimist": "1.2.2",
"@types/nodemailer": "6.4.14",
"@types/pluralize": "0.0.33",
"@types/react-datepicker": "6.2.0",
"react-datepicker": "7.5.0",
"@types/uuid": "10.0.0",
"@types/ws": "^8.5.10",
"copyfiles": "2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/payload/src/admin/elements/DatePicker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ReactDatePickerProps } from 'react-datepicker'
import type { DatePickerProps } from 'react-datepicker'

export type SharedProps = {
displayFormat?: string
overrides?: ReactDatePickerProps
overrides?: DatePickerProps
pickerAppearance?: 'dayAndTime' | 'dayOnly' | 'default' | 'monthOnly' | 'timeOnly'
}

Expand Down
3 changes: 1 addition & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"md5": "2.3.0",
"object-to-formdata": "4.5.1",
"qs-esm": "7.0.2",
"react-datepicker": "6.9.0",
"react-datepicker": "7.5.0",
"react-image-crop": "10.1.8",
"react-select": "5.8.3",
"scheduler": "0.0.0-experimental-3edc000d-20240926",
Expand All @@ -134,7 +134,6 @@
"@payloadcms/eslint-config": "workspace:*",
"@types/body-scroll-lock": "^3.1.0",
"@types/react": "npm:[email protected]",
"@types/react-datepicker": "6.2.0",
"@types/react-dom": "npm:[email protected]",
"@types/uuid": "10.0.0",
"babel-plugin-react-compiler": "0.0.0-experimental-24ec0eb-20240918",
Expand Down
19 changes: 14 additions & 5 deletions packages/ui/src/elements/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import type { ReactDatePickerProps } from 'react-datepicker'
import type { DatePickerProps } from 'react-datepicker'

import React from 'react'
import ReactDatePickerDefaultImport, { registerLocale, setDefaultLocale } from 'react-datepicker'
Expand All @@ -11,9 +11,9 @@ import type { Props } from './types.js'
import { CalendarIcon } from '../../icons/Calendar/index.js'
import { XIcon } from '../../icons/X/index.js'
import { useTranslation } from '../../providers/Translation/index.js'
import { getFormattedLocale } from './getFormattedLocale.js'
import './library.scss'
import './index.scss'
import { getFormattedLocale } from './getFormattedLocale.js'

const baseClass = 'date-time-picker'

Expand Down Expand Up @@ -55,7 +55,10 @@ const DatePicker: React.FC<Props> = (props) => {
}
}

const onChange = (incomingDate: Date) => {
const onChange: Extract<
DatePickerProps,
{ selectsMultiple?: never; selectsRange?: never }
>['onChange'] = (incomingDate) => {
const newDate = incomingDate
if (newDate instanceof Date && ['dayOnly', 'default', 'monthOnly'].includes(pickerAppearance)) {
const tzOffset = incomingDate.getTimezoneOffset() / 60
Expand All @@ -66,7 +69,10 @@ const DatePicker: React.FC<Props> = (props) => {
}
}

const dateTimePickerProps: ReactDatePickerProps = {
const dateTimePickerProps: Extract<
DatePickerProps,
{ selectsMultiple?: never; selectsRange?: never }
> = {
customInputRef: 'ref',
dateFormat,
disabled: readOnly,
Expand All @@ -84,7 +90,10 @@ const DatePicker: React.FC<Props> = (props) => {
showTimeSelect: pickerAppearance === 'dayAndTime' || pickerAppearance === 'timeOnly',
timeFormat,
timeIntervals,
...overrides,
...(overrides as Extract<
DatePickerProps,
{ selectsMultiple?: never; selectsRange?: never } // to satisfy TypeScript. Overrides can enable selectsMultiple or selectsRange but then it's up to the user to ensure they pass in the correct onChange
>),
}

const classes = [baseClass, `${baseClass}__appearance--${pickerAppearance}`]
Expand Down
51 changes: 12 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d72408

Please sign in to comment.