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] Add option to change order of displayed years #11780

Merged
merged 24 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
68a3179
[pickers] Add prop to show years in reverse chronological order
thomasmoon Sep 12, 2024
70d25f2
[pickers] Update proptypes and typescript formatting
thomasmoon Sep 13, 2024
446eb8f
[pickers] Fix lint errors
thomasmoon Sep 13, 2024
c448b76
[pickers] Fix typescript formatting
thomasmoon Sep 13, 2024
69db587
[pickers] Update api docs
thomasmoon Sep 13, 2024
d17edec
[pickers] Last changes based on feedback
thomasmoon Sep 13, 2024
16edac1
[pickers] Fix typescript formatting
thomasmoon Sep 13, 2024
9f3bd98
Update docs/data/date-pickers/date-calendar/ReverseYearCalendar.tsx
thomasmoon Sep 13, 2024
052ca9d
[pickers] Update reverseYears to yearsOrder
thomasmoon Sep 13, 2024
7f89a3b
[pickers] Fix prettier issues
thomasmoon Sep 13, 2024
1aa5f89
[picker] Update default text for yearsPerRow to cover all the cases
thomasmoon Sep 13, 2024
f7c41fe
[pickers] Update default for yearsPerRow on DesktopDatePicker
thomasmoon Sep 13, 2024
ce637ed
[pickers] Fix types on DateTimePicker
thomasmoon Sep 13, 2024
51c21b0
[pickers] Update DesktopDatePicker default for yearsPerRow
thomasmoon Sep 13, 2024
787ee3e
[pickers] Finalize prop types
thomasmoon Sep 13, 2024
80a4e4c
[pickers] Update api docs
thomasmoon Sep 13, 2024
4984898
[pickers] Harmonize display of variables on slot props
thomasmoon Sep 13, 2024
c303d25
Texts on new lines.
thomasmoon Sep 17, 2024
4a7c1a1
[pickers] Order of years texts on new lines
thomasmoon Sep 17, 2024
babd9c1
[pickers] Improve yearsOrder documentation on YearCalendar types
thomasmoon Sep 17, 2024
bb75868
[pickers] Remove unneeded default for yearsOrder on dateViewRenderers
thomasmoon Sep 17, 2024
09a74a3
[pickers] Remove unneeded default for yearsOrder on DateCalendar comp…
thomasmoon Sep 17, 2024
aed3349
[pickers] Adjust component specific documentation by adding correct o…
thomasmoon Sep 17, 2024
fde39ca
Apply suggestions from code review
LukasTy Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer, DemoItem } from '@mui/x-date-pickers/internals/demo';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { YearCalendar } from '@mui/x-date-pickers/YearCalendar';

const currentYear = dayjs();

export default function YearsOrderDescendingCalendar() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['YearCalendar']}>
<DemoItem label="Years in descending order">
<YearCalendar maxDate={currentYear} yearsOrder="desc" />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer, DemoItem } from '@mui/x-date-pickers/internals/demo';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { YearCalendar } from '@mui/x-date-pickers/YearCalendar';

const currentYear = dayjs();

export default function YearsOrderDescendingCalendar() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['YearCalendar']}>
<DemoItem label="Years in descending order">
<YearCalendar maxDate={currentYear} yearsOrder="desc" />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<DemoItem label="Years in descending order">
<YearCalendar maxDate={currentYear} yearsOrder="desc" />
</DemoItem>
6 changes: 6 additions & 0 deletions docs/data/date-pickers/date-calendar/date-calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ If you only need the `year` view or the `month` view, you can use the `YearCalen

{{"demo": "YearMonthCalendar.js", "defaultCodeOpen": false}}

### Order of years

By default, years are displayed in ascending order, chronologically from the minimum year to the maximum. Set the `yearsOrder` prop to `desc` to show the years in descending order.
thomasmoon marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "YearsOrderDescendingCalendar.js", "defaultCodeOpen": false}}

## Day view customization

### Show additional days
Expand Down
24 changes: 24 additions & 0 deletions docs/data/date-pickers/date-picker/DatePickerYearsOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

const currentYear = dayjs();

export default function DatePickerYearsOrder() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker
label="Years in descending order"
maxDate={currentYear}
openTo="year"
views={['year', 'month']}
yearsOrder="desc"
/>
</DemoContainer>
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
</LocalizationProvider>
);
}
24 changes: 24 additions & 0 deletions docs/data/date-pickers/date-picker/DatePickerYearsOrder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

const currentYear = dayjs();

export default function DatePickerYearsOrder() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker
label="Years in descending order"
maxDate={currentYear}
openTo="year"
views={['year', 'month']}
yearsOrder="desc"
/>
</DemoContainer>
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DatePicker
label="Years in descending order"
maxDate={currentYear}
openTo="year"
views={['year', 'month']}
yearsOrder="desc"
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
/>
6 changes: 6 additions & 0 deletions docs/data/date-pickers/date-picker/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ If the view defined in `openTo` is not the first view, then the views before wil
(for example view the default behaviors, the `year` is only accessible when clicking on the toolbar).
:::

## Order of years

By default, years are displayed in ascending order, chronologically from the minimum year to the maximum. Set the `yearsOrder` prop to `desc` to show the years in descending order.
thomasmoon marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "DatePickerYearsOrder.js"}}

## Landscape orientation

By default, the Date Picker component automatically sets the orientation based on the `window.orientation` value.
Expand Down
2 changes: 1 addition & 1 deletion docs/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
12 changes: 8 additions & 4 deletions docs/pages/x/api/date-pickers/date-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@
"description": "Array&lt;'day'<br>&#124;&nbsp;'month'<br>&#124;&nbsp;'year'&gt;"
}
},
"yearsOrder": {
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'" },
"default": "'asc'"
},
"yearsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "3"
"default": "4 on desktop, 3 on mobile"
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
}
},
"name": "DateCalendar",
Expand Down Expand Up @@ -172,7 +176,7 @@
},
{
"name": "monthButton",
"description": "Button displayed to render a single month in the \"month\" view.",
"description": "Button displayed to render a single month in the `month` view.",
"default": "MonthCalendarButton",
"class": null
},
Expand Down Expand Up @@ -202,13 +206,13 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
{
"name": "yearButton",
"description": "Button displayed to render a single year in the \"year\" view.",
"description": "Button displayed to render a single year in the `year` view.",
"default": "YearCalendarButton",
"class": null
}
Expand Down
12 changes: 8 additions & 4 deletions docs/pages/x/api/date-pickers/date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@
"description": "Array&lt;'day'<br>&#124;&nbsp;'month'<br>&#124;&nbsp;'year'&gt;"
}
},
"yearsOrder": {
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'" },
"default": "'asc'"
},
"yearsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "4 on desktop, 3 on mobile"
"default": "4"
}
},
"name": "DatePicker",
Expand Down Expand Up @@ -281,7 +285,7 @@
},
{
"name": "monthButton",
"description": "Button displayed to render a single month in the \"month\" view.",
"description": "Button displayed to render a single month in the `month` view.",
"default": "MonthCalendarButton",
"class": null
},
Expand Down Expand Up @@ -334,7 +338,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand All @@ -352,7 +356,7 @@
},
{
"name": "yearButton",
"description": "Button displayed to render a single year in the \"year\" view.",
"description": "Button displayed to render a single year in the `year` view.",
"default": "YearCalendarButton",
"class": null
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/date-range-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/date-range-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand Down
10 changes: 7 additions & 3 deletions docs/pages/x/api/date-pickers/date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@
"description": "Array&lt;'day'<br>&#124;&nbsp;'hours'<br>&#124;&nbsp;'minutes'<br>&#124;&nbsp;'month'<br>&#124;&nbsp;'seconds'<br>&#124;&nbsp;'year'&gt;"
}
},
"yearsOrder": {
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'" },
"default": "'asc'"
},
"yearsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "4 on desktop, 3 on mobile"
Expand Down Expand Up @@ -321,7 +325,7 @@
},
{
"name": "monthButton",
"description": "Button displayed to render a single month in the \"month\" view.",
"description": "Button displayed to render a single month in the `month` view.",
"default": "MonthCalendarButton",
"class": null
},
Expand Down Expand Up @@ -374,7 +378,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand All @@ -398,7 +402,7 @@
},
{
"name": "yearButton",
"description": "Button displayed to render a single year in the \"year\" view.",
"description": "Button displayed to render a single year in the `year` view.",
"default": "YearCalendarButton",
"class": null
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/date-time-range-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand Down
10 changes: 7 additions & 3 deletions docs/pages/x/api/date-pickers/desktop-date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
"description": "Array&lt;'day'<br>&#124;&nbsp;'month'<br>&#124;&nbsp;'year'&gt;"
}
},
"yearsOrder": {
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'" },
"default": "'asc'"
},
"yearsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "4"
Expand Down Expand Up @@ -259,7 +263,7 @@
},
{
"name": "monthButton",
"description": "Button displayed to render a single month in the \"month\" view.",
"description": "Button displayed to render a single month in the `month` view.",
"default": "MonthCalendarButton",
"class": null
},
Expand Down Expand Up @@ -312,7 +316,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand All @@ -330,7 +334,7 @@
},
{
"name": "yearButton",
"description": "Button displayed to render a single year in the \"year\" view.",
"description": "Button displayed to render a single year in the `year` view.",
"default": "YearCalendarButton",
"class": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand Down
10 changes: 7 additions & 3 deletions docs/pages/x/api/date-pickers/desktop-date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
"description": "Array&lt;'day'<br>&#124;&nbsp;'hours'<br>&#124;&nbsp;'minutes'<br>&#124;&nbsp;'month'<br>&#124;&nbsp;'seconds'<br>&#124;&nbsp;'year'&gt;"
}
},
"yearsOrder": {
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'" },
"default": "'asc'"
},
"yearsPerRow": {
"type": { "name": "enum", "description": "3<br>&#124;&nbsp;4" },
"default": "4"
Expand Down Expand Up @@ -299,7 +303,7 @@
},
{
"name": "monthButton",
"description": "Button displayed to render a single month in the \"month\" view.",
"description": "Button displayed to render a single month in the `month` view.",
"default": "MonthCalendarButton",
"class": null
},
Expand Down Expand Up @@ -352,7 +356,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand All @@ -376,7 +380,7 @@
},
{
"name": "yearButton",
"description": "Button displayed to render a single year in the \"year\" view.",
"description": "Button displayed to render a single year in the `year` view.",
"default": "YearCalendarButton",
"class": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
},
{
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is \"year\".",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is `year`.",
"default": "ArrowDropDown",
"class": null
},
Expand Down
Loading