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

@uxf/datepicker

v11.45.0

Published

A set of React hooks to create an awesome datepicker.

Downloads

1,030

Readme

@uxf/datepicker

npm size quality license

A set of React hooks to create an awesome datepicker.

Quick start

Main logic component

export const DatePicker: FC = () => {
    // prepare state to handle selected date
    const [selectedDate, setSelectedDate] = useState<OnDateChangeType>(null);

    const {
        activeMonths,
        firstDayOfWeek,
    } = useDatePicker({
        selectedDate,
        minBookingDate: new Date(),
        onDateChange: setSelectedDate,
    });

    // you can use DatePickerContext that helps you avoid passing callbacks throught components
    return (
        <DatePickerContext.Provider value={{ addPropsHere }}>
              {activeMonths.map(month => (
                    <DateRangePickerMonth
                        firstDayOfWeek={firstDayOfWeek}
                        key={`${month.year}-${month.month}`}
                        month={month.month}
                        year={month.year}
                    />
              ))}
        </DatePickerContext.Provider>
    );
};

Month component

export const DateRangePickerMonth: FC<UseMonthProps> = ({
    firstDayOfWeek,
    month,
    year,
}) => {
    const { days, monthLabel } = useMonth({
        year,
        month,
        firstDayOfWeek,
    });

    return (
        <div>
            <p>{monthLabel}</p>
            <div style={{ display: "grid" }}>
                {days.map((day, index) => {
                    return <DateRangePickerDay date={day.date} key={day.dayLabel + index} day={day.dayLabel} />;
                })}
            </div>
        </div>
    );
};

Day component

export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date }) => {
    const dayRef = useRef(null);
    const {
        focusedDate,
        isDateFocused,
        isDateSelected,
        isDateHovered,
        isDateBlocked,
        onDateSelect,
        onDateFocus,
        onDateHover,
    } = useContext(DatePickerContext);

    const { disabledDate, isSelected, isWithinHoverRange, onClick, isToday } =
        useDay<HTMLDivElement>({
            date,
            dayRef,
            focusedDate,
            isDateFocused,
            isDateSelected,
            isDateHovered,
            isDateBlocked,
            onDateFocus,
            onDateSelect,
            onDateHover,
        });

    if (!day) {
        return <div />;
    }

    return (
        <button
            type="button"
            ref={dayRef}
            onClick={onClick}
            className= {clsx({
                "day__disabled": disabledDate,
                "day__selected": isSelected,
                "day__today": isToday,
            })}
        >
            {day}
        </button>
    );
};

API

useDatePicker()

UseDatePickerProps

| name | type | required | default | description | |---------------------|----------------------------------|----------|---------------|-------------| | firstDayOfWeek | FirstDayOfWeek | | 0 | | | initialVisibleMonth | Date | | | | | isDateBlocked | (date: Date) => boolean | | () => false | | | maxBookingDate | Date | | | | | minBookingDate | Date | | | | | numberOfMonths | number | | 1 | | | onDateChange | (data: OnDateChangeType): void | yes | | | | selectedDate | Date \| null | yes | | | | unavailableDates | Date[] | | [] | @deprecated | | datesConfig | DatesConfig[] | | [] | |

UseDatePickerReturnType

| name | type | description | |------------------------------|--------------------------------|-------------| | canGoToMonth | (month: Date) => boolean | | | canGoToNextMonth | boolean | | | canGoToNextYear | boolean | | | canGoToPrevMonth | boolean | | | canGoToPrevYear | boolean | | | canGoToYear | (month: Date) => boolean | | | goToDate | (date: Date) => void | | | goToNextMonths | () => void | | | goToNextMonthsByOneMonth | () => void | | | goToNextYear | () => void | | | goToPrevMonths | () => void | | | goToPrevMonthsByOneMonth | () => void | | | goToPrevYear | () => void | | | activeMonths | MonthType[] | | | firstDayOfWeek | FirstDayOfWeek | | | focusedDate | Date \| null | | | hoveredDate | Date \| null | | | isDateBlocked | (date: Date) => boolean | | | isDateFocused | (date: Date) => boolean | | | isDateHovered | (date: Date) => boolean | | | isDateSelected | (date: Date) => boolean | | | numberOfMonths | number | | | onDateFocus | (date: Date) => void | | | onDateHover | (date: Date \| null) => void | | | onDateSelect | (date: Date) => void | | | onResetDates | () => void | |

useDateRangePicker()

UseDateRangePickerProps

