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

abstract-datepicker

v0.1.3

Published

An abstract logic handler for rendering datepickers in any UI framework.

Downloads

10

Readme

Abstract Date Picker

An abstract logic handler for rendering datepickers in any UI framework.

⚠️ WARNING: This package is still in need of heavy testing before it is ready for production use. ⚠️

Installation

yarn add abstract-datepicker

Usage

The current intended use for this module is a business application that I work on which uses React for the front end. The below example describes how one would utilize this package in a React context.

import React from 'react';
import { createDatePicker } from 'abstract-datepicker';

import { Date, Button, Row, Week } from './styled';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.picker = createDatePicker({
      groupByWeek: true,
    });

    this.state = {
      monthName: '',
      month: [],
    };
  }

  componentDidMount() {
    this.unsubscribe = this.picker.subscribe(({ month, monthName, year }) => {
      this.setState({
        month,
        monthName,
        year,
      });
    });
  }

  componentWillUnmount() {
    this.unsubscribe();
  }

  incrementMonth = () => this.picker.incrementMonth();
  decrementMonth = () => this.picker.decrementMonth();

  render() {
    const { monthName, year, month } = this.state;

    return (
      <>
        <Row>
          <Button onClick={this.decrementMonth}>Prev Month</Button>
          <span>{monthName} {year}</span>
          <Button onClick={this.incrementMonth}>Next Month</Button>
        </Row>
        <div>
          {
            month.map((week, idx) => (
              <Week key={`${year}-${monthName}-week-${idx}`}>
                {
                  week.map((day) => (
                    <Date
                      key={day.iso}
                      selected={day.selected}
                    >
                      {day.date}
                    </Date>
                  ))
                }
              </Week>
            ))
          }
        </div>
      </>
    )
  }
}

API

createDatePicker

  • Type: (?DatePickerOptions) => DatePicker
  • Default: {}

TODO: Quality description

DatePickerOptions

  • Type: Object

Params:

| Name | Type | Description | --- | --- | --- | groupByWeek | boolean | When true, returns a 2D array where each top-level array represents a week beginning on Sunday in the month | initialDate | Date \| string | The initial date the datepicker should utilize. The initial month will be calculated based on initialDate. Default: new Date() | includeTrailers | boolean | Often the first week of a month begins at the end of a previous month (e.g. July 2019 started on a Monday, leaving a trailing Sunday from the previous month). By default, "trailers" are included in the month. | retainMonthsRadius | number | (NOT YET IMPLEMENTED/UNDER CONSIDERATION) For potential gains (needs benchmarking), calculated months can be retained based on a radius of months relative the currently selected month. That is, a radius of 2 with a selected month of July would hold on to a previously calculated May, June, August and September. | monthNameFormat | 'short' \| 'long' | (WILL LIKELY ABROGATE IN FAVOR OF A FORMATTER OR LEAVE UP TO THE CONSUMER)

DatePicker

  • Type: Object

Params:

| Name | Type | Description | --- | --- | --- | subscribe | (DatePickerState) => () => void | A function that will subscribe a callback to changes in the datepicker. The function returns a function that when called will unsubscribe the function from updates. | incrementMonth | () => void | Increment the current month forward | decrementMonth | () => void | Decrement the current month backward | resetMonth | () => void | Reset the current month to be inline with the currently selected date | setDate | (Date) => void | Set the selected date

DatePickerState

  • Type: Object

Params:

| Name | Type | Description | --- | --- | --- | month | Array<DatePickerDate> | An array of dates to be rendered by the renderer | selectedDate | Date | The current selected date | selectedMonth | Date | The current selected month (may not align with date)

DatePickerDate

  • Type: Object

Params:

| Name | Type | Description | --- | --- | --- | day | Date | The day of the week to which the date belongs | date | number | The day of the month | iso | string | An ISO-8601 formatted date-time string in UTC | obj | Date | A native JS Date object | selected | boolean | Whether the date is the currently selected date