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

[docs] Inform about specific files for DataGrid locales #30411

Merged
merged 3 commits into from
Jan 13, 2022
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
13 changes: 9 additions & 4 deletions docs/src/pages/guides/localization/Locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import TablePagination from '@mui/material/TablePagination';
import Autocomplete from '@mui/material/Autocomplete';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
import * as locales from '@mui/material/locale';

export default function Locales() {
const [locale, setLocale] = React.useState('zhCN');

const theme = useTheme();

const themeWithLocale = React.useMemo(
() => createTheme(theme, locales[locale]),
[locale, theme],
);

return (
<Box sx={{ width: '100%' }}>
<ThemeProvider
theme={(outerTheme) => createTheme(outerTheme, locales[locale])}
>
<ThemeProvider theme={themeWithLocale}>
<Autocomplete
options={Object.keys(locales)}
getOptionLabel={(key) => `${key.substring(0, 2)}-${key.substring(2, 4)}`}
Expand Down
13 changes: 9 additions & 4 deletions docs/src/pages/guides/localization/Locales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import TablePagination from '@mui/material/TablePagination';
import Autocomplete from '@mui/material/Autocomplete';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
import * as locales from '@mui/material/locale';

type SupportedLocales = keyof typeof locales;

export default function Locales() {
const [locale, setLocale] = React.useState<SupportedLocales>('zhCN');

const theme = useTheme();

const themeWithLocale = React.useMemo(
() => createTheme(theme, locales[locale]),
[locale, theme],
);

return (
<Box sx={{ width: '100%' }}>
<ThemeProvider
theme={(outerTheme) => createTheme(outerTheme, locales[locale])}
>
<ThemeProvider theme={themeWithLocale}>
<Autocomplete
options={Object.keys(locales)}
getOptionLabel={(key) => `${key.substring(0, 2)}-${key.substring(2, 4)}`}
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/guides/localization/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const theme = createTheme(

### Example

{{"demo": "pages/guides/localization/Locales.js", "defaultCodeOpen": false}}
{{"demo": "pages/guides/localization/Locales.js"}}

> ⚠️ For [`DataGrid` and `DataGridPro`](/components/data-grid/) components, they have their own [localization](/components/data-grid/localization/).

### Supported locales

Expand Down