-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
2218 lines (1959 loc) · 76.9 KB
/
docs.html
File metadata and controls
2218 lines (1959 loc) · 76.9 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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SimpleCalendarJs — Documentation</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--primary: #4f46e5;
--primary-dark: #4338ca;
--primary-light: #eef2ff;
--bg: #ffffff;
--bg-secondary: #f8fafc;
--text: #0f172a;
--text-secondary: #64748b;
--border: #e2e8f0;
--code-bg: #f1f5f9;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
line-height: 1.6;
color: var(--text);
background: var(--bg);
}
.header {
background: var(--primary);
color: white;
padding: 3rem 2rem;
text-align: center;
}
.header h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
letter-spacing: -0.02em;
}
.header p {
font-size: 1.125rem;
opacity: 0.9;
}
.nav {
position: sticky;
top: 0;
background: var(--bg);
border-bottom: 1px solid var(--border);
padding: 0 2rem;
z-index: 100;
box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.nav-inner {
max-width: 1200px;
margin: 0 auto;
display: flex;
gap: 2rem;
overflow-x: auto;
}
.nav a {
display: block;
padding: 1rem 0;
color: var(--text-secondary);
text-decoration: none;
font-weight: 500;
font-size: 0.875rem;
white-space: nowrap;
border-bottom: 2px solid transparent;
transition: all 150ms;
}
.nav a:hover {
color: var(--primary);
border-bottom-color: var(--primary);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 3rem 2rem;
}
.section {
margin-bottom: 4rem;
}
.section h2 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 1rem;
color: var(--text);
padding-bottom: 0.5rem;
border-bottom: 2px solid var(--border);
}
.section h3 {
font-size: 1.5rem;
font-weight: 600;
margin: 2rem 0 1rem;
color: var(--text);
}
.section h4 {
font-size: 1.125rem;
font-weight: 600;
margin: 1.5rem 0 0.75rem;
color: var(--text);
}
.section p {
margin-bottom: 1rem;
color: var(--text-secondary);
}
.section ul, .section ol {
margin: 1rem 0 1rem 1.5rem;
color: var(--text-secondary);
}
.section li {
margin-bottom: 0.5rem;
}
code {
background: var(--code-bg);
padding: 0.125rem 0.375rem;
border-radius: 3px;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
font-size: 0.875em;
color: var(--primary-dark);
}
pre {
background: var(--code-bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
overflow-x: auto;
margin: 1rem 0;
font-size: 0.875rem;
}
pre code {
background: none;
padding: 0;
border-radius: 0;
color: var(--text);
}
.table-wrapper {
overflow-x: auto;
margin: 1.5rem 0;
border: 1px solid var(--border);
border-radius: 8px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.875rem;
}
table th {
background: var(--bg-secondary);
padding: 0.75rem 1rem;
text-align: left;
font-weight: 600;
color: var(--text);
border-bottom: 1px solid var(--border);
}
table td {
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--border);
color: var(--text-secondary);
}
table tr:last-child td {
border-bottom: none;
}
.badge {
display: inline-block;
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.025em;
}
.badge-required {
background: #fee2e2;
color: #b91c1c;
}
.badge-optional {
background: #dbeafe;
color: #1e40af;
}
.note {
background: var(--primary-light);
border-left: 4px solid var(--primary);
padding: 1rem 1.5rem;
margin: 1.5rem 0;
border-radius: 4px;
}
.note p {
color: var(--text);
margin: 0;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
background: var(--primary);
color: white;
text-decoration: none;
border-radius: 6px;
font-weight: 600;
transition: background 150ms;
margin-top: 1rem;
}
.btn:hover {
background: var(--primary-dark);
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
margin: 2rem 0;
}
.card {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
}
.card h4 {
margin-top: 0;
}
.footer {
background: var(--bg-secondary);
border-top: 1px solid var(--border);
padding: 2rem;
text-align: center;
color: var(--text-secondary);
font-size: 0.875rem;
}
</style>
</head>
<body>
<div class="header">
<h1>SimpleCalendarJs</h1>
<p>A lightweight, zero-dependency JavaScript calendar component</p>
</div>
<nav class="nav">
<div class="nav-inner">
<a href="#installation">Installation</a>
<a href="#quickstart">Quick Start</a>
<a href="#options">Options</a>
<a href="#picker-modes">Picker Modes</a>
<a href="#callbacks">Callbacks</a>
<a href="#timezones">Timezones</a>
<a href="#tooltips">Tooltips</a>
<a href="#dragdrop">Drag and Drop</a>
<a href="#timed-event-style">Timed Event Style</a>
<a href="#row-heights">Row Heights</a>
<a href="#auto-contrast">Auto-Contrast Text</a>
<a href="#html-events">HTML in Events</a>
<a href="#listview">List View</a>
<a href="#methods">Methods</a>
<a href="#preferences">Preferences</a>
<a href="#theming">Theming</a>
<a href="#react">React</a>
<a href="#vue">Vue</a>
<a href="#angular">Angular</a>
<a href="#styling">Styling</a>
</div>
</nav>
<div class="container">
<!-- Installation -->
<section id="installation" class="section">
<h2>Installation</h2>
<p>SimpleCalendarJs is a zero-dependency calendar component. Include the CSS and JS files in your project:</p>
<h3>Via Script Tags</h3>
<pre><code><link rel="stylesheet" href="simple-calendar-js.css" />
<script src="simple-calendar-js.js"></script></code></pre>
<h3>Via ES Modules</h3>
<pre><code>import SimpleCalendarJs from './simple-calendar-js.js';
import './simple-calendar-js.css';</code></pre>
<div class="note">
<p><strong>Note:</strong> Make sure to include the CSS file for proper styling.</p>
</div>
</section>
<!-- Quick Start -->
<section id="quickstart" class="section">
<h2>Quick Start</h2>
<p>Create a calendar instance by passing a container element and options:</p>
<pre><code>// Create a container in your HTML
<div id="calendar"></div>
// Initialize the calendar
const calendar = new SimpleCalendarJs('#calendar', {
defaultView: 'month',
weekStartsOn: 1, // 0 = Sunday, 1 = Monday
locale: 'en-US',
use24Hour: false,
fetchEvents: async (start, end) => {
// Fetch events from your API
const response = await fetch(`/api/events?start=${start}&end=${end}`);
return response.json();
},
onEventClick: (event) => {
console.log('Event clicked:', event);
},
onSlotClick: (date) => {
console.log('Empty slot clicked:', date);
}
});</code></pre>
<a href="demo.html" class="btn">View Live Demo</a>
</section>
<!-- Options -->
<section id="options" class="section">
<h2>Options</h2>
<p>All available options when creating a calendar instance:</p>
<h3>View Options</h3>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mode</code></td>
<td>String</td>
<td><code>'calendar'</code></td>
<td>Calendar mode: <code>'calendar'</code> (standard calendar with events), <code>'date-picker'</code> (single date selection), or <code>'range-picker'</code> (date range selection)</td>
</tr>
<tr>
<td><code>defaultView</code></td>
<td>String</td>
<td><code>'month'</code></td>
<td>Initial view: <code>'month'</code>, <code>'week'</code>, or <code>'day'</code></td>
</tr>
<tr>
<td><code>defaultDate</code></td>
<td>Date</td>
<td><code>null</code></td>
<td>Initial date to display (defaults to today if not provided)</td>
</tr>
<tr>
<td><code>weekStartsOn</code></td>
<td>Number</td>
<td><code>0</code></td>
<td>First day of week: <code>0</code> (Sunday) or <code>1</code> (Monday)</td>
</tr>
<tr>
<td><code>locale</code></td>
<td>String</td>
<td><code>'default'</code></td>
<td>Locale code (e.g., <code>'en-US'</code>, <code>'fr-FR'</code>, <code>'pt-PT'</code>). Supports 34+ locales.</td>
</tr>
<tr>
<td><code>weekdayFormat</code></td>
<td>String</td>
<td><code>'short'</code></td>
<td>Weekday name format: <code>'narrow'</code> (1-2 letters), <code>'short'</code> (abbreviated), or <code>'long'</code> (full name)</td>
</tr>
<tr>
<td><code>use24Hour</code></td>
<td>Boolean</td>
<td><code>false</code></td>
<td>Use 24-hour time format instead of 12-hour with AM/PM</td>
</tr>
<tr>
<td><code>showTimeInItems</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show time in event items across all views</td>
</tr>
<tr>
<td><code>showGridLines</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide grid lines (borders between cells and time slots)</td>
</tr>
<tr>
<td><code>showBorder</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide calendar outer border</td>
</tr>
</tbody>
</table>
</div>
<h3>Display Options</h3>
<p>Control which toolbar elements are visible:</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>showToolbar</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide the entire toolbar</td>
</tr>
<tr>
<td><code>showTodayButton</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide the "Today" button</td>
</tr>
<tr>
<td><code>showNavigation</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide navigation arrows (← →)</td>
</tr>
<tr>
<td><code>showTitle</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide the month/week/day title</td>
</tr>
<tr>
<td><code>showYearPicker</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Enable/disable year selection (clickable year)</td>
</tr>
<tr>
<td><code>showViewSwitcher</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide Month/Week/Day view switcher buttons</td>
</tr>
<tr>
<td><code>enabledViews</code></td>
<td>Array</td>
<td><code>['month', 'week', 'day']</code></td>
<td>Which views are available to switch to</td>
</tr>
<tr>
<td><code>showTooltips</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Show/hide event tooltips on hover</td>
</tr>
<tr>
<td><code>tooltipAllowHtml</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Allow HTML in tooltips (sanitized for security). Supports: <code><b></code>, <code><i></code>, <code><strong></code>, <code><em></code>, <code><span></code>, <code><br></code>, <code><a></code> with safe attributes and URL validation</td>
</tr>
<tr>
<td><code>tooltipBgColor</code></td>
<td>String | null</td>
<td><code>null</code></td>
<td>Custom tooltip background color (hex). If <code>null</code>, uses CSS variable <code>--cal-tooltip-bg</code></td>
</tr>
<tr>
<td><code>tooltipTextColor</code></td>
<td>String | null</td>
<td><code>null</code></td>
<td>Custom tooltip text color (hex). If <code>null</code>, uses CSS variable <code>--cal-tooltip-text</code></td>
</tr>
<tr>
<td><code>tooltipMaxWidth</code></td>
<td>Number</td>
<td><code>250</code></td>
<td>Maximum tooltip width in pixels</td>
</tr>
<tr>
<td><code>tooltipDelay</code></td>
<td>Number</td>
<td><code>400</code></td>
<td>Delay in milliseconds before tooltip appears on hover</td>
</tr>
<tr>
<td><code>enableDragDrop</code></td>
<td>Boolean</td>
<td><code>false</code></td>
<td>Enable drag and drop to move events</td>
</tr>
<tr>
<td><code>enableResize</code></td>
<td>Boolean</td>
<td><code>false</code></td>
<td>Enable resizing events to change duration</td>
</tr>
<tr>
<td><code>autoContrastText</code></td>
<td>Boolean</td>
<td><code>false</code></td>
<td>Automatically calculate contrasting text color based on event background color for better readability</td>
</tr>
<tr>
<td><code>contrastLevel</code></td>
<td>String</td>
<td><code>'high'</code></td>
<td>Text contrast level when <code>autoContrastText</code> is enabled: <code>'high'</code> (black/white), <code>'medium'</code> (darker/lighter shade), <code>'low'</code> (subtle variation)</td>
</tr>
<tr>
<td><code>allowHtmlInEvents</code></td>
<td>Boolean</td>
<td><code>true</code></td>
<td>Allow basic HTML tags in event titles (sanitized for security). Supports: <code><b></code>, <code><i></code>, <code><strong></code>, <code><em></code>, <code><span></code>, <code><br></code> with <code>class</code> attribute for icons</td>
</tr>
<tr>
<td><code>monthTimedEventStyle</code></td>
<td>String</td>
<td><code>'list'</code></td>
<td>Display style for timed events in month view: <code>'list'</code> (schedule format) or <code>'block'</code> (traditional blocks)</td>
</tr>
<tr>
<td><code>monthDayNumberAlign</code></td>
<td>String</td>
<td><code>'left'</code></td>
<td>Horizontal alignment of day numbers in month view cells: <code>'left'</code>, <code>'center'</code>, or <code>'right'</code></td>
</tr>
<tr>
<td><code>showEventBorder</code></td>
<td>Boolean</td>
<td><code>false</code></td>
<td>Display borders around events. Border color adaptively darkens from event background (light colors darken more for visibility), or use event's <code>borderColor</code> property</td>
</tr>
</tbody>
</table>
</div>
<div class="note">
<p><strong>Example:</strong> Start calendar on a specific date:</p>
<pre><code>new SimpleCalendarJs('#calendar', {
defaultView: 'month',
defaultDate: new Date(2024, 5, 15) // June 15, 2024
});</code></pre>
</div>
<div class="note">
<p><strong>Example:</strong> Hide grid lines for a cleaner look:</p>
<pre><code>new SimpleCalendarJs('#calendar', {
showGridLines: false
});</code></pre>
</div>
<div class="note">
<p><strong>Example:</strong> Hide toolbar and only allow month view:</p>
<pre><code>new SimpleCalendarJs('#calendar', {
showToolbar: false,
enabledViews: ['month']
});</code></pre>
</div>
<div class="note">
<p><strong>Example:</strong> Customize weekday name format:</p>
<pre><code>// Portuguese with full day names
new SimpleCalendarJs('#calendar', {
locale: 'pt-PT',
weekdayFormat: 'long' // Domingo, Segunda-feira, Terça-feira...
});
// English with narrow format (single letters)
new SimpleCalendarJs('#calendar', {
locale: 'en-US',
weekdayFormat: 'narrow' // S, M, T, W, T, F, S
});</code></pre>
<p><strong>Note:</strong> Different locales format the same option differently. Use <code>weekdayFormat</code> to control the style: <code>'narrow'</code> (1-2 letters), <code>'short'</code> (abbreviated), or <code>'long'</code> (full name).</p>
</div>
</section>
<!-- Callbacks -->
<section id="picker-modes" class="section">
<h2>Picker Modes</h2>
<p>SimpleCalendarJs includes built-in date selection functionality with two picker modes:</p>
<h3>Date Picker Mode</h3>
<p>Select a single date:</p>
<pre><code>const datePicker = new SimpleCalendarJs('#date-picker', {
mode: 'date-picker',
onDateSelect: (date) => {
console.log('Selected date:', date);
// Update your form, input field, etc.
}
});
// Programmatic selection
datePicker.setSelectedDate(new Date('2024-12-25'));
// Get selected date
const selected = datePicker.getSelectedDate();</code></pre>
<h3>Range Picker Mode</h3>
<p>Select a date range (start and end dates):</p>
<pre><code>const rangePicker = new SimpleCalendarJs('#range-picker', {
mode: 'range-picker',
onRangeSelect: (startDate, endDate) => {
console.log('Selected range:', startDate, 'to', endDate);
// Update your booking form, filter dates, etc.
}
});
// Programmatic selection
rangePicker.setSelectedRange(
new Date('2024-12-01'),
new Date('2024-12-07')
);
// Get selected range
const range = rangePicker.getSelectedRange(); // { start: Date, end: Date }
// Clear selection
rangePicker.clearSelection();</code></pre>
<h3>Picker Mode Behavior</h3>
<p>When using picker modes:</p>
<ul>
<li><strong>No events displayed</strong> - Events are not fetched or rendered</li>
<li><strong>Month view only</strong> - View switcher is automatically hidden</li>
<li><strong>Centered day numbers</strong> - Day numbers are always centered (ignores monthDayNumberAlign)</li>
<li><strong>No today highlight</strong> - Today's date is not highlighted to avoid confusion with selection</li>
<li><strong>Visual feedback</strong> - Selected dates are highlighted with clear visual indicators</li>
<li><strong>Smart range selection</strong> - In range-picker mode, dates are automatically ordered</li>
</ul>
<h3>Picker API Methods</h3>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>getSelectedDate()</code></td>
<td>Date | null</td>
<td>Returns the currently selected date (date-picker mode)</td>
</tr>
<tr>
<td><code>setSelectedDate(date)</code></td>
<td>void</td>
<td>Programmatically set the selected date (date-picker mode)</td>
</tr>
<tr>
<td><code>getSelectedRange()</code></td>
<td>{start: Date, end: Date}</td>
<td>Returns the currently selected range (range-picker mode)</td>
</tr>
<tr>
<td><code>setSelectedRange(startDate, endDate)</code></td>
<td>void</td>
<td>Programmatically set the selected range (range-picker mode)</td>
</tr>
<tr>
<td><code>clearSelection()</code></td>
<td>void</td>
<td>Clear all selections (works in both picker modes)</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="callbacks" class="section">
<h2>Callbacks</h2>
<p>Register event handlers for user interactions:</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Callback</th>
<th>Parameters</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>fetchEvents</code></td>
<td><code>(start: Date, end: Date)</code></td>
<td>Async function to fetch events for the visible date range. Should return an array of event objects.</td>
</tr>
<tr>
<td><code>onEventClick</code></td>
<td><code>(event: Object)</code></td>
<td>Called when an event is clicked</td>
</tr>
<tr>
<td><code>onSlotClick</code></td>
<td><code>(date: Date)</code></td>
<td>Called when an empty time slot is clicked</td>
</tr>
<tr>
<td><code>onDateSelect</code></td>
<td><code>(date: Date)</code></td>
<td>Called when a date is selected in date-picker mode</td>
</tr>
<tr>
<td><code>onRangeSelect</code></td>
<td><code>(startDate: Date, endDate: Date)</code></td>
<td>Called when a date range is selected in range-picker mode</td>
</tr>
<tr>
<td><code>onViewChange</code></td>
<td><code>(view: String)</code></td>
<td>Called when the view changes (month/week/day)</td>
</tr>
<tr>
<td><code>onNavigate</code></td>
<td><code>(start: Date, end: Date)</code></td>
<td>Called when navigating to a different date range</td>
</tr>
<tr>
<td><code>onEventDrop</code></td>
<td><code>(event: Object, oldStart: Date, oldEnd: Date, newStart: Date, newEnd: Date)</code></td>
<td>Called when an event is dropped after being dragged</td>
</tr>
</tbody>
</table>
</div>
<h3>Event Object Format</h3>
<p>Events returned from <code>fetchEvents</code> should have the following structure:</p>
<pre><code>{
id: 'unique-id', // Required: Unique identifier
title: 'Event Title', // Required: Event name (can contain HTML if allowHtmlInEvents is enabled)
start: Date, // Required: Start date/time
end: Date, // Required: End date/time
allDay: false, // Optional: All-day event flag
color: '#4f46e5', // Optional: Custom background color (hex)
textColor: '#ffffff', // Optional: Custom text color (hex) - overrides autoContrastText
allowHtml: true, // Optional: Override global allowHtmlInEvents setting for this event
description: 'Details', // Optional: Event description (also used for tooltip)
tooltip: 'Custom tooltip' // Optional: Custom tooltip text (overrides description)
}</code></pre>
<div class="note">
<p><strong>Minute Precision:</strong> The calendar supports minute-level precision for event times. Events are positioned exactly according to their start/end times in week and day views. For example, an event starting at 9:15 AM will be positioned 15 minutes (25%) below the 9:00 AM hour line.</p>
</div>
<h3>Example</h3>
<pre><code>const calendar = new SimpleCalendarJs('#calendar', {
fetchEvents: async (start, end) => {
return [
{
id: '1',
title: 'Team Meeting',
start: new Date(2024, 0, 15, 9, 15), // 9:15 AM
end: new Date(2024, 0, 15, 10, 45), // 10:45 AM
color: '#4f46e5'
},
{
id: '2',
title: 'Lunch Break',
start: new Date(2024, 0, 15, 12, 30), // 12:30 PM
end: new Date(2024, 0, 15, 13, 30), // 1:30 PM
allDay: false,
color: '#059669'
}
];
},
onEventClick: (event) => {
alert(`Clicked: ${event.title}`);
},
onSlotClick: (date) => {
console.log('Create event at:', date);
}
});</code></pre>
</section>
<!-- Timezones -->
<section id="timezones" class="section">
<h2>Timezone Handling</h2>
<p>SimpleCalendarJs relies on JavaScript's native Date object for timezone handling, which means events are automatically displayed in the <strong>user's local timezone</strong>.</p>
<h3>How It Works</h3>
<ol>
<li><strong>Automatic Conversion</strong>: JavaScript Date objects automatically convert to the user's browser timezone</li>
<li><strong>No Configuration Needed</strong>: The calendar has no timezone settings - it uses the browser's timezone</li>
<li><strong>Backend Responsibility</strong>: Your backend should send timezone-aware date strings</li>
</ol>
<h3>Best Practices</h3>
<div class="card">
<h4>✓ Recommended - Send ISO 8601 strings with timezone</h4>
<pre><code>fetchEvents: async (start, end) => {
const response = await fetch(`/api/events?start=${start}&end=${end}`);
const events = await response.json();
// Backend returns ISO 8601 strings with timezone info
// Example: "2024-03-15T10:00:00Z" (UTC)
// or: "2024-03-15T10:00:00-05:00" (EST)
return events.map(event => ({
...event,
start: new Date(event.start), // Automatically converts to local timezone
end: new Date(event.end)
}));
}</code></pre>
</div>
<div class="card">
<h4>✗ Avoid - Sending dates without timezone info</h4>
<pre><code>// BAD: "2024-03-15T10:00:00" (no timezone)
// JavaScript interprets this as LOCAL time, not UTC
// This can cause issues for users in different timezones</code></pre>
</div>
<h3>Multi-Timezone Example</h3>
<p><strong>Scenario</strong>: Your server stores events in UTC, users are in different timezones</p>
<pre><code>// Server returns (stored in UTC):
{
"title": "Team Meeting",
"start": "2024-03-15T14:00:00Z", // 2:00 PM UTC
"end": "2024-03-15T15:00:00Z" // 3:00 PM UTC
}
// User in New York (EST, UTC-5):
// Calendar displays: 9:00 AM - 10:00 AM
// User in London (GMT, UTC+0):
// Calendar displays: 2:00 PM - 3:00 PM
// User in Tokyo (JST, UTC+9):
// Calendar displays: 11:00 PM - 12:00 AM</code></pre>
<h3>Important Notes</h3>
<ul>
<li><strong>Storage</strong>: Always store events in UTC in your database</li>
<li><strong>API Format</strong>: Send dates as ISO 8601 strings with timezone information</li>
<li><strong>Display</strong>: The calendar automatically shows events in the user's local timezone</li>
<li><strong>No Timezone Selector</strong>: The calendar doesn't provide UI to change timezone - it always uses the browser's timezone</li>
<li><strong>Time Formatting</strong>: Uses <code>Intl.DateTimeFormat</code> which respects the user's locale and timezone</li>
</ul>
<h3>Example Backend Response</h3>
<pre><code>{
"events": [
{
"id": 1,
"title": "Global Team Standup",
"start": "2024-03-15T14:00:00Z",
"end": "2024-03-15T14:30:00Z",
"description": "Daily standup - all timezones welcome"
}
]
}</code></pre>
<div class="note">
<p><strong>Summary</strong>: As long as your backend sends properly formatted ISO 8601 date strings with timezone information (e.g., with 'Z' for UTC or timezone offset like '-05:00'), the calendar will automatically handle timezone conversion for each user's location.</p>
</div>
</section>
<!-- Tooltips -->
<section id="tooltips" class="section">
<h2>Tooltips</h2>
<p>SimpleCalendarJs includes a powerful tooltip system with <strong>HTML support</strong>, smart positioning, and extensive customization options.</p>
<h3>How Tooltips Work</h3>
<p>Tooltips appear when you hover over an event (default 400ms delay). They display content based on the following priority:</p>
<ol>
<li><strong><code>tooltip</code> property</strong> (highest priority) - Custom tooltip content</li>
<li><strong><code>description</code> property</strong> - Falls back if no tooltip is provided</li>
<li><strong><code>title</code> property</strong> - Falls back if neither tooltip nor description is provided</li>
</ol>
<h3>Basic Text Tooltips</h3>
<pre><code>const events = [
{
id: 1,
title: 'Team Meeting',
start: new Date(2024, 2, 15, 10, 0),
end: new Date(2024, 2, 15, 11, 0),
tooltip: 'Weekly team sync' // Simple text tooltip
},
{
id: 2,
title: 'Client Call',
start: new Date(2024, 2, 15, 14, 0),
end: new Date(2024, 2, 15, 15, 0),
description: 'Requirements gathering session' // Used as tooltip
}
];</code></pre>
<h3>Rich HTML Tooltips</h3>
<p><strong>By default</strong>, tooltips support HTML formatting with secure sanitization:</p>
<pre><code>{
id: 1,
title: 'Design Review',
start: new Date(2024, 2, 20, 14, 0),
end: new Date(2024, 2, 20, 15, 30),
tooltip: '<b>Product Design Review</b><br><br><i>New feature mockups:</i><br>• Dashboard v2.0<br>• Mobile redesign<br><br><a href="https://figma.com/example">View in Figma</a>'
}</code></pre>
<div class="card">
<h4>Supported HTML Tags</h4>
<ul>
<li><code><b></code>, <code><strong></code> - Bold text</li>
<li><code><i></code>, <code><em></code> - Italic text</li>
<li><code><br></code> - Line breaks</li>
<li><code><span style="color: #xxx;"></code> - Colored text (only <code>color</code> and <code>background-color</code> allowed)</li>
<li><code><a href="..."></code> - Links (automatically open in new tab, URL validated for safety)</li>
</ul>
</div>
<div class="card">
<h4>Security Features</h4>
<ul>
<li>Dangerous protocols blocked (<code>javascript:</code>, <code>data:</code>, <code>vbscript:</code>)</li>
<li>Only safe CSS properties allowed in <code>style</code> attributes</li>
<li>All event handlers stripped (<code>onclick</code>, etc.)</li>
<li>Script tags and other dangerous elements removed</li>
</ul>
</div>
<h3>Configuration Options</h3>
<p>Control tooltip behavior globally:</p>
<pre><code>const calendar = new SimpleCalendarJs('#calendar', {
showTooltips: true, // Enable/disable tooltips (default: true)
tooltipAllowHtml: true, // Allow HTML in tooltips (default: true)
tooltipBgColor: '#1f2937', // Custom background color (default: null)
tooltipTextColor: '#f9fafb', // Custom text color (default: null)
tooltipMaxWidth: 250, // Maximum width in pixels (default: 250)
tooltipDelay: 400, // Hover delay in milliseconds (default: 400)
fetchEvents: async (start, end) => { /* ... */ }
});</code></pre>
<h3>Per-Event HTML Override</h3>
<p>Override the global <code>tooltipAllowHtml</code> setting for specific events:</p>
<pre><code>{
id: 1,
title: 'Secure Event',
tooltip: '<script>alert("xss")</script>', // This will be sanitized/removed
tooltipAllowHtml: false // Force plain text for this event only
}</code></pre>
<h3>Smart Positioning</h3>
<p>Tooltips use <strong>fixed positioning</strong> and automatically adjust to stay visible:</p>
<div class="card">
<ul>
<li><strong>Fixed to viewport</strong>: Never clipped by calendar container boundaries</li>
<li><strong>Edge detection</strong>:
<ul>
<li>Near <strong>top</strong>: tooltip appears below the event</li>
<li>Near <strong>right edge</strong>: tooltip shifts left</li>
<li>Near <strong>left edge</strong>: tooltip shifts right</li>
</ul>
</li>
<li><strong>Dynamic arrow</strong>: Arrow always points to the hovered event center</li>
</ul>
</div>
<h3>Styling Tooltips</h3>
<p>Customize via CSS variables:</p>
<pre><code>:root {
--cal-tooltip-bg: #1f2937; /* Background color */
--cal-tooltip-text: #f9fafb; /* Text color */