mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.53k stars 1.32k forks source link

[pickers][datagrid] - export Localization interfaces for each package #5124

Open rodrigofariow opened 2 years ago

rodrigofariow commented 2 years ago

Duplicates

Latest version

Summary 💡

I'm currently extending material-ui components into a design system used in my company. To better type our locales custom object, it would be nice if you exported the Localization interfaces used on @mui/x-data-grid and @mui/x-date-pickers.

Examples 🌈

Here is the content of @mui/x-data-grid/utils/getGridLocalization.d.ts:

import { Localization as CoreLocalization } from '@mui/material/locale';
import { GridLocaleText } from '../models/api/gridLocaleTextApi';
export interface Localization {
    components: {
        MuiDataGrid: {
            defaultProps: {
                localeText: Partial<GridLocaleText>;
            };
        };
    };
}
export declare const getGridLocalization: (gridTranslations: Partial<GridLocaleText>, coreTranslations?: CoreLocalization | undefined) => Localization;

I would like to use this Localization interface but according to your guidelines, we should not import stuff from more than 2 levels deep since those exports might be private:

// ✅ OK
import { Add as AddIcon } from '@mui/icons-material';
import { Tabs } from '@mui/material';
//                         ^^^^^^^^ 1st or top-level

// ✅ OK
import AddIcon from '@mui/icons-material/Add';
import Tabs from '@mui/material/Tabs';
//                              ^^^^ 2nd level

// ❌ NOT OK
import TabIndicator from '@mui/material/Tabs/TabIndicator';
//                                           ^^^^^^^^^^^^ 3rd level

To be honest I could just import a locale and do:

import {ptBR} from '@mui/x-data-grid-pro'

type DataGridLocalization = typeof ptBR

But honestly we might as well have these interfaces be exported at a public level :P The same applies for @mui/x-date-pickers.

Thank your for your time 🙏

Motivation 🔦

No response

Order ID 💳 (optional)

33240

DanailH commented 2 years ago

Hi @rodrigofariow thanks for raising this. This seems like a relevant request. I'm trying to think what could go wrong by exporting this interface and if we would need to remove/change some of the keys there or only add new ones (to avoid breaking changes). I don't think we had a case where we needed to change/remove a key so I don't think it will be a problem.

alexfauquette commented 2 years ago

The most important interface is GridLocaleText which contains all the keys. This interface is already exported because it is the type of prop localeText

Localization is just a wrapper that allows you to add translations to the theme with const theme = createTheme(ptBR, corePtBR, ...);

So as long a core team does not modify how default props are defined, this should not be modified