-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathtypes.ts
More file actions
375 lines (361 loc) · 10.4 KB
/
types.ts
File metadata and controls
375 lines (361 loc) · 10.4 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import { DialogProps, GridSize } from "@mui/material";
import { DateCalendarProps } from "@mui/x-date-pickers";
import { Locale } from "date-fns";
import { DragEvent } from "react";
import { SelectOption } from "./components/inputs/SelectInput";
import { View } from "./components/nav/Navigation";
import { Store } from "./store/types";
import { StateItem } from "./views/Editor";
import type { RRule } from "rrule";
export type DayHours =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24;
export type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6;
interface CommonWeekViewProps {
weekDays: WeekDays[];
weekStartOn: WeekDays;
disableGoToDay?: boolean;
}
interface CommonViewProps {
startHour: DayHours;
endHour: DayHours;
cellRenderer?(props: CellRenderedProps): React.ReactNode;
headRenderer?(props: {
day: Date;
events: ProcessedEvent[];
resource?: DefaultResource;
}): React.ReactNode;
navigation?: boolean;
step: number;
}
export interface MonthProps extends CommonWeekViewProps, CommonViewProps {}
export interface WeekProps extends CommonWeekViewProps, CommonViewProps {
hourRenderer?(hour: string): React.ReactNode;
}
export interface DayProps extends CommonViewProps {
hourRenderer?(hour: string): React.ReactNode;
}
export interface CellRenderedProps {
day: Date;
start: Date;
end: Date;
height: number;
onClick(): void;
onDragOver(e: DragEvent<HTMLButtonElement>): void;
onDragEnter(e: DragEvent<HTMLButtonElement>): void;
onDragLeave(e: DragEvent<HTMLButtonElement>): void;
onDrop(e: DragEvent<HTMLButtonElement>): void;
}
interface CalendarEvent {
event_id: number | string;
title: React.ReactNode;
subtitle?: React.ReactNode;
start: Date;
end: Date;
recurring?: RRule;
disabled?: boolean;
color?: string;
textColor?: string;
editable?: boolean;
deletable?: boolean;
draggable?: boolean;
allDay?: boolean;
/**
* @default " "
* passed as a children to mui <Avatar /> component
*/
agendaAvatar?: React.ReactElement | string;
}
export interface Translations {
navigation: Record<View, string> & { today: string; agenda: string };
form: {
addTitle: string;
editTitle: string;
confirm: string;
delete: string;
cancel: string;
};
event: Record<string, string> & {
title: string;
subtitle: string;
start: string;
end: string;
allDay: string;
};
validation?: {
required?: string;
invalidEmail?: string;
onlyNumbers?: string;
min?: string | ((min: number) => string);
max?: string | ((max: number) => string);
};
moreEvents: string;
noDataToDisplay: string;
loading: string;
}
export type InputTypes = "input" | "date" | "select" | "hidden";
export interface EventRendererProps
extends Pick<
React.HTMLAttributes<HTMLElement>,
"draggable" | "onDragStart" | "onDragEnd" | "onDragOver" | "onDragEnter" | "onClick"
> {
event: ProcessedEvent;
}
export interface FieldInputProps {
/** Available to all InputTypes */
label?: string;
/** Available to all InputTypes */
placeholder?: string;
/** Available to all InputTypes
* @default false
*/
required?: boolean;
/** Available to all InputTypes
* @default "outline"
*/
variant?: "standard" | "filled" | "outlined";
/** Available to all InputTypes */
disabled?: boolean;
/** Available when @input="text" ONLY - Minimum length */
min?: number;
/** Available when @input="text" ONLY - Maximum length */
max?: number;
/** Available when @input="text" ONLY - Apply email Regex */
email?: boolean;
/** Available when @input="text" ONLY - Only numbers(int/float) allowed */
decimal?: boolean;
/** Available when @input="text" ONLY - Allow Multiline input. Use @rows property to set initial rows height */
multiline?: boolean;
/** Available when @input="text" ONLY - initial rows height*/
rows?: number;
/** Available when @input="date" ONLY
* @default "datetime"
*/
type?: "date" | "datetime";
/** Available when @input="select" ONLY - Multi-Select input style.
* if you use "default" property with this, make sure your "default" property is an instance of Array
*/
multiple?: "chips" | "default";
/** Available when @input="select" ONLY - display loading spinner instead of expand arrow */
loading?: boolean;
/** Available when @input="select" ONLY - Custom error message */
errMsg?: string;
/* Used for Grid alignment in a single row md | sm | xs */
md?: GridSize;
/* Used for Grid alignment in a single row md | sm | xs */
sm?: GridSize;
/* Used for Grid alignment in a single row md | sm | xs */
xs?: GridSize;
}
export interface FieldProps {
name: string;
type: InputTypes;
/** Required for type="select" */
options?: Array<SelectOption>;
default?: string | number | Date | any;
config?: FieldInputProps;
}
export type ProcessedEvent = CalendarEvent & Record<string, any>;
export type EventActions = "create" | "edit";
export type RemoteQuery = {
start: Date;
end: Date;
view: "day" | "week" | "month";
};
export type DefaultResource = {
assignee?: string | number;
text?: string;
subtext?: string;
avatar?: string;
color?: string;
} & Record<string, any>;
export type ResourceFields = {
idField: string;
textField: string;
subTextField?: string;
avatarField?: string;
colorField?: string;
} & Record<string, string>;
export interface SchedulerHelpers {
state: Record<string, StateItem>;
close(): void;
loading(status: boolean): void;
edited?: ProcessedEvent;
onConfirm(event: ProcessedEvent | ProcessedEvent[], action: EventActions): void;
[resourceKey: string]: unknown;
}
export interface SchedulerProps {
/**Min height of table
* @default 600
*/
height: number;
/** Initial view to load */
view: View;
/**Activate Agenda view */
agenda?: boolean;
/** if true, day rows without event will be shown */
alwaysShowAgendaDays?: boolean;
/**Month view settings */
month: MonthProps | null;
/**Week view settings */
week: WeekProps | null;
/**Day view settings */
day: DayProps | null;
/**Initial date selected */
selectedDate: Date;
/** Show/Hide date navigation */
navigation?: boolean;
/** Show/Hide view navigator */
disableViewNavigator?: boolean;
/** */
navigationPickerProps?: Partial<
Omit<
DateCalendarProps<Date>,
"open" | "onClose" | "openTo" | "views" | "value" | "readOnly" | "onChange"
>
>;
/**Events to display */
events: ProcessedEvent[];
/** Custom event render method */
eventRenderer?: (props: EventRendererProps) => React.ReactNode | null;
/**Async function to load remote data with current view data. */
getRemoteEvents?(params: RemoteQuery): Promise<ProcessedEvent[] | void>;
/**Custom additional fields with it's settings */
fields: FieldProps[];
/**Table loading state */
loading?: boolean;
/** Custom loading component */
loadingComponent?: React.ReactNode;
/**Async function triggered when add/edit event */
onConfirm?(event: ProcessedEvent, action: EventActions): Promise<ProcessedEvent>;
/**Async function triggered when delete event */
onDelete?(deletedId: string | number): Promise<string | number | void>;
/**Override editor modal */
customEditor?(scheduler: SchedulerHelpers): React.ReactNode;
/** Custom viewer/popper component. If used, `viewerExtraComponent` & `viewerTitleComponent` will be ignored */
customViewer?(event: ProcessedEvent, close: () => void): React.ReactNode;
/**Additional component in event viewer popper */
viewerExtraComponent?:
| React.ReactNode
| ((fields: FieldProps[], event: ProcessedEvent) => React.ReactNode);
/**Override viewer title component */
viewerTitleComponent?(event: ProcessedEvent): React.ReactNode;
/**Override viewer subtitle component */
viewerSubtitleComponent?(event: ProcessedEvent): React.ReactNode;
/** if true, the viewer popover will be disabled globally */
disableViewer?: boolean;
/**Resources array to split event views with resources */
resources: DefaultResource[];
/**Map resources fields */
resourceFields: ResourceFields;
/**Override header component of resource */
resourceHeaderComponent?(resource: DefaultResource): React.ReactNode;
/** Triggered when resource tabs changes */
onResourceChange?(resource: DefaultResource): void;
/**Resource header view mode
* @default "default"
*/
resourceViewMode: "default" | "vertical" | "tabs";
/**Direction of table */
direction: "rtl" | "ltr";
/**Editor dialog maxWith
* @default "md"
*/
dialogMaxWidth: DialogProps["maxWidth"];
/**
* date-fns Locale object
*/
locale: Locale;
/**
* Localization
*/
translations: Translations;
/**
* Hour Format
*/
hourFormat: "12" | "24";
/**
* Time zone IANA ID: https://data.iana.org/time-zones/releases
*/
timeZone?: string;
/**
* Triggered when event is dropped on time slot.
*/
onEventDrop?(
event: DragEvent<HTMLButtonElement>,
droppedOn: Date,
updatedEvent: ProcessedEvent,
originalEvent: ProcessedEvent
): Promise<ProcessedEvent | void>;
/**
*
*/
onEventClick?(event: ProcessedEvent): void;
/**
* Triggered when an event item is being edited from the popover
*/
onEventEdit?(event: ProcessedEvent): void;
/**
* If event is deletable, applied to all events globally, overridden by event specific deletable prop
* @default true
*/
deletable?: boolean;
/**
* If calendar is editable, applied to all events/cells globally, overridden by event specific editable prop
* @default true
*/
editable?: boolean;
/**
* If event is draggable, applied to all events globally, overridden by event specific draggable prop
* @default true
*/
draggable?: boolean;
/**
* Triggered when the `selectedDate` prop changes by navigation date picker or `today` button.
*/
onSelectedDateChange?(date: Date): void;
/**
* Triggered when navigation view changes.
*/
onViewChange?(view: View, agenda?: boolean): void;
/**
* If true, the navigation controller bar will be sticky
*/
stickyNavigation?: boolean;
/**
* Overrides the default behavior of more events button
*/
onClickMore?(date: Date, gotToDay: (date: Date) => void): void;
/**
*
*/
onCellClick?(start: Date, end: Date, resourceKey?: string, resourceVal?: string | number): void;
}
export interface SchedulerRef {
el: HTMLDivElement;
scheduler: Store;
}
export interface Scheduler extends Partial<SchedulerProps> {}