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

@jalik/react-datetime-picker

v1.0.3

Published

Date and time picker for React

Downloads

31

Readme

@jalik/react-datetime-picker

GitHub package.json version GitHub GitHub last commit GitHub issues npm

Introduction

This lib allows you to add datetime inputs in your React applications with the following advantages.

  • Available in CJS and ESM
  • Multiple selection views (year, month, day, time, hour, minute, second)
  • Support for min and max datetime
  • Support for custom day renderer
  • Customizable datetime format
  • Customizable view (locale, week numbers, timezone...)
  • Works like a normal input (onChange/value)
  • Based on Intl API to support any language (English, French, Chinese...)
  • Based on luxon for date and time manipulation

NOTICE : The code has been tested with controlled components only.

Calendar Calendar Calendar Calendar Calendar Calendar

Quickstart

The code below shows how to add a datetime input field with a default value and handling its changes.

import { DateTimeInput } from '@jalik/react-datetime-picker';
import React, {
  useCallback,
  useState
} from 'react';

// Don't forget to load default styles.
import '@jalik/react-datetime-picker/src/styles.css';

function App() {
  const [date, setDate] = useState(new Date().toISOString());

  const handleChange = useCallback((event) => {
    setDate(event.target.value);
  }, [])

  return (
    <div>
      <DateTimeInput
        format="D tt"
        locale="fr"
        name="date"
        onChange={handleChange}
        showCalendarIcon
        showCalendarOnFocus
        showTimeZone
        showWeekNumbers
        value={date}
      />
    </div>
  )
}

Props

calendarIcon: string

Allow to change the calendar icon in the input field.

disabled: bool

Set to true to avoid changes of the input value.

format: string

Allow to set a custom format for parsing/formatting the date in the input field.
Formatting is based on Luxon (https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens).
The default value is D tt (localized date and time).

locale: string

Set the locale to use when displaying dates, month... (based on the Intl API).
The default value is navigator.language.

Example of different locales (fr-FR, ru, zh):

Calendar Calendar Calendar

max: string

Pass an ISO date string that is the maximal valid datetime.

Example with 2021-06-10T23:59:59.000-10:00:

Calendar

min: string

Pass an ISO date string that is the minimal valid datetime.

Example with 2021-06-10T00:00:00.000-10:00:

Calendar

renderDay: function

Pass a function or functional component to customize days rendering.

showCalendarIcon: bool

Set to true to display the calendar icon in the input field.

showCalendarOnFocus: bool

Set to true to open the calendar when the input receives the focus (by click or keyboard).

showTimeZone: bool

Set to true to display the current timezone in the calendar.

showWeekNumbers: bool

Set to true to display week numbers in the calendar.

value: string

Used to pass the date in the format defined with format.

Customization

renderDay: function

The example below shows how to disable selection of week-end days.

import {
  CalendarDay,
  DateTimeInput
} from '@jalik/react-datetime-picker';
import React, {
  useCallback,
  useState
} from 'react';

// Don't forget to load default styles.
import '@jalik/react-datetime-picker/src/styles.css';

// Custom component that renders week-end days in red.
function CustomDayCell(props) {
  const { dateTime, currentMonth, selectedDateTime } = props;
  const isWeekEnd = dateTime.weekday > 5;
  const style = isWeekEnd ? { color: 'red' } : {};
  // We use the default component for rendering day, so we have less code to write.
  // But we could use another component with a complete different logic.
  return <CalendarDay {...props} style={style} />;
}

function App() {
  const [date, setDate] = useState(new Date().toISOString());

  const handleChange = useCallback((event) => {
    setDate(event.target.value);
  }, [])

  return (
    <div>
      <DateTimeInput
        name="date"
        onChange={handleChange}
        renderDay={CustomDayCell}
        value={date}
      />
    </div>
  )
}

Changelog

History of releases is in the changelog.

License

The code is released under the MIT License.