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] Remove plural in "Pickers" on recently introduced APIs #15297

Merged
merged 4 commits into from
Nov 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';

import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';

function CustomActionBar(props) {
const { onAccept, onClear, onCancel, onSetToday, actions, className } = props;
const translations = usePickersTranslations();
const translations = usePickerTranslations();
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
const id = useId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';
import { PickersActionBarProps } from '@mui/x-date-pickers/PickersActionBar';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';

function CustomActionBar(props: PickersActionBarProps) {
const { onAccept, onClear, onCancel, onSetToday, actions, className } = props;
const translations = usePickersTranslations();
const translations = usePickerTranslations();
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
const open = Boolean(anchorEl);
const id = useId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useValidation, validateDate } from '@mui/x-date-pickers/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';

function ButtonDateField(props) {
Expand All @@ -24,7 +24,7 @@ function ButtonDateField(props) {
...other
} = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -35,10 +35,10 @@ function ButtonDateField(props) {
});

const handleTogglePicker = (event) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useValidation, validateDate } from '@mui/x-date-pickers/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';

function ButtonDateField(props: DatePickerFieldProps) {
Expand All @@ -28,7 +28,7 @@ function ButtonDateField(props: DatePickerFieldProps) {
...other
} = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -39,10 +39,10 @@ function ButtonDateField(props: DatePickerFieldProps) {
});

const handleTogglePicker = (event: React.UIEvent) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { validateDateRange } from '@mui/x-date-pickers-pro/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';

function ButtonDateRangeField(props) {
Expand All @@ -26,7 +26,7 @@ function ButtonDateRangeField(props) {
...other
} = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -37,10 +37,10 @@ function ButtonDateRangeField(props) {
});

const handleTogglePicker = (event) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { validateDateRange } from '@mui/x-date-pickers-pro/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';

function ButtonDateRangeField(props: DateRangePickerFieldProps) {
Expand All @@ -30,7 +30,7 @@ function ButtonDateRangeField(props: DateRangePickerFieldProps) {
...other
} = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -41,10 +41,10 @@ function ButtonDateRangeField(props: DateRangePickerFieldProps) {
});

const handleTogglePicker = (event: React.UIEvent) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useValidation, validateDate } from '@mui/x-date-pickers/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';
import { CalendarIcon } from '@mui/x-date-pickers/icons';

Expand All @@ -16,7 +16,7 @@ function ReadOnlyDateField(props) {
const { value, timezone, format } = internalProps;
const { InputProps, slotProps, slots, ...other } = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -27,10 +27,10 @@ function ReadOnlyDateField(props) {
});

const handleTogglePicker = (event) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useValidation, validateDate } from '@mui/x-date-pickers/validation';
import {
useSplitFieldProps,
useParsedFormat,
usePickersContext,
usePickerContext,
} from '@mui/x-date-pickers/hooks';
import { CalendarIcon } from '@mui/x-date-pickers/icons';

