Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency react-datepicker to v7 #3907

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/renovate-d243585.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ultraviolet/ui': patch
---

Updated dependency `react-datepicker` to `7.1.0`.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
"@testing-library/user-event": "14.5.2",
"@types/node": "20.16.2",
"@types/react": "18.3.5",
"@types/react-datepicker": "6.2.0",
"@types/react-dom": "18.3.0",
"@types/zxcvbn": "4.4.5",
"@ultraviolet/themes": "workspace:*",
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"@emotion/react": "11.13.3",
"@emotion/styled": "11.13.0",
"@types/react": "18.3.5",
"@types/react-datepicker": "6.2.0",
"@types/react-dom": "18.3.0",
"@utils/test": "workspace:*",
"react": "18.3.1",
Expand All @@ -94,7 +93,7 @@
"@ultraviolet/icons": "workspace:*",
"@ultraviolet/themes": "workspace:*",
"deepmerge": "4.3.1",
"react-datepicker": "6.9.0",
"react-datepicker": "7.3.0",
"react-select": "5.8.0",
"react-toastify": "10.0.5",
"react-use-clipboard": "1.0.9",
Expand Down
78 changes: 42 additions & 36 deletions packages/ui/src/components/DateInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Global } from '@emotion/react'
import styled from '@emotion/styled'
import { Icon } from '@ultraviolet/icons'
import type { FocusEvent, ReactNode } from 'react'
import type { ReactNode } from 'react'
import { useId } from 'react'
import type { ReactDatePickerProps } from 'react-datepicker'
import type { DatePickerProps } from 'react-datepicker'
import DatePicker, { registerLocale } from 'react-datepicker'
import { Button } from '../Button'
import { Stack } from '../Stack'
Expand Down Expand Up @@ -187,40 +187,49 @@ const StyledText = styled(Text)`
`

type DateInputProps = Pick<
ReactDatePickerProps<boolean | undefined, boolean>,
'locale' | 'onChange'
DatePickerProps,
| 'locale'
| 'maxDate'
| 'minDate'
| 'excludeDates'
| 'startDate'
| 'endDate'
| 'value'
| 'showMonthYearPicker'
| 'onBlur'
| 'onFocus'
| 'disabled'
| 'autoFocus'
// XOR props
// | 'selectsRange'
// | 'onChange'
// | 'selectsMultiple'
> & {
autoFocus?: boolean
disabled?: boolean
maxDate?: Date | null
minDate?: Date | null
name?: string
onBlur?: (event: FocusEvent<HTMLInputElement>) => void
onFocus?: (event: FocusEvent<HTMLInputElement>) => void
error?: string
required?: boolean
format?: (value?: Date | string) => string | undefined
/**
* Label of the field
*/
label?: string
value?: Date | string | [Date | null, Date | null]
// value?: Date | string | [Date | null, Date | null]
className?: string
'data-testid'?: string
selectsRange?: boolean
startDate?: Date | null
endDate?: Date | null
excludeDates?: Date[]
id?: string
labelDescription?: ReactNode
success?: string | boolean
helper?: string
size?: 'small' | 'medium' | 'large'
readOnly?: boolean
tooltip?: string
showMonthYearPicker?: boolean
}

type DatePicker = Pick<
DatePickerProps,
'selectsRange' | 'onChange' | 'selectsMultiple'
>

const DEFAULT_FORMAT: DateInputProps['format'] = value =>
value instanceof Date ? value.toISOString() : value

Expand Down Expand Up @@ -256,20 +265,16 @@ export const DateInput = ({
readOnly = false,
tooltip,
showMonthYearPicker,
selectsMultiple,
'data-testid': dataTestId,
}: DateInputProps) => {
}: DateInputProps & DatePicker) => {
const uniqueId = useId()
const localId = id ?? uniqueId

// Linked to: https://github.com/Hacker0x01/react-datepicker/issues/3834
const ReactDatePicker =
(DatePicker as unknown as { default: typeof DatePicker }).default ??
DatePicker

const localeCode =
(typeof locale === 'string' ? locale : locale?.code) ?? 'en-GB'
const localeCode = (typeof locale === 'string' ? locale : locale) ?? 'en-GB'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check why they remove the code of locale?.code in the type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (typeof locale === 'object') {
// TODO: ask why locale type is pick and remove localCode of date-fns
registerLocale(localeCode, locale)
}

Expand All @@ -282,15 +287,20 @@ export const DateInput = ({
endDate !== undefined && endDate !== null ? format(endDate) : ''
}`

const valueFormat = selectsRange
? `${valueStart} ${valueEnd}`
: format(value as Date)
const valueFormat = selectsRange ? `${valueStart} ${valueEnd}` : format(value)

return (
<>
<Global styles={style} />
<StyledWrapper>
<ReactDatePicker
{/* */}
<DatePicker
// ts-expect-error https://github.com/Hacker0x01/react-datepicker/issues/4924
selectsMultiple={selectsMultiple}
// ts-expect-error https://github.com/Hacker0x01/react-datepicker/issues/4924
onChange={onChange}
// ts-expect-error https://github.com/Hacker0x01/react-datepicker/issues/4924
selectsRange={selectsRange}
required={required}
data-testid={dataTestId}
className={className}
Expand All @@ -299,12 +309,8 @@ export const DateInput = ({
name={name}
locale={localeCode}
onBlur={onBlur}
onChange={onChange}
onFocus={onFocus}
selected={
value && !selectsRange ? new Date(value as Date) : undefined
}
selectsRange={selectsRange}
selected={value && !selectsRange ? new Date(value) : undefined}
excludeDates={excludeDates}
showPopperArrow={false}
popperPlacement="bottom-start"
Expand All @@ -322,7 +328,7 @@ export const DateInput = ({
suffix={
<Icon
name="calendar-range"
color="neutral"
sentiment="neutral"
disabled={disabled}
/>
}
Expand All @@ -340,9 +346,9 @@ export const DateInput = ({
dateFormat={showMonthYearPicker ? 'MM/yyyy' : undefined}
renderCustomHeader={({
date,
/* eslint-disable-next-line @typescript-eslint/unbound-method */

decreaseMonth,
/* eslint-disable-next-line @typescript-eslint/unbound-method */

increaseMonth,
prevMonthButtonDisabled,
nextMonthButtonDisabled,
Expand Down
28 changes: 5 additions & 23 deletions pnpm-lock.yaml

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

Loading