5.0.0 • Published 1 year ago

rn-select-date-range v5.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rn-select-date-range

A simple React Native date range picker component


Installing

npm install rn-select-date-range

or

yarn add rn-select-date-range

Screenshot


Prerequisites

CalendarPicker requires Moment JS.

npm install --save moment

Example React Native App

import moment from "moment";
import React, { useState } from "react";
import { SafeAreaView, StyleSheet, View, Text } from "react-native";
import DateRangePicker from "rn-select-date-range";

const App = () => {
  const [selectedRange, setRange] = useState({});
  return (
    <SafeAreaView>
      <View style={styles.container}>
        <DateRangePicker
          onSelectDateRange={(range) => {
            setRange(range);
          }}
          blockSingleDateSelection={true}
          responseFormat="YYYY-MM-DD"
          maxDate={moment()}
          minDate={moment().subtract(100, "days")}
          selectedDateContainerStyle={styles.selectedDateContainerStyle}
          selectedDateStyle={styles.selectedDateStyle}
        />
        <View style={styles.container}>
          <Text>first date: {selectedRange.firstDate}</Text>
          <Text>second date: {selectedRange.secondDate}</Text>
        </View>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    margin: 50,
  },
  selectedDateContainerStyle: {
    height: 35,
    width: "100%",
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "blue",
  },
  selectedDateStyle: {
    fontWeight: "bold",
    color: "white",
  },
});

export default App;

CalendarPicker Props

PropTypeRequiredDescription
onSelectDateRangeMethodRequiredThis will return a object with firstDate and lastDate
maxDateMoment DateOptionalIf you need to pass Max Date user can select, set this prop as a moment date
minDateMoment DateOptionalIf you need to pass Min Date user can select, set this prop as a moment date
responseFormatStringOptionalPlease refere the date formats here Moment Date Formats
blockSingleDateSelectionbooleanOptionalThis will block the user to click single date without date range
fontStringOptionalName of the font you are using in your theme
selectedDateContainerStyleStyleOptionalStyle of the selected date container
selectedDateStyleStyleOptionalStyle of the selected date
lnstringOptionalTwo letter locales string that is supported by the Moment library
onConfirmMethodOptionalThis function will be executed if confirm button pressed
onClearMethodOptionalThis function will be executed if clear button pressed
clearBtnTitlestringOptionalText for the button to clear data. If empty string passed, button will not be shown
confirmBtnTitlestringOptionalText for the button to confirm selection of dates. If empty string passed, button will not be shown

onSelectDateRange response

{
    firstDate: if you pass responseFormat it will be a formatted date, if not it will be a moment date
    lastDate: if you pass responseFormat it will be a formatted date, if not it will be a moment date
}

Run the sample app

cd example
npm install
npx react-native run-ios

Suggestions?

Open Issues. Submit PRs.

5.0.0

1 year ago

4.0.0

1 year ago

3.3.0

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.2

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago