1.0.3 • Published 4 years ago

react-native-customize-selected-date-v2 v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

React Native Customize Selected Date Version 2

This module is the newest version of the previous one, there are some changes in styling and some functions. Thanks for the author of React Native Customize Selected Date. previous module download here! https://github.com/hungdev/react-native-customize-selected-date

Github : https://github.com/arwysyah/react-native-customize-selected-date-v2

NPM : https://www.npmjs.com/package/react-native-customize-selected-date-v2

Install

npm install react-native-customize-selected-date-v2 --save

Usage:

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import DateTime from 'react-native-customize-selected-date-v2'

export default class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      date:[]
    }
  }
  onChangeDate(date) {
    // alert(date);
    const today = new Date();

    if (new Date(date) <= today) {
      return Alert.alert(
        'Oops',
        'can not go back from today',
      );
    } else if (this.state.date.includes(date)) {
      this.removeDate(date);
    } else {
      this.setState({
        date: [...this.state.date, date].sort(function(a, b) {
          return a < b ? -1 : a > b ? 1 : 0;
        }),
      });
    }
  }
  removeDate(selectedDate) {
    let filteredArray = this.state.date.filter(item => item !== selectedDate);
    this.setState({date: filteredArray});
  }
  renderChildDay(day) {
    if (_.includes(this.state.date, day)) {
      return <View style={styles.icLockRed} />;
    }
  }

  render() {
    return (
      <View style={styles.container}>
          <DateTime
              containerStyle={{top: -40}}
              warpDayStyle={{backgroundColor: 'white'}}
              textDayStyle={{color: 'black'}}
              notCurrentDayOfMonthStyle={{color: '#adadad'}}
              currentDayStyle={{color: '#FA4B41', fontWeight: 'bold'}}
              dateSelectedWarpDayStyle={{backgroundColor: 'red'}}
              changeDate={date => this.onChangeDate(date)}
              format="YYYY-MM-DD"
              renderChildDay={day => this.renderChildDay(day)}
            />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  icLockRed: {
    width: 40,
    height: 40,
    position: 'absolute',
    alignSelf: 'center',
    borderRadius: 20,
    backgroundColor: '#A1DD70',
  },
});

Props

PropertyTypeDescription
datePropTypes.stringDefault date
changeDatePropTypes.funcfunction call back after select date
formatPropTypes.arrayFormat date output
renderChildDayPropTypes.funcreturn child element injected to date
customWeekdaysPropTypes.funcArray Weekdays, default: 'Sun', 'Mon', 'Tue', 'Wes', 'Thu', 'Fri', 'Sat'
renderPrevYearButtonPropTypes.funcRender function for customize prev year button
renderPrevMonthButtonPropTypes.funcRender function for customize prev month button
renderNextYearButtonPropTypes.funcRender function for customize next year button
renderNextMonthButtonPropTypes.funcRender function for customize next year button

Styles

PropertyTypeDescription
containerStylePropTypes.objectContainer Style
warpRowControlMonthYearPropTypes.objectStyle for row control next or prev month, year.
warpRowWeekdaysPropTypes.objectWarp row weekdays style
weekdayStylePropTypes.objectWeekday text style
warpDayStylePropTypes.objectStyle for each day in month
dateSelectedWarpDayStylePropTypes.objectStyle for selected day in month
textDayStylePropTypes.objectStyle for text day in month
currentDayStylePropTypes.objectStyle for text current day in month
notCurrentDayOfMonthStylePropTypes.objectStyle for text when day is not current day in month

Pull Request

Pull requests are welcome!

  • Author Account
hungdev and team
Arwy Syahputra Siregar
github.com/arwysyah