| name | type | required | default | description | |---------------------------|-----------------------------------|----------|---------------|-------------| | changeActiveMonthOnSelect | boolean | | false | | | endDate | Date \| null | yes | | | | exactMinBookingDays | boolean | | false | | | firstDayOfWeek | FirstDayOfWeek | | 0 | | | focusedInput | FocusedInput | yes | startDate | | | initialVisibleMonth | Date | | | | | isDateBlocked | (date: Date) => boolean | | () => false | | | maxBookingDate | Date | | | | | minBookingDate | Date | | | | | minBookingDates | number | | 1 | | | numberOfMonths | number | | 2 | | | onDatesChange | (data: OnDatesChangeType): void | yes | | | | startDate | Date \| null | yes | | | | unavailableDates | Date[] | | [] | @deprecated | | datesConfig | DatesConfig[] | | [] | |

UseDateRangePickerReturnType

| name | type | description | |------------------------------|--------------------------------|-------------| | canGoToMonth | (month: Date) => boolean | | | canGoToNextMonth | boolean | | | canGoToNextYear | boolean | | | canGoToPrevMonth | boolean | | | canGoToPrevYear | boolean | | | canGoToYear | (month: Date) => boolean | | | goToDate | (date: Date) => void | | | goToNextMonths | () => void | | | goToNextMonthsByOneMonth | () => void | | | goToNextYear | () => void | | | goToPrevMonths | () => void | | | goToPrevMonthsByOneMonth | () => void | | | goToPrevYear | () => void | | | activeMonths | MonthType[] | | | firstDayOfWeek | FirstDayOfWeek | | | focusedDate | Date \| null | | | hoveredDate | Date \| null | | | isDateBlocked | (date: Date) => boolean | | | isDateFocused | (date: Date) => boolean | | | isDateHovered | (date: Date) => boolean | | | isDateSelected | (date: Date) => boolean | | | isEndDate | (date: Date) => boolean | | | isStartDate | (date: Date) => boolean | | | numberOfMonths | number | | | onDateFocus | (date: Date) => void | | | onDateHover | (date: Date \| null) => void | | | onDateSelect | (date: Date) => void | | | onResetDates | () => void | |

useDecade()

UseDecadeProps

| name | type | required | default | description | |-------------------|--------------------------------------|----------|---------|-------------| | decadeLabelFormat | (start: Date, end: Date) => string | | | | | year | number | yes | | | | yearLabelFormat | 'date: Date) => string | | | |

UseDecadeReturnType

| name | type | description | |---------------|-------------------------------------------|-------------| | years | { yearLabel : string; date: Date }[] | | | decadeLabel | string | |

useYear()

UseYearProps

| name | type | required | default | description | |------------------|--------------------------|----------|---------|-------------| | year | number | yes | | | | yearLabelFormat | (date: Date) => string | | | | | monthLabelFormat | (date: Date) => string | | | |

UseYearReturnType

| name | type | description | |---------------|--------------------------------------------|-------------| | months | { monthLabel : string; date: Date }[] | | | yearLabel | string | |

useMonth()

UseMonthProps

| name | type | required | default | description | |--------------------|--------------------------|----------|---------|-------------| | year | number | yes | | | | month | number | yes | | | | firstDayOfWeek | FirstDayOfWeek | | 0 | | | dayLabelFormat | (date: Date) => string | | | | | weekdayLabelFormat | (date: Date) => string | | | | | monthLabelFormat | (date: Date) => string | | | |

UseMonthReturnType

| name | type | description | |---------------|--------------------------------------------------------------|-------------| | days | {currentMonth: boolean; dayLabel: string; date: Date })[] | | | monthLabel | string | | | weekdayLabels | string[] | |

useDay()

UseDayProps

| name | type | required | default | description | |------------------|---------------------------|----------|---------|-------------| | date | Date | yes | | | | dayRef | RefObject | | | | | focusedDate | Date \| null | yes | | | | isDateBlocked | (date: Date) => boolean | yes | | | | isDateFocused | (date: Date) => boolean | yes | | | | isDateHovered | (date: Date) => boolean | yes | | | | isDateSelected | (date: Date) => boolean | yes | | | | onDateFocus | (date: Date) => void | yes | | | | onDateHover | (date: Date) => void | yes | | | | onDateSelect | (date: Date) => void | yes | | | | unavailableDates | Date[] | | | @deprecated | | datesConfig | DatesConfig[] | | | |

UseDayReturnType

| name | type | description | |--------------------|------------------------------|-------------| | disabledDate | boolean | | | isFirstDisabled | boolean | | | isLastDisabled | boolean | | | disabledDate | boolean | | | isHovered | boolean | | | isSelected | boolean | | | isToday | boolean | | | isWithinHoverRange | boolean | | | onClick | () => void | | | onKeyDown | (e: KeyboardEvent) => void | | | onMouseEnter | () => void | | | tabIndex | number | | | flags | Flag[] | |

Known issues

  • keyboard navigation doesn't work for year and decade view
  • the demo needs a little more love!