UNPKG

@flyyer/use-googlefonts

Version:

React hook to dynamically load Google Fonts v2 during execution.

62 lines (61 loc) 1.75 kB
/** * Font family name and styles * @see https://fonts.google.com/ */ export interface GoogleFontFamily { /** * Font family name. Eg: `Inter`, `Andika New Basic` */ family: string; /** * Array of styles * @example * "600..700" * "100..200italic" * "300italic" * "regular" * "italic" * "500" * 444 * @see https://developers.google.com/fonts/docs/css2 * @see https://github.com/adriano-tirloni/google-fonts-css2 */ styles: (string | number)[]; } export declare enum GoogleFontsStatus { LOADING = 0, LOADED = 1, FAILED = -1 } export declare type GoogleFontOptions = { /** * `"swap"` is recommended. */ display: "swap" | "auto"; }; export declare const defaultOptions: GoogleFontOptions; /** * Returned object from the `useGoogleFonts` hook. */ export interface UseGoogleFontsResult { /** * Generated URL (Google Font css2) */ href: string | undefined; /** * Current operation status */ status: GoogleFontsStatus; /** * Error object if `status` is `FAILED` (`-1`). */ error: Error | undefined; } /** * Load fonts from `fonts` argument by creating a single URL which will be appended to the `<head/>` of the document as `<link href={} rel="stylesheet" />`. * * If there is any change in the arguments the current `<link />` will be removed and replaced by the new tag. * * Get the operation status (and `error` if present) via the `status` attribute of the returned object. */ export declare function useGoogleFonts(fonts?: GoogleFontFamily[] | undefined | null, options?: GoogleFontOptions): UseGoogleFontsResult;