Skip to content

Commit

Permalink
add zh locale examples
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Dec 23, 2022
1 parent a05af58 commit 314ae83
Show file tree
Hide file tree
Showing 37 changed files with 589 additions and 20 deletions.
10 changes: 10 additions & 0 deletions apps/material-react-table-docs/example-groups/LocaleExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const TR_Table = dynamic(() => import('../examples/localization-i18n-tr'), {
const VI_Table = dynamic(() => import('../examples/localization-i18n-vi'), {
suspense: true,
});
const ZH_HANS_Table = dynamic( () => import('../examples/localization-i18n-zh-hans'), {
suspense: true,
});
const ZH_HANT_Table = dynamic( () => import('../examples/localization-i18n-zh-hant'), {
suspense: true,
});

const supportedLocales = [
'cs',
Expand All @@ -72,6 +78,8 @@ const supportedLocales = [
'ru',
'tr',
'vi',
'zh-hans',
'zh-hant',
];

const LocaleExamples = () => {
Expand Down Expand Up @@ -118,6 +126,8 @@ const LocaleExamples = () => {
{currentLocale === 'ru' && <RU_Table />}
{currentLocale === 'tr' && <TR_Table />}
{currentLocale === 'vi' && <VI_Table />}
{currentLocale === 'zh-hans' && <ZH_HANS_Table />}
{currentLocale === 'zh-hant' && <ZH_HANT_Table />}
</Suspense>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { SourceCodeSnippet } from '../../components/mdx/SourceCodeSnippet';
import Example from './sandbox/src/TS';
const JS = require('!!raw-loader!./sandbox/src/JS.js').default;
const TS = require('!!raw-loader!./sandbox/src/TS.tsx').default;

const ExampleTable = () => {
return (
<SourceCodeSnippet
Component={Example}
javaScriptCode={JS}
typeScriptCode={TS}
tableId="localization-i18n-zh-hans"
/>
);
};

export default ExampleTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install` or `yarn`
- `npm run start` or `yarn start`
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material React Table Example</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "material-react-table-example-localization-i18n-zh-hans",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite --port 3001",
"build": "vite build",
"serve": "vite preview",
"start": "vite"
},
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.6",
"material-react-table": "^1.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"typescript": "^4.8.3",
"vite": "^3.1.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';

//Import Material React Table and its Types
import MaterialReactTable from 'material-react-table';

//Import Material React Table Translations
import { MRT_Localization_ZH_HANS } from 'material-react-table/locales/zh-Hans';

//mock data
import { data } from './makeData';

const columns = [
//column definitions...
{
accessorKey: 'firstName',
header: '名',
},
{
accessorKey: 'lastName',
header: '姓',
enableClickToCopy: true,
},
{
accessorKey: 'age',
header: '年龄',
},
//end
];

const Example = () => {
return (
<MaterialReactTable
columns={columns}
data={data}
enableColumnFilterModes
enableColumnOrdering
enableEditing
enablePinning
enableRowActions
enableRowSelection
enableSelectAll={false}
initialState={{ showColumnFilters: true, showGlobalFilter: true }}
localization={MRT_Localization_ZH_HANS}
/>
);
};

//App.tsx or similar
import { createTheme, ThemeProvider, useTheme } from '@mui/material';
import { zhCN } from '@mui/material/locale';

const ExampleWithThemeProvider = () => {
const theme = useTheme(); //replace with your theme/createTheme
return (
//Setting Material UI locale as best practice to result in better accessibility
<ThemeProvider theme={createTheme(theme, zhCN)}>
<Example />
</ThemeProvider>
);
};

export default ExampleWithThemeProvider;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { FC } from 'react';

//Import Material React Table and its Types
import MaterialReactTable, { MRT_ColumnDef } from 'material-react-table';

//Import Material React Table Translations
import { MRT_Localization_ZH_HANS } from 'material-react-table/locales/zh-Hans';

//mock data
import { data, Person } from './makeData';

const columns: MRT_ColumnDef<Person>[] = [
//column definitions...
{
accessorKey: 'firstName',
header: '名',
},
{
accessorKey: 'lastName',
header: '姓',
enableClickToCopy: true,
},
{
accessorKey: 'age',
header: '年龄',
},
//end
];

const Example: FC = () => {
return (
<MaterialReactTable
columns={columns}
data={data}
enableColumnFilterModes
enableColumnOrdering
enableEditing
enablePinning
enableRowActions
enableRowSelection
enableSelectAll={false}
initialState={{ showColumnFilters: true, showGlobalFilter: true }}
localization={MRT_Localization_ZH_HANS}
/>
);
};

//App.tsx or similar
import { createTheme, ThemeProvider, useTheme } from '@mui/material';
import { zhCN } from '@mui/material/locale';

const ExampleWithThemeProvider: FC = () => {
const theme = useTheme(); //replace with your theme/createTheme
return (
//Setting Material UI locale as best practice to result in better accessibility
<ThemeProvider theme={createTheme(theme, zhCN)}>
<Example />
</ThemeProvider>
);
};

export default ExampleWithThemeProvider;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import Example from './TS';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<Example />
</React.StrictMode>,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type Person = {
firstName: string;
lastName: string;
age: number;
};

export const data: Person[] = [
{
firstName: 'Kevin',
lastName: 'Vandy',
age: 26,
},
{
firstName: 'Theodore',
lastName: 'Browne',
age: 28,
},
{
firstName: 'Tanner',
lastName: 'Linsley',
age: 33,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { SourceCodeSnippet } from '../../components/mdx/SourceCodeSnippet';
import Example from './sandbox/src/TS';
const JS = require('!!raw-loader!./sandbox/src/JS.js').default;
const TS = require('!!raw-loader!./sandbox/src/TS.tsx').default;

const ExampleTable = () => {
return (
<SourceCodeSnippet
Component={Example}
javaScriptCode={JS}
typeScriptCode={TS}
tableId="localization-i18n-zh-hant"
/>
);
};

export default ExampleTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install` or `yarn`
- `npm run start` or `yarn start`
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material React Table Example</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "material-react-table-example-localization-i18n-zh-hant",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite --port 3001",
"build": "vite build",
"serve": "vite preview",
"start": "vite"
},
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.6",
"material-react-table": "^1.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"typescript": "^4.8.3",
"vite": "^3.1.3"
}
}
Loading

2 comments on commit 314ae83

@vercel
Copy link

@vercel vercel bot commented on 314ae83 Dec 23, 2022

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 314ae83 Dec 23, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.