Skip to content

Commit

Permalink
Merge branch 'master' into clean-validation-api
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 5, 2024
2 parents db2fbcc + 2e38064 commit 80162f2
Show file tree
Hide file tree
Showing 69 changed files with 808 additions and 250 deletions.
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ module.exports = function getBabelConfig(api) {
'@babel/plugin-transform-runtime',
{
useESModules,
// any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0
version: '^7.4.4',
// any package needs to declare 7.25.0 as a runtime dependency. default is ^7.0.0
version: process.env.MUI_BABEL_RUNTIME_VERSION || '^7.25.0',
},
],
[
Expand Down
13 changes: 13 additions & 0 deletions docs/data/common-concepts/custom-components/CustomSlot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import FlightTakeoffIcon from '@mui/icons-material/FlightTakeoff';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlot() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker slots={{ openPickerIcon: FlightTakeoffIcon }} />
</LocalizationProvider>
);
}
13 changes: 13 additions & 0 deletions docs/data/common-concepts/custom-components/CustomSlot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import FlightTakeoffIcon from '@mui/icons-material/FlightTakeoff';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlot() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker slots={{ openPickerIcon: FlightTakeoffIcon }} />
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<DatePicker slots={{ openPickerIcon: FlightTakeoffIcon }} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import FlightTakeoffIcon from '@mui/icons-material/FlightTakeoff';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotAndSlotProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slots={{ openPickerIcon: FlightTakeoffIcon }}
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import FlightTakeoffIcon from '@mui/icons-material/FlightTakeoff';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotAndSlotProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slots={{ openPickerIcon: FlightTakeoffIcon }}
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<DatePicker
slots={{ openPickerIcon: FlightTakeoffIcon }}
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
18 changes: 18 additions & 0 deletions docs/data/common-concepts/custom-components/CustomSlotProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
</LocalizationProvider>
);
}
18 changes: 18 additions & 0 deletions docs/data/common-concepts/custom-components/CustomSlotProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DatePicker
slotProps={{
openPickerIcon: {
color: 'primary',
},
}}
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotPropsCallback() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slotProps={{
openPickerIcon: (ownerState) => ({
color: ownerState.open ? 'secondary' : 'primary',
}),
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function CustomSlotPropsCallback() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DatePicker
slotProps={{
openPickerIcon: (ownerState) => ({
color: ownerState.open ? 'secondary' : 'primary',
}),
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DatePicker
slotProps={{
openPickerIcon: (ownerState) => ({
color: ownerState.open ? 'secondary' : 'primary',
}),
}}
/>
63 changes: 63 additions & 0 deletions docs/data/common-concepts/custom-components/TypescriptCasting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as React from 'react';

import Stack from '@mui/material/Stack';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';

import { PickersCalendarHeader } from '@mui/x-date-pickers/PickersCalendarHeader';

function DisplayWeekNumberToggle({ value, onChange }) {
return (
<FormControlLabel
sx={{ ml: 2 }}
control={
<Switch
checked={value}
onChange={(event) => onChange(event.target.checked)}
/>
}
label="Display week number"
/>
);
}

function CustomCalendarHeader({
displayWeekNumber,
setDisplayWeekNumber,
...other
}) {
return (
<Stack>
<DisplayWeekNumberToggle
value={displayWeekNumber}
onChange={setDisplayWeekNumber}
/>
<PickersCalendarHeader {...other} />
</Stack>
);
}

export default function TypescriptCasting() {
const [displayWeekNumber, setDisplayWeekNumber] = React.useState(false);

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateCalendar
displayWeekNumber={displayWeekNumber}
// Cast the custom component to the type expected by the X component
slots={{
calendarHeader: CustomCalendarHeader,
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
},
}}
/>
</LocalizationProvider>
);
}
80 changes: 80 additions & 0 deletions docs/data/common-concepts/custom-components/TypescriptCasting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import {
DateCalendar,
DateCalendarSlots,
DateCalendarSlotProps,
} from '@mui/x-date-pickers/DateCalendar';
import { PropsFromSlot } from '@mui/x-date-pickers/models';
import { PickersCalendarHeader } from '@mui/x-date-pickers/PickersCalendarHeader';

function DisplayWeekNumberToggle({
value,
onChange,
}: {
value: boolean;
onChange: (value: boolean) => void;
}) {
return (
<FormControlLabel
sx={{ ml: 2 }}
control={
<Switch
checked={value}
onChange={(event) => onChange(event.target.checked)}
/>
}
label="Display week number"
/>
);
}

interface CustomCalendarHeaderProps
extends PropsFromSlot<DateCalendarSlots<Dayjs>['calendarHeader']> {
displayWeekNumber: boolean;
setDisplayWeekNumber: (displayWeekNumber: boolean) => void;
}

function CustomCalendarHeader({
displayWeekNumber,
setDisplayWeekNumber,
...other
}: CustomCalendarHeaderProps) {
return (
<Stack>
<DisplayWeekNumberToggle
value={displayWeekNumber}
onChange={setDisplayWeekNumber}
/>
<PickersCalendarHeader {...other} />
</Stack>
);
}

export default function TypescriptCasting() {
const [displayWeekNumber, setDisplayWeekNumber] = React.useState(false);

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateCalendar
displayWeekNumber={displayWeekNumber}
// Cast the custom component to the type expected by the X component
slots={{
calendarHeader:
CustomCalendarHeader as DateCalendarSlots<Dayjs>['calendarHeader'],
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
} as DateCalendarSlotProps<Dayjs>['calendarHeader'],
}}
/>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<DateCalendar
displayWeekNumber={displayWeekNumber}
// Cast the custom component to the type expected by the X component
slots={{
calendarHeader:
CustomCalendarHeader as DateCalendarSlots<Dayjs>['calendarHeader'],
}}
slotProps={{
calendarHeader: {
displayWeekNumber,
setDisplayWeekNumber,
} as DateCalendarSlotProps<Dayjs>['calendarHeader'],
}}
/>
Loading

0 comments on commit 80162f2

Please sign in to comment.