@eperedo/calendar-hooks
Advanced tools
Comparing version 0.11.0 to 0.14.0
{ | ||
"name": "@eperedo/calendar-hooks", | ||
"version": "0.11.0", | ||
"version": "0.14.0", | ||
"main": "./src/hooks/index.js", | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
@@ -16,3 +16,3 @@ > Basic hooks for calendar components | ||
function CustomCalendar() { | ||
const { year, month, days, changeDate } = useCalendar(new Date()); | ||
const { year, month, day, days, changeDate } = useCalendar(new Date()); | ||
@@ -25,6 +25,6 @@ function onClick(day) { | ||
if (action === 'prev') { | ||
const newMonth = month.number - 1 - 1; | ||
const newMonth = (month.number - 1) - 1; | ||
changeDate(new Date(year, newMonth, day.number, 0, 0, 0)); | ||
} else { | ||
const newMonth = month.number + 1 - 1; | ||
const newMonth = (month.number + 1) - 1; | ||
changeDate(new Date(year, newMonth, day.number, 0, 0, 0)); | ||
@@ -50,3 +50,3 @@ } | ||
return ( | ||
<button onClick={(e) => changeDate(day.date)} key={day.number}> | ||
<button type="button" onClick={(e) => changeDate(day)} key={day.number}> | ||
{day.number} | ||
@@ -63,1 +63,64 @@ </button> | ||
``` | ||
### API | ||
### useCalendar(selectedDate) | ||
Generate an object with calendar information | ||
- selectedDate: A valid javascript date object | ||
Returns: | ||
`{ day, days, month, year, changeDate }` | ||
- day: an object with information about the day of the **selectedDate** parameter | ||
```js | ||
{ | ||
name: 'Monday', | ||
abbr: 'Mon', | ||
number: 2, | ||
} | ||
``` | ||
- days: an array with all days of one month | ||
```js | ||
[ | ||
{ | ||
date: 'Sun Jul 07 2019 13:17:38 GMT-0500 (Peru Standard Time)', // a valid js date object | ||
isToday: false, | ||
number: 1, | ||
}, | ||
{ | ||
date: 'Mon Jul 08 2019 13:17:38 GMT-0500 (Peru Standard Time)', // a valid js date object | ||
isToday: true, | ||
number: 2, | ||
}, | ||
// until last day of the month | ||
{ | ||
date: 'Mon Jul 31 2019 13:17:38 GMT-0500 (Peru Standard Time)', // a valid js date object | ||
isToday: false, | ||
number: 31, | ||
}, | ||
] | ||
``` | ||
- month: an object with information about the month of the **selectedDate** parameter | ||
```js | ||
{ | ||
name: 'July', | ||
number: 7, | ||
jsNumber: 6, | ||
} | ||
``` | ||
- year: the year of the **selectedDate** parameter | ||
```js | ||
2019 | ||
``` | ||
- changeDate(selectedDate): a function that mutates the **selectedDate** value |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10364
122