2.0.5 • Published 3 years ago

react-single-calendar v2.0.5

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

React Single Calendar

Description:

react-single-calendar is a very useful and easy to use date picker, no external dependency is needed for this. You can chagne theme of it's color, by simply editing css variables.

How to install?

npm i react-single-calendar

Implementation

import React, {useState} from 'react';
import SingleCalendar from 'react-single-calendar';


const App = () => {
    let [date, filterDate] = useState('');
    return (
        ....
        <SingleCalendar selectedDate={filterDate} />
    )
}
export default App;

In this date useState you will get the selectedDate, selectedDate is the props for SingleCalendar component. It will return this filterDate method, you can use your own method.

react-single-calendar returns a string value like March 21, 2019, if no formate has been provied. You can use Date.parse() method to convert it as a date.

react-single-calendar can be used with input field on, or off. If dateInput property is true, it will work as a form input field. If value is false you can open or close this component on a freedom of your own button click function

Getting Date Range

For getting date range, add a on for < SingleCalendar />, named as range={true}, by default range is false.

When using range, this filterDate method returns an array of to strings

Stateless or Functional Component

import React, {useState} from 'react';
import SingleCalendar from 'react-single-calendar';


const App = () => {
    let [date, filterDate] = useState('');
    return (
        ....
        <SingleCalendar selectedDate={filterDate} range={true} />
    )
}
export default App;

Class Component

import React from 'react';
import SingleCalendar from 'react-single-calendar';
class App extends React.Component {
  // let [nodes, setNodes] = useState(null);
  constructor(props) {
    super(props);
    this.state = {
      date: '21-09-2020',
      currentDate: "October 13, 2021"
    }
  }

  filterDate(date) {
    this.setState({
      date: date
    })
  }
  render() {
    return (
      <div>
        <SingleCalendar selectedDate={(date) => this.filterDate(date)} dateInput={true} />
      </div>
    )
  }
}

export default App;

In this example it the date variable will return:

Example: 'March 21, 2019', 'August 10, 2019'

Again you can use Date.parse() method, to gate a date value, or you can use this strings in your way.

Disable Future Dates

react-single-calendar has a feature to disable upcoming dates. For that you need to add upcoming as a prop and set the value to false. By default it is set to true.

<SingleCalendar selectedDate={filterDate} upcoming={false}/> 

You can use this feature with date range also, see the below code:

<SingleCalendar selectedDate={filterDate} range={true} upcoming={false}/>

Theming:

On your css/ scss add this variables. You can customize your theme color and width, height through this css variables.

:root {
  --weekend: rgba(0, 0, 0, 0);
  --date-light: #f8f9fa;
  --date-primary: #5644c1;
  --date-success: #37d37d;
  --date-primaryLight: #eceaf5;
  --date-primaryTitle: #dbd8f0;
  --date-hover: #262769;
  --date-highlight: #f83854;
  --date-disabled:#c2c1cc;
  --date-width: 260px;
  --date-height: 280px;

These fields are added, for the range:

  1. date-rangebg: is for highlighting dates between two selected dates
  2. date-rangetext: changing color of text in range area
  3. date-rangeDateBg: two main dates which will indicate "from" and "to" dates
  --date-rangebg:#8072d0;
  --date-rangetext:#f8f9fa;
  --date-rangeDateBg:#5644c1;
}

Options

PropertiesTypeDescriptionValues
selectedDateFunctionReturns selected date or date range
formatStringDefine the format of date, if not set it will return like Month day, year formate like "November 12, 1998", year will be always yyyy format and you can use your choice of seperator '-', '/' even 'a', 'b' alsodd-mm-yyyy, mm/dd/yyyy, **yyyymmdd**
currentDateStringIt need to be provided "month day, year" format, like "December 03, 2012" if not provided it will show date format on the input fieldDecember 03, 2012
maxStringIf you want to put a limit, like user cannot entry after this date, then you will use it as a max date limit, To use max you need to provide format option and the format of this max should be same as the format optiondd-mm-yyyy, mm/dd/yyyy, **yyyymmdd**
minStringIf you want to put a limit, like user cannot entry beyond this date, then you will use it as a min date limit, To use min you need to provide format option and the format of this min should be same as the format optiondd-mm-yyyy, mm/dd/yyyy, **yyyymmdd**
iconsObject*You can change the default icon of this library, by providing svg or image files, import calendar from './assets/calendar.svg'*icons={{ 'calendar': calendarIcon, 'done': tickIcon, 'reset': resetIcon, 'previous': prevIcon, 'next': nextIcon }}
upcomingBooleanBy default its true, if set to false, means future dates will be hiddentrue / false
rangeBooleanIf true, will use as a date reange selector, but max option will not be applicable heretrue / false
dateInputBooleanIf true, calendar will have an input field, onFocus calendar will open, also calendar proerty from icon will have a small icon beside this input fieldtrue / false
cssClassStringIf dateInput is true this option will provide className to the input field, So if anyone using bootstrap and want to use form-control class, can provide from this optionform-control myClass
cssClassStringIf This option will provide className to the input field, So if anyone using bootstrap and want to use form-control class, can provide from this optionform-control myClass
placeHolderStringThis option will provide placeholder text to the input fieldplaceHolder={'Enter your DOB' }

Raise an Issue

If you are facing any issue regarding installation and usage, raise your issue in Git repo.

https://github.com/devsubhajit/react-single-calendar/issues
2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.9

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago