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

@sz.frankyy/next-datepicker-range

v1.0.3

Published

Datepicker next component

Downloads

3

Readme

NextDataRangePicker Component

This is a straightforward date picker built in Next.js that enables the marking of date ranges. It features a prop, onChange, responsible for handling both the lower and upper limits of the selected range. For instance:

<NextDataRangePicker onChange={({ lower, upper }) => {
    setLowerDay(lower);
    setUpperDay(upper);
}} />

If you wish to exclude certain dates, pass a function as a prop to check whether the day should be disabled. Additionally, you can provide a strategy to determine what occurs when a disabled date is included in the selected range. If the strategy is set to remove, the disabled dates are simply removed from the selected range. In the case where the strategy is set to disallow, the onError function is called instead. It's important to note that when the disabledDates prop is passed, the onChange function manages an array of dates, for example:


 const disabledDates = (data: Dayjs): boolean => {
    return data.day() === 0 || data.day() === 3;
  }
  
  ...

 <NextDataRangePicker
      onChange={(days: Dayjs[])=>{
        setDays(days);
      
      }}
      disabledDates={disabledDates}
      strategy="remove" />

If you wish to translate the names of weekdays, simply provide the updated values to the daysOfWeek prop:

   <NextDataRangePicker
        onChange={({ lower, upper }: { lower?: Dayjs, upper?: Dayjs }) => {
          setLowerDay(lower);
          setUpperDay(upper);
        }
      }
      daysOfWeek={['Pon', 'Wt', 'Śr', 'Czw', 'Pią', 'Sob', 'Nie']}
      />

Additionally, when the upper bound of the range is selected, some actions can be performed. For example, the calendar can be closed:

<button className='material-button' onClick={()=>{ setCallendarOpened(value=>!value)}}>Open / Close callendar </button>

    { callendarOpened && <NextDataPickerRange
        onChange={({ lower, upper }: { lower?: Dayjs, upper?: Dayjs }) => {
          setLowerDay(lower);
          setUpperDay(upper?.clone());
        }
      }
      daysOfWeek={['Pon', 'Wt', 'Śr', 'Czw', 'Pią', 'Sob', 'Nie']}
      namesOfMonths={
          ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec',
          'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'
        ]}

        onSelection={()=>{ setCallendarOpened(false)}} 
      />
      }

If you need to translate the panel of the date picker, you can pass translation strings through the appropriate props:

      <NextDatePickerRange
        onChange={({ lower, upper }: { lower?: Dayjs, upper?: Dayjs }) => {
          setLowerDay(lower);
          setUpperDay(upper);
        }}
        daysOfWeek={['Pon', 'Wt', 'Śr', 'Czw', 'Pią', 'Sob', 'Nie']}
        namesOfMonths={[
          'Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec',
          'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'
        ]}
        
        toTheBeginning="Do początku"
        toTheEnd="Do końca"
        updateBeginning="Zmień początek"
        updateEnd="Zmień koniec"
        add="Dodaj"
        subtract="Odejmin"
      />

Some styles can be overridden by overwriting some css variables, for example:

  --primary-color-date-picker: rgba(161, 145, 255, 255);
  --sunday-color-date-picker: #ff0000;
  --begin-end-radius-datepicker: 10px; 
  --animations-speed-datepicker: 0.1s;

See page.module.css file.

To use the component, simply import it.