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
Prop | Type | Default | Description |
---|---|---|---|
enabled | boolean | false | Enables the date picker functionality (transforms the component into a date picker) |
withTime | boolean | false | Include time selection in the date picker (only works with mode='single') |
disableFutureDates | boolean | false | Disable selection of future dates |
disablePastDates | boolean | false | Disable selection of past dates |
initialDate | Date | undefined | Initial date value for single date picker (mode='single') |
initialRange | DateRange | undefined | Initial date range for range picker (mode='range') |
initialDates | Date[] | undefined | Initial dates array for multiple date picker (mode='multiple') |
onDateChange | (date: Date) => void | undefined | Callback function called when a single date changes (mode='single') |
sendDateValue | (dateValue: string) => void | undefined | Callback with formatted date string (mode='single') |
onDateRangeChange | (range: DateRange) => void | undefined | Callback when date range changes (mode='range') |
sendDateRangeValues | (startDateValue: string, endDateValue: string) => void | undefined | Callback with formatted date range strings (mode='range') |
onDatesChange | (dates: Date[] | undefined) => void | undefined | Callback when multiple dates change (mode='multiple') |
sendDatesValues | (datesValues: string[]) => void | undefined | Callback with formatted multiple date strings (mode='multiple') |
backgroundColor | string | undefined | Background color for the date picker |
showCloseButton | boolean | false | Show close button in the date picker |
closeButtonColor | string | undefined | Color for the close button |
mode | 'single' | 'range' | 'multiple' | 'single' | Mode of the date picker for selecting a single date, date range, or multiple dates |
selectedItemColor | string | undefined | Color for selected items in the date picker |
firstDayOfWeek | number | 0 | First day of the week (0 = Sunday, 1 = Monday, etc.) |
placeholder | string | undefined | Placeholder text for the date picker |
placeholderStyle | TextStyle | undefined | Style for the placeholder text |
animationType | 'zoomIn' | 'slideUp' | 'slideDown' | 'slideLeft' | 'slideRight' | 'none' | 'none' | Animation type for the date picker modal |
animationDuration | number | 300 | Duration for the animation in milliseconds |
hideConfirmButton | boolean | false | Hide the confirm button in the date picker |
dateFormat | string | 'DD/MM/YYYY' | Custom format for the date / date range / dates |
dateTimeFormat | string | 'DD/MM/YYYY HH/MM/SS' | Custom format for the date and time (when withTime is true) |
componentProps | any | undefined | Additional props for the date picker component |
styles | DatePickerStyleProps | undefined | Additional styles for the date picker component |
DatePickerStyle Properties
Prop | Type | Default | Description |
---|---|---|---|
headerTextColor | string | #000000 | Color of the header text in the date picker modal |
headerBackgroundColor | string | #FFFFFF | Background color of the header in the date picker modal |
calendarBackgroundColor | string | #FFFFFF | Background color of the calendar in the date picker modal |
selectedTextColor | string | #FFFFFF | Text color of the selected date |
selectedBackgroundColor | string | #3B82F6 | Background color of the selected date |
todayTextColor | string | #3B82F6 | Text color of today's date |
dayTextColor | string | #000000 | Text color of regular days |
disabledTextColor | string | #A0A0A0 | Text color of disabled dates (outside min/max range) |
confirmButtonColor | string | #3B82F6 | Color of the confirm button text |
cancelButtonColor | string | #9CA3AF | Color 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 withmode: "single"
) - The
format
prop determines how the selected date/time is displayed in the input field using date-fns format patterns - Set
minDate
andmaxDate
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