-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.ts
66 lines (53 loc) · 1.43 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
import React, { DOMAttributes } from 'react';
// maybe there is a better interface for my use case
export type DOMEvent = keyof DOMAttributes<HTMLElement>;
export type ModalId = string | number | symbol | null;
// 0 -> close
// 1 -> opening in progress
// 2 -> open
export type StateValues = 0 | 1 | 2;
export interface TriggerPropsOptions {
id?: ModalId;
event?: DOMEvent;
onOpen?: () => any;
onClose?: () => any;
background?: string;
}
export type HookOptions = Omit<TriggerPropsOptions, 'id'>;
export interface TriggerProps {
ref: React.MutableRefObject<any>;
[x: string]: React.MutableRefObject<any> | (() => void);
}
export type ModalState = Record<
'IS_CLOSE' | 'IS_IN_PROGRESS' | 'IS_OPEN',
StateValues
>;
export type ActiveTriggerRef = {
nodeRef: React.MutableRefObject<any> | null;
options?: TriggerPropsOptions | null;
};
export interface GetTriggerProps {
(id?: ModalId): TriggerProps;
(options?: TriggerPropsOptions): TriggerProps;
}
export interface OpenModal {
(
triggerRef: React.MutableRefObject<any>,
triggerOptions?: ModalId | TriggerPropsOptions
): void;
}
export interface CloseModal {
(): void;
}
export interface ModalProps {
placeholderRef: React.MutableRefObject<HTMLDivElement | null>;
state: StateValues;
close: CloseModal;
}
export interface UseModal {
open: OpenModal;
close: CloseModal;
activeModal: ModalId;
modalProps: ModalProps;
getTriggerProps: GetTriggerProps;
}