New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-ui-datepicker

Package Overview
Dependencies
Maintainers
0
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-ui-datepicker

Customizable date picker for React Native

  • 3.0.0-beta.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
decreased by-10.6%
Maintainers
0
Weekly downloads
 
Created
Source
react-native-ui-datepicker

npm version npm downloads Github gzipped size

DateTimePicker component for React Native that allows you to create a customizable datetime picker. The component uses extensive set of props that allows you to customizing the calendar based on your own UI design. Please visit demo.

Features

  • 📅 Supports different selection modes: single, range, and multiple days.
  • 🌿 Unstyled by default, every component is minimally styled and fully customizable.
  • 🛠️ Extensive set of props for fine-tuned calendar customization.
  • 🎨 Fully compatible with NativeWind.
  • 🌎 Easily localizable into any language.
  • 🕗 Handles different time zones seamlessly.
  • ⚙️ Customizable components allow extending rendered elements.
  • ⚡ Fast & lightweight, only re-renders the elements that actually change.

Installation

npm install react-native-ui-datepicker

Or

yarn add react-native-ui-datepicker

Basic Usage

  1. Import the component and default styles or classNames from react-native-ui-datepicker.
  2. Choose a selection mode using the mode prop. The available modes are: single, range, and multiple.
import { useState } from  'react';
import DateTimePicker, { DateType } from 'react-native-ui-datepicker';

export function Calendar() {
  const [selected, setSelected] = useState<DateType>();

  return (
    <DateTimePicker
      mode="single"
      date={selected}
      onChange={({ date }) =>  setSelected(date)}
    />
  );
}

Calendar Base Props

NameTypeDescription
mode"single" | "range" | "multiple"Defines the DatePicker mode.
minDateDateTypeDefines the minimum selectable date in the DatePicker.
maxDateDateTypeDefines the maximum selectable date in the DatePicker.
disabledDatesDateType[] | (date: DateType) => booleanDefines an array of disabled dates or a function that returns true for disabled dates.
firstDayOfWeeknumberDefines the first day of the week: 0-6 (0 = Sunday, 6 = Saturday).
initialView"day" | "month" | "year" | "time"Defines the initial view of the DatePicker
monthnumberDefines the currently selected month.
yearnumberDefines the currently selected year.
onMonthChange(month: number) => voidCallback function triggered when the current month changes.
onYearChange(year: number) => voidCallback function triggered when the current year changes.

Example

export function Calendar() {
  let today = new Date();
  const [selected, setSelected] = useState<DateType>();

  return (
    <DateTimePicker
      mode="single"
      date={selected}
      onChange={({ date }) =>  setSelected(date)}
      firstDayOfWeek={6} // Set Saturday to be first day of week
      minDate={today}
      disabledDates={(date) => [0, 6].includes(dayjs(date).day())} // Disable weekends
    />
  );
}

Single Mode props

NameTypeDescription
dateDateTypeSpecifies the currently selected date.
onChange({date}) => voidCallback function triggered when the date change.
timePickerbooleanWhether to enable the time picker.

Range Mode props

NameTypeDescription
startDateDateTypeDefines the start date for a range selection.
endDateDateTypeDefines the end date for a range selection.
onChange({startDate, endDate}) => voidCallback function triggered when the start and end change.
minnumberDefines the minimum allowed nights.
maxnumberDefines the maximum allowed nights.

Multiple Mode props

NameTypeDescription
datesDateType[]Defines the selected dates for multiple date selection.
onChange({dates}) => voidCallback function triggered when the dates change.
maxnumberDefines the maximum allowed days to select.
multiRangeModebooleanWhether to display selecting multiple dates in a range row.

react-native-ui-datepicker-styles

Customization

NameTypeDescription
showOutsideDaysbooleanWhether to show the days of the previous and next months.
navigationPosition"around" | "right" | "left"Defines the position of the navigation.
containerHeightnumberDefines the height of the calendar days container.
weekdaysHeightnumberDefines the height of the weekdays row.
weekdaysFormat"short" | "full" | "min"Defines the format for displaying weekdays.
monthsFormat"short" | "full"Defines the format for displaying months.
monthCaptionFormat"short" | "full"Defines the format for displaying the month caption.
hideHeaderbooleanWhether to hide the calendar header.
hideWeekdaysbooleanWhether to hide the weekdays row.
disableMonthPickerbooleanWhether to disable the month picker.
disableYearPickerbooleanWhether to disable the year picker.

Styling