Expand All @@ -20,7 +20,7 @@ function ReadOnlyDateField(props: DatePickerFieldProps) {
const { value, timezone, format } = internalProps;
const { InputProps, slotProps, slots, ...other } = forwardedProps;

const pickersContext = usePickersContext();
const pickerContext = usePickerContext();

const parsedFormat = useParsedFormat(internalProps);
const { hasValidationError } = useValidation({
Expand All @@ -31,10 +31,10 @@ function ReadOnlyDateField(props: DatePickerFieldProps) {
});

const handleTogglePicker = (event: React.UIEvent) => {
if (pickersContext.open) {
pickersContext.onClose(event);
if (pickerContext.open) {
pickerContext.onClose(event);
} else {
pickersContext.onOpen(event);
pickerContext.onOpen(event);
}
};

Expand Down
6 changes: 3 additions & 3 deletions docs/data/date-pickers/localization/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ Note that these translations of the date and time picker components depend on th

## Access the translations in slots and subcomponents

You can use the `usePickersTranslations` hook to access the translations in your custom components.
You can use the `usePickerTranslations` hook to access the translations in your custom components.

```tsx
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';

const translations = usePickersTranslations();
const translations = usePickerTranslations();
```

:::info
Expand Down
36 changes: 35 additions & 1 deletion docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,40 @@ const theme = createTheme({
});
```

## Renamed variables

The following variables were renamed to have a coherent `Picker` / `Pickers` prefix:

- `usePickersTranslation`

```diff
- import { usePickersTranslation } from '@mui/x-date-pickers/hooks';
- import { usePickersTranslation } from '@mui/x-date-pickers';
- import { usePickersTranslation } from '@mui/x-date-pickers-pro';

+ import { usePickerTranslation } from '@mui/x-date-pickers/hooks';
+ import { usePickerTranslation } from '@mui/x-date-pickers';
+ import { usePickerTranslation } from '@mui/x-date-pickers-pro';

- const translations = usePickersTranslation();
+ const translations = usePickerTranslation();
```

- `usePickersContext`

```diff
- import { usePickersContext } from '@mui/x-date-pickers/hooks';
- import { usePickersContext } from '@mui/x-date-pickers';
- import { usePickersContext } from '@mui/x-date-pickers-pro';

+ import { usePickerContext } from '@mui/x-date-pickers/hooks';
+ import { usePickerContext } from '@mui/x-date-pickers';
+ import { usePickerContext } from '@mui/x-date-pickers-pro';

- const pickersContext = usePickersContext();
+ const pickerContext = usePickerContext();
```

## Removed types

The following types are no longer exported by `@mui/x-date-pickers` and/or `@mui/x-date-pickers-pro`.
Expand Down Expand Up @@ -381,7 +415,7 @@ If you have customized those translation keys, you have to update them following
- If you using this translation key in a custom component:

```diff
const translations = usePickersTranslations();
const translations = usePickerTranslations();

-const clockLabelText = translations.clockLabelText(
- view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
useControlledValueWithTimezone,
useViews,
PickerRangeValue,
usePickersPrivateContext,
usePickerPrivateContext,
} from '@mui/x-date-pickers/internals';
import { warnOnce } from '@mui/x-internals/warning';
import { PickerValidDate } from '@mui/x-date-pickers/models';
Expand Down Expand Up @@ -305,7 +305,7 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar(
timezone,
});

const { ownerState: pickersOwnerState } = usePickersPrivateContext();
const { ownerState: pickersOwnerState } = usePickerPrivateContext();
const ownerState: DateRangeCalendarOwnerState = {
...pickersOwnerState,
isDraggingDay: isDragging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ExportedBaseToolbarProps,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
import { UseRangePositionResponse } from '../internals/hooks/useRangePosition';
import {
DateRangePickerToolbarClasses,
Expand Down Expand Up @@ -91,7 +91,7 @@ const DateRangePickerToolbar = React.forwardRef(function DateRangePickerToolbar(
...other
} = props;

const translations = usePickersTranslations();
const translations = usePickerTranslations();

const startDateValue = start
? utils.formatByString(start, toolbarFormat || utils.formats.shortDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ExportedBaseTabsProps,
isDatePickerView,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
import IconButton from '@mui/material/IconButton';
import Button from '@mui/material/Button';
import {
Expand Down Expand Up @@ -123,7 +123,7 @@ const DateTimeRangePickerTabs = function DateTimeRangePickerTabs(
sx,
} = props;

const translations = usePickersTranslations();
const translations = usePickerTranslations();
const classes = useUtilityClasses(props);
const value = React.useMemo(() => viewToTab(view, rangePosition), [view, rangePosition]);
const isPreviousHidden = value === 'start-date';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
WrapperVariant,
PickerRangeValue,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import {
DateTimePickerToolbarProps,
Expand Down Expand Up @@ -156,7 +156,7 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
toolbarPlaceholder,
};

const translations = usePickersTranslations();
const translations = usePickerTranslations();

const ownerState = props;
const classes = useUtilityClasses(ownerState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@mui/x-date-pickers/internals';
import { extractValidationProps } from '@mui/x-date-pickers/validation';
import { PickerOwnerState } from '@mui/x-date-pickers/models';
import { PickersLayoutOwnerState } from '@mui/x-date-pickers/PickersLayout';
import { PickerLayoutOwnerState } from '@mui/x-date-pickers/PickersLayout';
import resolveComponentProps from '@mui/utils/resolveComponentProps';
import { refType } from '@mui/utils';
import {
Expand Down Expand Up @@ -193,7 +193,7 @@ const DesktopDateTimeRangePicker = React.forwardRef(function DesktopDateTimeRang
toolbarVariant: 'desktop',
...defaultizedProps.slotProps?.toolbar,
},
actionBar: (ownerState: PickersLayoutOwnerState) => ({
actionBar: (ownerState: PickerLayoutOwnerState) => ({
actions: actionBarActions,
...resolveComponentProps(defaultizedProps.slotProps?.actionBar, ownerState),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
usePreviousMonthDisabled,
useUtils,
} from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
import { PickersRangeCalendarHeaderProps } from './PickersRangeCalendarHeader.types';

type PickersRangeCalendarHeaderComponent = ((
Expand All @@ -28,7 +28,7 @@ const PickersRangeCalendarHeader = React.forwardRef(function PickersRangeCalenda
ref: React.Ref<HTMLDivElement>,
) {
const utils = useUtils();
const translations = usePickersTranslations();
const translations = usePickerTranslations();

const { calendars, month, monthIndex, labelId, ...other } = props;
const {
Expand Down
Loading