-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathui.d.ts
196 lines (158 loc) · 5.52 KB
/
ui.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
189
190
191
192
193
194
195
196
import { Setting, SettingGroupProps } from "./components";
export interface UI {
/** Shows a generic but customizable modal. */
alert(title: string, content: React.ReactNode): void;
/** Creates a tooltip to show on hover. */
createTooltip(
node: HTMLElement,
content: string | HTMLElement,
options?: TooltipOptions,
): Tooltip;
/** Shows a generic but customizable confirmation modal with optional confirm and cancel callbacks. */
showConfirmationModal(
title: string,
content: React.ReactNode,
options?: ConfirmationModalOptions,
): string;
/** Shows a toast towards the bottom of the screen. */
showToast(content: string, options?: ToastOptions): void;
/** Shows a notice above Discord's chat layer. */
showNotice(content: string | Node, options?: NoticeOptions): CloseNotice;
/** Opens an Electron dialog. */
openDialog(options: DialogSaveOptions): Promise<DialogSaveResult>;
openDialog(options: DialogOpenOptions): Promise<DialogOpenResult>;
/** Shows a changelog modal. Customizable with images, videos, colored sections and supports markdown. */
showChangelogModal(options: ChangelogModalOptions): string;
/** Creates a single setting input wrapped in a setting item that has a name and note. */
buildSettingItem(setting: Setting): React.ReactElement;
/** Creates a settings panel. */
buildSettingsPanel(options: SettingsPanelOptions): React.ReactElement;
}
export interface TooltipOptions {
style?: "primary" | "info" | "success" | "warn" | "danger";
side?: "top" | "right" | "bottom" | "left";
preventFlip?: boolean;
disabled?: boolean;
}
interface Tooltip {
active: boolean;
disabled: boolean;
element: HTMLElement;
label: string | HTMLElement;
labelElement: HTMLElement;
node: HTMLElement;
preventFlip: boolean;
side: "top" | "right" | "bottom" | "left";
style: "primary" | "info" | "success" | "warn" | "danger";
tooltipElement: HTMLElement;
/** Container where the tooltip will be appended. */
get container(): HTMLElement;
/** Boolean representing if the tooltip will fit on screen above the element */
get canShowAbove(): boolean;
/** Boolean representing if the tooltip will fit on screen below the element */
get canShowBelow(): boolean;
/** Boolean representing if the tooltip will fit on screen to the left of the element */
get canShowLeft(): boolean;
/** Boolean representing if the tooltip will fit on screen to the right of the element */
get canShowRight(): boolean;
/** Hides the tooltip. Automatically called on mouseleave. */
hide(): void;
/** Shows the tooltip. Automatically called on mouseenter. Will attempt to flip if position was wrong. */
show(): void;
/** Force showing the tooltip above the node. */
showAbove(): void;
/** Force showing the tooltip below the node. */
showBelow(): void;
/** Force showing the tooltip to the left of the node. */
showLeft(): void;
/** Force showing the tooltip to the right of the node. */
showRight(): void;
centerHorizontally(): void;
centerVertically(): void;
}
export interface ConfirmationModalOptions {
danger?: boolean;
confirmText?: string;
cancelText?: string;
onConfirm?: () => void;
onCancel?: () => void;
onClose?: () => void;
}
export interface NoticeOptions {
type?: "info" | "error" | "warning" | "success";
buttons?: { label: string; onClick: () => void }[];
timeout?: number;
}
export type CloseNotice = (immediately?: boolean) => void;
export interface ToastOptions {
type?: "" | "info" | "success" | "danger" | "error" | "warning" | "warn";
icon?: boolean;
timeout?: number;
forceShow?: boolean;
}
export interface DialogOptions {
mode?: "open" | "save";
defaultPath?: string;
filters?: FileFilter[];
title?: string;
message?: string;
showOverwriteConfirmation?: boolean;
showHiddenFiles?: boolean;
promptToCreate?: boolean;
openDirectory?: boolean;
openFile?: boolean;
multiSelections?: boolean;
modal?: boolean;
}
export interface FileFilter {
name: string;
extensions: string[];
}
export interface DialogOpenOptions extends DialogOptions {
mode?: "open";
}
export interface DialogSaveOptions extends DialogOptions {
mode: "save";
}
export interface DialogResult {
canceled: boolean;
filePath?: string;
filePaths?: string[];
}
export interface DialogOpenResult extends Omit<DialogResult, "filePath"> {
filePaths: string[];
}
export interface DialogSaveResult extends Omit<DialogResult, "filePaths"> {
filePath: string;
}
export interface Changes {
title: string;
type: "fixed" | "added" | "progress" | "changed";
items: string[];
blurb?: string;
}
export interface ChangelogModalOptions {
title: string;
subtitle: string;
blurb?: string;
banner?: string;
video?: string;
poster?: string;
footer?: React.ReactNode;
changes?: Changes[];
}
type CategorySetting = Omit<
SettingGroupProps,
"onChange" | "onDrawerToggle" | "shown"
> & { type: "category" };
export type SettingsPanelSetting = Setting | CategorySetting;
export interface SettingsPanelOptions {
settings: SettingsPanelSetting[];
onChange: (
categoryId: string | null,
settingId: string,
value: any,
) => void;
onDrawerToggle?: (categoryId: string, state: boolean) => void;
getDrawerState?: (categoryId: string, defaultState: boolean) => boolean;
}