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