Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
uvarov-frontend committed Dec 6, 2023
1 parent 792dd33 commit 65925c9
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 139 deletions.
8 changes: 0 additions & 8 deletions docs/en/learn/action-handlers/click-a-day.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ Example with logging the selected day to the console:
Please note that the selected day is represented as an array because the user can select not only one day but also a range of dates if allowed by the calendar parameters.

<Sandbox example="action-handlers-click-a-day-ranged" />

By default, an array of all selected dates is provided, which is logical. However, most of the time, you will want to obtain only the start and end dates.

To ensure that the dates are in the correct order, you can use the standard `.sort()` method:

```js
dates.sort((a, b) => +new Date(a) - +new Date(b))
```
73 changes: 35 additions & 38 deletions docs/en/reference/additionally/actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Actions in VanillaCalendar are event handlers that allow you to receive and process various interaction data with the calendar.

<Info>
Starting from version 2.9.0, all methods contain `self` - a link to the initialized calendar. This allows you to obtain the maximum amount of data. `self` contains all the [read-only parameters](/docs/reference/main/readonly-options) and more.
</Info>

<Info>
Note that month numbering starts from `0`, so December is the 11th month. This is related to the behavior of the standard JavaScript method <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth" target="_blank" rel="nofollow noreferrer">`.getMonth()`</a>.
</Info>
Expand All @@ -12,19 +16,19 @@ Actions in VanillaCalendar are event handlers that allow you to receive and proc

`Default: null`

`Options: clickDay(e, dates) => void | null`
`Options: clickDay(e, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
clickDay(e, dates) {},
clickDay(e, self) {},
},
});
```

This method triggers after clicking on a day in the calendar. You can get the following parameters:
- `e` - the mouse event;
- `dates` - an array of selected dates.
- `self` - reference to the initialized calendar.

<Info>
It's important to know that each HTML element of the day you clicked on contains a data attribute that holds the full date in the `YYYY-MM-DD` format. If you need to get the day, month, and year separately, you can use standard JavaScript methods. For example, `new Date('2022-11-07').getDate()` will return `7`.
Expand All @@ -38,12 +42,12 @@ This method triggers after clicking on a day in the calendar. You can get the fo

`Default: null`

`Options: clickWeekNumber(e, number, days, year) => void | null`
`Options: clickWeekNumber(e, number, days, year, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
clickWeekNumber(e, number, days, year) {},
clickWeekNumber(e, number, days, year, self) {},
},
});
```
Expand All @@ -53,6 +57,7 @@ This method triggers after clicking on the week number in the calendar, but it r
- `number` - the week number;
- `days` - an array of days (HTML elements);
- `year` - the year of the week.
- `self` - reference to the initialized calendar.

---

Expand All @@ -62,19 +67,19 @@ This method triggers after clicking on the week number in the calendar, but it r

`Default: null`

`Options: clickMonth(e, month) => void | null`
`Options: clickMonth(e, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
clickMonth(e, month) {},
clickMonth(e, self) {},
},
});
```

This method triggers after selecting a month in the calendar. You can get the following parameters:
- `e` - the mouse event;
- `month` - the number of the selected month.
- `self` - reference to the initialized calendar.

---

Expand All @@ -84,19 +89,19 @@ This method triggers after selecting a month in the calendar. You can get the fo

`Default: null`

`Options: clickYear(e, year) => void | null`
`Options: clickYear(e, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
clickYear(e, year) {},
clickYear(e, self) {},
},
});
```

This method triggers after selecting a year in the calendar. You can get the following parameters:
- `e` - the mouse event;
- `year` - the selected year.
- `self` - reference to the initialized calendar.

---

Expand All @@ -106,20 +111,19 @@ This method triggers after selecting a year in the calendar. You can get the fol

`Default: null`

`Options: clickArrow(e, year, month) => void | null`
`Options: clickArrow(e, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
clickArrow(e, year, month) {},
clickArrow(e, self) {},
},
});
```

