@mlopezlara90/react-scheduler 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +124 -0
  3. package/SchedulerComponent.d.ts +3 -0
  4. package/components/common/Cell.d.ts +14 -0
  5. package/components/common/LocaleArrow.d.ts +8 -0
  6. package/components/common/ResourceHeader.d.ts +6 -0
  7. package/components/common/Tabs.d.ts +16 -0
  8. package/components/common/TodayTypo.d.ts +8 -0
  9. package/components/common/WithResources.d.ts +6 -0
  10. package/components/events/Actions.d.ts +8 -0
  11. package/components/events/AgendaEventsList.d.ts +7 -0
  12. package/components/events/CurrentTimeBar.d.ts +9 -0
  13. package/components/events/EmptyAgenda.d.ts +2 -0
  14. package/components/events/EventItem.d.ts +10 -0
  15. package/components/events/EventItemPopover.d.ts +9 -0
  16. package/components/events/MonthEvents.d.ts +13 -0
  17. package/components/events/TodayEvents.d.ts +13 -0
  18. package/components/hoc/DateProvider.d.ts +5 -0
  19. package/components/inputs/DatePicker.d.ts +14 -0
  20. package/components/inputs/Input.d.ts +19 -0
  21. package/components/inputs/SelectInput.d.ts +22 -0
  22. package/components/month/MonthTable.d.ts +8 -0
  23. package/components/nav/DayDateBtn.d.ts +6 -0
  24. package/components/nav/MonthDateBtn.d.ts +6 -0
  25. package/components/nav/Navigation.d.ts +5 -0
  26. package/components/nav/WeekDateBtn.d.ts +8 -0
  27. package/components/week/WeekTable.d.ts +11 -0
  28. package/helpers/constants.d.ts +4 -0
  29. package/helpers/generals.d.ts +70 -0
  30. package/hooks/useArrowDisable.d.ts +5 -0
  31. package/hooks/useCellAttributes.d.ts +18 -0
  32. package/hooks/useDragAttributes.d.ts +10 -0
  33. package/hooks/useEventPermissions.d.ts +7 -0
  34. package/hooks/useIsClient.d.ts +2 -0
  35. package/hooks/useStore.d.ts +2 -0
  36. package/hooks/useSyncScroll.d.ts +8 -0
  37. package/hooks/useWindowResize.d.ts +5 -0
  38. package/index.d.ts +3 -0
  39. package/index.js +2812 -0
  40. package/package.json +65 -0
  41. package/positionManger/context.d.ts +14 -0
  42. package/positionManger/provider.d.ts +5 -0
  43. package/positionManger/usePosition.d.ts +4 -0
  44. package/store/context.d.ts +2 -0
  45. package/store/default.d.ts +233 -0
  46. package/store/provider.d.ts +7 -0
  47. package/store/types.d.ts +27 -0
  48. package/styles/styles.d.ts +22 -0
  49. package/types.d.ts +327 -0
  50. package/views/Day.d.ts +2 -0
  51. package/views/DayAgenda.d.ts +7 -0
  52. package/views/Editor.d.ts +11 -0
  53. package/views/Month.d.ts +2 -0
  54. package/views/MonthAgenda.d.ts +7 -0
  55. package/views/Week.d.ts +2 -0
  56. package/views/WeekAgenda.d.ts +8 -0
