Skip to content

Commit 0522cf9

Browse files
committed
feat(components/input): 国际化
1 parent bc16b50 commit 0522cf9

File tree

9 files changed

+30
-3
lines changed

9 files changed

+30
-3
lines changed

packages/components/src/config-provider/config-provider.types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type {
22
PopConfirmLocale,
33
CalendarLocale,
44
SelectLocale,
5+
InputLocale,
56
EmptyLocale,
67
} from '../';
78

89
export interface Locale {
910
popConfirm: Partial<PopConfirmLocale>;
1011
calendar: Partial<CalendarLocale>;
1112
select: Partial<SelectLocale>;
13+
input: Partial<InputLocale>;
1214
empty: Partial<EmptyLocale>;
1315
}
1416

packages/components/src/input/Input.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
useWatch,
66
} from '@pkg/shared';
77
import { InputSwitch, InputSuffix, InputSkin } from './components';
8+
import { useLocale } from '~/config-provider/useLocale';
89
import type { RequiredPart } from '@tool-pack/types';
910
import { getClassNames } from '@tool-pack/basic';
1011
import type { InputProps } from './input.types';
1112
import React, { useState, useRef } from 'react';
13+
import EnUS from '~/input/locale/en-US';
1214

1315
const cls = getClasses(
1416
'input',
@@ -26,10 +28,11 @@ export const Input: React.FC<InputProps> = React.forwardRef<
2628
HTMLInputElement,
2729
InputProps
2830
>((props, ref) => {
31+
const locale = useLocale('input', EnUS);
2932
const {
33+
placeholder = locale.placeholder,
3034
showPasswordOn,
3135
rootAttrs = {},
32-
placeholder,
3336
attrs = {},
3437
clearable,
3538
showCount,

packages/components/src/input/demo/basic.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react';
99
const App: React.FC = () => {
1010
return (
1111
<>
12-
<Input placeholder="input" />
12+
<Input />
1313
<br />
1414
<Input placeholder="disabled" disabled />
1515
</>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export type { InputProps } from './input.types';
1+
export type { InputLocale, InputProps } from './input.types';
22
export * from './Input';

packages/components/src/input/input.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ export interface InputProps extends BaseInputProps, TextareaProps {
3535
value?: string;
3636
size?: Size;
3737
}
38+
39+
export interface InputLocale {
40+
placeholder: string;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { InputLocale } from '../input.types';
2+
3+
const locale: InputLocale = {
4+
placeholder: 'Please input',
5+
};
6+
7+
export default locale;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { InputLocale } from '../input.types';
2+
3+
const locale: InputLocale = {
4+
placeholder: '请输入',
5+
};
6+
7+
export default locale;

packages/react-ui/src/locale/en-US.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import popConfirm from '@pkg/components/pop-confirm/locale/en-US';
22
import calendar from '@pkg/components/calendar/locale/en-US';
33
import select from '@pkg/components/select/locale/en-US';
4+
import input from '@pkg/components/input/locale/en-US';
45
import empty from '@pkg/components/empty/locale/en-US';
56
import type { Locale } from '@pkg/components';
67

@@ -9,4 +10,5 @@ export default {
910
calendar,
1011
select,
1112
empty,
13+
input,
1214
} satisfies Locale;

packages/react-ui/src/locale/zh-CN.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import calendar from '@pkg/components/calendar/locale/zh-CN';
33
import empty from '@pkg/components/empty/locale/zh-CN';
44
import type { Locale } from '@pkg/components';
55
import select from '~/select/locale/zh-CN';
6+
import input from '~/input/locale/zh-CN';
67

78
export default {
89
popConfirm,
910
calendar,
1011
select,
1112
empty,
13+
input,
1214
} satisfies Locale;

0 commit comments

Comments
 (0)