This method triggers after clicking the arrow in the calendar. You can get the following parameters:
- `e` - the mouse event;
- `year` - the selected year;
- `month` - the number of the selected month.
- `self` - reference to the initialized calendar.

---

Expand All @@ -129,22 +133,19 @@ This method triggers after clicking the arrow in the calendar. You can get the f

`Default: null`

`Options: changeTime(e, time, hours, minutes, keeping) => void | null`
`Options: changeTime(e, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
changeTime(e, time, hours, minutes, keeping) {},
changeTime(e, self) {},
},
});
```

This method triggers after changing the time in the calendar. You can get the following parameters:
- `e` - the change event;
- `time` - the selected time;
- `hours` - the selected hour;
- `minutes` - the selected minutes;
- `keeping` - the selected AM/PM marker for the 12-hour time format.
- `self` - reference to the initialized calendar.

---

Expand All @@ -154,12 +155,12 @@ This method triggers after changing the time in the calendar. You can get the fo

`Default: null`

`Options: changeToInput(e, calendar, dates, time, hours, minutes, keeping) => void | null`
`Options: changeToInput(e, calendar, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
changeToInput(e, calendar, dates, time, hours, minutes, keeping) {},
changeToInput(e, calendar, self) {},
},
});
```
Expand All @@ -168,11 +169,8 @@ To use this method, you need the <a href="/docs/reference/main/main-settings#inp
This method triggers after clicking on a day in the calendar or changing the time in any way.
You can get the following parameters:
- `e` - the event;
- `calendar` - an object that includes HTMLInputElement, HTMLElement, and the methods show() and hide();
- `dates` - an array of selected dates;
- `time` - the selected time;
- `hours` - the selected hour;
- `minutes` - the selected minutes;
- `calendar` - an object that includes the methods show() and hide();
- `self` - reference to the initialized calendar.

---

Expand All @@ -182,12 +180,12 @@ You can get the following parameters:

`Default: null`

`Options: getDays(day, date, HTMLElement, HTMLButtonElement) => void | null`
`Options: getDays(day, date, HTMLElement, HTMLButtonElement, self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
getDays(day, date, HTMLElement, HTMLButtonElement) {},
getDays(day, date, HTMLElement, HTMLButtonElement, self) {},
},
});
```
Expand All @@ -197,6 +195,7 @@ This method triggers during the calendar initialization and any changes. It prov
- `date` - the full date in the `YYYY-MM-DD` format;
- `HTMLElement` - the parent (wrapper) HTML element of the day;
- `HTMLButtonElement` - the child (button) HTML element of the day.
- `self` - reference to the initialized calendar.

---

Expand All @@ -206,19 +205,18 @@ This method triggers during the calendar initialization and any changes. It prov

`Default: null`

`Options: hideCalendar(HTMLInputElement, HTMLElement) => void | null`
`Options: hideCalendar(self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
hideCalendar(HTMLInputElement, HTMLElement) {},
hideCalendar(self) {},
},
});
```

This method triggers when the calendar is hiding, but only if the <a href="/docs/reference/main/main-settings#input">`input`</a> parameter is set to `true`.
- `HTMLInputElement` - represents the root HTML element, which is an input field;
- `HTMLElement` - root HTML element of the calendar.
- `self` - reference to the initialized calendar.

---

Expand All @@ -228,16 +226,15 @@ This method triggers when the calendar is hiding, but only if the <a href="/docs

`Default: null`

`Options: showCalendar(HTMLInputElement, HTMLElement) => void | null`
`Options: showCalendar(self) => void | null`

```js
new VanillaCalendar('#calendar', {
actions: {
showCalendar(HTMLInputElement, HTMLElement) {},
showCalendar(self) {},
},
});
```

