Skip to content

Commit 9e6ec7a

Browse files
committed
feat(configprovider): migrate locale type to useLocale
1 parent 220dbfb commit 9e6ec7a

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

src/configProvider/index.tsx

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
1-
import React, { createContext } from 'react';
1+
import React from 'react';
22

3-
export interface Locale {
4-
locale: string;
5-
BlockHeader: { expand: string; collapse: string };
6-
Copy: { copied: string; copy: string };
7-
Dropdown: { selectAll: string; resetText: string; okText: string };
8-
Fullscreen: { exitFull: string; full: string };
9-
GlobalLoading: { loading: string };
10-
Input: {
11-
case: string;
12-
precise: string;
13-
front: string;
14-
tail: string;
15-
};
16-
LoadError: {
17-
please: string;
18-
get: string;
19-
refresh: string;
20-
title: string;
21-
};
22-
Modal: {
23-
okText: string;
24-
cancelText: string;
25-
};
26-
MxGraph: { newNode: string };
27-
NotFound: {
28-
description: string;
29-
};
30-
SpreadSheet: {
31-
description: string;
32-
copy: string;
33-
copyAll: string;
34-
};
35-
}
36-
37-
export interface LocaleContextProps {
38-
locale: Locale;
39-
}
40-
41-
export const LocaleContext = createContext<LocaleContextProps>({ locale: {} as Locale });
3+
import { LocaleContext, LocaleContextProps } from '../locale/useLocale';
424

435
const ConfigProvider = ({
446
locale,

src/locale/useLocale.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
1-
import { useContext, useMemo } from 'react';
1+
import { createContext, useContext, useMemo } from 'react';
22

3-
import type { Locale, LocaleContextProps } from '../configProvider';
4-
import { LocaleContext } from '../configProvider';
53
import defaultLocaleData from './zh-CN';
64

5+
export interface Locale {
6+
locale: string;
7+
BlockHeader: { expand: string; collapse: string };
8+
Copy: { copied: string; copy: string };
9+
Dropdown: { selectAll: string; resetText: string; okText: string };
10+
Fullscreen: { exitFull: string; full: string };
11+
GlobalLoading: { loading: string };
12+
Input: {
13+
case: string;
14+
precise: string;
15+
front: string;
16+
tail: string;
17+
};
18+
LoadError: {
19+
please: string;
20+
get: string;
21+
refresh: string;
22+
title: string;
23+
};
24+
Modal: {
25+
okText: string;
26+
cancelText: string;
27+
};
28+
MxGraph: { newNode: string };
29+
NotFound: {
30+
description: string;
31+
};
32+
SpreadSheet: {
33+
description: string;
34+
copy: string;
35+
copyAll: string;
36+
};
37+
}
38+
39+
export interface LocaleContextProps {
40+
locale: Locale;
41+
}
42+
43+
export const LocaleContext = createContext<LocaleContextProps>({ locale: {} as Locale });
44+
745
export type LocaleComponentName = keyof Locale;
846

947
const useLocale = <C extends LocaleComponentName = LocaleComponentName>(

0 commit comments

Comments
 (0)