-
Notifications
You must be signed in to change notification settings - Fork 118
/
index.d.ts
188 lines (173 loc) · 5.54 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import * as React from "react";
export interface ReactAvatarProps {
children?: React.ReactNode;
/**
* Name of the CSS class you want to add to this component alongside the default sb-avatar.
*/
className?: string;
/**
* String of the email address of the user.
*/
email?: string;
/**
* String of the MD5 hash of email address of the user.
*/
md5Email?: string;
facebookId?: string;
twitterHandle?: string;
googleId?: string;
instagramId?: string;
githubHandle?: string;
skypeId?: string;
/**
* Will be used to generate avatar based on the initials of the person
*/
name?: string;
/**
* Set max nr of characters used for the initials. If maxInitials=2 and the name is Foo Bar Var the initials will be FB
*/
maxInitials?: number;
/**
* Initials to show or a method converting name into initials
* @param {string} name
* @param {any} value
* @returns {string}
*/
initials?: string | ((name: string, props: any) => string);
/**
* Show a value as avatar
*/
value?: string;
/**
* The alt attribute used on the avatar img tag. If not set we will fallback to either name or value
*/
alt?: string | boolean;
/**
* The title attribute used on the avatar img tag. If not set we will fallback to either name or value
*/
title?: string | boolean;
/**
* Used in combination with `name` and `value`. Give the background a fixed color with a hex like for example #FF0000
*/
color?: string;
/**
* Used in combination with `name` and `value`. Give the text a fixed color with a hex like for example #FF0000
*/
fgColor?: string;
/**
* Size of the avatar
*/
size?: string;
/**
* For text based avatars the size of the text as a fragment of size (size / textSizeRatio)
*/
textSizeRatio?: number;
/**
* For text based avatars. The size of the minimum margin between the text and the avatar's edge, used to make sure the text will always fit inside the avatar. (calculated as `size * textMarginRatio`)
*/
textMarginRatio?: number;
/**
* The amount of `border-radius` to apply to the avatar corners, `true` shows the avatar in a circle.
*/
round?: boolean | string;
/**
* Fallback image to use
*/
src?: string;
/**
* Style that will be applied on the root element
*/
style?: any;
/**
* Disable all styles
*/
unstyled?: boolean;
/**
* Mouse click event
* @param {React.SyntheticEvent<any>} e
* @returns {any}
*/
onClick?: (e: React.SyntheticEvent<any>) => any;
}
interface CreateAvatarOptions {
sources?: SourceConstructor[]
}
export interface ConfigProvider {
/**
* A list of color values as strings from which the getRandomColor picks one at random.
*/
colors?: string[];
/**
* Cache implementation used to track broken img URLs
*/
cache?: Cache;
/**
* Method converting name into initials
* @param {string} name
* @param {any} value
* @returns {string}
*/
initials?: (name: string, props: any) => string;
/**
* The baseUrl for a avatar-redirect service
*/
avatarRedirectUrl?: string;
}
export interface Cache {
/**
* Save `value` at `key`, such that it can be retrieved using `get(key)`
* @param {string} key
* @param {string} value
*/
set: (key: string, value: string) => void;
/**
* Retrieve the value stored at `key`, if the cache does not contain a value for `key` return `null`
* @param {string} key
* @returns {string | null}
*/
get: (key: string) => string | null;
/**
* Mark the image URL specified in `source` as failed.
* @param {string} source
*/
sourceFailed: (source: string) => void;
/**
* Returns `true` if the `source` has been tagged as failed using `sourceFailed(source)`, otherwise `false`.
* @param {string} source
* @returns {boolean}
*/
hasSourceFailedBefore: (source: string) => boolean;
}
export interface CacheOptions {
cachePrefix?: string,
sourceTTL?: number,
sourceSize?: number
}
type CacheConstructor = new (options: CacheOptions) => Cache;
interface Source {
isCompatible: () => boolean;
get: (setState: (update: object) => void) => void;
}
type SourceConstructor = new (props: object) => Source;
export const RedirectSource: (network: string, property: string) => SourceConstructor
/**
* Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user.
* We use a fallback system that if for example an invalid Facebook ID is used it will try Google, and so on.
*/
type ReactAvatar = React.ComponentType<ReactAvatarProps>;
declare const Avatar : ReactAvatar;
export const createAvatarComponent: (options: CreateAvatarOptions) => ReactAvatar;
export const ConfigProvider: React.ComponentType<ConfigProvider>;
export const Cache: CacheConstructor;
export const GravatarSource: SourceConstructor;
export const FacebookSource: SourceConstructor;
export const GithubSource: SourceConstructor;
export const SkypeSource: SourceConstructor;
export const ValueSource: SourceConstructor;
export const SrcSource: SourceConstructor;
export const IconSource: SourceConstructor;
export const VKontakteSource: SourceConstructor;
export const InstagramSource: SourceConstructor;
export const TwitterSource: SourceConstructor;
export const GoogleSource: SourceConstructor;
export default Avatar;