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 utils and value params from translations #14986

Merged
Show file tree
Hide file tree
Changes from 6 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
27 changes: 27 additions & 0 deletions docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,30 @@ const theme = createTheme({
},
});
```

## Deprecated parameters used on translation keys functions
arthurbalduini marked this conversation as resolved.
Show resolved Hide resolved

If you are using a Picker with controlled value and views and you need to compose some of the following translation keys: `openDatePickerDialogue`, `openTimePickerDialogue`, or `clockLabelText`, after upgrading to v8 you only need to pass the formatted value and the time view (only for `clockLabelText`):
arthurbalduini marked this conversation as resolved.
Show resolved Hide resolved

```js
const translations = useTranslations();

const openDatePickerDialogue = translations.openDatePickerDialogue(
value == null ? null : value.format('MM/DD/YYY'),
);
const openTimePickerDialogue = translations.openTimePickerDialogue(
value == null ? null : value.format('HH:mm:ss'),
);
const clockLabelText = translations.clockLabelText(
view,
value == null ? null : value.format('HH:mm:ss'),
);
```

Also the following types and interfaces no longer receive a generic type parameter:
arthurbalduini marked this conversation as resolved.
Show resolved Hide resolved

- `PickersComponentAgnosticLocaleText`
- `PickersInputComponentLocaleText`
- `PickersInputLocaleText`
- `PickersLocaleText`
- `PickersTranslationKeys`
4 changes: 2 additions & 2 deletions packages/x-date-pickers-pro/src/DateRangePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface BaseDateRangePickerProps<TDate extends PickerValidDate>
type UseDateRangePickerDefaultizedProps<
TDate extends PickerValidDate,
Props extends BaseDateRangePickerProps<TDate>,
> = LocalizedComponent<TDate, DefaultizedProps<Props, keyof BaseDateValidationProps<TDate>>>;
> = LocalizedComponent<DefaultizedProps<Props, keyof BaseDateValidationProps<TDate>>>;

export function useDateRangePickerDefaultizedProps<
TDate extends PickerValidDate,
Expand All @@ -81,7 +81,7 @@ export function useDateRangePickerDefaultizedProps<
name,
});

const localeText = React.useMemo<PickersInputLocaleText<TDate> | undefined>(() => {
const localeText = React.useMemo<PickersInputLocaleText | undefined>(() => {
if (themeProps.localeText?.toolbarTitle == null) {
return themeProps.localeText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ type UseDateTimeRangePickerDefaultizedProps<
TDate extends PickerValidDate,
Props extends BaseDateTimeRangePickerProps<TDate>,
> = LocalizedComponent<
TDate,
Omit<DefaultizedProps<Props, 'openTo' | 'ampm' | keyof BaseDateValidationProps<TDate>>, 'views'>
> & {
shouldRenderTimeInASingleColumn: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface UseEnrichedRangePickerFieldPropsParams<
disableOpenPicker?: boolean;
onBlur?: () => void;
label?: React.ReactNode;
localeText: PickersInputLocaleText<TDate> | undefined;
localeText: PickersInputLocaleText | undefined;
pickerSlotProps: RangePickerFieldSlotProps<TDate, TEnableAccessibleFieldDOMStructure> | undefined;
pickerSlots: RangePickerFieldSlots | undefined;
fieldProps: RangePickerPropsForFieldSlot<
Expand Down
3 changes: 1 addition & 2 deletions packages/x-date-pickers/src/DatePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ type UseDatePickerDefaultizedProps<
TDate extends PickerValidDate,
Props extends BaseDatePickerProps<TDate>,
> = LocalizedComponent<
TDate,
DefaultizedProps<Props, 'views' | 'openTo' | keyof BaseDateValidationProps<TDate>>
>;

Expand All @@ -86,7 +85,7 @@ export function useDatePickerDefaultizedProps<
name,
});

const localeText = React.useMemo<PickersInputLocaleText<TDate> | undefined>(() => {
const localeText = React.useMemo<PickersInputLocaleText | undefined>(() => {
if (themeProps.localeText?.toolbarTitle == null) {
return themeProps.localeText;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/x-date-pickers/src/DateTimePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type UseDateTimePickerDefaultizedProps<
TView extends DateOrTimeViewWithMeridiem,
Props extends BaseDateTimePickerProps<TDate, TView>,
> = LocalizedComponent<
TDate,
DefaultizedProps<
Props,
| 'views'
Expand All @@ -138,7 +137,7 @@ export function useDateTimePickerDefaultizedProps<

const ampm = themeProps.ampm ?? utils.is12HourCycleInCurrentLocale();

const localeText = React.useMemo<PickersInputLocaleText<TDate> | undefined>(() => {
const localeText = React.useMemo<PickersInputLocaleText | undefined>(() => {
if (themeProps.localeText?.toolbarTitle == null) {
return themeProps.localeText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('<LocalizationProvider />', () => {
</ThemeProvider>,
);

const localeText: PickersLocaleText<any> = handleContextChange.lastCall.args[0].localeText;
const localeText: PickersLocaleText = handleContextChange.lastCall.args[0].localeText;
expect(localeText.start).to.equal('Debut');
expect(localeText.end).to.equal('End');
});
Expand All @@ -72,7 +72,7 @@ describe('<LocalizationProvider />', () => {
</ThemeProvider>,
);

const localeText: PickersLocaleText<any> = handleContextChange.lastCall.args[0].localeText;
const localeText: PickersLocaleText = handleContextChange.lastCall.args[0].localeText;
expect(localeText.start).to.equal('Start');
});

Expand All @@ -87,7 +87,7 @@ describe('<LocalizationProvider />', () => {
</LocalizationProvider>,
);

const localeText: PickersLocaleText<any> = handleContextChange.lastCall.args[0].localeText;
const localeText: PickersLocaleText = handleContextChange.lastCall.args[0].localeText;
expect(localeText.start).to.equal('Début');
});

Expand All @@ -102,7 +102,7 @@ describe('<LocalizationProvider />', () => {
</LocalizationProvider>,
);

const localeText: PickersLocaleText<any> = handleContextChange.lastCall.args[0].localeText;
const localeText: PickersLocaleText = handleContextChange.lastCall.args[0].localeText;
expect(localeText.start).to.equal('Empezar');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface MuiPickersAdapterContextValue<TDate extends PickerValidDate> {
};

utils: MuiPickersAdapter<TDate>;
localeText: PickersInputLocaleText<TDate> | undefined;
localeText: PickersInputLocaleText | undefined;
}

export type MuiPickersAdapterContextNullableValue<TDate extends PickerValidDate> = {
Expand Down Expand Up @@ -49,7 +49,7 @@ export interface LocalizationProviderProps<TDate extends PickerValidDate, TLocal
/**
* Locale for components texts
*/
localeText?: PickersInputLocaleText<TDate>;
localeText?: PickersInputLocaleText;
}

type LocalizationProviderComponent = (<TDate extends PickerValidDate, TLocale>(
Expand Down
2 changes: 0 additions & 2 deletions packages/x-date-pickers/src/TimeClock/Clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ export function Clock<TDate extends PickerValidDate>(inProps: ClockProps<TDate>)
aria-activedescendant={selectedId}
aria-label={translations.clockLabelText(
type,
value,
utils,
value == null ? null : utils.format(value, 'fullTime'),
)}
ref={listboxRef}
Expand Down
3 changes: 1 addition & 2 deletions packages/x-date-pickers/src/TimePicker/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type UseTimePickerDefaultizedProps<
TView extends TimeViewWithMeridiem,
Props extends BaseTimePickerProps<TDate, TView>,
> = LocalizedComponent<
TDate,
DefaultizedProps<Props, 'views' | 'openTo' | 'ampm' | keyof BaseTimeValidationProps>
>;

Expand All @@ -91,7 +90,7 @@ export function useTimePickerDefaultizedProps<

const ampm = themeProps.ampm ?? utils.is12HourCycleInCurrentLocale();

const localeText = React.useMemo<PickersInputLocaleText<TDate> | undefined>(() => {
const localeText = React.useMemo<PickersInputLocaleText | undefined>(() => {
if (themeProps.localeText?.toolbarTitle == null) {
return themeProps.localeText;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { PickerValidDate } from '../../models';
import { PickersInputLocaleText } from '../../locales';
import { LocalizationProvider } from '../../LocalizationProvider';

Expand All @@ -12,9 +11,7 @@ export const PickersContext = React.createContext<PickersContextValue | null>(nu
*
* @ignore - do not document.
*/
export function PickersProvider<TDate extends PickerValidDate>(
props: PickersFieldProviderProps<TDate>,
) {
export function PickersProvider(props: PickersFieldProviderProps) {
const { contextValue, localeText, children } = props;

return (
Expand All @@ -24,9 +21,9 @@ export function PickersProvider<TDate extends PickerValidDate>(
);
}

interface PickersFieldProviderProps<TDate extends PickerValidDate> {
interface PickersFieldProviderProps {
contextValue: PickersContextValue;
localeText: PickersInputLocaleText<TDate> | undefined;
localeText: PickersInputLocaleText | undefined;
children: React.ReactNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BuildSectionsFromFormatParams<TDate extends PickerValidDate> {
formatDensity: 'dense' | 'spacious';
isRtl: boolean;
shouldRespectLeadingZeros: boolean;
localeText: PickersLocaleText<TDate>;
localeText: PickersLocaleText;
localizedDigits: string[];
date: TDate | null;
enableAccessibleFieldDOMStructure: boolean;
Expand Down Expand Up @@ -63,7 +63,7 @@ const getEscapedPartsFromFormat = <TDate extends PickerValidDate>({

const getSectionPlaceholder = <TDate extends PickerValidDate>(
utils: MuiPickersAdapter<TDate>,
localeText: PickersLocaleText<TDate>,
localeText: PickersLocaleText,
sectionConfig: Pick<FieldSection, 'type' | 'contentType'>,
sectionFormat: string,
) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/internals/hooks/useUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useLocalizationContext = <TDate extends PickerValidDate>() => {
...localization,
localeText,
}) as Omit<MuiPickersAdapterContextValue<TDate>, 'localeText'> & {
localeText: PickersLocaleText<TDate>;
localeText: PickersLocaleText;
},
[localization, localeText],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface BasePickerProps<
* Locale for components texts.
* Allows overriding texts coming from `LocalizationProvider` and `theme`.
*/
localeText?: PickersInputComponentLocaleText<TDate>;
localeText?: PickersInputComponentLocaleText;
}

/**
Expand Down
18 changes: 7 additions & 11 deletions packages/x-date-pickers/src/locales/beBY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const views: Record<TimeViewWithMeridiem, string> = {
meridiem: 'мерыдыем',
};

const beBYPickers: Partial<PickersLocaleText<any>> = {
const beBYPickers: Partial<PickersLocaleText> = {
// Calendar navigation
previousMonth: 'Папярэдні месяц',
nextMonth: 'Наступны месяц',
Expand Down Expand Up @@ -44,8 +44,8 @@ const beBYPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Абраць каляндарны перыяд',

// Clock labels
clockLabelText: (view, time, utils, formattedTime) =>
`Абярыце ${views[view]}. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Час не абраны' : `Абраны час ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
clockLabelText: (view, formattedTime) =>
`Абярыце ${views[view]}. ${!formattedTime ? 'Час не абраны' : `Абраны час ${formattedTime}`}`,
hoursClockNumberText: (hours) => `${hours} гадзін`,
minutesClockNumberText: (minutes) => `${minutes} хвілін`,
secondsClockNumberText: (seconds) => `${seconds} секунд`,
Expand All @@ -60,14 +60,10 @@ const beBYPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Абраць дату, абрана дата ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Абраць дату',
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Абраць час, абрыны час ${formattedTime ?? utils.format(value, 'fullTime')}`
: 'Абраць час',
openDatePickerDialogue: (formattedDate) =>
formattedDate ? `Абраць дату, абрана дата ${formattedDate}` : 'Абраць дату',
openTimePickerDialogue: (formattedTime) =>
formattedTime ? `Абраць час, абрыны час ${formattedTime}` : 'Абраць час',
// fieldClearLabel: 'Clear',

// Table labels
Expand Down
18 changes: 7 additions & 11 deletions packages/x-date-pickers/src/locales/bgBG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const views: Record<TimeViewWithMeridiem, string> = {
meridiem: 'преди обяд/след обяд',
};

const bgBGPickers: Partial<PickersLocaleText<any>> = {
const bgBGPickers: Partial<PickersLocaleText> = {
// Calendar navigation
previousMonth: 'Предишен месец',
nextMonth: 'Следващ месец',
Expand Down Expand Up @@ -43,8 +43,8 @@ const bgBGPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Избери времеви период',

// Clock labels
clockLabelText: (view, time, adapter) =>
`Избери ${views[view]}. ${time === null ? 'Не е избран час' : `Избраният час е ${adapter.format(time, 'fullTime')}`}`,
clockLabelText: (view, formattedTime) =>
`Избери ${views[view]}. ${!formattedTime ? 'Не е избран час' : `Избраният час е ${formattedTime}`}`,
hoursClockNumberText: (hours) => `${hours} часа`,
minutesClockNumberText: (minutes) => `${minutes} минути`,
secondsClockNumberText: (seconds) => `${seconds} секунди`,
Expand All @@ -59,14 +59,10 @@ const bgBGPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Избери дата, избраната дата е ${utils.format(value, 'fullDate')}`
: 'Избери дата',
openTimePickerDialogue: (value, utils) =>
value !== null && utils.isValid(value)
? `Избери час, избраният час е ${utils.format(value, 'fullTime')}`
: 'Избери час',
openDatePickerDialogue: (formattedTime) =>
formattedTime ? `Избери дата, избраната дата е ${formattedTime}` : 'Избери дата',
openTimePickerDialogue: (formattedTime) =>
formattedTime ? `Избери час, избраният час е ${formattedTime}` : 'Избери час',
fieldClearLabel: 'Изчисти стойност',

