-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TS Strict Calendar #6076
base: main
Are you sure you want to change the base?
TS Strict Calendar #6076
Conversation
hi can work on this if you 're not actively doing this. |
Thank you @ishank-s you're welcome to have a go at it |
Contributor help <3
# Conflicts: # packages/@react-stately/calendar/src/useCalendarState.ts
@@ -71,7 +70,7 @@ export function useCalendarState<T extends DateValue = DateValue>(props: Calenda | |||
} = props; | |||
let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]); | |||
|
|||
let [value, setControlledValue] = useControlledState<DateValue>(props.value, props.defaultValue, props.onChange); | |||
let [value, setControlledValue] = useControlledState<DateValue | null, MappedDateValue<T>>(props.value!, props.defaultValue ?? null!, props.onChange); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain we can fix useControlledState without overload syntax. This is the only way I've seen to prevent that syntax from propagating to every hook and component that uses useControlledState
, but I'm open to other ideas.
I'm also unable to reproduce the issue in ts playground https://tinyurl.com/2p98znas
I don't know if that means I've over engineered it or have missed some setting
} | ||
|
||
if (maxValue) { | ||
date = minDate(date, toCalendarDate(maxValue)); | ||
let newDate = minDate(date, toCalendarDate(maxValue)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can minDate return null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can't? only A | B | undefined
@@ -238,7 +238,7 @@ export function getWeeksInMonth(date: DateValue, locale: string): number { | |||
} | |||
|
|||
/** Returns the lesser of the two provider dates. */ | |||
export function minDate<A extends DateValue, B extends DateValue>(a: A, b: B): A | B { | |||
export function minDate<A extends DateValue, B extends DateValue>(a?: A, b?: B): A | B | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we pass in null/undefined for these?
If we keep this, I guess the parameters shouldn't be optional but should allow null/undefined? I think making them optional only allows undefined not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why allow null? we only pass it undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like if we are going to allow undefined we'd also want to allow null 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better not to have to account for both and we just restrict it to one of them. You can check it out in the latest commit though.
## API Changes
unknown top level export { type: 'any' } @internationalized/dateminDate minDate<A extends DateValue, B extends DateValue> {
- a: A
- b: B
+ a?: A | null
+ b?: B | null
returnVal: undefined
} maxDate maxDate<A extends DateValue, B extends DateValue> {
- a: A
- b: B
+ a?: A | null
+ b?: B | null
returnVal: undefined
} @react-aria/calendarAriaCalendarProps AriaCalendarProps<T extends DateValue> {
autoFocus?: boolean = false
defaultFocusedValue?: DateValue
errorMessage?: ReactNode
focusedValue?: DateValue
isDateUnavailable?: (DateValue) => boolean
isDisabled?: boolean = false
isInvalid?: boolean
isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
onFocusChange?: (CalendarDate) => void
pageBehavior?: PageBehavior = visible
} AriaRangeCalendarProps AriaRangeCalendarProps<T extends DateValue> {
allowsNonContiguousRanges?: boolean
autoFocus?: boolean = false
defaultFocusedValue?: DateValue
errorMessage?: ReactNode
focusedValue?: DateValue
isDateUnavailable?: (DateValue) => boolean
isDisabled?: boolean = false
isInvalid?: boolean
isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
onFocusChange?: (CalendarDate) => void
pageBehavior?: PageBehavior = visible
} CalendarProps-CalendarProps<T extends DateValue> {
- autoFocus?: boolean = false
- defaultFocusedValue?: DateValue
- errorMessage?: ReactNode
- focusedValue?: DateValue
- isDateUnavailable?: (DateValue) => boolean
- isDisabled?: boolean = false
- isInvalid?: boolean
- isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
- onFocusChange?: (CalendarDate) => void
- pageBehavior?: PageBehavior = visible
-}
+ RangeCalendarProps-RangeCalendarProps<T extends DateValue> {
- allowsNonContiguousRanges?: boolean
- autoFocus?: boolean = false
- defaultFocusedValue?: DateValue
- errorMessage?: ReactNode
- focusedValue?: DateValue
- isDateUnavailable?: (DateValue) => boolean
- isDisabled?: boolean = false
- isInvalid?: boolean
- isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
- onFocusChange?: (CalendarDate) => void
- pageBehavior?: PageBehavior = visible
-}
+ undefined-
+CalendarProps<T extends DateValue | null> {
+ autoFocus?: boolean = false
+ defaultFocusedValue?: DateValue
+ errorMessage?: ReactNode
+ focusedValue?: DateValue
+ isDateUnavailable?: (DateValue) => boolean
+ isDisabled?: boolean = false
+ isInvalid?: boolean
+ isReadOnly?: boolean = false
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
+ onFocusChange?: (CalendarDate) => void
+ pageBehavior?: PageBehavior = visible
+} undefined-
+RangeCalendarProps<T extends DateValue | null> {
+ allowsNonContiguousRanges?: boolean
+ autoFocus?: boolean = false
+ defaultFocusedValue?: DateValue
+ errorMessage?: ReactNode
+ focusedValue?: DateValue
+ isDateUnavailable?: (DateValue) => boolean
+ isDisabled?: boolean = false
+ isInvalid?: boolean
+ isReadOnly?: boolean = false
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
+ onFocusChange?: (CalendarDate) => void
+ pageBehavior?: PageBehavior = visible
+} @react-spectrum/calendarCalendarchanged by:
SpectrumCalendarProps<T extends DateValue> {
autoFocus?: boolean = false
defaultFocusedValue?: DateValue
errorMessage?: ReactNode
focusedValue?: DateValue
isDateUnavailable?: (DateValue) => boolean
isDisabled?: boolean = false
isInvalid?: boolean
isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
onFocusChange?: (CalendarDate) => void
pageBehavior?: PageBehavior = visible
visibleMonths?: number = 1
} it changed:
RangeCalendar SpectrumRangeCalendarProps<T extends DateValue> {
allowsNonContiguousRanges?: boolean
autoFocus?: boolean = false
defaultFocusedValue?: DateValue
errorMessage?: ReactNode
focusedValue?: DateValue
isDateUnavailable?: (DateValue) => boolean
isDisabled?: boolean = false
isInvalid?: boolean
isReadOnly?: boolean = false
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
onFocusChange?: (CalendarDate) => void
pageBehavior?: PageBehavior = visible
visibleMonths?: number = 1
} @react-stately/calendarCalendarState CalendarState {
focusNextDay: () => void
focusNextPage: () => void
focusNextRow: () => void
focusNextSection: (boolean) => void
focusPreviousDay: () => void
focusPreviousPage: () => void
focusPreviousRow: () => void
focusPreviousSection: (boolean) => void
focusSectionEnd: () => void
focusSectionStart: () => void
focusedDate: CalendarDate
getDatesInWeek: (number, CalendarDate) => Array<CalendarDate | null>
isCellDisabled: (CalendarDate) => boolean
isCellFocused: (CalendarDate) => boolean
isCellUnavailable: (CalendarDate) => boolean
isDisabled: boolean
isFocused: boolean
isInvalid: (CalendarDate) => boolean
isNextVisibleRangeInvalid: () => boolean
isPreviousVisibleRangeInvalid: () => boolean
isReadOnly: boolean
isSelected: (CalendarDate) => boolean
isValueInvalid: boolean
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
selectDate: (CalendarDate) => void
selectFocusedDate: () => void
setFocused: (boolean) => void
setFocusedDate: (CalendarDate) => void
timeZone: string
value: CalendarDate | null
visibleRange: RangeValue<CalendarDate>
}
RangeCalendarState RangeCalendarState {
anchorDate: CalendarDate | null
focusNextDay: () => void
focusNextPage: () => void
focusNextRow: () => void
focusNextSection: (boolean) => void
focusPreviousDay: () => void
focusPreviousPage: () => void
focusPreviousRow: () => void
focusPreviousSection: (boolean) => void
focusSectionEnd: () => void
focusSectionStart: () => void
focusedDate: CalendarDate
getDatesInWeek: (number, CalendarDate) => Array<CalendarDate | null>
highlightDate: (CalendarDate) => void
- highlightedRange: RangeValue<CalendarDate>
+ highlightedRange: RangeValue<CalendarDate> | null
isCellDisabled: (CalendarDate) => boolean
isCellFocused: (CalendarDate) => boolean
isCellUnavailable: (CalendarDate) => boolean
isDisabled: boolean
isDragging: boolean
isFocused: boolean
isInvalid: (CalendarDate) => boolean
isNextVisibleRangeInvalid: () => boolean
isPreviousVisibleRangeInvalid: () => boolean
isReadOnly: boolean
isSelected: (CalendarDate) => boolean
isValueInvalid: boolean
- maxValue?: DateValue
- minValue?: DateValue
+ maxValue?: DateValue | null
+ minValue?: DateValue | null
selectDate: (CalendarDate) => void
selectFocusedDate: () => void
setAnchorDate: (CalendarDate | null) => void
setDragging: (boolean) => void
setFocused: (boolean) => void
setFocusedDate: (CalendarDate) => void
- setValue: (RangeValue<DateValue>) => void
+ setValue: (RangeValue<DateValue> | null) => void
timeZone: string
- value: RangeValue<DateValue>
+ value: RangeValue<DateValue> | null
visibleRange: RangeValue<CalendarDate>
} |
Closes
I need help figuring out
useRangeCalendarState
I'm getting caught up trying to get the types to work foruseControlledState
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: