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

[pickers] Remove TDate generics in favor of PickerValidDate direct usage #15001

Merged
merged 70 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
dcfddcc
[fields] Enable the new field DOM structure by default
flaviendelangle Sep 17, 2024
28cd5ea
Regen API
flaviendelangle Sep 17, 2024
7b1784d
Fix links
flaviendelangle Sep 17, 2024
931a1a1
Remove enableAccessibleFieldDOMStructure prop when not needed
flaviendelangle Sep 17, 2024
25a258d
Fix
flaviendelangle Sep 17, 2024
fab5833
Fix
flaviendelangle Sep 17, 2024
65e3462
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Sep 20, 2024
edfddd3
Merge
flaviendelangle Sep 20, 2024
9c1c822
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Sep 24, 2024
28dbc40
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Sep 30, 2024
5a8a5ec
Fix
flaviendelangle Sep 30, 2024
e634bab
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 8, 2024
a029653
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 8, 2024
448f209
Work
flaviendelangle Oct 8, 2024
af1436e
Work
flaviendelangle Oct 8, 2024
eed2459
Work
flaviendelangle Oct 8, 2024
2b5dfeb
Work
flaviendelangle Oct 8, 2024
2faf846
Work
flaviendelangle Oct 8, 2024
832baaf
Work
flaviendelangle Oct 8, 2024
f6963d7
Work
flaviendelangle Oct 8, 2024
3d6bc8d
Work
flaviendelangle Oct 8, 2024
dec8394
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 8, 2024
626ed02
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 10, 2024
8b7a8f6
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 11, 2024
80eac3b
Fix
flaviendelangle Oct 11, 2024
1f3d73c
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 16, 2024
7bedcd5
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 16, 2024
5f76be6
Review: Arthur
flaviendelangle Oct 16, 2024
24334a1
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 16, 2024
f003b41
[pickers] Remove TDate generics in favor of PickerValidDate direct usage
flaviendelangle Oct 16, 2024
c0ef9ab
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 17, 2024
90cb5f1
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 17, 2024
25f4e36
Fix
flaviendelangle Oct 17, 2024
bf76526
Merge
flaviendelangle Oct 18, 2024
e9d3833
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 18, 2024
b1a9bab
Work
flaviendelangle Oct 18, 2024
749643a
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 21, 2024
dc5ad3b
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 21, 2024
67c6821
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 22, 2024
4d448a3
Remove RangeValue
flaviendelangle Oct 22, 2024
30c53f1
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 22, 2024
37906a4
Merge branch 'master' into enabledAccessibleFieldDOMStructure
flaviendelangle Oct 22, 2024
b6a8a24
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 22, 2024
530a60e
Empty
flaviendelangle Oct 22, 2024
3238c69
Empty
flaviendelangle Oct 22, 2024
0204496
Empty
flaviendelangle Oct 22, 2024
9d7d0b6
Merge branch 'enabledAccessibleFieldDOMStructure' into remove-tdate
flaviendelangle Oct 22, 2024
14c98c4
Merge
flaviendelangle Oct 22, 2024
5f7ad5e
Fix
flaviendelangle Oct 23, 2024
ea894c6
Merge branch 'master' into remove-tdate
flaviendelangle Oct 24, 2024
8765825
Fix
flaviendelangle Oct 24, 2024
f49dc88
Merge
flaviendelangle Oct 28, 2024
31a152d
Merge
flaviendelangle Oct 29, 2024
f866561
Merge
flaviendelangle Oct 29, 2024
98eb539
Work
flaviendelangle Oct 29, 2024
a1e1090
Fix
flaviendelangle Oct 29, 2024
a2435b0
Fix CI
flaviendelangle Oct 29, 2024
df2da8c
Review: Lukas
flaviendelangle Oct 29, 2024
f8e43e7
Fix
flaviendelangle Oct 29, 2024
3851a35
Update .circleci/config.yml
flaviendelangle Oct 29, 2024
47f3e6d
Fix
flaviendelangle Oct 29, 2024
b252ca8
Fix
flaviendelangle Oct 29, 2024
98a52a9
Merge
flaviendelangle Oct 31, 2024
d6a3284
Merge
flaviendelangle Oct 31, 2024
dee0238
Review: Lukas
flaviendelangle Oct 31, 2024
704c772
Merge branch 'master' into remove-tdate
flaviendelangle Nov 4, 2024
d38a91a
Fix
flaviendelangle Nov 4, 2024
1573e01
Revert unrelated changes
flaviendelangle Nov 4, 2024
a7a1102
Merge branch 'master' into remove-tdate
flaviendelangle Nov 5, 2024
9683c45
Merge branch 'master' into remove-tdate
flaviendelangle Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ jobs:
pnpm --filter @mui/x-charts-vendor build
git add -A && git diff --exit-code --staged
fi
- run:
name: 'No dynamic date library import in the Pickers built types?'
command: |
pnpm --filter @mui/x-date-pickers* prebuild
pnpm --filter @mui/x-date-pickers* build:types
if grep -nr 'import("luxon")\|import("dayjs")\|import("moment")' --exclude Adapter*.d.ts packages/{x-date-pickers,x-date-pickers-pro}/build
then
exit 1
else
exit 0
fi
test_browser:
<<: *default-job
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import Stack from '@mui/material/Stack';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import Stack from '@mui/material/Stack';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
Expand Down Expand Up @@ -35,7 +34,7 @@ function DisplayWeekNumberToggle({
}

interface CustomCalendarHeaderProps
extends PropsFromSlot<DateCalendarSlots<Dayjs>['calendarHeader']> {
extends PropsFromSlot<DateCalendarSlots['calendarHeader']> {
displayWeekNumber: boolean;
setDisplayWeekNumber: (displayWeekNumber: boolean) => void;
}
Expand Down Expand Up @@ -66,13 +65,13 @@ export default function TypescriptCasting() {
// Cast the custom component to the type expected by the X component
slots={{
calendarHeader:
CustomCalendarHeader as DateCalendarSlots<Dayjs>['calendarHeader'],
CustomCalendarHeader as DateCalendarSlots['calendarHeader'],
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
} as DateCalendarSlotProps<Dayjs>['calendarHeader'],
} as DateCalendarSlotProps['calendarHeader'],
}}
/>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Cast the custom component to the type expected by the X component
slots={{
calendarHeader:
CustomCalendarHeader as DateCalendarSlots<Dayjs>['calendarHeader'],
CustomCalendarHeader as DateCalendarSlots['calendarHeader'],
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
} as DateCalendarSlotProps<Dayjs>['calendarHeader'],
} as DateCalendarSlotProps['calendarHeader'],
}}
/>
11 changes: 5 additions & 6 deletions docs/data/common-concepts/custom-components/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ you can declare your component using the `PropsFromSlot` interface:
```tsx
function CustomCalendarHeader({
currentMonth,
}: PropsFromSlot<DateCalendarSlots<Dayjs>['calendarHeader']>) {
}: PropsFromSlot<DateCalendarSlots['calendarHeader']>) {
return <div>{currentMonth?.format('MM-DD-YYYY')}</div>;
}
```
Expand All @@ -129,7 +129,7 @@ import { DateCalendarSlots } from '@mui/x-date-pickers';
type ToolbarProps = PropsFromSlot<GridSlots['toolbar']>;

