UNPKG

13.5 kBMarkdownView Raw
1<p><img src="https://raw.githubusercontent.com/PawanKolhe/color-calendar/master/screenshots/logo.png" alt="logo" width="20%" /></p>
2<p>
3 <h1>Color Calendar</h1>
4</p>
5<p>
6 <a href="https://www.npmjs.com/package/color-calendar">
7 <img src="https://img.shields.io/npm/v/color-calendar?style=flat-square" alt="npm version" />
8 </a>
9 <a href="https://www.npmjs.com/package/color-calendar">
10 <img src="https://img.shields.io/npm/dw/color-calendar?style=flat-square" alt="npm downloads" />
11 </a>
12 <img src="https://img.shields.io/bundlephobia/min/color-calendar?style=flat-square" alt="size" />
13 <a href="https://www.jsdelivr.com/package/npm/color-calendar">
14 <img src="https://data.jsdelivr.com/v1/package/npm/color-calendar/badge" alt="jsdelivr" />
15 </a>
16 <img src="https://hitcounter.pythonanywhere.com/count/tag.svg?url=https%3A%2F%2Fgithub.com%2FPawanKolhe%2Fcolor-calendar" alt="Hits">
17 <img src="https://img.shields.io/npm/l/color-calendar?style=flat-square" alt="license" />
18</p>
19<p>
20 A customizable events calendar component library. Checkout <a href="https://online-tech-confs.herokuapp.com/">Demo 1</a>, <a href="https://v84yk.csb.app/">Demo 2</a> and <a href="https://codesandbox.io/s/color-calendar-bnwdu">Demo 3.</a>
21</p>
22
23<!-- # Color Calendar
24![npm](https://img.shields.io/npm/v/color-calendar?style=flat-square)
25![npm](https://img.shields.io/npm/dw/color-calendar?style=flat-square)
26![npm bundle size](https://img.shields.io/bundlephobia/min/color-calendar?style=flat-square)
27[![](https://data.jsdelivr.com/v1/package/npm/color-calendar/badge)](https://www.jsdelivr.com/package/npm/color-calendar)
28![HitCount](http://hits.dwyl.com/PawanKolhe/color-calendar.svg)
29![NPM](https://img.shields.io/npm/l/color-calendar?style=flat-square) -->
30
31![Color Calendar](https://raw.githubusercontent.com/PawanKolhe/color-calendar/master/screenshots/poster_calendar.png)
32
33* [Features](#features)
34* [Getting Started](#getting-started)
35 * [CDN](#cdn)
36 * [NPM](#npm)
37* [Usage](#usage)
38 * [Basic](#usage-basic)
39 * [React](#usage-react)
40 * [Vue](#usage-vue)
41* [Options](#options)
42* [Events](#events)
43* [Methods](#methods)
44* [Types](#types)
45* [Themes](#themes)
46* [Bug Reporting](#bug)
47* [Feature Request](#feature-request)
48* [Release Notes](#release-notes)
49* [License](#license)
50
51<a id="features"></a>
52## 🚀 Features
53- Zero dependencies
54- Add events to calendar
55- Perform some action on calendar date change
56- Month and year picker built-in
57- Themes available
58- Fully customizable using CSS variables, passing options parameters while creating calendar, or overriding CSS.
59- [Request more features](#feature-request)...
60
61<a id="getting-started"></a>
62## 📦 Getting Started
63
64### CDN
65#### JavaScript
66```html
67<script src="https://cdn.jsdelivr.net/npm/color-calendar/dist/bundle.js">
68```
69Also available on [unpkg](https://unpkg.com/browse/color-calendar/dist/).
70
71#### CSS
72Pick a css file according to the theme you want.
73```html
74<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/color-calendar/dist/css/theme-basic.css">
75<!-- or -->
76<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/color-calendar/dist/css/theme-glass.css">
77```
78
79#### Fonts
80Get fonts from [Google Fonts](https://fonts.google.com/)
81```html
82<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap" rel="stylesheet">
83```
84Check what fonts the [theme](#themes) needs or pass your own fonts in [options](#options-fonts).
85
86### NPM
87> _You might need to use a module bundler such as webpack, rollup, parcel, etc._
88#### Installation
89```bash
90npm i color-calendar
91```
92#### Import
93```javascript
94import Calendar from 'color-calendar';
95```
96
97#### CSS
98```javascript
99import 'color-calendar/dist/css/theme-<THEME-NAME>.css';
100```
101
102Then add fonts.
103
104<a id="usage"></a>
105## 🔨 Usage
106<a id="usage-basic"></a>
107### Basic
108#### JavaScript
109```javascript
110new Calendar()
111```
112_Or_ you can pass in **options**.
113```javascript
114new Calendar({
115 id: '#color-calendar',
116 calendarSize: 'small'
117})
118```
119
120#### HTML
121```html
122<div id="color-calendar"></div>
123```
124[Example](https://codesandbox.io/s/color-calendar-bnwdu)
125
126<a id="usage-react"></a>
127### React
128[Example](https://codesandbox.io/s/color-calendar-react-y0cyf?file=/src/CalendarComponent.jsx)
129
130<a id="usage-vue"></a>
131### Vue
132[Example](https://codesandbox.io/s/color-calendar-vue-byo6e?file=/src/components/ColorCalendar.vue)
133
134<a id="options"></a>
135## ⚙️ Options
136
137### `id`
138Type: `String`
139Default: `#color-calendar`
140
141Selector referencing HTMLElement where the calendar instance will bind to.
142
143### `calendarSize`
144Type: `String`
145Default: `large`
146Options: `small` | `large`
147
148Size of calendar UI.
149
150### `layoutModifiers`
151Type: [`LayoutModifier`](#type-layout-modifier)[]
152Default: `[]`
153Example: `['month-left-align']`
154
155Modifiers to alter the layout of the calendar.
156
157### `eventsData`
158Type: [`EventData`](#type-event-data)[]
159Default: `null`
160
161```javascript
162[
163 {
164 start: '2020-08-17T06:00:00',
165 end: '2020-08-18T20:30:00',
166 name: 'Blockchain 101'
167 ...
168 },
169 ...
170]
171```
172
173Array of objects containing events information.
174> Note: Properties `start` and `end` are *required* for each event in the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time format. You can _optionally_ choose to add other properties.
175
176### `theme`
177Type: `String`
178Default: `basic`
179Options: `basic` | `glass`
180
181Choose from available themes.
182
183### `primaryColor`
184Type: `String`
185Default: *based on theme*
186Example: `#1a237e`
187
188Main color accent of calendar. *Pick a color in rgb, hex or hsl format.*
189
190### `headerColor`
191Type: `String`
192Default: *based on theme*
193Example: `rgb(0, 102, 0)`
194
195Color of header text.
196
197### `headerBackgroundColor`
198Type: `String`
199Default: *based on theme*
200Example: `black`
201
202Background color of header. *Only works on some themes.*
203
204### `weekdaysColor`
205Type: `String`
206Default: *based on theme*
207
208Color of weekdays text. *Only works on some themes.*
209
210### `weekdayDisplayType`
211Type: `String`
212Default: `short`
213Options: [WeekdayDisplayType](#type-weekday-display-type) (`short` | `long-lower` | `long-upper`)
214
215Select how weekdays will be displayed. E.g. M, Mon, or MON.
216
217### `monthDisplayType`
218Type: `String`
219Default: `long`
220Options: [MonthDisplayType](#type-month-display-type) (`short` | `long`)
221
222Select how month will be displayed in header. E.g. Feb, February.
223
224### `startWeekday`
225Type: `Number`
226Default: `0`
227Options: `0` | `1` | `2` | `3` | `4` | `5` | `6`
228
229Starting weekday. Mapping: 0 (Sun), 1 (Mon), 2 (Tues), 3 (Wed), 4 (Thurs), 5 (Fri), 6 (Sat)
230
231<a id="options-fonts"></a>
232### `fontFamilyHeader`
233Type: `String`
234Default: *based on theme*
235Example value: `'Open Sans', sans-serif`
236
237Font of calendar header text.
238
239### `fontFamilyWeekdays`
240Type: `String`
241Default: *based on theme*
242
243Font of calendar weekdays text.
244
245### `fontFamilyBody`
246Type: `String`
247Default: *based on theme*
248
249Font of calendar days as well as month and year picker text.
250
251### `dropShadow`
252Type: `String`
253Default: *based on theme*
254
255Set CSS of calendar drop shadow.
256
257### `border`
258Type: `String`
259Default: *based on theme*
260Example value: `5px solid black`
261
262Set CSS style of border.
263
264### `borderRadius`
265Type: `String`
266Default: `0.5rem`
267
268Set CSS border radius of calendar.
269
270### `disableMonthYearPickers`
271Type: `Boolean`
272Default: `false`
273
274If month and year picker should be disabled.
275
276### `disableDayClick`
277Type: `Boolean`
278Default: `false`
279
280If day click should be disabled.
281
282### `disableMonthArrowClick`
283Type: `Boolean`
284Default: `false`
285
286If month arrows should be disabled.
287
288<a id="events"></a>
289## 🖱 Events
290
291### `dateChanged`
292Type: `Function`
293Props:
294- `currentDate`
295 - Type: `Date`
296 - Currently selected date
297- `filteredDateEvents`
298 - Type: [`EventData`](#type-event-data)[]
299 - All events on that particular date
300```typescript
301const options = {
302 ...
303 dateChanged: (currentDate?: Date, filteredDateEvents?: EventData[]) => {
304 // do something
305 };
306 ...
307}
308```
309
310Emitted when the selected date is changed.
311
312### `monthChanged`
313Type: `Function`
314Props:
315- `currentDate`
316 - Type: `Date`
317 - Currently selected date
318- `filteredMonthEvents`
319 - Type: [`EventData`](#type-event-data)[]
320 - All events on that particular month
321
322Emitted when the current month is changed.
323
324<a id="methods"></a>
325## 🔧 Methods
326### `reset()`
327
328Reset calendar to today's date.
329```javascript
330// Example
331let myCal = new Calendar();
332myCal.reset();
333```
334
335### `setDate()`
336Props:
337| Props | Type | Required | Description |
338|-------|------|----------|--------------------|
339| date | Date | required | New date to be set |
340
341Set new selected date.
342
343```javascript
344// Example
345myCal.setDate(new Date());
346```
347
348### `getSelectedDate()`
349Return:
350- Type: `Date`
351- Description: `Currently selected date`
352
353Get currently selected date.
354
355### `getEventsData()`
356Return:
357- Type: [EventData](#type-event-data)[]
358- Description: `All events`
359
360Get events array.
361
362### `setEventsData()`
363Props:
364| Props | Type | Required | Description |
365|--------|------------|----------|------------------|
366| events | [EventData](#type-event-data)[] | required | Events to be set |
367
368Return:
369- Type: `Number`
370- Description: `Number of events set`
371
372Set a new events array.
373
374### `addEventsData()`
375Props:
376| Props | Type | Required | Description |
377|--------|------------|----------|--------------------|
378| events | [EventData](#type-event-data)[] | required | Events to be added |
379
380Return:
381- Type: `Number`
382- Description: `Number of events added`
383
384Add events of the events array.
385
386### `setWeekdayDisplayType()`
387Props:
388| Props | Type | Required | Description |
389|--------|------------|----------|--------------------|
390| weekdayDisplayType | [WeekdayDisplayType](#type-weekday-display-type) | required | New weekday type |
391
392Set weekdays display type.
393
394```javascript
395// Example
396myCal.setWeekdayDisplayType("short");
397```
398
399### `setMonthDisplayType()`
400Props:
401| Props | Type | Required | Description |
402|--------|------------|----------|--------------------|
403| monthDisplayType | [MonthDisplayType](#type-month-display-type) | required | New month display type |
404
405Set month display type.
406
407<a id="types"></a>
408## 💎 Types
409<a id="type-event-data"></a>
410### `EventData`
411```javascript
412{
413 start: string, // ISO 8601 date and time format
414 end: string, // ISO 8601 date and time format
415 [key: string]: any,
416}
417```
418
419<a id="type-weekday-display-type"></a>
420### `WeekdayDisplayType`
421`"short"` | `"long-lower"` | `"long-upper"`
422
423```markdown
424// "short"
425M T W ...
426
427// "long-lower"
428Mon Tue Wed ...
429
430// "long-upper"
431MON TUE WED ...
432```
433
434<a id="type-month-display-type"></a>
435### `MonthDisplayType`
436`"short"` | `"long"`
437
438```markdown
439// "short"
440Jan Feb Mar ...
441
442// "long"
443January February March ...
444```
445
446<a id="type-layout-modifier"></a>
447### `LayoutModifier`
448`"month-align-left"`
449
450<a id="themes"></a>
451## 🎨 Themes
452Currently 2 themes available. More on the way.
453
454### `basic`
455<img src="https://raw.githubusercontent.com/PawanKolhe/color-calendar/master/screenshots/theme-basic.PNG" alt="Basic Theme" width="400" />
456
457#### CSS Custom Properties
458`--cal-color-primary`: #000000;
459`--cal-font-family-header`: "Work Sans", sans-serif;
460`--cal-font-family-weekdays`: "Work Sans", sans-serif;
461`--cal-font-family-body`: "Work Sans", sans-serif;
462`--cal-drop-shadow`: 0 7px 30px -10px rgba(150, 170, 180, 0.5);
463`--cal-border`: none;
464`--cal-border-radius`: 0.5rem;
465`--cal-header-color`: black;
466`--cal-weekdays-color`: black;
467
468### `glass`
469<img src="https://raw.githubusercontent.com/PawanKolhe/color-calendar/master/screenshots/theme-glass.PNG" alt="Glass Theme" width="400" />
470
471#### CSS Custom Properties
472`--cal-color-primary`: #EC407A;
473`--cal-font-family-header`: 'Open Sans', sans-serif;
474`--cal-font-family-weekdays`: 'Open Sans', sans-serif;
475`--cal-font-family-body`: 'Open Sans', sans-serif;
476`--cal-drop-shadow`: 0 7px 30px -10px rgba(150, 170, 180, 0.5);
477`--cal-border`: none;
478`--cal-border-radius`: 0.5rem;
479`--cal-header-color`: white;
480`--cal-header-background-color`: rgba(0, 0, 0, 0.3);
481
482<a id="bug"></a>
483## 🐛 Bug Reporting
484Feel free to [open an issue](https://github.com/PawanKolhe/color-calendar/issues) on GitHub if you find any bug.
485
486<a id="feature-request"></a>
487## ⭐ Feature Request
488- Feel free to [Open an issue](https://github.com/PawanKolhe/color-calendar/issues) on GitHub to request any additional features you might need for your use case.
489- Connect with me on [LinkedIn](https://www.linkedin.com/in/kolhepawan/). I'd love ❤️️ to hear where you are using this library.
490
491<a id="release-notes"></a>
492## 📋 Release Notes
493Check [here](https://github.com/PawanKolhe/color-calendar/releases) for release notes.
494
495<a id="license"></a>
496## 📜 License
497This software is open source, licensed under the [MIT License](https://github.com/PawanKolhe/color-calendar/blob/master/LICENSE).