DateTimePicker comes with a minimal style, making it easy to extend and customize according to your needs.

NameTypeDescription
styleViewStylestyle for the calendar container.
classNamestringclassName for the calendar container.
stylesStylesCustom styles for specific components inside the calendar.
classNamesClassNamesCustom classNames for specific components inside the calendar.

Custom Styles

Use the styles prop to apply custom styles instead of the default ones.

These styles are mapped to the values of the UI Theme enums.

import DateTimePicker, { getDefaultStyles } from 'react-native-ui-datepicker';

export function Calendar() {
  const defaultStyles = getDefaultStyles();

  return (
    <DateTimePicker
      styles={{
        ...defaultStyles,
        today: { borderColor: 'blue', borderWidth: 1 }, // Add a border to today's date
        selected: { backgroundColor: 'blue' }, // Highlight the selected day
        selected_label: { color: 'white' }, // Highlight the selected day label
      }}
    />
  );
}

NativeWind (Tailwind CSS)

If you're using NativeWind in your project, apply Tailwind CSS class names to style the calendar. Use the classNames prop to apply custom class names instead of the default ones.

These class names are mapped to the values of the UI Theme enums.

import DateTimePicker, { getDefaultClassNames } from 'react-native-ui-datepicker';

export function Calendar() {
  const defaultClassNames = getDefaultClassNames();

  return (
    <DateTimePicker
      classNames={{
        ...defaultClassNames,
        today: 'border-amber-500', // Add a border to today's date
        selected: 'bg-amber-500 border-amber-500', // Highlight the selected day
        selected_label: "text-white", // Highlight the selected day label
        day: `${defaultClassNames.day} hover:bg-amber-100`, // Change background color on hover
        disabled: 'opacity-50', // Make disabled dates appear more faded
      }}
    />
  );
}

Time Zones

Use the timeZone prop to set the time zone for the calendar.

NameTypeDescription
timeZonestringDefines the timezone for the DatePicker.

The time zone can be set using either an IANA time zone identifier or a UTC offset.

<DateTimePicker timeZone="UTC" /> // Use Coordinated Universal Time
<DateTimePicker timeZone="Asia/Tokyo" /> //  Use Japan Standard Time (JST)
<DateTimePicker timeZone="+03:00" /> // Use UTC+3

Localization

DateTimePicker offers multiple options to customize the calendar for different languages.

NameTypeDescription
localestringDefines the locale of the DateTimePicker. Default is en
numeralsNumeralsSpecifies the numeral system to use (e.g., Arabic, Persian).

Custom Components

Use the components prop to replace the default rendered elements with your own custom components.

NameTypeDescription
componentsCalendarComponentsCustom components to replace default calendar elements.

Implementing a Custom Component

Pass the custom components to the components prop. Refer to the list below for available custom components.

import DateTimePicker, {
  CalendarDay,
  CalendarMonth,
  CalendarComponents,
} from 'react-native-ui-datepicker';

const components: CalendarComponents = {
  Day: (day: CalendarDay) => <YourCustomDay day={day} />,
  Month: (month: CalendarMonth) => <YourCustomMonth month={month} />
  // etc
};

export function Calendar() {
  return (
      <DateTimePicker
        components={components}
      />
  );
}

List of Custom Components

NameTypeDescription
Day(day: CalendarDay) => React.ReactNodeThe component containing the day in the days grid.
Month(month: CalendarMonth) => React.ReactNodeThe component containing the month in the months grid.
Year(year: CalendarYear) => React.ReactNodeThe component containing the year in the years grid.
Weekday(weekday: CalendarWeek) => React.ReactNodeThe component containing the weekday in the header.
IconPrevReact.ReactNodeThe previous month/year button icon in the header.
IconNextReact.ReactNodeThe next month button/year icon in the header.

List of Numeral Systems

NameDescription
latnWestern Latin.
arabStandard Arabic.
arabextEastern Arabic-Indic (Persian).
devaDevanagari, used in Indian languages.
bengBengali, used in Bengali and Assamese.
guruGurmukhi, used in Punjab, India.
gujrGujarati, used in Gujarat, India.
oryaOdia, used in Odisha, India.
tamldecTamil, used in Tamil-speaking regions.
teluTelugu, used in Andhra Pradesh and Telangana.
kndaKannada, used in Karnataka, India.
mlymMalayalam, used in Kerala, India.

License

MIT. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please feel free to submit a PR.

Keywords

FAQs

Package last updated on 16 Feb 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc