|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -declare module '@endiliey/react-ideal-image'; |
| 8 | +/** |
| 9 | + * @see https://github.com/endiliey/react-ideal-image/blob/master/index.d.ts |
| 10 | + */ |
| 11 | +declare module '@endiliey/react-ideal-image' { |
| 12 | + export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error'; |
| 13 | + |
| 14 | + export type IconKey = |
| 15 | + | 'load' |
| 16 | + | 'loading' |
| 17 | + | 'loaded' |
| 18 | + | 'error' |
| 19 | + | 'noicon' |
| 20 | + | 'offline'; |
| 21 | + |
| 22 | + export interface SrcType { |
| 23 | + width: number; |
| 24 | + src?: string; |
| 25 | + size?: number; |
| 26 | + format?: 'webp' | 'jpeg' | 'png' | 'gif'; |
| 27 | + } |
| 28 | + |
| 29 | + type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript'; |
| 30 | + |
| 31 | + export interface ImageProps { |
| 32 | + /** |
| 33 | + * This function decides what icon to show based on the current state of the component. |
| 34 | + */ |
| 35 | + getIcon?: (state: LoadingState) => IconKey; |
| 36 | + /** |
| 37 | + * This function decides what message to show based on the icon (returned from getIcon prop) and |
| 38 | + * the current state of the component. |
| 39 | + */ |
| 40 | + getMessage?: (icon: IconKey, state: LoadingState) => string; |
| 41 | + /** |
| 42 | + * This function is called as soon as the component enters the viewport and is used to generate urls |
| 43 | + * based on width and format if props.srcSet doesn't provide src field. |
| 44 | + */ |
| 45 | + getUrl?: (srcType: SrcType) => string; |
| 46 | + /** |
| 47 | + * The Height of the image in px. |
| 48 | + */ |
| 49 | + height: number; |
| 50 | + /** |
| 51 | + * This provides a map of the icons. By default, the component uses icons from material design, |
| 52 | + * implemented as React components with the SVG element. You can customize icons |
| 53 | + */ |
| 54 | + icons: Partial<Record<IconKey, ComponentType>>; |
| 55 | + /** |
| 56 | + * This prop takes one of the 2 options, xhr and image. |
| 57 | + * Read more about it: |
| 58 | + * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#cancel-download |
| 59 | + */ |
| 60 | + loader?: 'xhr' | 'image'; |
| 61 | + /** |
| 62 | + * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#lqip |
| 63 | + */ |
| 64 | + placeholder: {color: string} | {lqip: string}; |
| 65 | + /** |
| 66 | + * This function decides if image should be downloaded automatically. The default function |
| 67 | + * returns false for a 2g network, for a 3g network it decides based on props.threshold |
| 68 | + * and for a 4g network it returns true by default. |
| 69 | + */ |
| 70 | + shouldAutoDownload?: (options: { |
| 71 | + connection?: 'slow-2g' | '2g' | '3g' | '4g'; |
| 72 | + size?: number; |
| 73 | + threshold?: number; |
| 74 | + possiblySlowNetwork?: boolean; |
| 75 | + }) => boolean; |
| 76 | + /** |
| 77 | + * This provides an array of sources of different format and size of the image. |
| 78 | + * Read more about it: |
| 79 | + * https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset |
| 80 | + */ |
| 81 | + srcSet: SrcType[]; |
| 82 | + /** |
| 83 | + * This provides a theme to the component. By default, the component uses inline styles, |
| 84 | + * but it is also possible to use CSS modules and override all styles. |
| 85 | + */ |
| 86 | + theme?: Partial<Record<ThemeKey, string | CSSProperties>>; |
| 87 | + /** |
| 88 | + * Tells how much to wait in milliseconds until consider the download to be slow. |
| 89 | + */ |
| 90 | + threshold?: number; |
| 91 | + /** |
| 92 | + * Width of the image in px. |
| 93 | + */ |
| 94 | + width: number; |
| 95 | + } |
| 96 | + |
| 97 | + type IdealImageComponent = ComponentClass<ImageProps>; |
| 98 | + |
| 99 | + declare const IdealImage: IdealImageComponent; |
| 100 | + export default IdealImage; |
| 101 | +} |
0 commit comments