npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-dropdown-date-3

v2.2.9

Published

Highly customizable react based date picker. Select date from Day, Month and Year dropdown

Downloads

18

Readme

react-dropdown-date-3

Highly customizable react based date picker. Select date from Day, Month and Year dropdown

Notice:

This is an update to the original package here:

https://www.npmjs.com/package/react-dropdown-date

This update adds peer dep support for react >16.

npm

npm i react-dropdown-date-3

https://www.npmjs.com/package/react-dropdown-date-3

Demo Link

https://codesandbox.io/s/react-dropdown-date-demo-gbm2k

Date component, with combined functionality

see further below for individual components

import React, { Component } from 'react';
import { DropdownDate, DropdownComponent } from 'react-dropdown-date';

const formatDate = (date) => {	// formats a JS date to 'yyyy-mm-dd'
  var d = new Date(date),
    month = '' + (d.getMonth() + 1),
    day = '' + d.getDate(),
    year = d.getFullYear();

  if (month.length < 2) month = '0' + month;
  if (day.length < 2) day = '0' + day;

  return [year, month, day].join('-');
}

class App extends Component {
  constructor(props) {
    super(props);
    this.state = { date: null, selectedDate: '2012-11-15' };
  }

  render() {
    return (
      <div>

        <DropdownDate
          startDate={                       // optional, if not provided 1900-01-01 is startDate
            '2012-01-01'                    // 'yyyy-mm-dd' format only
          }
          endDate={                         // optional, if not provided current date is endDate
            '2013-12-31'                    // 'yyyy-mm-dd' format only
          }
          selectedDate={                    // optional
            this.state.selectedDate         // 'yyyy-mm-dd' format only
          }
          order={[                          // optional
            DropdownComponent.year,         // Order of the dropdowns
            DropdownComponent.day,
            DropdownComponent.month
          ]}
          onMonthChange={(month) => {       // optional
            console.log(month);
          }}
          onDayChange={(day) => {           // optional
            console.log(day);
          }}
          onYearChange={(year) => {         // optional
            console.log(year);
          }}
          onDateChange={(date) => {         // optional
            console.log(date);
            this.setState({ date: date, selectedDate: formatDate(date) });
          }}
          ids={                             // optional
            {
              year: 'select-year',
              month: 'select-month',
              day: 'select-day'
            }
          }
          names={                           // optional
            {
              year: 'year',
              month: 'month',
              day: 'day'
            }
          }
          classes={                         // optional
            {
              dateContainer: 'classes',
              yearContainer: 'classes',
              monthContainer: 'classes',
              dayContainer: 'classes',
              year: 'classes classes',
              month: 'classes classes',
              day: 'classes classes',
              yearOptions: 'classes',
              monthOptions: 'classes',
              dayOptions: 'classes'
            }
          }
          defaultValues={                   // optional
            {
              year: 'select year',
              month: 'select month',
              day: 'select day'
            }
          }
          options={                         // optional
            {
              yearReverse: true,            // false by default
              monthShort: true,             // false by default
              monthCaps: true               // false by default
            }
          }
        />
      </div>
    );
  }
}

export default App;

HTML Reference for classes

<!-- dateContainer -->
<div class="classes">

    <!-- yearContainer -->
   <div class="classes">

      <!-- year -->
      <select class="classes classes">
         <option value="" class="classes">select year</option>
      </select>
   </div>

   <!-- monthContainer -->
   <div class="classes">

      <!-- month -->
      <select class="classes classes">
         <option value="" class="classes">select month</option>
      </select>
   </div>

   <!-- dayContainer -->
   <div class="classes">

      <!-- day -->
      <select class="classes classes">
         <option value="" class="classes">select day</option>
      </select>
   </div>
</div>

Individual Components: YearPicker, MonthPicker, DayPicker

import React, { Component } from 'react';

import { YearPicker, MonthPicker, DayPicker } from 'react-dropdown-date';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = { year: null, month: null, day: null };
  }

  render() {
    return (
      <div>
        <YearPicker
          defaultValue={'select year'}
          start={2010}                // default is 1900
          end={2020}                  // default is current year
          reverse                     // default is ASCENDING
          required={true}             // default is false
          disabled={true}             // default is false
          value={this.state.year}     // mandatory
          onChange={(year) => {       // mandatory
            this.setState({ year });
            console.log(year);
          }}
          id={'year'}
          name={'year'}
          classes={'classes'}
          optionClasses={'option classes'}
        />
        <MonthPicker
          defaultValue={'select month'}
          numeric                   // to get months as numbers
          short                     // default is full name
          caps                      // default is Titlecase
          endYearGiven              // mandatory if end={} is given in YearPicker
          year={this.state.year}    // mandatory
          required={true}           // default is false
          disabled={true}           // default is false
          value={this.state.month}  // mandatory
          onChange={(month) => {    // mandatory
            this.setState({ month });
            console.log(month);
          }}
          id={'month'}
          name={'month'}
          classes={'classes'}
          optionClasses={'option classes'}
        />
        <DayPicker
          defaultValue={'select day'}
          year={this.state.year}    // mandatory
          month={this.state.month}  // mandatory
          endYearGiven              // mandatory if end={} is given in YearPicker
          required={true}           // default is false
          disabled={true}           // default is false
          value={this.state.day}    // mandatory
          onChange={(day) => {      // mandatory
            this.setState({ day });
            console.log(day);
          }}
          id={'day'}
          name={'day'}
          classes={'classes'}
          optionClasses={'option classes'}
        />
      </div>
    );
  }
}

export default App;