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

flatpickr-react

v1.0.3

Published

flatpickr an extensible date time picker for react

Downloads

21

Readme

React Wrapper for Flatpickr.js

This package provides a React wrapper for the popular date and time picker library, Flatpickr.js. It allows you to easily integrate Flatpickr into your React applications with a variety of customizable options and hooks with typescript support and fully tested functionality.

Installation

To install the package, use npm or yarn:

npm install flatpickr flatpickr-react

or

yarn add flatpickr flatpickr-react

Usage

Basic Usage

To use the DateTimePicker component, import it into your React component and include it in your JSX:

import React, { useState } from "react";
import DateTimePicker from "flatpickr-react";
import "flatpickr/dist/flatpickr.css";

function App() {
	const [date, setDate] = (useState < Date) | (null > null);

	return (
		<div>
			<DateTimePicker
				options={{
					dateFormat: "Y-m-d",
				}}
				value={date}
				onChange={(selectedDate: Date) => {
					setDate(selectedDate);
				}}
			/>
			<p>Selected Date: {date ? date.toString() : "None"}</p>
		</div>
	);
}

export default App;

Props

The DateTimePicker component accepts the following props:

  • defaultValue: The default value of the input.
  • options: Flatpickr options object.
  • locale: Locale settings for Flatpickr.
  • plugins: Array of Flatpickr plugins.
  • onChange: Callback function for the onChange event.
  • onOpen: Callback function for the onOpen event.
  • onClose: Callback function for the onClose event.
  • onMonthChange: Callback function for the onMonthChange event.
  • onYearChange: Callback function for the onYearChange event.
  • onReady: Callback function for the onReady event.
  • onValueUpdate: Callback function for the onValueUpdate event.
  • onDayCreate: Callback function for the onDayCreate event.
  • value: The current value of the input.
  • className: Custom class name for the input.
  • children: Custom children elements.
  • render: Custom render function for the input.
  • onCreate: Callback function for when the Flatpickr instance is created.
  • onDestroy: Callback function for when the Flatpickr instance is destroyed.

Examples

Example 1: Basic Date Picker

<DateTimePicker
	options={{
		dateFormat: "Y-m-d",
	}}
/>

Example 2: Date and Time Picker

<DateTimePicker
	options={{
		enableTime: true,
		dateFormat: "Y-m-d H:i",
	}}
/>

Example 3: Range Picker

<DateTimePicker
	options={{
		mode: "range",
		dateFormat: "Y-m-d",
	}}
/>

Example 4: Multiple Dates Picker

<DateTimePicker
	options={{
		mode: "multiple",
		dateFormat: "Y-m-d",
	}}
/>

Example 5: Custom Locale

import { Spanish } from "flatpickr/dist/l10n/es";

<DateTimePicker
	options={{
		dateFormat: "Y-m-d",
	}}
	locale={Spanish}
/>;

Example 6: Custom Render Function

<DateTimePicker
	render={(props, ref) => (
		<div className="custom-wrapper">
			<label>Select Date:</label>
			<button {...props} ref={ref}>
				Pick a date
			</button>
		</div>
	)}
/>

Example 7: Event Callbacks

<DateTimePicker
	onOpen={() => console.log("Opened")}
	onClose={() => console.log("Closed")}
	onChange={(selectedDates) => console.log("Date changed", selectedDates)}
	onMonthChange={(selectedDates, dateStr, instance) => console.log("Month changed")}
	onYearChange={(selectedDates, dateStr, instance) => console.log("Year changed")}
	onReady={(selectedDates, dateStr, instance) => console.log("Ready")}
	onValueUpdate={(selectedDates, dateStr, instance) => console.log("Value updated")}
	onDayCreate={(selectedDates, dateStr, instance, dayElement) => console.log("Day created")}
/>

Example 8: Custom Position

<DateTimePicker
	options={{
		position: "top",
	}}
/>

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.

Acknowledgements


Feel free to customize the README file further to match your specific needs and preferences.