DatePicker Props

The datePicker and datePickerStyle prop groups enable and configure the date and time picker functionality of the FormInput component. When datePicker.enabled is set to true, the input transforms into an interactive date/time picker.

Important: The date picker functionality requires date-fns as a dependency. Ensure you have it installed in your project.

DatePicker Properties

PropTypeDefaultDescription
enabledbooleanfalseEnables the date picker functionality (transforms the component into a date picker)
withTimebooleanfalseInclude time selection in the date picker (only works with mode='single')
disableFutureDatesbooleanfalseDisable selection of future dates
disablePastDatesbooleanfalseDisable selection of past dates
initialDateDateundefinedInitial date value for single date picker (mode='single')
initialRangeDateRangeundefinedInitial date range for range picker (mode='range')
initialDatesDate[]undefinedInitial dates array for multiple date picker (mode='multiple')
onDateChange(date: Date) => voidundefinedCallback function called when a single date changes (mode='single')
sendDateValue(dateValue: string) => voidundefinedCallback with formatted date string (mode='single')
onDateRangeChange(range: DateRange) => voidundefinedCallback when date range changes (mode='range')
sendDateRangeValues(startDateValue: string, endDateValue: string) => voidundefinedCallback with formatted date range strings (mode='range')
onDatesChange(dates: Date[] | undefined) => voidundefinedCallback when multiple dates change (mode='multiple')
sendDatesValues(datesValues: string[]) => voidundefinedCallback with formatted multiple date strings (mode='multiple')
backgroundColorstringundefinedBackground color for the date picker
showCloseButtonbooleanfalseShow close button in the date picker
closeButtonColorstringundefinedColor for the close button
mode'single' | 'range' | 'multiple''single'Mode of the date picker for selecting a single date, date range, or multiple dates
selectedItemColorstringundefinedColor for selected items in the date picker
firstDayOfWeeknumber0First day of the week (0 = Sunday, 1 = Monday, etc.)
placeholderstringundefinedPlaceholder text for the date picker
placeholderStyleTextStyleundefinedStyle for the placeholder text
animationType'zoomIn' | 'slideUp' | 'slideDown' | 'slideLeft' | 'slideRight' | 'none''none'Animation type for the date picker modal
animationDurationnumber300Duration for the animation in milliseconds
hideConfirmButtonbooleanfalseHide the confirm button in the date picker
dateFormatstring'DD/MM/YYYY'Custom format for the date / date range / dates
dateTimeFormatstring'DD/MM/YYYY HH/MM/SS'Custom format for the date and time (when withTime is true)
componentPropsanyundefinedAdditional props for the date picker component
stylesDatePickerStylePropsundefinedAdditional styles for the date picker component

DatePickerStyle Properties

PropTypeDefaultDescription
headerTextColorstring#000000Color of the header text in the date picker modal
headerBackgroundColorstring#FFFFFFBackground color of the header in the date picker modal
calendarBackgroundColorstring#FFFFFFBackground color of the calendar in the date picker modal
selectedTextColorstring#FFFFFFText color of the selected date
selectedBackgroundColorstring#3B82F6Background color of the selected date
todayTextColorstring#3B82F6Text color of today's date
dayTextColorstring#000000Text color of regular days
disabledTextColorstring#A0A0A0Text color of disabled dates (outside min/max range)
confirmButtonColorstring#3B82F6Color of the confirm button text
cancelButtonColorstring#9CA3AFColor of the cancel button text

Example

tsx
import { FormInput } from '@react-native-utils/forminput';
import { useState } from 'react';
import { View } from 'react-native';

const DatePickerExample = () => {
  const [birthdate, setBirthdate] = useState(null);
  const [appointmentTime, setAppointmentTime] = useState(null);
  
  // Calculate date 18 years ago for minimum birth date
  const eighteenYearsAgo = new Date();
  eighteenYearsAgo.setFullYear(eighteenYearsAgo.getFullYear() - 18);
  
  return (
    <View style={{ padding: 16, gap: 16 }}>
      {/* Date picker example */}
      <FormInput
        text={{
          labelText: "Date of Birth",
          placeholderText: "Select your date of birth",
        }}
        icon={{
          leftIcon: "calendar",
        }}
        datePicker={{
          enabled: true,
          initialDate: null,
          mode: "single",
          dateFormat: "MMMM d, yyyy",
          onDateChange: (date) => setBirthdate(date),
          disableFutureDates: false,
          disablePastDates: false,
          placeholder: "Select Your Birthdate",
          firstDayOfWeek: 1,  // Week starts on Monday
        }}
        style={{
          styles: {
            selectedTextColor: "#FFFFFF",
            selectedBackgroundColor: "#3B82F6",
          }
        }}
      />
      
      {/* Time picker example */}
      <FormInput
        text={{
          labelText: "Appointment Time",
          placeholderText: "Select appointment time",
        }}
        icon={{
          leftIcon: "clock",
        }}
        datePicker={{
          enabled: true,
          initialDate: null,
          mode: "single",
          withTime: true,
          dateTimeFormat: "h:mm a",  // Example: 3:30 PM
          onDateChange: (time) => setAppointmentTime(time),
          hideConfirmButton: false,
          placeholder: "Select Time",
          styles: {
            headerBackgroundColor: "#4F46E5",
            headerTextColor: "#FFFFFF",
            confirmButtonColor: "#4F46E5",
          }
        }}
      />
    </View>
  );
};

Notes

  • The date picker appears as a modal when the input is tapped
  • Use the mode prop to configure whether the picker should handle single date ("single"), date range ("range"), or multiple dates ("multiple")
  • To include time selection, set withTime: true (only works with mode: "single")
  • The format prop determines how the selected date/time is displayed in the input field using date-fns format patterns
  • Set minDate and maxDate to restrict the range of selectable dates
  • The onDateChange callback is triggered when a date/time is selected and the modal is confirmed
  • Use the datePickerStyle prop group to customize the visual appearance of the calendar modal