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 7 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
20 changes: 20 additions & 0 deletions docs/data/date-pickers/date-calendar/ReverseYearCalendar.js
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 ReverseYearCalendar() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['YearCalendar']}>
<DemoItem label="Years in reverse">
<YearCalendar maxDate={currentYear} reverseYears />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
);
}
20 changes: 20 additions & 0 deletions docs/data/date-pickers/date-calendar/ReverseYearCalendar.tsx
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 ReverseYearCalendar() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['YearCalendar']}>
<DemoItem label="Years in reverse">
thomasmoon marked this conversation as resolved.
Show resolved Hide resolved
<YearCalendar maxDate={currentYear} reverseYears />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<DemoItem label="Years in reverse">
<YearCalendar maxDate={currentYear} reverseYears />
</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}}

### Reverse years

The `reverseYears` prop can be set to show the years in reverse chronological order.

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

## Day view customization

### Show additional days
Expand Down
24 changes: 24 additions & 0 deletions docs/data/date-pickers/date-picker/DatePickerReverseYears.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';
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 DatePickerReverseYears() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker
label="Years in reverse"
maxDate={currentYear}
openTo="year"
reverseYears
views={['year', 'month']}
/>
</DemoContainer>
</LocalizationProvider>
);
}
24 changes: 24 additions & 0 deletions docs/data/date-pickers/date-picker/DatePickerReverseYears.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';
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 DatePickerReverseYears() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker
label="Years in reverse"
maxDate={currentYear}
openTo="year"
reverseYears
views={['year', 'month']}
/>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DatePicker
label="Years in reverse"
maxDate={currentYear}
openTo="year"
reverseYears
views={['year', 'month']}
/>
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).
:::

## Reverse years

The `reverseYears` prop can be set to show the years in reverse chronological order.

{{"demo": "DatePickerReverseYears.js"}}

## Landscape orientation

By default, the Date Picker component automatically sets the orientation based on the `window.orientation` value.
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/date-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"shouldDisableDate": {
"type": { "name": "func" },
"signature": {
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/desktop-date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/mobile-date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/mobile-date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"selectedSections": {
"type": {
"name": "union",
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/static-date-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"shouldDisableDate": {
"type": { "name": "func" },
"signature": {
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/static-date-time-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"returned": "React.ReactNode"
}
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"shouldDisableDate": {
"type": { "name": "func" },
"signature": {
Expand Down
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/year-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"type": { "name": "object" },
"default": "The closest valid year using the validation props, except callbacks such as `shouldDisableYear`."
},
"reverseYears": { "type": { "name": "bool" }, "default": "false" },
"shouldDisableYear": {
"type": { "name": "func" },
"signature": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"shouldDisableDate": {
"description": "Disable specific date.<br>Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.",
"typeDescriptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"selectedSections": {
"description": "The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type <code>FieldSectionType</code> is provided, the first section with that name will be selected. 3. If <code>&quot;all&quot;</code> is provided, all the sections will be selected. 4. If <code>null</code> is provided, no section will be selected. If not provided, the selected sections will be handled internally."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"shouldDisableDate": {
"description": "Disable specific date.<br>Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.",
"typeDescriptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
"description": "Component displaying when passed <code>loading</code> true.",
"typeDescriptions": { "React.ReactNode": "The node to render when loading." }
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"shouldDisableDate": {
"description": "Disable specific date.<br>Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.",
"typeDescriptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"referenceDate": {
"description": "The date used to generate the new value when both <code>value</code> and <code>defaultValue</code> are empty."
},
"reverseYears": {
"description": "If <code>false</code>, display the years in their default order (chronological) If <code>true</code>, reverse the order of displayed years"
},
"shouldDisableYear": {
"description": "Disable specific year.",
"typeDescriptions": {
Expand Down
8 changes: 8 additions & 0 deletions packages/x-date-pickers/src/DateCalendar/DateCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const DateCalendar = React.forwardRef(function DateCalendar<TDate extends
loading,
renderLoading,
displayWeekNumber,
reverseYears,
yearsPerRow,
monthsPerRow,
timezone: timezoneProp,
Expand Down Expand Up @@ -355,6 +356,7 @@ export const DateCalendar = React.forwardRef(function DateCalendar<TDate extends
hasFocus={hasFocus}
onFocusedViewChange={(isViewFocused) => setFocusedView('year', isViewFocused)}
yearsPerRow={yearsPerRow}
reverseYears={reverseYears}
referenceDate={referenceDate}
/>
)}
Expand Down Expand Up @@ -547,6 +549,12 @@ DateCalendar.propTypes = {
* @default () => <span data-mui-test="loading-progress">...</span>
*/
renderLoading: PropTypes.func,
/**
* If `false`, display the years in their default order (chronological)
* If `true`, reverse the order of displayed years
* @default false
*/
reverseYears: PropTypes.bool,
/**
* Disable specific date.
*
Expand Down
6 changes: 6 additions & 0 deletions packages/x-date-pickers/src/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ DatePicker.propTypes = {
* @default () => <span data-mui-test="loading-progress">...</span>
*/
renderLoading: PropTypes.func,
/**
* If `false`, display the years in their default order (chronological)
* If `true`, reverse the order of displayed years
* @default false
*/
reverseYears: PropTypes.bool,
/**
* The currently selected sections.
* This prop accepts four formats:
Expand Down
6 changes: 6 additions & 0 deletions packages/x-date-pickers/src/DateTimePicker/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ DateTimePicker.propTypes = {
* @default () => <span data-mui-test="loading-progress">...</span>
*/
renderLoading: PropTypes.func,
/**
* If `false`, display the years in their default order (chronological)
* If `true`, reverse the order of displayed years
* @default false
*/
reverseYears: PropTypes.bool,
/**
* The currently selected sections.
* This prop accepts four formats:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ export interface DateTimePickerProps<
* @example '@media (min-width: 720px)' or theme.breakpoints.up("sm")
*/
desktopModeMediaQuery?: string;
/**
* Years rendered per row.
* @default 4 on desktop, 3 on mobile
*/
yearsPerRow?: 3 | 4;
/**
* Overridable component slots.
* @default {}
Expand All @@ -58,4 +53,9 @@ export interface DateTimePickerProps<
* @default {}
*/
slotProps?: DateTimePickerSlotProps<TDate, TEnableAccessibleFieldDOMStructure>;
/**
* Years rendered per row.
* @default 4 on desktop, 3 on mobile
*/
yearsPerRow?: 3 | 4;
}
Loading