Feature-rich Calendar & Date Picker Components – Cally

Category: Date & Time , Javascript , Recommended | January 8, 2025
Author:WickyNilliams
Views Total:277 views
Official Page:Go to website
Last Update:January 8, 2025
License:MIT

Preview:

Feature-rich Calendar & Date Picker Components – Cally

Description:

Cally provides a set of responsive, customizable, accessible, feature-rich calendar web components for web applications, with a minimal bundle size of 8.5KB min/gzip. These components support single dates, date ranges, and multi-month displays while maintaining complete accessibility and localization support.

Key Features:

  • Single date selection and date ranges
  • Multiple month displays
  • RTL text direction
  • Screen reader compatibility
  • Keyboard navigation
  • Custom theming through CSS parts
  • Full localization via Intl.DateTimeFormat

How to use it:

1. To get started, you can either install it via npm or use a CDN link.

# NPM
$ npm install cally
import "cally";
<script type="module" src="https://unpkg.com/cally"></script>

2. Create a basic date picker using the <calendar-date> component, which includes a <calendar-month> component inside it.

<calendar-date>
  <calendar-month></calendar-month>
</calendar-date>

Properties and attributes:

Dates are expected in ISO-8601 format (YYYY-MM-DD).

PropertyAttributeDescriptionTypeDefault
valuevalueThe currently selected datestring""
minminThe earliest selectable datestring""
maxmaxThe latest selectable datestring""
focusedDatefocused-dateThe date currently focused by the calendarstringundefined
firstDayOfWeekfirst-day-of-weekThe first day of the week (Sunday is 0, Monday is 1, etc.)number1
showOutsideDaysshow-outside-daysDisplay days outside the current monthbooleanfalse
localelocaleThe locale for date formatting (uses browser’s locale if unset)string/undefinedundefined
monthsmonthsNumber of months to displaynumber1
pageBypage-byHow next/previous buttons navigate (“months” or “single”)"single", "months""months"
isDateDisallowedFunction that returns true if a date should not be selectable(date: Date) => boolean() => false

Events:

Cally emits non-bubbling CustomEvents in response to user interaction.

NameDescriptionType
changeEmitted when the selected date changes via user interactionEvent
focusdayEmitted when the focused day changes (via keyboard or next/previous buttons)CustomEvent<Date>

Methods:

NameDescription
focusFocuses the <calendar-month> containing the currently focused date

CSS Parts:

NameDescription
containerThe main container for the component
headerContainer for the heading and navigation buttons
buttonAny button within the component
previousThe previous page button
nextThe next page button
disabledA button disabled due to min/max limits
headingThe calendar heading label

Slots:

NameDescription
Default slotPlace your <calendar-month> components here, or other markup. <calendar-month> doesn’t need to be a direct descendant.
previousThe content of the previous page button (defaults to “Previous”). Slot an icon here.
nextThe content of the next page button (defaults to “Next”). Slot an icon here.
headingThe visible heading content. You might replace this with a year selector. A visually-hidden heading is always rendered for accessibility.

3. To enable users to select a range of dates, use the <calendar-range> component and include a <calendar-month> inside.

<calendar-range>
  <calendar-month></calendar-month>
</calendar-range>

Properties and attributes:

The value property expects a date range in ISO-8601 format (YYYY-MM-DD/YYYY-MM-DD). Other dates use the YYYY-MM-DD format.

 

PropertyAttributeDescriptionTypeDefault
valuevalueThe currently selected date rangestring""
minminThe earliest selectable datestring""
maxmaxThe latest selectable datestring""
focusedDatefocused-dateThe date currently focused by the calendarstringundefined
tentativetentativeThe tentatively selected date (e.g., the start of a range selection)string""
firstDayOfWeekfirst-day-of-weekThe first day of the week (Sunday is 0, Monday is 1, etc.)number1
showOutsideDaysshow-outside-daysDisplay days outside the current monthbooleanfalse
localelocaleThe locale for date formatting (uses browser’s locale if unset)string/undefinedundefined
monthsmonthsNumber of months to displaynumber1
pageBypage-byHow next/previous buttons navigate (“months” or “single”)"single", "months""months"
isDateDisallowedFunction that returns true if a date should not be selectable(date: Date) => boolean() => false

Events:

NameDescriptionType
changeEmitted when the selected range changes via user interactionEvent
focusdayEmitted when the focused day changes (via keyboard or next/previous buttons)CustomEvent<Date>
rangestartEmitted when the user starts selecting a rangeCustomEvent<Date>
rangeendEmitted when the user finishes selecting a rangeCustomEvent<Date>