This method triggers when displaying the calendar to the user, but only if the <a href="/docs/reference/main/main-settings#input">`input`</a> parameter is set to `true`.
- `HTMLInputElement` - represents the root HTML element, which is an input field;
- `HTMLElement` - root HTML element of the calendar.
- `self` - reference to the initialized calendar.
30 changes: 26 additions & 4 deletions docs/en/reference/additionally/settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ new VanillaCalendar('#calendar', {
This parameter allows you to disable specific dates regardless of the specified range.

<Info>
To specify a range of disabled dates, use any delimiter between dates within a single string.
To specify a range dates, use any delimiter between dates within a single string.
</Info>

---
Expand All @@ -230,7 +230,7 @@ new VanillaCalendar('#calendar', {
This parameter allows you to enable specific dates regardless of the range and disabled dates.

<Info>
To specify a range of disabled dates, use any delimiter between dates within a single string.
To specify a range dates, use any delimiter between dates within a single string.
</Info>

---
Expand Down Expand Up @@ -389,6 +389,28 @@ This parameter sets the step for the minute controller. You can choose any numbe

---

## settings.selection.cancelableDay

`Type: Number`

`Default: true`

`Options: boolean`

```js
new VanillaCalendar('#calendar', {
settings: {
selection: {
cancelableDay: false,
},
},
});
```

This option allows you to enable/disable cancellation of the selected date by pressing again.

---

## settings.selected.dates

`Type: String[]`
Expand All @@ -410,7 +432,7 @@ new VanillaCalendar('#calendar', {
This parameter allows you to specify a list of dates that will be selected when the calendar is initialized.

<Info>
To specify a range of disabled dates, use any delimiter between dates within a single string.
To specify a range dates, use any delimiter between dates within a single string.
</Info>

---
Expand Down Expand Up @@ -480,7 +502,7 @@ new VanillaCalendar('#calendar', {
This parameter allows you to specify dates that will be considered holidays and will receive additional CSS modifiers.

<Info>
To specify a range of disabled dates, use any delimiter between dates within a single string.
To specify a range dates, use any delimiter between dates within a single string.
</Info>

---
Expand Down
7 changes: 2 additions & 5 deletions docs/en/reference/main/initialize-and-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ const calendar = new VanillaCalendar(element, params);
calendar.init();
```

It's essential to note that you also have the ability to update the calendar with new settings at any time using the `update()` or `reset()` methods.
The `update()` method allows you to apply new settings to the calendar and reset it. This method takes an object with optional arguments to control the reset, by default retaining the user-selected date, month, and year after the update.

- The `update()` method allows you to apply new settings to the calendar while preserving the user-selected dates, month, and year after the update.
- The `reset()` method completely resets the calendar to its initial state, discarding any user-selected dates.

Example of usage:
All arguments, default `false`:

```js
calendar.settings.lang = 'de-AT';
Expand Down
13 changes: 0 additions & 13 deletions docs/en/reference/main/readonly-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,6 @@ The `selectedTime` property contains the full current time.

- - -

## userTime

`Type: boolean`

```js
const calendar = new VanillaCalendar('#calendar');
console.log(calendar.userTime);
```

The `userTime` property indicates how the time was set during the calendar initialization: automatically detecting the current time (default) or using the `settings.selected.time` parameter.

- - -

## correctMonths

`Type: number`
Expand Down
8 changes: 0 additions & 8 deletions docs/ru/learn/action-handlers/click-a-day.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@
Заметьте, что выбранный день представлен в виде массива, так как пользователь может выбрать не только один день, но и диапазон дат, если это разрешено параметрами календаря.

<Sandbox example="action-handlers-click-a-day-ranged" />

По умолчанию, предоставляется массив всех выбранных дат, что логично. Однако, чаще всего вам нужно будет получить только начальную и конечную даты.

Для того чтобы гарантировать, что даты будут в правильном порядке, вы можете воспользоваться стандартным методом `.sort()`:

```js
dates.sort((a, b) => +new Date(a) - +new Date(b))
```
Loading

0 comments on commit 65925c9

Please sign in to comment.