Skip to content

Calendar ​

Introduction ​

The calendar is a month view with no input field. Use it to show dates, to pick a date in a page layout, or as a base for something bigger. Each day shows the other calendar's day number underneath.

Click the month or year in the header to jump through month and year tiles.

Basic usage ​

tsx
import { Calendar } from '@nepdatejs/react';

export function Schedule() {
  return <Calendar onSelect={(selection) => console.log(selection)} />;
}
html
<nep-calendar id="schedule"></nep-calendar>

<script>
  document.querySelector('#schedule').addEventListener('nep-select', (event) => {
    console.log(event.detail.date); // the day, in the calendar on screen
    console.log(event.detail.value); // its AD "YYYY-MM-DD"
  });
</script>

Selecting ​

selectionMode can be 'single', 'range' or 'multiple', and selected sets the current selection:

tsx
import { useState } from 'react';
import { bsDate, type CalendarDate } from '@nepdatejs/core';
import { Calendar } from '@nepdatejs/react';

export function Picker() {
  const [selected, setSelected] = useState<CalendarDate>(bsDate(2083, 7, 1));

  return (
    <Calendar
      selected={selected}
      onSelect={(selection) => {
        if ('calendar' in selection) {
          setSelected(selection);
        }
      }}
    />
  );
}

onSelect receives whatever matches the mode:

ModeonSelect receives
'single'The day
'range'{ start, end }. end is null after the first click
'multiple'The list of chosen days, after the click added or removed one

On the element, the range attribute turns on range mode. nep-select then has event.detail.range. Multiple mode is only on the React component and the store.

Which month is shown ​

The calendar opens on the selected day's month, or else today's. To control the month, pair month with onMonthChange:

tsx
import { useState } from 'react';
import { bsDate, type CalendarDate } from '@nepdatejs/core';
import { Calendar } from '@nepdatejs/react';

export function Controlled() {
  const [month, setMonth] = useState<CalendarDate>(bsDate(2083, 1, 1));

  return <Calendar month={month} onMonthChange={setMonth} />;
}

Any day in the month works as month. To set only the starting month, use defaultVisibleMonth.

Calendar and language ​

tsx
<Calendar calendar="AD" locale="ne" />;
html
<nep-calendar calendar="AD" locale="ne"></nep-calendar>

Unlike the pickers, the calendar has no BS/AD switch.

Display options ​

PropDefaultMeaning
showOtherCalendartrueThe other calendar's day number under each day
showOutsideDaystrueDays from the previous and next months
fixedWeeksfalseAlways six rows, so the height never changes
weekStartsOn0First day of the week
weekendDays[6]Days shown as weekend

Limits, holidays and events ​

min, max and isDateDisabled work as on the pickers, except that on the React component and the store they take date objects, not strings:

tsx
<Calendar min={bsDate(2083, 1, 1)} max={bsDate(2083, 12, 30)} />;
html
<nep-calendar min="2026-04-14" max="2027-04-13"></nep-calendar>

See Holidays and events for marking days.

Options ​

PropTypeMeaning
calendar'BS' | 'AD'Default 'BS'
localestringNames and digits
selectionMode'single' | 'range' | 'multiple'Default 'single'
selecteddate, range or listThe selection
onSelect(selection) => voidCalled on a pick
month, onMonthChangeControl the visible month
defaultVisibleMonthCalendarDateThe month shown first
onViewChange(view) => voidCalled when the day, month or year view changes
min, maxCalendarDateEarliest and latest selectable days
isDateDisabled(date) => booleanRule out individual days
holidays, eventsSee Holidays and events
todayCalendarDateOverride "today"
theme, classNameStyling

Released under the MIT licence.