Skip to content

Commit

Permalink
[pickers] Replace TValue and TSection generics with TIsRange
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Nov 5, 2024
1 parent c41bfaa commit 8bb1bd4
Show file tree
Hide file tree
Showing 112 changed files with 802 additions and 1,004 deletions.
10 changes: 1 addition & 9 deletions docs/data/date-pickers/custom-field/BrowserV7Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
BaseSingleInputPickersTextFieldProps,
BaseSingleInputFieldProps,
DateValidationError,
FieldSection,
PickerValidDate,
} from '@mui/x-date-pickers/models';
import { Unstable_PickersSectionList as PickersSectionList } from '@mui/x-date-pickers/PickersSectionList';

Expand Down Expand Up @@ -106,13 +104,7 @@ const BrowserTextField = React.forwardRef(

interface BrowserDateFieldProps
extends UseDateFieldProps<true>,
BaseSingleInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
PickerValidDate | null,
FieldSection,
true,
DateValidationError
> {}
BaseSingleInputFieldProps<false, true, DateValidationError> {}

const BrowserDateField = React.forwardRef(
(props: BrowserDateFieldProps, ref: React.Ref<HTMLDivElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ import { styled } from '@mui/material/styles';
import Stack from '@mui/material/Stack';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import {
DateRangePicker,
DateRangePickerProps,
} from '@mui/x-date-pickers-pro/DateRangePicker';
import { unstable_useMultiInputDateRangeField as useMultiInputDateRangeField } from '@mui/x-date-pickers-pro/MultiInputDateRangeField';
import { Unstable_PickersSectionList as PickersSectionList } from '@mui/x-date-pickers/PickersSectionList';
import {
RangeFieldSection,
BaseMultiInputFieldProps,
BasePickersTextFieldProps,
MultiInputFieldSlotTextFieldProps,
DateRangeValidationError,
DateRange,
UseDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/models';

Expand Down Expand Up @@ -109,13 +106,7 @@ const BrowserTextField = React.forwardRef(

interface BrowserMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<true>,
BaseMultiInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
true,
DateRangeValidationError
> {}
BaseMultiInputFieldProps<true, DateRangeValidationError> {}

type BrowserMultiInputDateRangeFieldComponent = ((
props: BrowserMultiInputDateRangeFieldProps & React.RefAttributes<HTMLDivElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ import { Unstable_PickersSectionList as PickersSectionList } from '@mui/x-date-p
import {
BasePickersTextFieldProps,
DateRangeValidationError,
RangeFieldSection,
DateRange,
FieldType,
} from '@mui/x-date-pickers-pro/models';
import {
BaseSingleInputFieldProps,
PickerValidDate,
} from '@mui/x-date-pickers/models';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';

const BrowserFieldRoot = styled('div', { name: 'BrowserField', slot: 'Root' })({
display: 'flex',
Expand Down Expand Up @@ -117,13 +112,7 @@ const BrowserTextField = React.forwardRef(

interface BrowserSingleInputDateRangeFieldProps
extends UseSingleInputDateRangeFieldProps<true>,
BaseSingleInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
true,
DateRangeValidationError
> {
BaseSingleInputFieldProps<true, true, DateRangeValidationError> {
onAdornmentClick?: () => void;
}

Expand Down
10 changes: 1 addition & 9 deletions docs/data/date-pickers/custom-field/JoyV6Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { useClearableField } from '@mui/x-date-pickers/hooks';
import {
BaseSingleInputFieldProps,
DateValidationError,
FieldSection,
PickerValidDate,
} from '@mui/x-date-pickers/models';

const joyTheme = extendJoyTheme();
Expand Down Expand Up @@ -101,13 +99,7 @@ const JoyField = React.forwardRef(

interface JoyDateFieldProps
extends UseDateFieldProps<false>,
BaseSingleInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
PickerValidDate | null,
FieldSection,
false,
DateValidationError
> {}
BaseSingleInputFieldProps<false, false, DateValidationError> {}

const JoyDateField = React.forwardRef(
(props: JoyDateFieldProps, ref: React.Ref<HTMLDivElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ import FormLabel from '@mui/joy/FormLabel';
import Typography, { TypographyProps } from '@mui/joy/Typography';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import {
DateRangePicker,
DateRangePickerProps,
} from '@mui/x-date-pickers-pro/DateRangePicker';
import { unstable_useMultiInputDateRangeField as useMultiInputDateRangeField } from '@mui/x-date-pickers-pro/MultiInputDateRangeField';
import {
BaseMultiInputFieldProps,
DateRange,
DateRangeValidationError,
MultiInputFieldSlotTextFieldProps,
RangeFieldSection,
UseDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/models';

Expand Down Expand Up @@ -133,13 +130,7 @@ const MultiInputJoyDateRangeFieldSeparator = styled(

interface JoyMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<false>,
BaseMultiInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
false,
DateRangeValidationError
> {}
BaseMultiInputFieldProps<false, DateRangeValidationError> {}

type JoyMultiInputDateRangeFieldComponent = ((
props: JoyMultiInputDateRangeFieldProps & React.RefAttributes<HTMLDivElement>,
Expand Down
20 changes: 3 additions & 17 deletions docs/data/date-pickers/custom-field/JoyV6SingleInputRangeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,8 @@ import {
UseSingleInputDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
import { useClearableField } from '@mui/x-date-pickers/hooks';
import {
BaseSingleInputFieldProps,
PickerValidDate,
} from '@mui/x-date-pickers/models';
import {
RangeFieldSection,
DateRange,
DateRangeValidationError,
FieldType,
} from '@mui/x-date-pickers-pro/models';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';
import { DateRangeValidationError, FieldType } from '@mui/x-date-pickers-pro/models';

const joyTheme = extendJoyTheme();

Expand Down Expand Up @@ -104,13 +96,7 @@ const JoyField = React.forwardRef(

interface JoySingleInputDateRangeFieldProps
extends UseSingleInputDateRangeFieldProps<false>,
BaseSingleInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
false,
DateRangeValidationError
> {
BaseSingleInputFieldProps<true, false, DateRangeValidationError> {
onAdornmentClick?: () => void;
}

Expand Down
6 changes: 2 additions & 4 deletions docs/data/date-pickers/custom-field/custom-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,15 @@ On the examples below, you can see that the typing of the props received by a cu
interface JoyDateFieldProps
extends UseDateFieldProps<true>, // The headless field props
BaseSingleInputFieldProps<
Dayjs | null,
FieldSection,
false,
true, // `false` for `enableAccessibleFieldDOMStructure={false}`
DateValidationError
> {} // The DOM field props

interface JoyDateTimeFieldProps
extends UseDateTimeFieldProps<true>, // The headless field props
BaseSingleInputFieldProps<
Dayjs | null,
FieldSection,
false,
true, // `false` for `enableAccessibleFieldDOMStructure={false}`
DateTimeValidationError
> {} // The DOM field props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
FieldSelectedSections,
FieldRef,
} from '@mui/x-date-pickers/models';
import { RangeFieldSection, RangePosition } from '@mui/x-date-pickers-pro/models';
import { RangePosition } from '@mui/x-date-pickers-pro/models';
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';

export default function ControlledSelectedSectionsSingleInputRangeField() {
const [selectedSections, setSelectedSections] =
React.useState<FieldSelectedSections>(null);
const inputRef = React.useRef<HTMLInputElement>(null);
const fieldRef = React.useRef<FieldRef<RangeFieldSection>>(null);
const fieldRef = React.useRef<FieldRef<true>>(null);

const setSelectedSectionType = (
selectedSectionType: FieldSectionType,
Expand Down
15 changes: 2 additions & 13 deletions docs/src/modules/components/overview/mainDemo/PickerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@ import Card from '@mui/material/Card';
import CalendarTodayRoundedIcon from '@mui/icons-material/CalendarTodayRounded';
import { UseDateFieldProps } from '@mui/x-date-pickers/DateField';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
import {
BaseSingleInputFieldProps,
DateValidationError,
FieldSection,
PickerValidDate,
} from '@mui/x-date-pickers/models';
import { BaseSingleInputFieldProps, DateValidationError } from '@mui/x-date-pickers/models';

interface ButtonFieldProps
extends UseDateFieldProps<true>,
BaseSingleInputFieldProps<
// This usage of PickerValidDate will go away with TIsRange
PickerValidDate | null,
FieldSection,
true,
DateValidationError
> {
BaseSingleInputFieldProps<false, true, DateValidationError> {
setOpen?: React.Dispatch<React.SetStateAction<boolean>>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar(
} = props;

const { value, handleValueChange, timezone } = useControlledValueWithTimezone<
PickerRangeValue,
true,
NonNullable<typeof onChange>
>({
name: 'DateRangeCalendar',
Expand All @@ -221,7 +221,7 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar(
valueManager: rangeValueManager,
});

const { setValueAndGoToNextView, view } = useViews({
const { setValueAndGoToNextView, view } = useViews<true, 'day'>({
view: inView,
views,
openTo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export interface ExportedDateRangeCalendarProps
export interface DateRangeCalendarProps
extends ExportedDateRangeCalendarProps,
UseRangePositionProps,
ExportedUseViewsOptions<PickerRangeValue, 'day'> {
ExportedUseViewsOptions<true, 'day'> {
/**
* The selected value.
* Used when the component is controlled.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MakeRequired } from '@mui/x-internals/types';
import { BaseDateValidationProps, PickerRangeValue } from '@mui/x-date-pickers/internals';
import { BaseDateValidationProps } from '@mui/x-date-pickers/internals';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';
import {
DesktopDateRangePickerProps,
Expand All @@ -11,7 +11,7 @@ import {
MobileDateRangePickerSlots,
MobileDateRangePickerSlotProps,
} from '../MobileDateRangePicker';
import { DateRangeValidationError, RangeFieldSection, UseDateRangeFieldProps } from '../models';
import { DateRangeValidationError, UseDateRangeFieldProps } from '../models';

export interface DateRangePickerSlots
extends DesktopDateRangePickerSlots,
Expand Down Expand Up @@ -50,4 +50,4 @@ export type DateRangePickerFieldProps<TEnableAccessibleFieldDOMStructure extends
UseDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>,
'format' | 'timezone' | 'value' | keyof BaseDateValidationProps
> &
BaseSingleInputFieldProps<PickerRangeValue, RangeFieldSection, false, DateRangeValidationError>;
BaseSingleInputFieldProps<true, true, DateRangeValidationError>;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
useUtils,
BaseToolbarProps,
ExportedBaseToolbarProps,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { UseRangePositionResponse } from '../internals/hooks/useRangePosition';
Expand All @@ -32,7 +31,7 @@ const useUtilityClasses = (ownerState: DateRangePickerToolbarProps) => {

export interface DateRangePickerToolbarProps
extends ExportedDateRangePickerToolbarProps,
Omit<BaseToolbarProps<PickerRangeValue, 'day'>, 'onChange' | 'isLandscape'>,
Omit<BaseToolbarProps<true, 'day'>, 'onChange' | 'isLandscape'>,
Pick<UseRangePositionResponse, 'rangePosition' | 'onRangePositionChange'> {}

export interface ExportedDateRangePickerToolbarProps extends ExportedBaseToolbarProps {
Expand Down
5 changes: 2 additions & 3 deletions packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
BaseDateValidationProps,
BasePickerInputProps,
PickerViewRendererLookup,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { DateRangeValidationError } from '../models';
import {
Expand Down Expand Up @@ -38,7 +37,7 @@ export interface BaseDateRangePickerSlotProps extends DateRangeCalendarSlotProps

export interface BaseDateRangePickerProps
extends Omit<
BasePickerInputProps<PickerRangeValue, 'day', DateRangeValidationError>,
BasePickerInputProps<true, 'day', DateRangeValidationError>,
'view' | 'views' | 'openTo' | 'onViewChange' | 'orientation'
>,
ExportedDateRangeCalendarProps {
Expand All @@ -58,7 +57,7 @@ export interface BaseDateRangePickerProps
* If `undefined`, internally defined view will be used.
*/
viewRenderers?: Partial<
PickerViewRendererLookup<PickerRangeValue, 'day', DateRangeViewRendererProps<'day'>, {}>
PickerViewRendererLookup<true, 'day', DateRangeViewRendererProps<'day'>, {}>
>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { MakeRequired } from '@mui/x-internals/types';
import {
BaseDateValidationProps,
BaseTimeValidationProps,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { BaseDateValidationProps, BaseTimeValidationProps } from '@mui/x-date-pickers/internals';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';
import {
DesktopDateTimeRangePickerProps,
Expand All @@ -16,7 +12,7 @@ import {
MobileDateTimeRangePickerSlotProps,
} from '../MobileDateTimeRangePicker';
import { UseDateTimeRangeFieldProps } from '../internals/models';
import { DateTimeRangeValidationError, RangeFieldSection } from '../models';
import { DateTimeRangeValidationError } from '../models';

export interface DateTimeRangePickerSlots
extends DesktopDateTimeRangePickerSlots,
Expand Down Expand Up @@ -61,9 +57,4 @@ export type DateTimeRangePickerFieldProps<
| keyof BaseDateValidationProps
| keyof BaseTimeValidationProps
> &
BaseSingleInputFieldProps<
PickerRangeValue,
RangeFieldSection,
false,
DateTimeRangeValidationError
>;
BaseSingleInputFieldProps<true, true, DateTimeRangeValidationError>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useUtils,
DateOrTimeViewWithMeridiem,
WrapperVariant,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { PickerValidDate } from '@mui/x-date-pickers/models';
Expand Down Expand Up @@ -39,7 +38,7 @@ const useUtilityClasses = (ownerState: DateTimeRangePickerToolbarProps) => {
type DateTimeRangeViews = Exclude<DateOrTimeViewWithMeridiem, 'year' | 'month'>;

export interface DateTimeRangePickerToolbarProps
extends BaseToolbarProps<PickerRangeValue, DateTimeRangeViews>,
extends BaseToolbarProps<true, DateTimeRangeViews>,
Pick<UseRangePositionResponse, 'rangePosition' | 'onRangePositionChange'>,
ExportedDateTimeRangePickerToolbarProps {
ampm?: boolean;
Expand Down
Loading

0 comments on commit 8bb1bd4

Please sign in to comment.