Skip to content

Commit

Permalink
Merge pull request #32 from year-calendar/feature_startdate_numbermon…
Browse files Browse the repository at this point in the history
…thsdisplayed

Allow usage of the calendar for specific periods
  • Loading branch information
Paul-DS authored Aug 22, 2021
2 parents 561a8b3 + 5e0e89f commit 2f178e8
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 104 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ document.querySelector('.calendar').addEventListener('clickDay', function(e) {

You can find the exhaustive list of events in the [documentation](https://year-calendar.github.io/js-year-calendar/documentation).

## Migrating v1.x to v2.x

If you are using the dataSource option as a function (callback or promise), the first parameter has changed:
```
new Calendar('#calendar', {
dataSource: (year) => {
console.log(year);
}
}
```
becomes
```
new Calendar('#calendar', {
dataSource: (period) => {
console.log(period.year);
}
}
```

For more details, check [this PR](https://github.com/year-calendar/js-year-calendar/pull/32)

## Migrating from bootstrap-year-calendar

This widget is based on the [bootstrap-year-calendar](https://github.com/Paul-DS/bootstrap-year-calendar) widget.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-year-calendar",
"version": "1.0.2",
"version": "2.0.0-alpha.2",
"description": "A fully customizable year calendar widget",
"main": "./dist/js-year-calendar.js",
"scripts": {
Expand Down
23 changes: 21 additions & 2 deletions src/ts/interfaces/CalendarOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CalendarDayEventObject from './CalendarDayEventObject'
import CalendarRenderEndEventObject from './CalendarRenderEndEventObject'
import CalendarRangeEventObject from './CalendarRangeEventObject'
import CalendarYearChangedEventObject from './CalendarYearChangedEventObject'
import CalendarPeriodChangedEventObject from './CalendarPeriodChangedEventObject'

/**
* Options used for calendar customization.
Expand Down Expand Up @@ -113,14 +114,26 @@ export default interface CalendarOptions<T extends CalendarDataSourceElement> {
* The date from which days are enabled.
*/
minDate?: Date;

/**
* The number of months displayed by the calendar.
*/
numberMonthsDisplayed?: number;

/**
* Specifies whether the beginning and the end of each range should be displayed as rounded cells.
*/
roundRangeLimits?: boolean;

/**
* The date on which the calendar should be opened.
* The day is not considered (only the month and the year).
*/
startDate?: Date;

/**
* The year on which the calendar should be opened.
* If `startDate` is provided, this option will be ignored.
*/
startYear?: number;

Expand Down Expand Up @@ -163,9 +176,15 @@ export default interface CalendarOptions<T extends CalendarDataSourceElement> {
* Function fired when a date range is selected.
*/
selectRange?: (e: CalendarRangeEventObject) => void;
/**
/**
* Function fired when the visible year of the calendar is changed.
* This function will be fired only if the calendar is used in a full year mode. Otherwise, use `periodChanged` event.
*/
yearChanged?: (e: CalendarYearChangedEventObject) => void;

/**
* Function fired when the visible period of the calendar is changed.
*/
periodChanged?: (e: CalendarPeriodChangedEventObject) => void;
}
16 changes: 16 additions & 0 deletions src/ts/interfaces/CalendarPeriodChangedEventObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default interface CalendarPeriodChangedEventObject {
/**
* The beginning of the new period.
*/
startDate: Date;

/**
* The end of the new period.
*/
endDate: Date;

/**
* Indicates whether the automatic render after period changing must be prevented.
*/
preventRendering: boolean;
}
Loading

0 comments on commit 2f178e8

Please sign in to comment.