Skip to content

Commit

Permalink
feat(components/loading): 国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Feb 22, 2024
1 parent 2f4a926 commit b94a830
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
PopConfirmLocale,
DatePickerLocale,
CalendarLocale,
LoadingLocale,
SelectLocale,
InputLocale,
EmptyLocale,
Expand All @@ -12,6 +13,7 @@ export interface Locale {
datePicker: Partial<DatePickerLocale>;
popConfirm: Partial<PopConfirmLocale>;
calendar: Partial<CalendarLocale>;
loading: Partial<LoadingLocale>;
select: Partial<SelectLocale>;
input: Partial<InputLocale>;
empty: Partial<EmptyLocale>;
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
} from '~/transition';
import { useScrollLock, getClasses, useVisible, Z_INDEX } from '@pkg/shared';
import React, { useCallback, useMemo, useRef } from 'react';
import { useLocale } from '~/config-provider/useLocale';
import { Loading as LoadingIcon } from '@pkg/icons';
import { getClassNames } from '@tool-pack/basic';
import { RequiredPart } from '@tool-pack/types';
import { LoadingProps } from './loading.types';
import EnUS from '~/loading/locale/en-US';
import { createPortal } from 'react-dom';
import { Icon } from '~/icon';

Expand All @@ -20,7 +22,6 @@ const cls = getClasses(

const defaultProps = {
background: 'var(--t-mask-bg-color)',
text: 'loading...',
zIndex: Z_INDEX,
// color: 'var(--t-text-color)',
mode: 'insert',
Expand All @@ -30,8 +31,10 @@ const defaultProps = {
* loading组件
*/
export const Loading: React.FC<LoadingProps> = (props) => {
const locale = useLocale('loading', EnUS);
const {
visible: outerVisible,
text = locale.text,
wrapperAttrs = {},
closeOnClick,
attrs = {},
Expand All @@ -43,7 +46,6 @@ export const Loading: React.FC<LoadingProps> = (props) => {
color,
mode,
icon,
text,
} = props as RequiredPart<LoadingProps, keyof typeof defaultProps>;

const wrapperRef = useRef<HTMLDivElement>(null);
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/loading/loading.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export interface LoadingProps extends Omit<PropsBase, 'ref'> {
zIndex?: number;
color?: string;
}

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

const locale: LoadingLocale = {
text: 'loading...',
};

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

const locale: LoadingLocale = {
text: '加载中...',
};

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 datePicker from '@pkg/components/date-picker/locale/en-US';
import popConfirm from '@pkg/components/pop-confirm/locale/en-US';
import calendar from '@pkg/components/calendar/locale/en-US';
import loading from '@pkg/components/loading/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';
Expand All @@ -11,6 +12,7 @@ export default {
popConfirm,
datePicker,
calendar,
loading,
select,
empty,
input,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-ui/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import popConfirm from '@pkg/components/pop-confirm/locale/zh-CN';
import datePicker from '@pkg/components/date-picker/locale/zh-CN';
import calendar from '@pkg/components/calendar/locale/zh-CN';
import loading from '@pkg/components/loading/locale/zh-CN';
import select from '@pkg/components/select/locale/zh-CN';
import input from '@pkg/components/input/locale/zh-CN';
import empty from '@pkg/components/empty/locale/zh-CN';
Expand All @@ -11,6 +12,7 @@ export default {
popConfirm,
datePicker,
calendar,
loading,
select,
empty,
input,
Expand Down

0 comments on commit b94a830

Please sign in to comment.