@ices/react-locale
Version:
React components for locale
86 lines (85 loc) • 5.05 kB
TypeScript
import * as React from 'react';
import { HTMLAttributes } from 'react';
import { LocaleResourceLoader } from './context';
import { MessageDefinitions, PluginFunction } from './message';
declare type HTMLTagName = keyof HTMLElementTagNameMap;
interface RendererVFCProps<T extends HTMLTagName = HTMLTagName> extends Omit<HTMLAttributes<HTMLElementTagNameMap[T]>, 'id' | 'children' | 'dangerouslySetInnerHTML'> {
content: string;
enableHTML?: boolean;
tagName?: T;
forwardedRef?: React.Ref<any>;
}
interface LocaleTransProps extends Omit<RendererVFCProps, 'content'> {
id: string;
plugins?: PluginFunction | PluginFunction[] | null;
data?: any;
fallback?: string;
definitions?: MessageDefinitions | LocaleResourceLoader;
}
/**
* 语言内容转译组件属性定义类型。
*/
export declare type TranslateProps = React.PropsWithoutRef<Omit<LocaleTransProps, 'definitions'>>;
/**
* 语言内容转译组件定义类型。
*/
export declare type TranslateType = ReturnType<typeof withDefinitionsComponent>;
/**
* 注入消息定义至转译消息组件。
* @param definitions 消息定义数据对象。
*/
export declare function withDefinitionsComponent(definitions?: MessageDefinitions | LocaleResourceLoader): {
new (props: Omit<LocaleTransProps, "definitions"> | Readonly<Omit<LocaleTransProps, "definitions">>): {
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<Omit<LocaleTransProps, "definitions">>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callback?: (() => void) | undefined): void;
readonly props: Readonly<Omit<LocaleTransProps, "definitions">> & Readonly<{
children?: React.ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: React.ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<Omit<LocaleTransProps, "definitions">>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<Omit<LocaleTransProps, "definitions">>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): void;
};
new (props: Omit<LocaleTransProps, "definitions">, context: any): {
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<Omit<LocaleTransProps, "definitions">>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callback?: (() => void) | undefined): void;
readonly props: Readonly<Omit<LocaleTransProps, "definitions">> & Readonly<{
children?: React.ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: React.ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<Omit<LocaleTransProps, "definitions">>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<Omit<LocaleTransProps, "definitions">>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<Omit<LocaleTransProps, "definitions">>, nextState: Readonly<{}>, nextContext: any): void;
};
contextType: React.Context<string>;
enableDangerouslySetInnerHTML: boolean;
};
export {};