Skip to content

Commit

Permalink
remove internal contexts from RAC Calendar (#7593)
Browse files Browse the repository at this point in the history
  • Loading branch information
reidbarber authored Jan 10, 2025
1 parent e4497fd commit 73bbc40
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/react-aria-components/src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import {ButtonContext} from './Button';
import {CalendarDate, createCalendar, DateDuration, endOfMonth, getWeeksInMonth, isSameDay, isSameMonth} from '@internationalized/date';
import {CalendarState, RangeCalendarState, useCalendarState, useRangeCalendarState} from 'react-stately';
import {ContextValue, DOMProps, Provider, RenderProps, SlotProps, StyleProps, useContextProps, useRenderProps} from './utils';
import {ContextValue, DOMProps, Provider, RenderProps, SlotProps, StyleProps, useContextProps, useRenderProps, useSlottedContext} from './utils';
import {DOMAttributes, FocusableElement, forwardRefType, HoverEvents} from '@react-types/shared';
import {filterDOMProps} from '@react-aria/utils';
import {HeadingContext} from './RSPContexts';
Expand Down Expand Up @@ -73,12 +73,10 @@ export interface RangeCalendarProps<T extends DateValue> extends Omit<AriaRangeC
visibleDuration?: DateDuration
}

export const CalendarContext = createContext<ContextValue<CalendarProps<any>, HTMLDivElement>>({});
export const RangeCalendarContext = createContext<ContextValue<RangeCalendarProps<any>, HTMLDivElement>>({});
export const CalendarContext = createContext<ContextValue<CalendarProps<any>, HTMLDivElement>>(null);
export const RangeCalendarContext = createContext<ContextValue<RangeCalendarProps<any>, HTMLDivElement>>(null);
export const CalendarStateContext = createContext<CalendarState | null>(null);
export const RangeCalendarStateContext = createContext<RangeCalendarState | null>(null);
const InternalCalendarContext = createContext<CalendarProps<any> | null>(null);
const InternalRangeCalendarContext = createContext<RangeCalendarProps<any> | null>(null);

/**
* A calendar displays one or more date grids and allows users to select a single date.
Expand Down Expand Up @@ -122,7 +120,7 @@ export const Calendar = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
}],
[HeadingContext, {'aria-hidden': true, level: 2, children: title}],
[CalendarStateContext, state],
[InternalCalendarContext, props],
[CalendarContext, props as CalendarProps<any>],
[TextContext, {
slots: {
errorMessage: errorMessageProps
Expand Down Expand Up @@ -199,7 +197,7 @@ export const RangeCalendar = /*#__PURE__*/ (forwardRef as forwardRefType)(functi
}],
[HeadingContext, {'aria-hidden': true, level: 2, children: title}],
[RangeCalendarStateContext, state],
[InternalRangeCalendarContext, props],
[RangeCalendarContext, props as RangeCalendarProps<any>],
[TextContext, {
slots: {
errorMessage: errorMessageProps
Expand Down Expand Up @@ -343,8 +341,8 @@ const InternalCalendarGridContext = createContext<InternalCalendarGridContextVal
export const CalendarGrid = /*#__PURE__*/ (forwardRef as forwardRefType)(function CalendarGrid(props: CalendarGridProps, ref: ForwardedRef<HTMLTableElement>) {
let calendarState = useContext(CalendarStateContext);
let rangeCalendarState = useContext(RangeCalendarStateContext);
let calenderProps = useContext(InternalCalendarContext)!;
let rangeCalenderProps = useContext(InternalRangeCalendarContext)!;
let calenderProps = useSlottedContext(CalendarContext)!;
let rangeCalenderProps = useSlottedContext(RangeCalendarContext)!;
let state = calendarState ?? rangeCalendarState!;
let startDate = state.visibleRange.start;
if (props.offset) {
Expand Down

1 comment on commit 73bbc40

@rspbot
Copy link

@rspbot rspbot commented on 73bbc40 Jan 10, 2025

Choose a reason for hiding this comment

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

Please sign in to comment.