// Most of the picker slots interfaces need to receive the date type as a generic.
type CalendarHeaderProps = PropsFromSlot<DateCalendarSlots<Dayjs>['calendarHeader']>;
type CalendarHeaderProps = PropsFromSlot<DateCalendarSlots['calendarHeader']>;
```

:::
Expand All @@ -140,7 +140,7 @@ If you are passing additional props to your slot, you can add them to the props

```ts
interface CustomCalendarHeaderProps
extends PropsFromSlot<DateCalendarSlots<Dayjs>['calendarHeader']> {
extends PropsFromSlot<DateCalendarSlots['calendarHeader']> {
displayWeekNumber: boolean;
setDisplayWeekNumber: (displayWeekNumber: boolean) => void;
}
Expand Down Expand Up @@ -178,14 +178,13 @@ function MyApp() {
<DateCalendar
displayWeekNumber={displayWeekNumber}
slots={{
calendarHeader:
CustomCalendarHeader as DateCalendarSlots<Dayjs>['calendarHeader'],
calendarHeader: CustomCalendarHeader as DateCalendarSlots['calendarHeader'],
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
} as DateCalendarSlotProps<Dayjs>['calendarHeader'],
} as DateCalendarSlotProps['calendarHeader'],
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Stack from '@mui/material/Stack';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Stack from '@mui/material/Stack';
Expand All @@ -21,7 +20,7 @@ const CustomCalendarHeaderRoot = styled('div')({
alignItems: 'center',
});

function CustomCalendarHeader(props: PickersCalendarHeaderProps<Dayjs>) {
function CustomCalendarHeader(props: PickersCalendarHeaderProps) {
const { currentMonth, onMonthChange } = props;

const selectNextMonth = () => onMonthChange(currentMonth.add(1, 'month'), 'left');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
Expand All @@ -18,7 +17,7 @@ const CustomCalendarHeaderRoot = styled('div')({
alignItems: 'center',
});

function CustomCalendarHeader(props: PickersRangeCalendarHeaderProps<Dayjs>) {
function CustomCalendarHeader(props: PickersRangeCalendarHeaderProps) {
const { currentMonth, onMonthChange, month, calendars, monthIndex } = props;

const selectNextMonth = () =>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/date-pickers/custom-components/ToolbarComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import dayjs, { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
import Box from '@mui/material/Box';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
Expand All @@ -10,7 +10,7 @@ import {
DatePickerToolbarProps,
} from '@mui/x-date-pickers/DatePicker';

function CustomToolbar(props: DatePickerToolbarProps<Dayjs>) {
function CustomToolbar(props: DatePickerToolbarProps) {
return (
<Box
// Pass the className to the root element to get correct layout
Expand Down
6 changes: 1 addition & 5 deletions docs/data/date-pickers/custom-field/BrowserV7Field.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import useForkRef from '@mui/utils/useForkRef';
import { styled } from '@mui/material/styles';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
Expand Down Expand Up @@ -84,10 +83,7 @@ const BrowserTextField = React.forwardRef((props, ref) => {
const BrowserDateField = React.forwardRef((props, ref) => {
const { slots, slotProps, ...textFieldProps } = props;

const fieldResponse = useDateField({
...textFieldProps,
enableAccessibleFieldDOMStructure: true,
});
const fieldResponse = useDateField(textFieldProps);

/* If you don't need a clear button, you can skip the use of this hook */
const processedFieldProps = useClearableField({
Expand Down
15 changes: 6 additions & 9 deletions docs/data/date-pickers/custom-field/BrowserV7Field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import useForkRef from '@mui/utils/useForkRef';
import { styled } from '@mui/material/styles';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
Expand All @@ -15,6 +14,7 @@ import {
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 @@ -105,10 +105,10 @@ const BrowserTextField = React.forwardRef(
);

interface BrowserDateFieldProps
extends UseDateFieldProps<Dayjs, true>,
extends UseDateFieldProps<true>,
BaseSingleInputFieldProps<
Dayjs | null,
Dayjs,
// This usage of PickerValidDate will go away with TIsRange
PickerValidDate | null,
FieldSection,
true,
DateValidationError
Expand All @@ -118,10 +118,7 @@ const BrowserDateField = React.forwardRef(
(props: BrowserDateFieldProps, ref: React.Ref<HTMLDivElement>) => {
const { slots, slotProps, ...textFieldProps } = props;

const fieldResponse = useDateField<Dayjs, true, typeof textFieldProps>({
...textFieldProps,
enableAccessibleFieldDOMStructure: true,
});
const fieldResponse = useDateField<true, typeof textFieldProps>(textFieldProps);

/* If you don't need a clear button, you can skip the use of this hook */
const processedFieldProps = useClearableField({
Expand All @@ -135,7 +132,7 @@ const BrowserDateField = React.forwardRef(
);

const BrowserDatePicker = React.forwardRef(
(props: DatePickerProps<Dayjs>, ref: React.Ref<HTMLDivElement>) => {
(props: DatePickerProps, ref: React.Ref<HTMLDivElement>) => {
return (
<DatePicker
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';

import useForkRef from '@mui/utils/useForkRef';
import useSlotProps from '@mui/utils/useSlotProps';
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 { DateRangePicker } 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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import useForkRef from '@mui/utils/useForkRef';
import useSlotProps from '@mui/utils/useSlotProps';
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,
Expand Down Expand Up @@ -108,10 +108,10 @@ const BrowserTextField = React.forwardRef(
);

interface BrowserMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<Dayjs, true>,
extends UseDateRangeFieldProps<true>,
BaseMultiInputFieldProps<
DateRange<Dayjs>,
Dayjs,
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
true,
DateRangeValidationError
Expand Down Expand Up @@ -157,7 +157,6 @@ const BrowserMultiInputDateRangeField = React.forwardRef(
}) as MultiInputFieldSlotTextFieldProps;

const fieldResponse = useMultiInputDateRangeField<
Dayjs,
true,
MultiInputFieldSlotTextFieldProps
>({
Expand Down Expand Up @@ -201,7 +200,7 @@ const BrowserMultiInputDateRangeField = React.forwardRef(
) as BrowserMultiInputDateRangeFieldComponent;

const BrowserDateRangePicker = React.forwardRef(
(props: DateRangePickerProps<Dayjs>, ref: React.Ref<HTMLDivElement>) => {
(props: DateRangePickerProps, ref: React.Ref<HTMLDivElement>) => {
return (
<DateRangePicker
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import useForkRef from '@mui/utils/useForkRef';
import useSlotProps from '@mui/utils/useSlotProps';
import { styled } from '@mui/material/styles';
Expand Down Expand Up @@ -105,10 +104,7 @@ const BrowserSingleInputDateRangeField = React.forwardRef((props, ref) => {
),
};

const fieldResponse = useSingleInputDateRangeField({
...textFieldProps,
enableAccessibleFieldDOMStructure: true,
});
const fieldResponse = useSingleInputDateRangeField(textFieldProps);

/* If you don't need a clear button, you can skip the use of this hook */
const processedFieldProps = useClearableField({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { Dayjs } from 'dayjs';
import useForkRef from '@mui/utils/useForkRef';
import useSlotProps from '@mui/utils/useSlotProps';
import { styled } from '@mui/material/styles';
Expand All @@ -25,7 +24,10 @@ import {
DateRange,
FieldType,
} from '@mui/x-date-pickers-pro/models';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';
import {
BaseSingleInputFieldProps,
PickerValidDate,
} from '@mui/x-date-pickers/models';

const BrowserFieldRoot = styled('div', { name: 'BrowserField', slot: 'Root' })({
display: 'flex',
Expand Down Expand Up @@ -114,10 +116,10 @@ const BrowserTextField = React.forwardRef(
);

interface BrowserSingleInputDateRangeFieldProps
extends UseSingleInputDateRangeFieldProps<Dayjs, true>,
extends UseSingleInputDateRangeFieldProps<true>,
BaseSingleInputFieldProps<
DateRange<Dayjs>,
Dayjs,
// This usage of PickerValidDate will go away with TIsRange
DateRange<PickerValidDate>,
RangeFieldSection,
true,
DateRangeValidationError
Expand Down Expand Up @@ -151,11 +153,9 @@ const BrowserSingleInputDateRangeField = React.forwardRef(
),
};

const fieldResponse = useSingleInputDateRangeField<
Dayjs,
true,
typeof textFieldProps
>({ ...textFieldProps, enableAccessibleFieldDOMStructure: true });
const fieldResponse = useSingleInputDateRangeField<true, typeof textFieldProps>(
textFieldProps,
);

/* If you don't need a clear button, you can skip the use of this hook */
const processedFieldProps = useClearableField({
Expand All @@ -179,7 +179,7 @@ const BrowserSingleInputDateRangeField = React.forwardRef(
BrowserSingleInputDateRangeField.fieldType = 'single-input';

const BrowserSingleInputDateRangePicker = React.forwardRef(
(props: DateRangePickerProps<Dayjs>, ref: React.Ref<HTMLDivElement>) => {
(props: DateRangePickerProps, ref: React.Ref<HTMLDivElement>) => {
const [isOpen, setIsOpen] = React.useState(false);

const toggleOpen = () => setIsOpen((currentOpen) => !currentOpen);
Expand Down
1 change: 0 additions & 1 deletion docs/data/date-pickers/custom-field/JoyV6Field.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import {
useTheme as useMaterialTheme,
useColorScheme as useMaterialColorScheme,
Expand Down
Loading
Loading