-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Allow to customize the month and the year buttons
- Loading branch information
1 parent
35f56dc
commit 51bcf00
Showing
50 changed files
with
356 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
docs/data/date-pickers/custom-views/MonthButtonComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
import { styled } from '@mui/material/styles'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar'; | ||
|
||
const CustomMonthButton = styled('button')({ | ||
margin: '8px 0', | ||
height: 36, | ||
width: 72, | ||
}); | ||
|
||
export default function MonthButtonComponent() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateCalendar']}> | ||
<DateCalendar | ||
slots={{ monthButton: CustomMonthButton }} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
docs/data/date-pickers/custom-views/MonthButtonComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
import { styled } from '@mui/material/styles'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar'; | ||
|
||
const CustomMonthButton = styled('button')({ | ||
margin: '8px 0', | ||
height: 36, | ||
width: 72, | ||
}); | ||
|
||
export default function MonthButtonComponent() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateCalendar']}> | ||
<DateCalendar | ||
slots={{ monthButton: CustomMonthButton }} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
docs/data/date-pickers/custom-views/MonthButtonComponent.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<DateCalendar | ||
slots={{ monthButton: CustomMonthButton }} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> |
23 changes: 23 additions & 0 deletions
23
docs/data/date-pickers/custom-views/MonthButtonComponentProps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar'; | ||
|
||
export default function MonthButtonComponentProps() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateCalendar']}> | ||
<DateCalendar | ||
slotProps={{ | ||
monthButton: (ownerState) => ({ | ||
title: ownerState['aria-label'], | ||
}), | ||
}} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
docs/data/date-pickers/custom-views/MonthButtonComponentProps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar'; | ||
|
||
export default function MonthButtonComponentProps() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateCalendar']}> | ||
<DateCalendar | ||
slotProps={{ | ||
monthButton: (ownerState) => ({ | ||
title: ownerState['aria-label'], | ||
}), | ||
}} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
docs/data/date-pickers/custom-views/MonthButtonComponentProps.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<DateCalendar | ||
slotProps={{ | ||
monthButton: (ownerState) => ({ | ||
title: ownerState['aria-label'], | ||
}), | ||
}} | ||
views={['month', 'day']} | ||
openTo="month" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
productId: x-date-pickers | ||
title: Date and Time Pickers - Custom views | ||
components: PickersCalendarHeader, PickersRangeCalendarHeader, PickersMonth | ||
--- | ||
|
||
# Custom views | ||
|
||
<p class="description">Learn how to override the default DOM structure of the views.</p> | ||
|
||
## Calendar header | ||
|
||
The calendar header is available on any component that renders a calendar to select a date or a range of dates. | ||
It allows the user to navigate through months and to switch to the month and year views when available. | ||
|
||
### Component props | ||
|
||
You can pass props to the calendar header as shown below: | ||
|
||
{{"demo": "CalendarHeaderComponentProps.js", "defaultCodeOpen": false}} | ||
|
||
### Component | ||
|
||
You can pass custom components to replace the header, as shown below: | ||
|
||
{{"demo": "CalendarHeaderComponent.js", "defaultCodeOpen": false}} | ||
|
||
When used with a date range component, | ||
you receive three additional props to let you handle scenarios where multiple months are rendered: | ||
|
||
- `calendars`: The number of calendars rendered | ||
- `month`: The month used for the header being rendered | ||
- `monthIndex`: The index of the month used for the header being rendered | ||
|
||
The demo below shows how to navigate the months two by two: | ||
|
||
{{"demo": "CalendarHeaderComponentRange.js", "defaultCodeOpen": false}} | ||
|
||
## Month button | ||
|
||
### Component props | ||
|
||
You can pass props to the month button as shown below: | ||
|
||
{{"demo": "MonthButtonComponentProps.js"}} | ||
|
||
### Component | ||
|
||
You can pass custom components to replace the month button, as shown below: | ||
|
||
{{"demo": "MonthButtonComponent.js"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import * as pageProps from 'docsx/data/date-pickers/custom-views/custom-views.md?muiMarkdown'; | ||
|
||
export default function Page() { | ||
return <MarkdownDocs {...pageProps} />; | ||
} |
Oops, something went wrong.