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

alpinejs-breakpoints

v2.1.1

Published

Alpine v3.x breakpoints plugin

Downloads

2,026

Readme

Alpine Breakpoints Plugin

A Alpine.js plugin and magic method that helps components respond to 📱 💻 🖥 breakpoint changes.

Installation

CDN

You can include the CDN build of this plugin as a <script> tag, just make sure to include it before Alpinejs file.

  <script defer src="https://unpkg.com/alpinejs-breakpoints"></script>
  <script defer src="https://unpkg.com/alpinejs"></script>

NPM

You can install Intersect from NPM for use inside your bundle like so:

  npm install alpinejs-breakpoints

Then initialize it from your bundle:

import Alpine from 'alpinejs'
import breakpoint from 'alpinejs-breakpoints'
 
Alpine.plugin(breakpoint)
Alpine.start()

Usage

First define the breakpoints for all screen sizes you want, as in the example below:

:root { --breakpoint: 'unset';}
@media screen and (min-width: 567px) {
  :root { --breakpoint: 'sm'; }
}
@media screen and (min-width: 900px) {
  :root { --breakpoint: 'md'; }
}
@media screen and (min-width: 1200px) {
  :root { --breakpoint: 'lg'; }
}
@media screen and (min-width: 1600px) {
  :root { --breakpoint: '2xl'; }
}

An example of markup for a component that reacts to screen size changes.

<div
  x-data="{ text: null }"
  x-text="text"
  x-breakpoint="
    if($isBreakpoint('lg+')) text = 'Large screen and above'
    if($isBreakpoint('md-')) text = 'Medium screen and below'
  ">
</div>

How it works

The plugin monitors changes to the --breakpoint variable through x-effect, with each change using the $isBreakpoint() magic method, you can check the current breakpoint and call the desired behavior.

$isBreakpoint() method takes a breakpoint string from your css and optional + or - modifier.

Example:

  $isBreakpoint('xl')  <!-- will work only on [xl] screen -->
  $isBreakpoint('lg+') <!-- will work on [lg xl 2xl] (lg and above) screens -->   
  $isBreakpoint('md-') <!-- will work on [md sm unset] (md and below) screens -->

Customization

  // The default breakpoints array:
  // ['unset', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl']
  // 
  // You can change default breakpoints array: 
  window.AlpineBreakpointPluginBreakpointsList = ['mobile', 'tablet', 'desktop']