-
Notifications
You must be signed in to change notification settings - Fork 30
/
types.ts
85 lines (71 loc) · 2.12 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
import type { SvelteComponent } from 'svelte';
export type ToastType = 'success' | 'error' | 'loading' | 'blank' | 'custom';
/** Specifies the toast's position on the screen
*
* Logical positions (`start`, `end`) are recommended over absolute positions
* (`left`, `right`), as they automatically adjust based on the text direction
* of the locale (LTR or RTL). Examples:
* - Use `top-start` instead of `top-left`.
* - Use `top-end` instead of `top-right`. */
export type ToastPosition =
| 'top-left'
| 'top-center'
| 'top-right'
| 'bottom-left'
| 'bottom-center'
| 'bottom-right'
| 'top-start'
| 'top-end'
| 'bottom-start'
| 'bottom-end';
export type Renderable = typeof SvelteComponent | string | null;
export interface IconTheme {
primary: string;
secondary: string;
}
export type ValueFunction<TValue, TArg> = (arg: TArg) => TValue;
export type ValueOrFunction<TValue, TArg> = TValue | ValueFunction<TValue, TArg>;
const isFunction = <TValue, TArg>(
valOrFunction: ValueOrFunction<TValue, TArg>
): valOrFunction is ValueFunction<TValue, TArg> => typeof valOrFunction === 'function';
export const resolveValue = <TValue, TArg>(
valOrFunction: ValueOrFunction<TValue, TArg>,
arg: TArg
): TValue => (isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction);
export interface Toast {
type: ToastType;
id: string;
message: Renderable;
icon?: Renderable;
duration?: number;
pauseDuration: number;
position?: ToastPosition;
ariaProps: {
role: 'status' | 'alert';
'aria-live': 'assertive' | 'off' | 'polite';
};
style?: string;
className?: string;
iconTheme?: IconTheme;
createdAt: number;
visible: boolean;
height?: number;
}
export type DOMToast = Toast & { offset: number };
export type ToastOptions = Partial<
Pick<
Toast,
'id' | 'icon' | 'duration' | 'ariaProps' | 'className' | 'style' | 'position' | 'iconTheme'
>
>;
export type DefaultToastOptions = ToastOptions & {
[key in ToastType]?: ToastOptions;
};
export interface ToasterProps {
position?: ToastPosition;
toastOptions?: DefaultToastOptions;
reverseOrder?: boolean;
gutter?: number;
containerStyle?: string;
containerClassName?: string;
}