{"id":22893329,"url":"https://github.com/yet3/use-calendar","last_synced_at":"2026-04-28T08:32:57.613Z","repository":{"id":57747798,"uuid":"523525987","full_name":"yet3/use-calendar","owner":"yet3","description":"React hook useful for creating calendars","archived":false,"fork":false,"pushed_at":"2024-04-02T12:35:41.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T17:45:42.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yet3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-10T23:31:23.000Z","updated_at":"2022-08-10T23:31:44.000Z","dependencies_parsed_at":"2022-09-09T05:10:45.569Z","dependency_job_id":null,"html_url":"https://github.com/yet3/use-calendar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yet3%2Fuse-calendar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yet3%2Fuse-calendar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yet3%2Fuse-calendar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yet3%2Fuse-calendar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yet3","download_url":"https://codeload.github.com/yet3/use-calendar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246552354,"owners_count":20795807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T23:14:04.861Z","updated_at":"2026-04-28T08:32:52.587Z","avatar_url":"https://github.com/yet3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useCalendar\n\n![GitHub license](https://img.shields.io/github/license/yet3/use-calendar?style=flat)\n\u003ca href='https://www.npmjs.com/package/@yet3/use-calendar'\u003e\n  ![npm](https://img.shields.io/npm/v/@yet3/use-calendar)\n\u003c/a\u003e\n\nReact hook that makes creating calendars easier.\n\n### Table of Contents\n\n- [Installation](#installation)\n- [Usage](#quick-usage)\n  - [Quick](#quick-usage)\n  - [Full example](#full-example)\n  - [Controlled calendar date example](#controlled-calendar-date-example)\n- [.format()](#format)\n- [useCalendar](#usecalendar-1)\n- [UseCalendar](#usecalendar-2)\n  - [Setting locale](#usecalendar-2)\n- [Options](#options)\n- [CalendarDay](#calendarday)\n- [CalendarGroup](#calendargroup)\n- [Other types](#other-types)\n- [Depends on](#depends-on)\n\n### Installation\n\n```sh\nyarn add @yet3/use-calendar\n```\n\nor with npm\n\n```sh\nnpm install @yet3/use-calendar\n```\n\n### Quick usage\n\n```tsx\nimport { useCalendar, UseCalendar } from '@yet3/use-calendar';\n\nconst MyCalendar = () =\u003e {\n  const { calendarDate, days, daysOfWeek } = useCalendar()\n\n  ...\n}\n```\n\n### .format()\n\nEach `.format(pattern, options)` method accepts pattern and options, both of those arguments are optional as each format method has a default pattern.\n\nSee date-fns's [format docs](https://date-fns.org/v2.29.1/docs/format) for possible patterns.\n\n### useCalendar\n\nuseCalendar hook returns:\n\n- calendarDate:\n  - date: Date - calendar's date\n  - format: [FormatFunc](#types) - format function (default pattern: 'MM-yyyy')\n  - set: Dispatch\u003cSetStateAction\u003cDate\u003e\u003e - setter function\n  - add: (amt: number, unit: [Unit](#types)) =\u003e void - add x of specified unit to calendar's date\n  - subtract: (amt: number, unit: [Unit](#types)) =\u003e void - subtract x of specified unit from calendar's date\n  - addMonth: () =\u003e void - add 1 month to calendar's date\n  - subtractMonth: () =\u003e void - subtract 1 month to calendar's date\n  - addYear: () =\u003e void - add 1 year to calendar's date\n  - subtractYear: () =\u003e void - subtract 1 year to calendar's date\n- calendarStartDate:\n  - date: Date - first day of calendar's date month\n  - format: [FormatFunc](#types) - format function (default pattern: 'MM-yyyy')\n- calendarEndDate:\n  - date: Date - last day of calendar's date month\n  - format: [FormatFunc](#types) - format function (default pattern: 'MM-yyyy')\n- daysOfWeek: CalendarDayOfWeek[] - array of each day of week (sorted based on [calendarStartDay](#options))\n- days: CalendarDay[] - days in calendar's date month\n- groupedDays: CalendarGroup[] - days in calendar's date month grouped by each day of week\n- isDisabled: boolean - whether entire calendar is disabled\n\n### UseCalendar\n\nUseCalendar is used to set options globally.\n\nProperties:\n\n- DEFAULT_OPTIONS: [Options](#options) - calendar's default options\n- options: [Options](#options) - calendar's options\n- setOptions(options: Partial\u003c[Options](#options)\u003e): void - calendar's options setter\n- setLocale: (locale: Locale) =\u003e void - function to set calendar's locale (it can also be set through setOptions)\n- setCalendarStartDay(day: DayOfWeek): void - function to set day at which calendar will start (it can also be set through setOptions)\n- resetOptions(): void - function to reset options\n\nExample:\n\n```ts\nimport { UseCalendar } from '@yet3/use-calendar';\nimport fr from 'date-fns/locale/fr';\n\nUseCalendar.setOptions({ alwaysSixRows: true });\nUseCalendar.setCalendarStartDay('tuesday');\nUseCalendar.setLocale(fr);\n```\n\n### Options\n\nOptions can be set by passing them to `useCalendar(Options)` hook or by setting them using `UseCalendar.setOptions(Options)`\n\n- defaultDate?: Date | null | false - date with which calendar will be initialized\n- calendarDate?: Date | null - controlled calendar date (can only be passed in hook)\n- setCalendarDate?: Dispatch\u003cSetStateAction\u003cDate\u003e\u003e | null - setter for controlled date (can only be passed in hook)\n- calendarStartDay?: [DayOfWeek](#types) - day at which calendar will start\n- disabled?: boolean - whether calendar is disabled\n- disableWeekDays?: boolean - whether week days are disabled\n- disableWeekends?: boolean - whether weekends are disabled\n- alwaysSixRows?: boolean - whether useCalendar's days/groupedDays should always return 42 days (6 rows \\* 7 days)\n- locale?: Locale - calendars locale\n- dayOfWeekFormat?: string - format pattern of each day of the week (monday...sunday);\n- dayFormat?: string - format pattern of each of the days in calendar\n- calendarDateFormat?: string - format pattern of calendars date\n- onlyCurrentMonth?: boolean - if true `days` and `groupedDays` will only contain days of current calendar date (option `alwaysSixRows` will be ignored)\n\n### CalendarDay\n\n- day: number - day of week (0...6)\n- isoDay: number - iso day of week (1...7)\n- dayOfMonth: number - day of month\n- date: Date - day's date\n- format: [FormatFunc](#types) - format function (default pattern: 'dd')\n- isWeekDay?: boolean - whether day is a week day (every day except weekends)\n- isWeekend?: boolean - whether day is a weekend\n- isCurrentMonth?: boolean - whether day is in current calendar's month\n- isPrevMonth?: boolean - whether day is in previous calendar's month\n- isNextMonth?: boolean - whether day is in next calendar's month\n- isDisabled?: boolean - whether day is disabled\n- key: string - unique key\n\n### CalendarGroup:\n\n- day: number - day of week (0...6)\n- isoDay: number - iso day of week (1...7)\n- format: [FormatFunc](#types) - format function (default pattern: 'EEEEEE')\n- week: number - week of month\n- isoWeek: number - iso week of month\n- days: [CalendarDay](#types)[];\n- key: string - unique key\n\n### Other types\n\n- Unit: 'days' | 'months' | 'years' | 'weeks'\n- FormatFunc: (pattern?: string, options?: FormatOptions) =\u003e string\n- DayOfWeek: 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'\n- CalendarDayOfWeek:\n  - day: number - from 0 to 6 (0 being sunday and 6 being saturday)\n  - date: Date\n  - format: [FormatFunc](#types)\n\n\n### Full example\n```tsx\nimport { useCalendar, UseCalendar } from '@yet3/use-calendar';\n\nUseCalendar.setOptions({ alwaysSixRows: true });\n\nconst MyCalendar = () =\u003e {\n  const { calendarDate, days, daysOfWeek } = useCalendar({ disableWeekends: true });\n\n  return (\n    \u003cdiv style={{ display: 'grid', justifyItems: 'center', gap: '0.5rem' }}\u003e\n      \u003cdiv\n        style={{\n          display: 'grid',\n          placeContent: 'center',\n          gridTemplateColumns: '1fr 1fr 4rem 1fr 1fr',\n          gap: '0.25rem',\n          justifyItems: 'center',\n        }}\n      \u003e\n        \u003cbutton onClick={calendarDate.subtractYear}\u003e{'\u003c\u003c'}\u003c/button\u003e\n        \u003cbutton onClick={calendarDate.subtractMonth}\u003e{'\u003c'}\u003c/button\u003e\n        \u003cspan\u003e{calendarDate.format()}\u003c/span\u003e\n        \u003cbutton onClick={calendarDate.addMonth}\u003e{'\u003e'}\u003c/button\u003e\n        \u003cbutton onClick={calendarDate.addYear}\u003e{'\u003e\u003e'}\u003c/button\u003e\n      \u003c/div\u003e\n      \u003col\n        style={{\n          listStyleType: 'none',\n          margin: 0,\n          padding: 0,\n          display: 'grid',\n          gridTemplateColumns: 'repeat(7, 2rem)',\n          gap: '0.1rem',\n          gridColumn: '1/-1',\n        }}\n      \u003e\n        {daysOfWeek.map((day) =\u003e (\n          \u003cli\n            key={day.day}\n            style={{\n              display: 'grid',\n              placeItems: 'center',\n              textAlign: 'center',\n              width: '100%',\n              fontWeight: 'bold',\n            }}\n          \u003e\n            {day.format()}\n          \u003c/li\u003e\n        ))}\n        {days.map((day) =\u003e (\n          \u003cli\n            key={day.key}\n            onClick={() =\u003e {\n              if (!day.isCurrentMonth \u0026\u0026 !day.isDisabled) calendarDate.set(day.date);\n            }}\n            style={{\n              color: day.isDisabled ? 'rgb(190, 190, 190)' : day.isCurrentMonth ? 'black' : 'rgb(120, 120, 120)',\n              display: 'grid',\n              placeItems: 'center',\n              textAlign: 'center',\n              width: '100%',\n              aspectRatio: '1/1',\n              cursor: 'pointer',\n            }}\n          \u003e\n            {day.format()}\n          \u003c/li\u003e\n        ))}\n      \u003c/ol\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### Controlled calendar date example\n```tsx\nimport { SetStateActions, useState } from 'react';\nimport { useCalendar, UseCalendar } from '@yet3/use-calendar';\n\nconst MyComponent = () =\u003e {\n  const [date, setDate] = useState\u003cDate\u003e(new Date())\n\n  return (\n    \u003cdiv\u003e\n      \u003ch1\u003eMy super cool calendar\u003c/h1\u003e\n      \u003cMyCalendar date={date} setDate={setDate} /\u003e\n    \u003c/div\u003e\n  )\n}\n\ninterface CalendarProps {\n  date: Date\n  setDate: (value: SetSateAction\u003cDate\u003e) =\u003e void\n}\n\nconst MyCalendar = ({ date, setDate }: CalendarProps) =\u003e {\n  const { calendarDate, days, daysOfWeek } = useCalendar({\n    calendarDate: date,\n    setCalendarDate: setDate\n  });\n\n  ...\n}\n```\n\n### Depends on\n\nThis package makes use of [date-fns](https://date-fns.org/docs/Getting-Started) library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyet3%2Fuse-calendar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyet3%2Fuse-calendar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyet3%2Fuse-calendar/lists"}