1.4.0 • Published 5 years ago

simple-react-date-selector v1.4.0

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

simple-react-date-selector

A simple react date picker component.

Preview:

selection

Default styling:

year month day

Custom styling:

year month day

Props:

PropRequiredTypeDescription
onChangetruefunctionThe callback function that should be executed when the complete date is chosen. The argument is the date value that is returned.
onOpenedfalsefunctionThe callback function that should be executed as soon as the datepicker becomes visible
onClosedfalsefunctionThe callback function that should be executed as soon as the datepicker is hidden
placeholdertruestringThe field label
valuetruestringThe current value that should be displayed in the date field.
headerStylesfalsestyle objectAdditional styles that should be added to the header - The day, month and year headings
bodyStylesfalsestyle objectAdditional styles that should be added to the body - The day, month and year options
containerStylesfalsestyle objectAdditional styles that should be added to the container - The modal in which the day, month and year pickers are rendered
footerStylesfalsestyle objectAdditional styles that should be added to the footer - The footer that displays the currently selected year, month and day
visiblefalsebooleanYou can programmatically set the visibility of the datepicker by specifying true (show the datepicker) or false (hide the datepicker)
yearRangefalseobjectSet the from and to year range. For example {from:2000,to:2015}. By default the range is from 15 years in the past to 15 years in the future

Steps for including the component in your project:

  • run "npm init" in the root of your application to create a package.json file if your application doesn't have one yet.
  • run "npm install simple-react-date-selector --save" OR "yarn add simple-react-date-selector" in the root of your ReactJS application.
  • Include the SCSS file - When using "create-react-app" this file can easily be included by @importing it into your application's root SCSS file.
  • Require the component at the top of your application's component where you want to use the date picker.

Example usage:

Add the SCSS file to your application's root SCSS file - for example:

/*Remember to reference your node_modules directory correctly*/

@import "../node_modules/simple-react-date-selector/styles/simple-react-date-selector";

Add it to your application's component - for example:

import React,{Component} from "react";

/*This is a default export so feel free to name it whatever you like. It doesn't have to be Datepicker */

import Datepicker from 'simple-react-date-selector';

export default class MyComponent extends Component{
    constructor(props){
        super(props);
        this.state={DateFrom:"",DateTo:""};
    }

    /*
        The first datepicker simply has the default styling
        The second datepicker component has been given custom styling
    */

    render(){
        return (
                <Datepicker  
                    onChange={date=>{this.setState({DateFrom:date})}}
                    placeholder={'From'}
                    value={this.state.DateFrom}
                    visible={true}
                />
                <Datepicker  
                    onChange={date=>{this.setState({DateTo:date})}}
                    placeholder={'To'}
                    value={this.state.DateTo}
                    headerStyles={{
                        backgroundColor:'#263238',
                        color:'white',
                        borderBottomWidth:0
                    }}
                    containerStyles={{
                        borderRadius:0,
                        backgroundColor:'#263238',
                        borderColor:'black',
                        borderWidth:1,
                        borderStyle:'solid'
                    }}
                    bodyStyles={{
                        borderRadius:10,
                        backgroundColor:'white',
                        borderWidth:1,
                        borderColor:'#263238',
                        borderStyle:'solid'
                    }}
                    footerStyles={{
                        borderRadius:0,
                        borderWidth:1,
                        borderColor:'#263238',
                        borderStyle:'solid'
                    }}
                />
        )

    }
}
1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago