UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

29 lines (26 loc) 1.42 kB
import { Languages } from './useLanguage.js'; import 'react/jsx-runtime'; import 'react'; type Translation<T> = Record<Languages, T>; type OverwriteTranslationType<Translation extends Record<string, unknown>> = { language?: Languages; translation?: Partial<Record<Languages, Partial<Translation>>>; }; /** * Adds the `language` prop to the component props. * * @param Translation the type of the translation object * * @param Props the type of the component props, defaults to `Record<string, never>`, * if you don't expect any other props other than `language` and get an * error when using your component (because it uses `forwardRef` etc.) * you can try out `Record<string, unknown>`, this might resolve your * problem as `SomeType & never` is still `never` but `SomeType & unknown` * is `SomeType` which means that adding back props (like `ref` etc.) * works properly */ type PropsForTranslation<Translation extends Record<string, unknown>, Props = Record<string, never>> = Props & { overwriteTranslation?: OverwriteTranslationType<Translation>; }; declare const useTranslation: <Translation extends Record<string, unknown>>(defaults: Record<Languages, Translation>, translationOverwrite?: OverwriteTranslationType<Translation>) => Translation; export { type PropsForTranslation, type Translation, useTranslation };