
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
@asphalt-react/date-picker
Advanced tools
DatePicker is a controlled component that lets a user pick a single date or a range of dates via a popover calendar. DatePicker also has an Datefield for users type in a date value. The format — which is also the placeholder - should be ISO-8601 YYYY-MM-DD for single date selection and YYYY-MM-DD to YYYY-MM-DD for range. Clicking the button in the date field toggles the calendar.
The calendar contains 2 sections:
The top section contains buttons to navigate to adjacent months and toggle the year panel. The user can choose a year from the year panel.
The bottom section displays the dates. You can configure the first day of the week and the non working days. DatePicker also supports a dual mode that renders two calendars simultaneously making it easier to select a range of dates. DatePicker supports i18n via the locale prop. To restrict the selectable dates, use the minDate & maxDate props.
DatePicker has 3 variants offering different date ranges:
In touch supported devices the DatePicker has the ability to render native date-picker. If the browser doesn't support <input type="date" />, or range selection is enabled, then it does not render the native date-picker.
import { DatePicker } from "@asphalt-react/date-picker"
function App() {
  const [date, setDate] = React.useState(null)
  return (
    <DatePicker value={date} onChange={(date, { event }) => setDate(date)} />
  )
}
Dates are complex objects to deal with and can easily cause issues. DatePicker checks for various issues which may arise during interaction. It detects & notifies these errors:
InvalidDate: When an invalid date is passed. Use the new Date() constructor to create date objects.InvalidRange: When the minDate is ahead of maxDate.RangeBreach: When the date falls outside of the selectable range.UserInvalidDate: When the user types an invalid date or the date does not match the required format. For example:
2020-12-25 ✅2019-2-10 ✅2019-2-10 to 2019-03-23 ✅lorem ipsum ❌ - invalid date2019-12-45 ❌ - invalid date25/12/2020 ❌ - incorrect formatUserRangeBreach: When the user enters a date which falls outside of the selectable rangeUserInvalidRange: When the user enters a date range, where the start date falls after the end date range. For example:
2023-10-12 to 2020-02-12 ❌DatePicker works well with assistive technologies. You can enable certain features via props.
The default focus lands on the date tile containing the selected date (if provided) or today's date. DatePicker traps & rotates focus among actionable elements.
You can navigate & select using these keyboard shortcuts:
DatePicker accepts data-* attributes and passes it to the date field.
The DatePicker component exposes two immensly powerful hooks - useNavigation() and useCalendar() that let you create a custom solution for date selection.
The useNavigation hook help you to use the Calendar unit component and integrate with the keyboard accessibility automagically. It returns the following values:
// shifts back the view by 3 months
previousMonth(3)
// shifts forward the view by 3 months
nextMonth(3)
Pass these in the Calendar component and you are done.
The hook accepts a few props:
const [base, setBase] = useState(null)
const onViewChange = (date) => {
  setBase(date)
}
const {focused, onNavigation, navigable} = useNavigation({
  base: new Date(2023, 4, 1)
  onViewChange
})
<Calendar
  month={base.getMonth()}
  year={base.getFullYear()}
  focused={focused}
  onNavigation={onNavigation}
  navigable={navigable}
