1.0.8 • Published 2 years ago

react-native-plain-calendar v1.0.8

Weekly downloads
7
License
MIT
Repository
github
Last release
2 years ago

React-Native-Plain-Calendar

This module includes customizable and flexibility react-native calendar component with possibility implement own picker or use existing in it.

Installation

npm i --save react-native-plain-calendar

The solution is implemented in TypeScript so no native module linking is required.

Examples

npm.io npm.io npm.io

Usage

The simplest usage of this calendar component. This library hasn't got any required props, so to use it just import Calendar component

import React from 'react';
import { View } from 'react-native';
import { Calendar } from 'react-native-plain-calendar';

export default const App = () => (
  <View>
    <Calendar />
  </View>
);

Simple usage of picker

import React from 'react';
import { View } from 'react-native';
import { Calendar } from 'react-native-plain-calendar';

export default const App = () => {
  function onSelected ({ selected, selectedStart, selectedEnd }) {
    // Your code
  }

  return(
    <View>
      <Calendar.Picker 
        onSelected={onSelected} 
        selectedType='single-range' 
      />
    </View>
  );
};

Usage with custom header and day components

import React from 'react';
import { View } from 'react-native';
import { Calendar } from 'react-native-plain-calendar';
import { CustomHeaderComponent, CustomDayComponent } from './components'

export default const App = () => (
  <View>
    <Calendar.Picker
      disabledDates={[new Date('10/01/2020'), new Date('11/01/2020'), new Date('12/01/2020')]}
      HeaderComponent={({
        currentMonth,
        onPrevMonth,
        onNextMonth,
      }) => (
        <CustomHeaderComponent
          onPressLeft={onPrevMonth}
          title={currentMonth}
          onPressRight={onNextMonth}
        />
      )}
      DayComponent={({
        isToday,
        isSelectedDate,
        isSingleSelectedDate,
        isStartSelectedDate,
        isEndSelectedDate,
        isIntermediateSelectedDate,
        isDisabledDate,
        isDisabledParticularDate,
        date,
        onPress,
      }) => (
        <CustomDayComponent
          isToday={isToday}
          isSelectedDate={isSelectedDate}
          isSingleSelectedDate={isSingleSelectedDate}
          isStartSelectedDate={isStartSelectedDate}
          isEndSelectedDate={isEndSelectedDate}
          isIntermediateSelectedDate={isIntermediateSelectedDate}
          isDisabledDate={isDisabledDate}
          isDisabledParticularDate={isDisabledParticularDate}
          date={date}
          onPress={onPress}
        />
      )}
    />
  </View>
);

Calendar props

PropTypeDescriptionDefault
onDayPressfunctionCallback which called when day pressed function (date: Date)-
initialDateDateThe date that the calendar opens to when it will be mounted-
selectedDateDateThe date which will be marked as selected single date-
startSelectedDateDateThe date which will be marked as begin date of the range-
endSelectedDateDateThe date which will be marked as end date of the range-
minDateDateMinimum date that can be selected-
maxDateDateMaximum date that can be selected-
disabledDatesDate[]Array of disabled days[]
headerDateFormatstringThe format of the date in the header. react-native-simple-calendar is using the library 'date-fns'. More information about supported dates formats you can find here: https://date-fns.org/v2.2.1/docs/format'MMMM yyyy'
headerContainerStylestyleThe style of the header container(View)-
headerTitleStylestyleThe style of the header title(Text)-
headerButtonStylestyleThe style of the header button container(View)-
HeaderButtonComponentcomponentTakes a component and renders it instead of default header button component-
HeaderComponentcomponentTakes a component and renders it instead of default header component-
WeekdaysComponentcomponentTakes a component and renders it instead of default weekdays component-
weekStartsOnnumberThe index of the first day of the week (0 - Sunday, 1 - Monday, 2 - Tuesday, etc )0
weekdaysstring[]List of days of the week. In the list Must be 7 days and begin from Sunday[]
weekContainerStylestyleThe style of the week container(View)-
weekdayContainerStylestyleThe style of the day container of the week(View)-
weekdayStylestyleThe style of the day of the week(Text)-
cellsStylestyleThe style of the cells component(View)-
daysRowStylestyleThe style of the rows that contains days of the week in cells (View)-
dayContainerStylestyleThe style of the day wrapper(container) component(View)-
DayComponentcomponentTakes a component and renders it instead of default day component.-
todayStylestyleThe style of the today(View)-
dayStylestyleThe style of the day(View)-
daySelectedStylestyleThe style of the selected day(View)-
daySingleSelectedStylestyleThe style of the single selected day(View)-
dayStartSelectedStylestyleThe style of the start selected day (day at the begin of the range)(View)-
dayEndSelectedStylestyleThe style of the end selected day (day at the end of the range)(View)-
dayIntermediateSelectedStylestyleThe style of the intermediate selected day (day within start and end selected days)(View)-
dayDisabledStylestyleThe style of the disabled day(View)-
dayDisabledParticularStylestyleThe style of the disabled particular day (days that passed in disabledDates props)(View)-
todayTextStylestyleThe style of the today text(Text)-
dayTextStylestyleThe style of the day text(Text)-
daySelectedTextStylestyleThe style of the selected day text(Text)-
dayDisabledTextStylestyleThe style of the disabled day text(Text)-
dayDisabledParticularTextStylestyleThe style of the disabled particular day text(Text)-
disabledDayPickbooleanDisable onDayPresstrue

Calendar.Picker props

Takes the same props as Calendar and also takes extra props

PropTypeDescriptionDefault
selectedTypeone of 'single','range','single-range'The type of picker-
onSelectedfunctionCallback which called when all dates will be selected depends on selectedType.-

License

MIT © Yura Pelehatiy 2019