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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-date-filter-lib

v1.1.1

Published

A lightweight, modern React date range filter component with quick presets (Today, Yesterday, Last 7 Days, This Month, 6 Months, This Year) and an optional custom date-range picker.

Downloads

336

Readme

React Date Filter Library (react-date-filter-lib)

A lightweight, modern React date range filter component with quick presets (Today, Yesterday, Last 7 Days, This Month, 6 Months, This Year) and an optional custom date-range picker.

Use it anywhere you need a clean date filter for dashboards, reports, admin panels, and analytics pages.


Features

  • Quick presets: Today, Yesterday, Last 7 Days, This Month, 6 Months, This Year, and Custom Date Range.
  • Custom date range picker: Two-month calendar view with range selection.
  • Nice UX & styles: Clean, modern UI with hover and focus states.
  • Simple callback API: Get selected dates in a ['YYYY-MM-DD', 'YYYY-MM-DD'] array.
  • Imperative API (via ref):
    • clear() – reset selection.
    • setDates([startDate, endDate]) – set dates programmatically.
  • Day.js based: Lightweight date handling using dayjs.

Installation

npm install react-date-filter-lib dayjs react-icons
# or
yarn add react-date-filter-lib dayjs react-icons

Make sure you already have react and react-dom installed (they are peer dependencies).


Basic Usage

import React, { useRef } from "react";
import DateFilter from "react-date-filter-lib";
// or: import { DateFilter } from 'react-date-filter-lib';

function App() {
  const filterRef = useRef(null);

  const handleChange = (dates) => {
    // dates is an array of strings: ['YYYY-MM-DD', 'YYYY-MM-DD']
    console.log("Selected range:", dates);
  };

  const clearFilter = () => {
    filterRef.current?.clear();
  };

  const setLast7Days = () => {
    const start = new Date();
    const end = new Date();
    start.setDate(start.getDate() - 7);
    filterRef.current?.setDates([start, end]);
  };

  return (
    <div>
      <DateFilter ref={filterRef} onChange={handleChange} />

      <button onClick={clearFilter}>Clear</button>
      <button onClick={setLast7Days}>Set Last 7 Days</button>
    </div>
  );
}

export default App;

Props

  • onChange?: (dates: string[]) => void
    Called whenever the user selects a range (either a preset or custom range).
    • dates is an array of two strings: ['YYYY-MM-DD', 'YYYY-MM-DD'].
    • For clear() it will receive an empty array [].

Imperative API (via ref)

You can call methods on the component using forwardRef:

const ref = useRef(null);

<DateFilter ref={ref} onChange={handleChange} />;

// Methods:
ref.current.clear(); // Clear selection and close dropdown
ref.current.setDates([start, end]); // Set range with two JS Date objects
  • clear()

    • Resets the selected date range.
    • Closes the dropdown.
    • Triggers onChange([]).
  • setDates(dates: [Date, Date])

    • Accepts two JavaScript Date objects.
    • Internally converted to dayjs and displayed.

Styling

This library ships with its own CSS via styles.css.

If you consume the package normally, the styles are bundled via Rollup + PostCSS and applied when you import the component.

If you need to override some styles, inspect the following main class names:

  • Container & button

    • .date-filter-container
    • .date-filter-button
    • .calendar-icon
  • Dropdown & quick ranges

    • .date-filter-dropdown
    • .quick-ranges-panel
    • .quick-range-item
  • Calendar

    • .custom-calendar
    • .calendar-months-container
    • .calendar-month
    • .calendar-day, .today, .disabled, .in-range, .range-start, .range-end

You can override these classes in your own CSS for custom branding.


When this library is helpful

  • Dashboards & analytics: Quickly filter charts and tables by fixed ranges (e.g. Last 7 Days) or custom ranges.
  • Admin panels: Filter user activity, orders, logs, etc.
  • Reports: Allow end-users to easily pick relevant date scopes.

Instead of re-building this date filter logic and styling every time, you can drop in DateFilter and focus on your data and logic.


Requirements

  • React: ^18 or ^19
  • React DOM: ^18 or ^19
  • Node / bundler: Any modern bundler that supports ES modules.

Author

Aryan Patel


License

ISC