ant-design/components/locale/index.tsx
叶枫 47bd5ecccc
Typography support collapse (#47264)
* feat: typograohy support collapse

* feat: snap

* feat: test

* feat: 单测不符合预期

* feat: test

* feat: 恢复

* feat: test

* feat: test

* feat: 修改命名

* feat: 代码优化

* feat: 添加控制台提示

* feat: snap

* feat: symbol support function

* feat: snap

* fix: text

* feat: snap

* feat: api 修改

* feat: key 修改

* feat: 去掉参数

* feat: lint

* feat: snap

* feat: test

* feat: use 2

* feat: review

* feat: test

* chore: part of it

* chore: fix auto collapse logic

* feat: 修改 doc 单测

* feat: doc

* test: update testcase

* docs: add more

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2024-03-20 11:39:03 +08:00

102 lines
2.8 KiB
TypeScript

import * as React from 'react';
import type { ValidateMessages } from 'rc-field-form/lib/interface';
import { devUseWarning } from '../_util/warning';
import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker';
import type { TransferLocale as TransferLocaleForEmpty } from '../empty';
import type { ModalLocale } from '../modal/locale';
import { changeConfirmLocale } from '../modal/locale';
import type { PaginationLocale } from '../pagination/Pagination';
import type { PopconfirmLocale } from '../popconfirm/PurePanel';
import type { TableLocale } from '../table/interface';
import type { TourLocale } from '../tour/interface';
import type { TransferLocale } from '../transfer';
import type { UploadLocale } from '../upload/interface';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
export { default as useLocale } from './useLocale';
export const ANT_MARK = 'internalMark';
export interface Locale {
locale: string;
Pagination?: PaginationLocale;
DatePicker?: DatePickerLocale;
TimePicker?: Record<string, any>;
Calendar?: Record<string, any>;
Table?: TableLocale;
Modal?: ModalLocale;
Tour?: TourLocale;
Popconfirm?: PopconfirmLocale;
Transfer?: TransferLocale;
Select?: Record<string, any>;
Upload?: UploadLocale;
Empty?: TransferLocaleForEmpty;
global?: Record<string, any>;
Icon?: Record<string, any>;
Text?: {
edit?: any;
copy?: any;
copied?: any;
expand?: any;
collapse?: any;
};
Form?: {
optional?: string;
defaultValidateMessages: ValidateMessages;
};
Image?: {
preview: string;
};
QRCode?: {
expired?: string;
refresh?: string;
scanned?: string;
};
ColorPicker?: {
presetEmpty: string;
};
}
export interface LocaleProviderProps {
locale: Locale;
children?: React.ReactNode;
/** @internal */
_ANT_MARK__?: string;
}
const LocaleProvider: React.FC<LocaleProviderProps> = (props) => {
const { locale = {} as Locale, children, _ANT_MARK__ } = props;
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('LocaleProvider');
warning(
_ANT_MARK__ === ANT_MARK,
'deprecated',
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',
);
}
React.useEffect(() => {
const clearLocale = changeConfirmLocale(locale && locale.Modal);
return clearLocale;
}, [locale]);
const getMemoizedContextValue = React.useMemo<LocaleContextProps>(
() => ({ ...locale, exist: true }),
[locale],
);
return (
<LocaleContext.Provider value={getMemoizedContextValue}>{children}</LocaleContext.Provider>
);
};
if (process.env.NODE_ENV !== 'production') {
LocaleProvider.displayName = 'LocaleProvider';
}
export default LocaleProvider;