Methods:

NameDescription
focusFocuses the <calendar-month> containing the currently focused date

CSS Parts:

NameDescription
containerThe main container for the component
headerContainer for the heading and navigation buttons
buttonAny button within the component
previousThe previous page button
nextThe next page button
disabledA button disabled due to min/max limits
headingThe calendar heading label

Slots:

NameDescription
Default slotPlace your <calendar-month> components here, or other markup. <calendar-month> doesn’t need to be a direct descendant.
previousThe content of the previous page button (defaults to “Previous”). Slot an icon here.
nextThe content of the next page button (defaults to “Next”). Slot an icon here.
headingThe visible heading content. You might replace this with a year selector. A visually-hidden heading is always rendered for accessibility.

4. To display several months simultaneously, include multiple <calendar-month> components within either <calendar-range> or <calendar-date>. Set the months attribute of the parent component to the total number of months you want to display. Use the offset attribute on each <calendar-month> to specify its position relative to the first visible month.

<calendar-range months="2">
  <div class="grid">
    <calendar-month></calendar-month>
    <calendar-month offset="1"></calendar-month>
  </div>
</calendar-range>

5. To enable users to select multiple dates (not date ranges), use the <calendar-multi> component:

Properties and attributes:

 

PropertyAttributeDescriptionTypeDefault
valuevalueA space-separated list of selected datesstring""
minminThe earliest selectable datestring""
maxmaxThe latest selectable datestring""
focusedDatefocused-dateThe date currently focused by the calendarstringundefined
firstDayOfWeekfirst-day-of-weekThe first day of the week (Sunday is 0, Monday is 1, etc.)number1
showOutsideDaysshow-outside-daysDisplay days outside the current monthbooleanfalse
localelocaleThe locale for date formatting (uses browser’s locale if unset)string/undefinedundefined
monthsmonthsNumber of months to displaynumber1
pageBypage-byHow next/previous buttons navigate (“months” or “single”)"single", "months""months"
isDateDisallowedFunction that returns true if a date should not be selectable(date: Date) => boolean() => false

Events:

NameDescriptionType
changeEmitted when the selected date(s) change via user interactionEvent
focusdayEmitted when the focused day changes (via keyboard or next/previous buttons)CustomEvent<Date>

Methods:

NameDescription
focusFocuses the <calendar-month> containing the currently focused date

CSS Parts:

NameDescription
containerThe main container for the component
headerContainer for the heading and navigation buttons
buttonAny button within the component
previousThe previous page button
nextThe next page button
disabledA button disabled due to min/max limits
headingThe calendar heading label

Slots:

NameDescription
Default slotPlace your <calendar-month> components here, or other markup. <calendar-month> doesn’t need to be a direct descendant.
previousThe content of the previous page button (defaults to “Previous”). Slot an icon here.
nextThe content of the next page button (defaults to “Next”). Slot an icon here.
headingThe visible heading content. You might replace this with a year selector. A visually-hidden heading is always rendered for accessibility.
<calendar-multi>
  <calendar-month></calendar-month>
</calendar-multi>

6. More about the <calendar-month> component:

Properties and attributes:

PropertyAttributeDescriptionTypeDefault
offsetoffsetIn a multi-month view, controls the displayed month relative to the start.number0

CSS Custom Properties:

NameDescriptionDefault
--color-accentThe primary accent colorblack
--color-text-on-accentText color when using --color-accentwhite

CSS Parts:

NameDescription
headingThe label for the month
tableThe <table> element
trAny row within the table
headThe table header row
weekThe table body rows
thThe table header cells
tdThe table body cells
buttonAny button used in the component
dayThe buttons representing each day
selectedAny selected days
todayToday’s day
disallowedAny day disallowed via isDateDisallowed
outsideAny days outside the current month
range-startThe day marking the start of a date range
range-endThe day marking the end of a date range
range-innerAny days between the start and end of a date range

7. Explore these guides for detailed information on using Cally’s components:

  • Frameworks: Learn how to integrate Cally with your preferred JavaScript framework.
  • Theming: Discover how to customize Cally’s appearance to match your application’s style.
  • Usage: Find examples of integrating Cally with existing components to create more complex user interfaces. For detailed information on each component, refer to the Component API documentation.

You Might Be Interested In:


Leave a Reply