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

@terrign/datepicker

v1.1.4

Published

Simple datepicker library for React.

Downloads

1

Readme

Datepicker

Simple datepicker library for React.

Install

npm i @terrign/datepicker or yarn add @terrign/datepicker

Description

Library provides absolutely standalone component, which can be used without any configuration:

  • <DatePicker />

And:

  • <DatePickerFrom />
  • <DatePickerTo />
  • <Range /> - provider to bound together <DatePickerFrom /> and <DatePickerTo />

All three components can be used together to create a date range picker without losing the customization flexibility and styling of each component separately.

Example

Storybook

Basic Usage


import { DatePicker } from '@terrign/datepicker';
import { useState } from 'react';

export function App() {
  const [selectedDate, setSelectedDate] = useState<string | null>(null);

  const dateSelectHandler = (date: string | null) => {
    setSelectedDate(date);
  };

  return (
    <>
      <p>Selected date: {selectedDate}</p>
      <form onSubmit={(e) => e.preventDefault()}>
        <label htmlFor='Date'>Date</label>
        <DatePicker id='Date' defaultSelectedDate={selectedDate} onDateSelect={dateSelectHandler} />
      </form>
    </>
  );
}

Usage With Range


import { Range, DatePickerFrom, DatePickerTo, DatePickerProps } from '@terrign/datepicker';
import { useState } from 'react';

const commonProps: DatePickerProps = {
  theme: 'light',
  weekStart: 'Monday',
  minDate: '2022-01-01',
  maxDate: '2024-01-01',
  customStyles: {
    bgColor: '#f1f1f1',
    hoverBgColor: '#7de9e3',
  },
  calendarConfig: {
    disableWeekends: true,
    holidays: ['2024-01-01', '2023-12-05'],
  },
};

export function App() {
  const [startDate, setStartDate] = useState<string | null>(null);
  const [endDate, setEndDate] = useState<string | null>(null);

  const startDateHandler = (date: string | null) => {
    setStartDate(date);
  };
  const endDateHandler = (date: string | null) => {
    setEndDate(date);
  };

  return (
    <>
      <p>Start date: {startDate}</p>
      <p>End date: {endDate}</p>
      /* Do not provide defaultSelectedDate in Datepicker itself, instead use defaultSelectionStart and defaultSelectionEnd Range props */
      <Range defaultSelectionStart={startDate} defaultSelectionEnd={endDate}>
        <form onSubmit={(e) => e.preventDefault()} style={{ display: 'flex' }}>
          <label>
            Start Date
            <DatePickerFrom  onDateSelect={startDateHandler} {...commonProps} />
          </label>

          <label>
            End Date <DatePickerTo onDateSelect={endDateHandler} {...commonProps} />
          </label>
        </form>
      </Range>
    </>
  );
}

Props

  • weekStart: 'Sunday' | 'Monday'

    First day of the week

  • theme: 'light | 'dark'

    Predefined color set

  • customStyles

    Object of custom styles. Overrides theme prop. Available options:

  • onDateSelect: (date: string | null) => void

    Callback to run on date selection in calendar or manual date input

  • defaultSelectedDate: string

    Default selected date in yyyy-mm-dd format

  • maxDate?: string

    Maximum date available for selection in yyyy-mm-dd format

  • minDate?: string

    Minimum date available for selection in yyyy-mm-dd format

  • calendarConfig

    • holidays?: string[]

      An array of dates in yyyy-mm-dd format, which should be marked as holidays

    • disableWeekends?: boolean

      Whether to disable weekends

    • contextMenuOptions?: { label: string, onClick: (date: string) => void }[] =>

      Adds options to context menu, onClick callback will be fired on option click,

    • enableTodos?: boolean

      Adds option to right-click context menu to add, see and remove todos. Saves todos in localStorage