// Table labels
Expand Down
18 changes: 7 additions & 11 deletions packages/x-date-pickers/src/locales/caES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const views: Record<TimeViewWithMeridiem, string> = {
meridiem: 'Meridià',
};

const caESPickers: Partial<PickersLocaleText<any>> = {
const caESPickers: Partial<PickersLocaleText> = {
// Calendar navigation
previousMonth: 'Mes anterior',
nextMonth: 'Mes següent',
Expand Down Expand Up @@ -43,8 +43,8 @@ const caESPickers: Partial<PickersLocaleText<any>> = {
dateRangePickerToolbarTitle: 'Seleccionar rang de dates',

// Clock labels
clockLabelText: (view, time, utils, formattedTime) =>
`Selecciona ${views[view]}. ${!formattedTime && (time === null || !utils.isValid(time)) ? 'Hora no seleccionada' : `L'hora seleccionada és ${formattedTime ?? utils.format(time, 'fullTime')}`}`,
clockLabelText: (view, formattedTime) =>
`Selecciona ${views[view]}. ${!formattedTime ? 'Hora no seleccionada' : `L'hora seleccionada és ${formattedTime}`}`,
hoursClockNumberText: (hours) => `${hours} hores`,
minutesClockNumberText: (minutes) => `${minutes} minuts`,
secondsClockNumberText: (seconds) => `${seconds} segons`,
Expand All @@ -59,14 +59,10 @@ const caESPickers: Partial<PickersLocaleText<any>> = {
calendarWeekNumberText: (weekNumber) => `${weekNumber}`,

// Open picker labels
openDatePickerDialogue: (value, utils, formattedDate) =>
formattedDate || (value !== null && utils.isValid(value))
? `Tria la data, la data triada és ${formattedDate ?? utils.format(value, 'fullDate')}`
: 'Tria la data',
openTimePickerDialogue: (value, utils, formattedTime) =>
formattedTime || (value !== null && utils.isValid(value))
? `Tria l'hora, l'hora triada és ${formattedTime ?? utils.format(value, 'fullTime')}`
: "Tria l'hora",
openDatePickerDialogue: (formattedDate) =>
formattedDate ? `Tria la data, la data triada és ${formattedDate}` : 'Tria la data',
openTimePickerDialogue: (formattedTime) =>
formattedTime ? `Tria l'hora, l'hora triada és ${formattedTime}` : "Tria l'hora",
fieldClearLabel: 'Netega el valor',

// Table labels
Expand Down
Loading