forked from nandorojo/burnt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
113 lines (106 loc) Β· 2.33 KB
/
types.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
import type { SFSymbol } from "sf-symbols-typescript";
export type IconParams = {
ios: {
/**
* The name of an iOS-only SF Symbol. For a full list, see https://developer.apple.com/sf-symbols/.
* @platform ios
*/
name: SFSymbol | (string & {});
/**
* Change the custom icon color, default is system blue.
* @platform ios
*/
color: string;
};
web?: JSX.Element;
};
export type AlertOptions = {
title: string;
message?: string;
/**
* Defaults to `true`.
*/
shouldDismissByTap?: boolean;
layout?: Layout;
} & (
| {
/**
* Defaults to `done`.
*/
preset?: "heart" | "done" | "error" | "none";
/**
* Duration in seconds.
*/
duration?: number;
}
| {
preset: "spinner";
/**
* Max timeout of the spinner in seconds. Required for this preset to avoid an infinite spinner.
*
* It's highly, highly recommended that you manually dismiss the alert using `Burnt.dismissAllAlerts()`.
*
* If you don't, then you risk having an infinite loading spinner for users.
*
* ```ts
* Burnt.alert({
* preset: "spinner",
* title: 'Loading...',
* duration: 10, // Maximum of 10 seconds
* })
*
* try {
* await createUser()
* } finally {
* Burnt.dismissAllAlerts()
* }
* ```
*/
duration: number;
}
| {
preset: "custom";
icon: IconParams;
/**
* Duration in seconds.
*/
duration?: number;
}
);
type Layout = {
iconSize?: {
width: number;
height: number;
};
};
export type BaseToastOptions = {
title: string;
message?: string;
/**
* Defaults to `done`.
*/
preset?: "done" | "error" | "none"; // TODO custom option
/**
* Duration in seconds.
*/
duration?: number;
haptic?: "success" | "warning" | "error" | "none";
/**
* Defaults to `true`.
*/
shouldDismissByDrag?: boolean;
/**
* Change the presentation side.
* @platform ios
*/
from?: "top" | "bottom";
layout?: Layout;
};
export type CustomToastOptions = Omit<BaseToastOptions, "preset"> & {
/**
* Defaults to `done`.
*/
preset?: "custom"; // TODO custom option
icon: IconParams;
};
export type ToastOptions = BaseToastOptions | CustomToastOptions;