/>
The useCalendar hook allows you to create your own Calendar. It returns the following:
The useCalendar hooks accepts the following props:
nonWorkingDays prop in DatePickerweekStartsOn prop in DatePicker.date-fns/locale(day: Date) => booleanconst {
  dates,
  startIndex,
  days,
  label: monthLabel,
} = useCalendar({
  month: 3,
  year: 2024,
});
const CustomCalendar = () => {
  return (
    <div>
      <span>{label}</span>
      <div>
        {days.map((day) => (
          <DayTile {...props} />
        ))}
      </div>
      <div>
        {dates.map((date) => (
          <DateTile {...props} />
        ))}
      </div>
    </div>
  );
};
An array of Date object(s). Accepts an instance of Date for the selected date. In case of range, the Date instance in the first index maps to the start date of the range, and the second index maps to the end date of range.
const value = [new Date()] // single date selection
const rangedValue = [new Date(), new Date()] // range selection
| type | required | default | 
|---|---|---|
| union | false | N/A | 
A callback to handle date change event. The callback has the following signature:
// date is an array of Date instance(s)
onChange = (date, {event}) => {}
| type | required | default | 
|---|---|---|
| func | false | N/A | 
A callback to handle errors. The DatePicker has a few pre-defined errors. The callback has the following signature:
onError = (error) => {}
| type | required | default | 
|---|---|---|
| func | false | N/A | 
Restricts the minimum selectable date.
| type | required | default | 
|---|---|---|
| union | false | N/A | 
Resricts the maximum selectable date.
| type | required | default | 
|---|---|---|
| union | false | N/A | 
Allows selection of a range of dates.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Renders the calendars of two successive months simultaneously.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Use locale for internationalization. It formats the day and month names based on the locale and sets the
starting day of the week.
DatePicker supports a set of pre-defined locale strings: "en-US" - English (United States) "en-IN" - English (India) "id" - Bahasa (Indonesia) "vi" - Vietnamese
If you need other locales, pass the locale objects from date-fns/locale
| type | required | default | 
|---|---|---|
| union | false | "en-US" | 
Configure the starting day of the week. Accepts one integer from 0 - 6, where 0 stands for Sunday.
| type | required | default | 
|---|---|---|
| enum | false | N/A | 
Configure the non-working days (or weekend) for the week. Accepts an array of integers from 0 - 6, where 0 stands for Sunday.
| type | required | default | 
|---|---|---|
| arrayOf | false | [0, 6] | 
Highlights the non-working days so that they stand apart from the normal days.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Controls the size of the DatePicker. Accepts one of "s", "m" or "l".
| type | required | default | 
|---|---|---|
| enum | false | "m" | 
DatePicker can render the web's native date-picker in touch-enabled devices, if the device's operating system supports
input fields of type "date". This behavior is overriden if range is set to true as native date-pickers don't support range
selection.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Renders "pro" variant.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Renders "dob" variant.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Renders "event" variant.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Highlights the DatePicker's field to show an error state.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Placeholder of the field. Overrides the default placeholder which displays the format of date selection.
| type | required | default | 
|---|---|---|
| string | false | N/A | 
Stretches the date field to take container's width.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Disables the DatePicker.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
A unique identifier for the Calendar.
| type | required | default | 
|---|---|---|
| string | false | N/A | 
Set as the "aria-label" for the button that toggles the picker. The label should cover 2 cases:
| type | required | default | 
|---|---|---|
| string | false | N/A | 
Set as the "aria-label" for the next month navigation button.
| type | required | default | 
|---|---|---|
| string | false | N/A | 
Set as the "aria-label" for the previous month navigation button.
| type | required | default | 
|---|---|---|
| string | false | N/A | 
Calendar renders the dates of a given month and year, allowing the user to select a date or a range of dates from that month.
An array of Date object(s). Accepts an instance of Date for the selected date. In case of range, the Date instance in the first index maps to the start date of the range, and the second index maps to the end date of range.
const value = [new Date()] // single date selection
const rangedValue = [new Date(), new Date()] // range selection
| type | required | default | 
|---|---|---|
| union | false | null | 
A callback to handle date change event. The callback has the following signature:
// date is an array of Date instance(s)
onSelect = (date, {event}) => {}
| type | required | default | 
|---|---|---|
| func | false | N/A | 
A callback to handle errors. The DatePicker has a few pre-defined errors. The callback has the following signature:
onError = (error) => {}
| type | required | default | 
|---|---|---|
| func | false | N/A | 
A zero-based value for the month, where "0" indicates the first month of the year.
| type | required | default | 
|---|---|---|
| enum | true | N/A | 
A 4-digit value for the year number, for instance: 2024.
| type | required | default | 
|---|---|---|
| number | true | N/A | 
Restricts the minimum selectable date.
| type | required | default | 
|---|---|---|
| union | false | null | 
Resricts the maximum selectable date.
| type | required | default | 
|---|---|---|
| union | false | null | 
Allows selection of a range of dates.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Use locale for internationalization. It formats the day and month names based on the locale and sets the
starting day of the week.
DatePicker supports a set of pre-defined locale strings: "en-US" - English (United States) "en-IN" - English (India) "id" - Bahasa (Indonesia) "vi" - Vietnamese
If you need other locales, pass the locale objects from date-fns/locale
| type | required | default | 
|---|---|---|
| union | false | "en-US" | 
Configure the starting day of the week. Accepts one integer from 0 - 6, where 0 stands for Sunday.
| type | required | default | 
|---|---|---|
| enum | false | N/A | 
Configure the non-working days (or weekend) for the week. Accepts an array of integers from 0 - 6, where 0 stands for Sunday.
| type | required | default | 
|---|---|---|
| arrayOf | false | [0, 6] | 
Highlights the non-working days so that they stand apart from the normal days.
| type | required | default | 
|---|---|---|
| bool | false | true | 
Disables the non-working days.
The non-working days are determined by the nonWorkingDays prop.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Controls the size of the DatePicker. Accepts one of "s", "m" or "l".
| type | required | default | 
|---|---|---|
| enum | false | "m" | 
Accepts a node for the Calendar's label. Defaults to month and year of the Calendar. For instance: "September 2023".
You can set the prop to false to not render a label.
| type | required | default | 
|---|---|---|
| union | false | null | 
A callback to handle keyboard navigation among the DateTiles in Calendar.
| type | required | default | 
|---|---|---|
| func | false | N/A | 
Hides the previous month dates.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Hides the next month dates.
| type | required | default | 
|---|---|---|
| bool | false | false | 
The date currently in focus. Accepts an instance of the Date class.
| type | required | default | 
|---|---|---|
| instanceOf | false | N/A | 
Handles the focus change event. The callback has the following signature:
handleSetFocused = (date) => {}
| type | required | default | 
|---|---|---|
| func | false | N/A | 
Hints the Calendar about the navigation direction initiated by useNavigation hook.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
A React ref to control whether the DateTiles should be focusable. The ref's value should be either "true" or "false".
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
If true, the range selection can include the same start and end date.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Renders dates.
Date to display
| type | required | default | 
|---|---|---|
| node | true | N/A | 
Controls whether the Date falls in current month or one of adjacent months.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Adds styles to distinguish the current date with rest of the dates.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Adds styles to distinguish dates that fall on non-working days or weekend.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Adds selected styles.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Adds styles to the start and end dates or range selection.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Dates not allowed for selection.
Use this to let users know the minimum and maximum selectable dates.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Removes border radius from the start edge of DateTiles.
Use it along with stickEnd to create a range selection.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Removes border radius from the end edge of DateTiles.
Use it along with stickStart to create a range selection.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Controls interactivity of a DateTile.
Use it to allow/disallow selection of holidays or dates of adjacent months.
| type | required | default | 
|---|---|---|
| bool | false | true | 
Size of DateTile. Accepts one of "s", "m" or "l".
| type | required | default | 
|---|---|---|
| enum | false | "m" | 
Makes DateTile focusable through Tab key.
| type | required | default | 
|---|---|---|
| bool | false | N/A | 
Renders the Day Tile.
Day to display.
Use a 3 letter notation for the day names. For example, "Mon" for Monday.
| type | required | default | 
|---|---|---|
| node | true | N/A | 
Adds styles to denote a day falls on weekend.
| type | required | default | 
|---|---|---|
| bool | false | false | 
Size of DayTile. Accepts one of "s", "m" & "l".
| type | required | default | 
|---|---|---|
| enum | false | "m" | 
FAQs
DatePicker
We found that @asphalt-react/date-picker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.