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

react-native-neat-date-picker

Package Overview
Dependencies
Maintainers
0
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-neat-date-picker

An easy-to-use date picker for React Native

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
496
decreased by-34.65%
Maintainers
0
Weekly downloads
 
Created
Source

React Native Neat Date Picker

An easy-to-use date picker for React Native.



Main Features

📲 Supports both Android and iOS devices.
👍 Provides range and single selection modes.
🕒 Utilizes modern Date object for date manipulation.
🌈 Offers color customization.
✨ Clean UI
🌐 Supports multiple languages by default: Chinese, English, Spanish, German, French, Portuguese, Malagasy, and Vietnamese. You can also add any language by yourself.

New Update

(v1.5.0) Supports custom languages. Improves performance and accessibility.

Limitation

This package is NOT designed for react-native-web. It can work on the web but may have issues.

For Expo users, it is recommended to use SDK 45 since react-native-modal v13.0 is compatible with react-native >= 0.65.

Dependencies

No manual dependency installation required.

Installation

npm i react-native-neat-date-picker

Example


import { useState } from 'react'
import { Button, StyleSheet, Text, View } from 'react-native'
import DatePicker, { RangeOutput, SingleOutput } from 'react-native-neat-date-picker'


const App = () => {
  const [showDatePickerSingle, setShowDatePickerSingle] = useState(false)
  const [showDatePickerRange, setShowDatePickerRange] = useState(false)

  const [date, setDate] = useState('')
  const [startDate, setStartDate] = useState('')
  const [endDate, setEndDate] = useState('')

  const openDatePickerSingle = () => setShowDatePickerSingle(true)
  const openDatePickerRange = () => setShowDatePickerRange(true)

  const onCancelSingle = () => {
    // You should close the modal here
    setShowDatePickerSingle(false)
  }

  const onConfirmSingle = (output: SingleOutput) => {
    // You should close the modal here
    setShowDatePickerSingle(false)

    // The parameter 'output' is an object containing date and dateString (for single mode).
    // For range mode, the output contains startDate, startDateString, endDate, and endDateString
    console.log(output)
    setDate(output.dateString ?? '')
  }

  const onCancelRange = () => {
    setShowDatePickerRange(false)
  }

  const onConfirmRange = (output: RangeOutput) => {
    setShowDatePickerRange(false)
    setStartDate(output.startDateString ?? '')
    setEndDate(output.endDateString ?? '')
  }

  return (
    <View style={styles.container}>
      {/* Single Date */}
      <Button title={'single'} onPress={openDatePickerSingle} />
      <DatePicker
        isVisible={showDatePickerSingle}
        mode={'single'}
        onCancel={onCancelSingle}
        onConfirm={onConfirmSingle}
      />
      <Text>{date}</Text>

      {/* Date Range */}
      <Button title={'range'} onPress={openDatePickerRange} />
      <DatePicker
        isVisible={showDatePickerRange}
        mode={'range'}
        onCancel={onCancelRange}
        onConfirm={onConfirmRange}
      />
      <Text>{startDate && `${startDate} ~ ${endDate}`}</Text>
    </View>
  )
}

export default App

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    justifyContent: 'center',
    alignItems: 'center',
  },
})


Properties

PropertyTypeDefaultDiscription
isVisibleBooleanREQUIREDShow or hide the date picker modal.
modeStringREQUIREDsingle for single date selection or range for date range selection.
onCancelFunctionREQUIREDExecuted when the cancel button is pressed.
onConfirmFunctionREQUIREDExecuted when the confirm button is pressed. See onConfirm.
initialDateDatenew Date()Sets the initial date displayed on the first open.
minDateDate-Specifies the earliest selectable date.
maxDateDate-Specifies the latest selectable date.
startDateDate-Initial start date for range mode.
endDateDate-Initial end date for range mode.
onBackButtonPressFunctiononCancelTriggered when the Android back button is pressed.
onBackdropPressFunctiononCancelTriggered when the backdrop is pressed.
languageStringenSupported languages out of the box: 'en', 'cn', 'de', 'es', 'fr', 'pt', 'mg', 'vi'.
customLanguageConfigObject-Custom language config. See Customize language
colorOptionsObjectnullSee ColorOptions.
dateStringFormatstring'yyyy-mm-dd'Format for date strings. e.g.'yyyymmdd', 'dd-mm-yyyy'
Availible characters are: y : year, m : month, d : day.
modalStylesObjectnullCustom styles for the modal.
chooseYearFirstbooleanfalseOpens the year selection modal first.
withoutModalbooleanfalseIf true, the date picker will be displayed directly instead of being placed in a modal.

onConfirm

The onConfirm prop provides an output object.

  • Single mode: { date, dateString }

  • Range mode: { startDate, startDateString, endDate, endDateString }

Example:

// Single mode
const handleConfirm = ({ date, dateString }) => {
  console.log(date.getTime());
  console.log(dateString);
};

// Range mode
const handleConfirm = ({ startDate, startDateString, endDate, endDateString }) => {
  console.log(startDate.getTime());
  console.log(startDateString);
  console.log(endDate.getTime());
  console.log(endDateString);
};

...

<DatePicker onConfirm={handleConfirm} />

Customize Language

Example:

{
  months: {
    '0': 'Jan',
    '1': 'Feb',
    '2': 'Mar',
    '3': 'Apr',
    '4': 'May',
    '5': 'Jun',
    '6': 'Jul',
    '7': 'Aug',
    '8': 'Sep',
    '9': 'Oct',
    '10': 'Nov',
    '11': 'Dec',
  },
  weekDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  accept: 'OK',
  cancel: 'Cancel',
}

ColorOptions

The colorOptions prop contains several color settings. It helps you customize the date picker.

OptionTypediscription
backgroundColorStringBackground color of the date picker and year selection modal.
headerColorStringBackground color of the header.
headerTextColorStringText and icon color in the header.
changeYearModalColorstringText and icon color in the year selection modal.
weekDaysColorstringText color for weekday labels (e.g., Monday, Tuesday).
dateTextColor*stringText color for unselected dates.
selectedDateTextColor*stringText color for selected dates.
selectedDateBackgroundColor*stringBackground color for selected dates.
confirmButtonColorstringText color of the confirm button.

* : Only six-digits HEX code colors (like #ffffff. #fff won't work) are supported because I do something like this behind the scene.

style={{color:'{dateTextColor}22'}}  // '#rrggbbaa'

Example:

const colorOptions = {
  headerColor:'#9DD9D2',
  backgroundColor:'#FFF8F0'
}
...
<DatePicker
  ...
  colorOptions={colorOptions}
/>

TODOs

  • Add font customization.
  • Turn to typescript.

Inspiration

Inspired by react-native-daterange-picker.

Contact Me

This is my first open-source project.

Feedback and contributions are welcome!

Email: 2roto93Stark@gmail.com

Keywords

FAQs

Package last updated on 21 Jan 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