Convert Figma logo to code with AI

gpbl logoreact-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.

6,003
719
6,003
12

Top Related Projects

React Native Calendar Components 🗓️ 📆

An easily internationalizable, mobile-friendly datepicker library for the web

Full-sized drag & drop event calendar in JavaScript

8,000

A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS

16,122

lightweight, powerful javascript datetimepicker with no dependencies

A simple and reusable datepicker component for React

Quick Overview

React-Day-Picker is a flexible and customizable date picker component for React applications. It provides a simple way to add date selection functionality to your React projects, offering various display modes and extensive customization options.

Pros

  • Highly customizable with numerous styling and configuration options
  • Supports multiple languages and localization
  • Lightweight and performant
  • Offers various selection modes (single day, multiple days, range)

Cons

  • Learning curve for advanced customizations
  • Limited built-in mobile-specific features
  • Styling can be complex for intricate designs
  • Documentation could be more comprehensive for some advanced use cases

Code Examples

  1. Basic usage with default settings:
import { DayPicker } from 'react-day-picker';
import 'react-day-picker/dist/style.css';

function MyDatePicker() {
  return <DayPicker />;
}
  1. Date range selection:
import { DayPicker, DateRange } from 'react-day-picker';
import { useState } from 'react';

function DateRangePicker() {
  const [range, setRange] = useState<DateRange | undefined>();

  return (
    <DayPicker
      mode="range"
      selected={range}
      onSelect={setRange}
    />
  );
}
  1. Customizing appearance with CSS modules:
import { DayPicker } from 'react-day-picker';
import styles from './custom-styles.module.css';

function StyledDatePicker() {
  return <DayPicker classNames={styles} />;
}

Getting Started

To use React-Day-Picker in your project, follow these steps:

  1. Install the package:

    npm install react-day-picker date-fns
    
  2. Import the component and styles in your React file:

    import { DayPicker } from 'react-day-picker';
    import 'react-day-picker/dist/style.css';
    
  3. Use the component in your JSX:

    function MyComponent() {
      return (
        <DayPicker
          mode="single"
          onSelect={(day) => console.log(day)}
        />
      );
    }
    

This basic setup provides a functional date picker. You can further customize it by exploring the various props and styling options available in the documentation.

Competitor Comparisons

React Native Calendar Components 🗓️ 📆

Pros of react-native-calendars

  • Specifically designed for React Native, ensuring better compatibility with mobile apps
  • Offers a wider range of calendar views, including agenda and timeline views
  • Provides more customization options for styling and theming

Cons of react-native-calendars

  • Limited to React Native projects, not suitable for web applications
  • May have a steeper learning curve due to more complex API and features

Code Comparison

react-native-calendars:

import {Calendar} from 'react-native-calendars';

<Calendar
  markedDates={{
    '2023-05-16': {selected: true, marked: true, selectedColor: 'blue'},
    '2023-05-17': {marked: true},
    '2023-05-18': {marked: true, dotColor: 'red', activeOpacity: 0},
  }}
/>

react-day-picker:

import DayPicker from 'react-day-picker';

<DayPicker
  selectedDays={new Date(2023, 4, 16)}
  modifiers={{
    highlighted: new Date(2023, 4, 17),
    disabled: new Date(2023, 4, 18),
  }}
/>

Both libraries offer easy-to-use components for rendering calendars, but react-native-calendars provides more specific features for mobile development, while react-day-picker is more focused on simplicity and web applications.

An easily internationalizable, mobile-friendly datepicker library for the web

Pros of react-dates

  • More comprehensive date range selection functionality
  • Extensive customization options for styling and behavior
  • Better support for mobile devices and touch interactions

Cons of react-dates

  • Larger bundle size and more dependencies
  • Steeper learning curve due to more complex API
  • Less frequent updates and maintenance compared to react-day-picker

Code Comparison

react-dates:

import { DateRangePicker } from 'react-dates';

<DateRangePicker
  startDate={this.state.startDate}
  endDate={this.state.endDate}
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })}
  focusedInput={this.state.focusedInput}
  onFocusChange={focusedInput => this.setState({ focusedInput })}
/>

react-day-picker:

import DayPicker from 'react-day-picker';

<DayPicker
  selectedDays={[this.state.from, { from: this.state.from, to: this.state.to }]}
  onDayClick={this.handleDayClick}
  modifiers={{ start: this.state.from, end: this.state.to }}
/>

Both libraries offer powerful date picking functionality, but react-dates provides more out-of-the-box features for date range selection and styling customization. react-day-picker, on the other hand, offers a simpler API and smaller footprint, making it easier to integrate for basic date picking needs. The choice between the two depends on the specific requirements of your project and the level of customization needed.

Full-sized drag & drop event calendar in JavaScript

Pros of FullCalendar

  • More comprehensive calendar solution with advanced features like event management, drag-and-drop, and various view options (month, week, day)
  • Supports multiple frameworks including React, Vue, and Angular
  • Extensive documentation and community support

Cons of FullCalendar

  • Larger bundle size due to its comprehensive feature set
  • Steeper learning curve for basic implementations
  • Commercial license required for some advanced features

Code Comparison

React-Day-Picker (basic implementation):

import { DayPicker } from 'react-day-picker';

