UNPKG

@enact/i18n

Version:

Internationalization support for Enact using iLib

59 lines (51 loc) 1.55 kB
// Type definitions for i18n/Text import * as React from "react"; type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N; export interface TextDecoratorConfig extends Object { /** * Configures the translated text passed to the wrapped component. */ mapPropsToText?: { [key: string]: string | object }; } export interface TextDecoratorProps { /** * Passed to the wrapped component. * * If `mapPropsToText` is `null` and `children` is a string, the string will be translated before being passed to the wrapped component. */ children?: any; /** * The locale for translation. * * If not supplied, the current locale is used. */ locale?: string; } export function TextDecorator<P>( config: TextDecoratorConfig, Component: React.ComponentType<P> | string, ): React.ComponentType<P & TextDecoratorProps>; export function TextDecorator<P>( Component: React.ComponentType<P> | string, ): React.ComponentType<P & TextDecoratorProps>; export interface TextProps extends TextDecoratorProps { /** * The string to be translated. */ children?: string; } /** * Translates its child string value in the current locale. * * If translations are not available yet, `Text` will render nothing. Once translations are available, the component will update with the translated string. * ``` <Text>Go</Text> ``` */ export class Text extends React.Component< Merge<React.HTMLProps<HTMLElement>, TextProps> > {} export default Text;