Giter Site home page Giter Site logo

giekus / rn-select-date-range Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dilipchandima/rn-select-date-range

0.0 0.0 0.0 851 KB

A simple and fully customizable React Native date range picker component

Home Page: https://www.npmjs.com/package/rn-select-date-range

License: MIT License

JavaScript 4.81% Starlark 2.38% Java 24.49% Ruby 2.89% Objective-C 17.74% TypeScript 47.70%

rn-select-date-range's Introduction

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

Prop Type Required Description
onSelectDateRange Method Required This will return a object with firstDate and lastDate
maxDate Moment Date Optional If you need to pass Max Date user can select, set this prop as a moment date
minDate Moment Date Optional If you need to pass Min Date user can select, set this prop as a moment date
responseFormat String Optional Please refere the date formats here Moment Date Formats
blockSingleDateSelection boolean Optional This will block the user to click single date without date range
font String Optional Name of the font you are using in your theme
selectedDateContainerStyle Style Optional Style of the selected date container
selectedDateStyle Style Optional Style of the selected date



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.

rn-select-date-range's People

Contributors

dilipchandima avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.