function MyComponent() {
  return <DayPicker />;
}

FullCalendar (basic implementation):

import FullCalendar from '@fullcalendar/react';
import dayGridPlugin from '@fullcalendar/daygrid';

function MyComponent() {
  return <FullCalendar plugins={[dayGridPlugin]} initialView="dayGridMonth" />;
}

React-Day-Picker is more lightweight and focused on date picking functionality, making it easier to implement for simple use cases. FullCalendar offers a more robust solution for complex calendar needs but requires more setup and configuration. The choice between the two depends on the specific requirements of your project, with React-Day-Picker being ideal for simple date selection and FullCalendar for full-featured calendar applications.

8,000

A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS

Pros of Pikaday

  • Lightweight and dependency-free, making it easier to integrate into various projects
  • Supports a wider range of browsers, including older versions
  • More customizable appearance through CSS

Cons of Pikaday

  • Not specifically designed for React, requiring additional setup for React projects
  • Less comprehensive feature set compared to React Day Picker
  • Lacks some modern JavaScript features and patterns

Code Comparison

React Day Picker:

import { DayPicker } from 'react-day-picker';

function MyComponent() {
  return <DayPicker />;
}

Pikaday:

import Pikaday from 'pikaday';

const picker = new Pikaday({
  field: document.getElementById('datepicker'),
  format: 'D MMM YYYY'
});

React Day Picker is specifically designed for React applications, offering a more seamless integration with React components and state management. It provides a declarative API and built-in accessibility features.

Pikaday, on the other hand, is a vanilla JavaScript library that can be used in various environments. It offers more flexibility for non-React projects but requires additional work to integrate with React applications.

Both libraries provide date picking functionality, but React Day Picker offers more React-specific features and a more modern development experience for React applications.

16,122

lightweight, powerful javascript datetimepicker with no dependencies

Pros of flatpickr

  • Lightweight and dependency-free
  • Supports a wide range of browsers and devices
  • Highly customizable with extensive options and hooks

Cons of flatpickr

  • Not specifically designed for React, may require additional setup
  • Less intuitive for React developers compared to React-specific solutions

Code Comparison

flatpickr:

flatpickr("#myInput", {
  dateFormat: "Y-m-d",
  minDate: "today",
  maxDate: new Date().fp_incr(14)
});

react-day-picker:

<DayPicker
  mode="single"
  selected={selected}
  onSelect={setSelected}
  fromDate={new Date()}
  toDate={addDays(new Date(), 14)}
/>

Key Differences

  • flatpickr is a vanilla JavaScript library, while react-day-picker is specifically designed for React applications
  • react-day-picker provides a more React-friendly API with hooks and components
  • flatpickr offers more built-in features and customization options out of the box

Use Cases

  • Choose flatpickr for non-React projects or when extensive customization is required
  • Opt for react-day-picker in React applications for better integration and ease of use

Community and Maintenance

  • Both projects are actively maintained and have strong community support
  • flatpickr has a larger user base due to its framework-agnostic nature
  • react-day-picker is more focused on the React ecosystem

A simple and reusable datepicker component for React

Pros of react-datepicker

  • More comprehensive feature set, including time selection and range selection
  • Better out-of-the-box styling and theming options
  • Larger community and more frequent updates

Cons of react-datepicker

  • Larger bundle size due to more features
  • Steeper learning curve for customization
  • Less flexible for building custom calendar interfaces

Code Comparison

react-datepicker:

import DatePicker from "react-datepicker";

<DatePicker
  selected={startDate}
  onChange={(date) => setStartDate(date)}
  showTimeSelect
  dateFormat="Pp"
/>

react-day-picker:

import { DayPicker } from 'react-day-picker';

<DayPicker
  mode="single"
  selected={selected}
  onSelect={setSelected}
/>

react-datepicker offers more built-in features like time selection, while react-day-picker provides a simpler API for basic date picking. react-datepicker's implementation includes more props for customization out of the box, whereas react-day-picker's approach is more minimalistic, requiring additional setup for advanced features.

Both libraries are popular choices for React date picking, with react-datepicker being more feature-rich and react-day-picker offering more flexibility for custom implementations. The choice between them depends on the specific requirements of your project and the level of customization needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React DayPicker

DayPicker is a React component for creating date pickers, calendars, and date inputs for web applications.

📖 See daypicker.dev for guides, examples and API reference.

Features

DayPicker is written in TypeScript and compiled to CommonJS and ESM. It relies on date-fns for date manipulation and formatting.

Installation

npm install react-day-picker

npm version npm downloads Min gzipped size

Example

import { DayPicker } from "react-day-picker";
import "react-day-picker/style.css";

function MyDatePicker() {
  const [selected, setSelected] = useState<Date>();

  return (
    <DayPicker
      mode="single"
      selected={selected}
      onSelect={setSelected}
      footer={
        selected ? `Selected: ${selected.toLocaleDateString()}` : "Pick a day."
      }
    />
  );
}

Compatibility

DayPicker is compatible with React 16.8 and later.

License

DayPicker is released under the MIT License.

Community

Ask for help and share your experience with DayPicker:

Funding

Consider supporting DayPicker's maintainer with a donation. Your support helps keep the project alive and up-to-date.

NPM DownloadsLast 30 Days