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] Stop using WrapperVariantContext in Clock #8083

Merged
merged 6 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/date-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/desktop-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true on desktop, false on mobile" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/mobile-date-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/mobile-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true on desktop, false on mobile" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/static-date-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"components": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/static-time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true on desktop, false on mobile" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"components": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/date-pickers/time-picker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"ampm": { "type": { "name": "bool" }, "default": "`utils.is12HourCycleInCurrentLocale()`" },
"ampmInClock": { "type": { "name": "bool" } },
"ampmInClock": { "type": { "name": "bool" }, "default": "true on desktop, false on mobile" },
"autoFocus": { "type": { "name": "bool" } },
"className": { "type": { "name": "string" } },
"closeOnSelect": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DateTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default was wrong. 🙈

*/
ampmInClock: PropTypes.bool,
/**
Expand Down
8 changes: 5 additions & 3 deletions packages/x-date-pickers/src/DateTimePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export interface BaseDateTimePickerProps<TDate>
extends BasePickerInputProps<TDate | null, TDate, DateOrTimeView, DateTimeValidationError>,
Omit<ExportedDateCalendarProps<TDate>, 'onViewChange'>,
ExportedTimeClockProps<TDate> {
// TODO: Change default to be false on mobile, when `DateTimePickerToolbar` will support `ampm` buttons
// https://github.com/mui/mui-x/issues/7279
/**
* 12h/24h view for hour selection clock.
* @default `utils.is12HourCycleInCurrentLocale()`
* Display ampm controls under the clock (instead of in the toolbar).
* @default true
*/
ampm?: boolean;
ampmInClock?: boolean;
/**
* Minimal selectable moment of time with binding to date, to set min time in each day use `minTime`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ const DesktopDateTimePicker = React.forwardRef(function DesktopDateTimePicker<TD
seconds: null,
...defaultizedProps.viewRenderers,
};
const ampmInClock = defaultizedProps.ampmInClock ?? true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be pointless until #7279 is implemented.
Do you think it makes sense to omit it for now?


// Props with the default values specific to the desktop variant
const props = {
...defaultizedProps,
viewRenderers,
yearsPerRow: defaultizedProps.yearsPerRow ?? 4,
ampmInClock,
slots: {
field: DateTimeField,
openPickerIcon: Calendar,
Expand All @@ -58,6 +60,7 @@ const DesktopDateTimePicker = React.forwardRef(function DesktopDateTimePicker<TD
}),
toolbar: {
hidden: true,
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
tabs: {
Expand Down Expand Up @@ -89,7 +92,7 @@ DesktopDateTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ const DesktopTimePicker = React.forwardRef(function DesktopTimePicker<TDate>(
...defaultizedProps.viewRenderers,
};

const ampmInClock = defaultizedProps.ampmInClock ?? true;

// Props with the default values specific to the desktop variant
const props = {
...defaultizedProps,
ampmInClock,
viewRenderers,
slots: {
field: TimeField,
Expand All @@ -53,6 +56,7 @@ const DesktopTimePicker = React.forwardRef(function DesktopTimePicker<TDate>(
}),
toolbar: {
hidden: true,
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
},
Expand Down Expand Up @@ -80,7 +84,7 @@ DesktopTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true on desktop, false on mobile
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ const MobileDateTimePicker = React.forwardRef(function MobileDateTimePicker<TDat
seconds: renderTimeViewClock,
...defaultizedProps.viewRenderers,
};
const ampmInClock = defaultizedProps.ampmInClock ?? false;
LukasTy marked this conversation as resolved.
Show resolved Hide resolved

// Props with the default values specific to the mobile variant
const props = {
...defaultizedProps,
viewRenderers,
ampmInClock,
slots: {
field: DateTimeField,
...defaultizedProps.slots,
Expand All @@ -60,6 +62,7 @@ const MobileDateTimePicker = React.forwardRef(function MobileDateTimePicker<TDat
}),
toolbar: {
hidden: false,
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
tabs: {
Expand Down Expand Up @@ -91,7 +94,7 @@ MobileDateTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ const MobileTimePicker = React.forwardRef(function MobileTimePicker<TDate>(
seconds: renderTimeViewClock,
...defaultizedProps.viewRenderers,
};
const ampmInClock = defaultizedProps.ampmInClock ?? false;

// Props with the default values specific to the mobile variant
const props = {
...defaultizedProps,
ampmInClock,
viewRenderers,
slots: {
field: TimeField,
Expand All @@ -51,6 +53,7 @@ const MobileTimePicker = React.forwardRef(function MobileTimePicker<TDate>(
}),
toolbar: {
hidden: false,
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
},
Expand Down Expand Up @@ -78,7 +81,7 @@ MobileTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true on desktop, false on mobile
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const StaticDateTimePicker = React.forwardRef(function StaticDateTimePicker<TDat
>(inProps, 'MuiStaticDateTimePicker');

const displayStaticWrapperAs = defaultizedProps.displayStaticWrapperAs ?? 'mobile';
const ampmInClock = defaultizedProps.ampmInClock ?? displayStaticWrapperAs === 'desktop';

const viewRenderers: PickerViewRendererLookup<TDate | null, DateOrTimeView, any, {}> = {
day: renderDateViewCalendar,
Expand All @@ -40,6 +41,7 @@ const StaticDateTimePicker = React.forwardRef(function StaticDateTimePicker<TDat
...defaultizedProps,
viewRenderers,
displayStaticWrapperAs,
ampmInClock,
yearsPerRow: defaultizedProps.yearsPerRow ?? (displayStaticWrapperAs === 'mobile' ? 3 : 4),
slotProps: {
...defaultizedProps.slotProps,
Expand All @@ -49,6 +51,7 @@ const StaticDateTimePicker = React.forwardRef(function StaticDateTimePicker<TDat
},
toolbar: {
hidden: displayStaticWrapperAs === 'desktop',
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
},
Expand Down Expand Up @@ -76,7 +79,7 @@ StaticDateTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const StaticTimePicker = React.forwardRef(function StaticTimePicker<TDate>(
);

const displayStaticWrapperAs = defaultizedProps.displayStaticWrapperAs ?? 'mobile';
const ampmInClock = defaultizedProps.ampmInClock ?? displayStaticWrapperAs === 'desktop';

const viewRenderers: PickerViewRendererLookup<TDate | null, TimeView, any, {}> = {
hours: renderTimeViewClock,
Expand All @@ -36,10 +37,12 @@ const StaticTimePicker = React.forwardRef(function StaticTimePicker<TDate>(
...defaultizedProps,
viewRenderers,
displayStaticWrapperAs,
ampmInClock,
slotProps: {
...defaultizedProps.slotProps,
toolbar: {
hidden: displayStaticWrapperAs === 'desktop',
ampmInClock,
...defaultizedProps.slotProps?.toolbar,
},
},
Expand Down Expand Up @@ -67,7 +70,7 @@ StaticTimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true on desktop, false on mobile
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
4 changes: 1 addition & 3 deletions packages/x-date-pickers/src/TimeClock/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@mui/utils';
import { ClockPointer } from './ClockPointer';
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
import { WrapperVariantContext } from '../internals/components/wrappers/WrapperVariantContext';
import type { PickerSelectionState } from '../internals/hooks/usePicker';
import { useMeridiemMode } from '../internals/hooks/date-helpers-hooks';
import { getHours, getMinutes } from './shared';
Expand Down Expand Up @@ -203,7 +202,6 @@ export function Clock<TDate>(inProps: ClockProps<TDate>) {

const utils = useUtils<TDate>();
const localeText = useLocaleText<TDate>();
const wrapperVariant = React.useContext(WrapperVariantContext);
const isMoving = React.useRef(false);
const classes = useUtilityClasses(ownerState);

Expand Down Expand Up @@ -352,7 +350,7 @@ export function Clock<TDate>(inProps: ClockProps<TDate>) {
{children}
</ClockWrapper>
</ClockClock>
{ampm && (wrapperVariant === 'desktop' || ampmInClock) && (
{ampm && ampmInClock && (
<React.Fragment>
<ClockAmButton
data-mui-test="in-clock-am-btn"
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TimePicker.propTypes = {
ampm: PropTypes.bool,
/**
* Display ampm controls under the clock (instead of in the toolbar).
* @default false
* @default true on desktop, false on mobile
*/
ampmInClock: PropTypes.bool,
/**
Expand Down
6 changes: 3 additions & 3 deletions packages/x-date-pickers/src/TimePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export interface BaseTimePickerProps<TDate>
extends BasePickerInputProps<TDate | null, TDate, TimeView, TimeValidationError>,
ExportedTimeClockProps<TDate> {
/**
* 12h/24h view for hour selection clock.
* @default `utils.is12HourCycleInCurrentLocale()`
* Display ampm controls under the clock (instead of in the toolbar).
* @default true on desktop, false on mobile
*/
ampm?: boolean;
ampmInClock?: boolean;
/**
* Overrideable components.
* @default {}
Expand Down