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

alpine-day-picker

v0.1.0

Published

Alpine.js Day Picker component

Downloads

1

Readme

Day Picker - Alpine.js

[!WARNING]
This component is still work in progress, may not work properly in international contexts and present unsolved issues.

How to use this component

Import the component and register it using Alpine.data():

import Alpine from 'alpinejs';
import { DayPicker } from 'alpine-day-picker';

Alpine.data('DayPicker', DayPicker);

Alpine.start();

...and use it wherever you need it!

<div x-data="DayPicker($refs.dayInput)">
    <input type="date" x-model="value" x-ref="dayInput">
    
    <template x-for="day of daysOfTheWeek" :key="day.getTime()">
        <a href="#" role="button" x-on:click.prevent="value = day" x-bind:aria-disabled="!isDayAvailable(day)">
            <div>
                <span x-text="day.getDate()"></span>
                <span x-text="day.toLocaleString('en', { month: 'long' })"></span>
                <span x-text="day.getFullYear()"></span>
                <span x-text="day.toLocaleString('en', { weekday: 'long' })"></span>
            </div>
        </a>
    </template>
</div>

Choose your structure

The component lets you decide how to control and display the days of the week; right now it comes unstyled to freely adapt to every need.

So customize it as you prefer!

Adapts to your needs

DayPicker($refs.dayInput, {
    startingDayOfTheWeek: 1,
    excludedWeekdays: [ 0, ],
    holidays: [
        new Date(2024, 2, 8), // Add a fixed date
        '12-25', // Or flexible ones as strings...
        { month: 1, day: 1 }, // ...and objects!
    ],
})

Or you can use take advantage of some utility enums that may result useful:

// main.js
import Alpine from 'alpinejs';
import { DayPicker, Months, Weekdays } from 'alpine-day-picker';

Alpine.data('DayPicker', DayPicker);

window.Months = Months;
window.Weekdays = Weekdays;

Alpine.start();

// In your x-data
DayPicker($refs.dayInput, {
    startingDayOfTheWeek: Weekdays.MONDAY,
    excludedWeekdays: [ Weekdays.SUNDAY, ],
    holidays: [
        new Date(2024, 2, 8), // Add a fixed date
        '12-25', // Or flexible ones as strings...
        { month: Months.JANUARY, day: 1 }, // ...and objects!
    ],
})

How to ensure date is valid

When the date input has a min and/or a max, the component will let you limit the selection of these elements (if you desire) by considering them unavailable (like holidays or excluded weekdays).

[!CAUTION]
Right now, these fields are not dynamic, so you need to call the updateMinMax() method to refresh them.