package/types.d.ts ADDED
@@ -0,0 +1,327 @@
1
+ import { DialogProps, GridSize } from '@mui/material';
2
+ import { DateCalendarProps } from '@mui/x-date-pickers';
3
+ import { Locale } from 'date-fns';
4
+ import { default as React, DragEvent } from 'react';
5
+ import { SelectOption } from './components/inputs/SelectInput';
6
+ import { View } from './components/nav/Navigation';
7
+ import { Store } from './store/types';
8
+ import { StateItem } from './views/Editor';
9
+ import { RRule } from 'rrule';
10
+ 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;
11
+ export type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6;
12
+ interface CommonWeekViewProps {
13
+ weekDays: WeekDays[];
14
+ weekStartOn: WeekDays;
15
+ disableGoToDay?: boolean;
16
+ }
17
+ interface CommonViewProps {
18
+ startHour: DayHours;
19
+ endHour: DayHours;
20
+ cellRenderer?(props: CellRenderedProps): React.ReactNode;
21
+ headRenderer?(props: {
22
+ day: Date;
23
+ events: ProcessedEvent[];
24
+ resource?: DefaultResource;
25
+ }): React.ReactNode;
26
+ navigation?: boolean;
27
+ step: number;
28
+ }
29
+ export interface MonthProps extends CommonWeekViewProps, CommonViewProps {
30
+ }
31
+ export interface WeekProps extends CommonWeekViewProps, CommonViewProps {
32
+ hourRenderer?(hour: string): React.ReactNode;
33
+ }
34
+ export interface DayProps extends CommonViewProps {
35
+ hourRenderer?(hour: string): React.ReactNode;
36
+ }
37
+ export interface CellRenderedProps {
38
+ day: Date;
39
+ start: Date;
40
+ end: Date;
41
+ height: number;
42
+ onClick(): void;
43
+ onDragOver(e: DragEvent<HTMLButtonElement>): void;
44
+ onDragEnter(e: DragEvent<HTMLButtonElement>): void;
45
+ onDragLeave(e: DragEvent<HTMLButtonElement>): void;
46
+ onDrop(e: DragEvent<HTMLButtonElement>): void;
47
+ }
48
+ interface CalendarEvent {
49
+ event_id: number | string;
50
+ title: React.ReactNode;
51
+ subtitle?: React.ReactNode;
52
+ start: Date;
53
+ end: Date;
54
+ recurring?: RRule;
55
+ disabled?: boolean;
56
+ color?: string;
57
+ textColor?: string;
58
+ editable?: boolean;
59
+ deletable?: boolean;
60
+ draggable?: boolean;
61
+ allDay?: boolean;
62
+ /**
63
+ * @default " "
64
+ * passed as a children to mui <Avatar /> component
65
+ */
66
+ agendaAvatar?: React.ReactElement | string;
67
+ }
68
+ export interface Translations {
69
+ navigation: Record<View, string> & {
70
+ today: string;
71
+ agenda: string;
72
+ };
73
+ form: {
74
+ addTitle: string;
75
+ editTitle: string;
76
+ confirm: string;
77
+ delete: string;
78
+ cancel: string;
79
+ };
80
+ event: Record<string, string> & {
81
+ title: string;
82
+ subtitle: string;
83
+ start: string;
84
+ end: string;
85
+ allDay: string;
86
+ };
87
+ validation?: {
88
+ required?: string;
89
+ invalidEmail?: string;
90
+ onlyNumbers?: string;
91
+ min?: string | ((min: number) => string);
92
+ max?: string | ((max: number) => string);
93
+ };
94
+ moreEvents: string;
95
+ noDataToDisplay: string;
96
+ loading: string;
97
+ }
98
+ export type InputTypes = "input" | "date" | "select" | "hidden";
99
+ export interface EventRendererProps extends Pick<React.HTMLAttributes<HTMLElement>, "draggable" | "onDragStart" | "onDragEnd" | "onDragOver" | "onDragEnter" | "onClick"> {
100
+ event: ProcessedEvent;
101
+ }
102
+ export interface FieldInputProps {
103
+ /** Available to all InputTypes */
104
+ label?: string;
105
+ /** Available to all InputTypes */
106
+ placeholder?: string;
107
+ /** Available to all InputTypes
108
+ * @default false
109
+ */
110
+ required?: boolean;
111
+ /** Available to all InputTypes
112
+ * @default "outline"
113
+ */
114
+ variant?: "standard" | "filled" | "outlined";
115
+ /** Available to all InputTypes */
116
+ disabled?: boolean;
117
+ /** Available when @input="text" ONLY - Minimum length */
118
+ min?: number;
119
+ /** Available when @input="text" ONLY - Maximum length */
120
+ max?: number;
121
+ /** Available when @input="text" ONLY - Apply email Regex */
122
+ email?: boolean;
123
+ /** Available when @input="text" ONLY - Only numbers(int/float) allowed */
124
+ decimal?: boolean;
125
+ /** Available when @input="text" ONLY - Allow Multiline input. Use @rows property to set initial rows height */
126
+ multiline?: boolean;
127
+ /** Available when @input="text" ONLY - initial rows height*/
128
+ rows?: number;
129
+ /** Available when @input="date" ONLY
130
+ * @default "datetime"
131
+ */
132
+ type?: "date" | "datetime";
133
+ /** Available when @input="select" ONLY - Multi-Select input style.
134
+ * if you use "default" property with this, make sure your "default" property is an instance of Array
135
+ */
136
+ multiple?: "chips" | "default";
137
+ /** Available when @input="select" ONLY - display loading spinner instead of expand arrow */
138
+ loading?: boolean;
139
+ /** Available when @input="select" ONLY - Custom error message */
140
+ errMsg?: string;
141
+ md?: GridSize;
142
+ sm?: GridSize;
143
+ xs?: GridSize;
144
+ }
145
+ export interface FieldProps {
146
+ name: string;
147
+ type: InputTypes;
148
+ /** Required for type="select" */
149
+ options?: Array<SelectOption>;
150
+ default?: string | number | Date;
151
+ config?: FieldInputProps;
152
+ }
153
+ export type ProcessedEvent = CalendarEvent & Record<string, any>;
154
+ export type EventActions = "create" | "edit";
155
+ export type RemoteQuery = {
156
+ start: Date;
157
+ end: Date;
158
+ view: "day" | "week" | "month";
159
+ };
160
+ export type DefaultResource = {
161
+ assignee?: string | number;
162
+ text?: string;
163
+ subtext?: string;
164
+ avatar?: string;
165
+ color?: string;
166
+ } & Record<string, any>;
167
+ export type ResourceFields = {
168
+ idField: string;
169
+ textField: string;
170
+ subTextField?: string;
171
+ avatarField?: string;
172
+ colorField?: string;
173
+ } & Record<string, string>;
174
+ export interface SchedulerHelpers {
175
+ state: Record<string, StateItem>;
176
+ close(): void;
177
+ loading(status: boolean): void;
178
+ edited?: ProcessedEvent;
179
+ onConfirm(event: ProcessedEvent | ProcessedEvent[], action: EventActions): void;
180
+ [resourceKey: string]: unknown;
181
+ }
182
+ export interface SchedulerProps {
183
+ /**Min height of table
184
+ * @default 600
185
+ */
186
+ height: number;
187
+ /** Initial view to load */
188
+ view: View;
189
+ /**Activate Agenda view */
190
+ agenda?: boolean;
191
+ /** if true, day rows without event will be shown */
192
+ alwaysShowAgendaDays?: boolean;
193
+ /**Month view settings */
194
+ month: MonthProps | null;
195
+ /**Week view settings */
196
+ week: WeekProps | null;
197
+ /**Day view settings */
198
+ day: DayProps | null;
199
+ /**Initial date selected */
200
+ selectedDate: Date;
201
+ /** Show/Hide date navigation */
202
+ navigation?: boolean;
203
+ /** Show/Hide view navigator */
204
+ disableViewNavigator?: boolean;
205
+ /** */
206
+ navigationPickerProps?: Partial<Omit<DateCalendarProps<Date>, "open" | "onClose" | "openTo" | "views" | "value" | "readOnly" | "onChange">>;
207
+ /**Events to display */
208
+ events: ProcessedEvent[];
209
+ /** Custom event render method */
210
+ eventRenderer?: (props: EventRendererProps) => React.ReactNode | null;
211
+ /**Async function to load remote data with current view data. */
212
+ getRemoteEvents?(params: RemoteQuery): Promise<ProcessedEvent[] | void>;
213
+ /**Custom additional fields with it's settings */
214
+ fields: FieldProps[];
215
+ /**Table loading state */
216
+ loading?: boolean;
217
+ /** Custom loading component */
218
+ loadingComponent?: React.ReactNode;
219
+ /**Async function triggered when add/edit event */
220
+ onConfirm?(event: ProcessedEvent, action: EventActions): Promise<ProcessedEvent>;
221
+ /**Async function triggered when delete event */
222
+ onDelete?(deletedId: string | number): Promise<string | number | void>;
223
+ /**Override editor modal */
224
+ customEditor?(scheduler: SchedulerHelpers): React.ReactNode;
225
+ /** Custom viewer/popper component. If used, `viewerExtraComponent` & `viewerTitleComponent` will be ignored */
226
+ customViewer?(event: ProcessedEvent, close: () => void): React.ReactNode;
227
+ /**Additional component in event viewer popper */
228
+ viewerExtraComponent?: React.ReactNode | ((fields: FieldProps[], event: ProcessedEvent) => React.ReactNode);
229
+ /**Override viewer title component */
230
+ viewerTitleComponent?(event: ProcessedEvent): React.ReactNode;
231
+ /**Override viewer subtitle component */
232
+ viewerSubtitleComponent?(event: ProcessedEvent): React.ReactNode;
233
+ /** if true, the viewer popover will be disabled globally */
234
+ disableViewer?: boolean;
235
+ /**Resources array to split event views with resources */
236
+ resources: DefaultResource[];
237
+ /**Map resources fields */
238
+ resourceFields: ResourceFields;
239
+ /**Override header component of resource */
240
+ resourceHeaderComponent?(resource: DefaultResource): React.ReactNode;
241
+ /** Triggered when resource tabs changes */
242
+ onResourceChange?(resource: DefaultResource): void;
243
+ /**Resource header view mode
244
+ * @default "default"
245
+ */
246
+ resourceViewMode: "default" | "vertical" | "tabs";
247
+ /**Direction of table */
248
+ direction: "rtl" | "ltr";
249
+ /**Editor dialog maxWith
250
+ * @default "md"
251
+ */
252
+ dialogMaxWidth: DialogProps["maxWidth"];
253
+ /**
254
+ * date-fns Locale object
255
+ */
256
+ locale: Locale;
257
+ /**
258
+ * Localization
259
+ */
260
+ translations: Translations;
261
+ /**
262
+ * Hour Format
263
+ */
264
+ hourFormat: "12" | "24";
265
+ /**
266
+ * Time zone IANA ID: https://data.iana.org/time-zones/releases
267
+ */
268
+ timeZone?: string;
269
+ /**
270
+ * Triggered when event is dropped on time slot.
271
+ */
272
+ onEventDrop?(event: DragEvent<HTMLButtonElement>, droppedOn: Date, updatedEvent: ProcessedEvent, originalEvent: ProcessedEvent): Promise<ProcessedEvent | void>;
273
+ /**
274
+ *
275
+ */
276
+ onEventClick?(event: ProcessedEvent): void;
277
+ /**
278
+ * Triggered when an event item is being edited from the popover
279
+ */
280
+ onEventEdit?(event: ProcessedEvent): void;
281
+ /**
282
+ * If event is deletable, applied to all events globally, overridden by event specific deletable prop
283
+ * @default true
284
+ */
285
+ deletable?: boolean;
286
+ /**
287
+ * If calendar is editable, applied to all events/cells globally, overridden by event specific editable prop
288
+ * @default true
289
+ */
290
+ editable?: boolean;
291
+ /**
292
+ * If event is draggable, applied to all events globally, overridden by event specific draggable prop
293
+ * @default true
294
+ */
295
+ draggable?: boolean;
296
+ /**
297
+ * Triggered when the `selectedDate` prop changes by navigation date picker or `today` button.
298
+ */
299
+ onSelectedDateChange?(date: Date): void;
300
+ /**
301
+ * Triggered when navigation view changes.
302
+ */
303
+ onViewChange?(view: View, agenda?: boolean): void;
304
+ /**
305
+ * If true, the navigation controller bar will be sticky
306
+ */
307
+ stickyNavigation?: boolean;
308
+ /**
309
+ * Overrides the default behavior of more events button
310
+ */
311
+ onClickMore?(date: Date, gotToDay: (date: Date) => void): void;
312
+ /**
313
+ *
314
+ */
315
+ onCellClick?(start: Date, end: Date, resourceKey?: string, resourceVal?: string | number): void;
316
+ /**
317
+ *
318
+ */
319
+ navigationSlot?: React.ReactNode;
320
+ }
321
+ export interface SchedulerRef {
322
+ el: HTMLDivElement;
323
+ scheduler: Store;
324
+ }
325
+ export interface IScheduler extends Partial<SchedulerProps> {
326
+ }
327
+ export {};
package/views/Day.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const Day: () => import("react/jsx-runtime").JSX.Element;
2
+ export { Day };
@@ -0,0 +1,7 @@
1
+ import { DefaultResource, ProcessedEvent } from '../types';
2
+ type Props = {
3
+ events: ProcessedEvent[];
4
+ resource?: DefaultResource;
5
+ };
6
+ declare const DayAgenda: ({ events, resource }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export { DayAgenda };
@@ -0,0 +1,11 @@
1
+ import { SelectedRange } from '../store/types';
2
+ import { FieldInputProps, InputTypes, ProcessedEvent } from '../types';
3
+ export type StateItem = {
4
+ value: any;
5
+ validity: boolean;
6
+ type: InputTypes;
7
+ config?: FieldInputProps;
8
+ };
9
+ export type StateEvent = (ProcessedEvent & SelectedRange) | Record<string, any>;
10
+ declare const Editor: () => import("react/jsx-runtime").JSX.Element;
11
+ export default Editor;
@@ -0,0 +1,2 @@
1
+ declare const Month: () => import("react/jsx-runtime").JSX.Element;
2
+ export { Month };
@@ -0,0 +1,7 @@
1
+ import { DefaultResource, ProcessedEvent } from '../types';
2
+ type Props = {
3
+ events: ProcessedEvent[];
4
+ resource?: DefaultResource;
5
+ };
6
+ declare const MonthAgenda: ({ events, resource }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export { MonthAgenda };
@@ -0,0 +1,2 @@
1
+ declare const Week: () => import("react/jsx-runtime").JSX.Element;
2
+ export { Week };
@@ -0,0 +1,8 @@
1
+ import { DefaultResource, ProcessedEvent } from '../types';
2
+ type Props = {
3
+ daysList: Date[];
4
+ resource?: DefaultResource;
5
+ events: ProcessedEvent[];
6
+ };
7
+ declare const WeekAgenda: ({ daysList, resource, events }: Props) => import("react/jsx-runtime").JSX.Element;
8
+ export { WeekAgenda };