Skip to content

Commit

Permalink
feat(components/input): 国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Feb 19, 2024
1 parent bc16b50 commit 0522cf9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type {
PopConfirmLocale,
CalendarLocale,
SelectLocale,
InputLocale,
EmptyLocale,
} from '../';

export interface Locale {
popConfirm: Partial<PopConfirmLocale>;
calendar: Partial<CalendarLocale>;
select: Partial<SelectLocale>;
input: Partial<InputLocale>;
empty: Partial<EmptyLocale>;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
useWatch,
} from '@pkg/shared';
import { InputSwitch, InputSuffix, InputSkin } from './components';
import { useLocale } from '~/config-provider/useLocale';
import type { RequiredPart } from '@tool-pack/types';
import { getClassNames } from '@tool-pack/basic';
import type { InputProps } from './input.types';
import React, { useState, useRef } from 'react';
import EnUS from '~/input/locale/en-US';

const cls = getClasses(
'input',
Expand All @@ -26,10 +28,11 @@ export const Input: React.FC<InputProps> = React.forwardRef<
HTMLInputElement,
InputProps
>((props, ref) => {
const locale = useLocale('input', EnUS);
const {
placeholder = locale.placeholder,
showPasswordOn,
rootAttrs = {},
placeholder,
attrs = {},
clearable,
showCount,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/input/demo/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
const App: React.FC = () => {
return (
<>
<Input placeholder="input" />
<Input />
<br />
<Input placeholder="disabled" disabled />
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/input/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { InputProps } from './input.types';
export type { InputLocale, InputProps } from './input.types';
export * from './Input';
4 changes: 4 additions & 0 deletions packages/components/src/input/input.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ export interface InputProps extends BaseInputProps, TextareaProps {
value?: string;
size?: Size;
}

export interface InputLocale {
placeholder: string;
}
7 changes: 7 additions & 0 deletions packages/components/src/input/locale/en-US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { InputLocale } from '../input.types';

const locale: InputLocale = {
placeholder: 'Please input',
};

export default locale;
7 changes: 7 additions & 0 deletions packages/components/src/input/locale/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { InputLocale } from '../input.types';

const locale: InputLocale = {
placeholder: '请输入',
};

export default locale;
2 changes: 2 additions & 0 deletions packages/react-ui/src/locale/en-US.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import popConfirm from '@pkg/components/pop-confirm/locale/en-US';
import calendar from '@pkg/components/calendar/locale/en-US';
import select from '@pkg/components/select/locale/en-US';
import input from '@pkg/components/input/locale/en-US';
import empty from '@pkg/components/empty/locale/en-US';
import type { Locale } from '@pkg/components';

Expand All @@ -9,4 +10,5 @@ export default {
calendar,
select,
empty,
input,
} satisfies Locale;
2 changes: 2 additions & 0 deletions packages/react-ui/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import calendar from '@pkg/components/calendar/locale/zh-CN';
import empty from '@pkg/components/empty/locale/zh-CN';
import type { Locale } from '@pkg/components';
import select from '~/select/locale/zh-CN';
import input from '~/input/locale/zh-CN';

export default {
popConfirm,
calendar,
select,
empty,
input,
} satisfies Locale;

0 comments on commit 0522cf9

Please sign in to comment.