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

@cesarfernandoig/alpine-responsive-plugin

v1.0.0

Published

A lightweight Alpine.js plugin that simplifies managing conditional attributes in responsive designs.

Readme

Alpine.js Responsive Plugin

Supercharge your Alpine.js apps with responsive superpowers! 🚀

A lightweight Alpine.js plugin that simplifies managing responsive behaviors and conditional attributes. This plugin provides utilities to manage media query states and apply conditional attributes or values based on screen size.

🌟 Features

  • 📱 Media Query State Management: Instantly know if your user is on mobile or desktop.
  • ✨ Magic Helpers: Use media and getMobileValue to make your components smarter.
  • 🎨 Custom Directive: Dynamically add or remove attributes with x-mobileattributes.

🛠️ Installation

Getting started with Responsive is a breeze! With just a few lines of code, you'll unlock the power of responsive design in your Alpine.js projects.

Via NPM

  1. Install the plugin with npm:
npm install @cesarfernandoig/alpine-responsive-plugin
  1. Import and initialize the plugin in your project:
import Alpine from 'alpinejs';
import responsive from '@cesarfernandoig/alpine-responsive-plugin';

Alpine.plugin(responsive);
Alpine.start();

Via CDN

If you prefer using a CDN, simply include the following script tag in your HTML file, make sure to include it BEFORE Alpine's core JS file:

<!-- Alpine Plugins -->
<script defer src="https://cdn.jsdelivr.net/npm/@cesarfernandoig/[email protected]/dist/responsive.min.js"></script>

<!-- Alpine Core -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>

🎮 Usage

Now that the plugin is set up, let’s explore the magic! You can use the features provided by Responsive to make your site smarter and more responsive.

🪄 Magic: $media

The media magic helper gives you access to isMobile and isDesktop properties. You can use these properties anywhere in your Alpine.js components to apply logic based on screen size.

Example:

<div x-data>
  <span x-text="$media.isMobile ? '📱 On Mobile!' : '🖥️ On Desktop!'"></span>
</div>
  • $media.isMobile is true if the screen width is less than 768px.
  • $media.isDesktop is true if the screen width is 768px or greater.

🪄 Magic: $getMobileValue

The $getMobileValue magic helper is your go-to for conditional values. It’s like having a chameleon that adapts to the device type! 🦎

Example:

<div x-data>
  <span x-text="$getMobileValue('This is for mobile 🐳', 'This is for desktop 🦖')"></span>
</div>
  • If the device is mobile, it returns 'This is for mobile 🐳'.
  • If the device is desktop, it returns 'This is for desktop 🦖'.

🖌️ Directive: x-mobileattributes

Want to conditionally add/remove attributes based on screen size? Look no further than the x-mobileattributes directive! You can pass in a set of attributes and their values for mobile and desktop resolutions, and Responsive will handle the rest.

Example:

<button
	type="button"
	x-mobileattributes="{
        title: ['Snake', 'Turtle'],
        'x-text': ['`🐍`', '`🐢`'],
        class: 'snake-class'
    }"
	>
</button>
  • Mobile: Sets the title to "Snake", x-text to "🐍", and applies the snake-class.
  • Desktop: Sets the title to "Turtle", x-text to "🐢", and removes the class attribute (since it doesn't have a desktop value — similar to writing class: ['snake-class', null]).

💡 Pro Tip:

By combining Responsive with Alpine’s built-in directives like x-show, x-if, or x-transition, you can create rich and highly dynamic UI elements tailored for different screen sizes.

🧑‍💻 API Reference

🪄 Magics

  • $media: Returns a reactive object with isMobile and isDesktop properties.
$media.isMobile; // true if mobile
$media.isDesktop; // true if desktop
  • $getMobileValue(mobileValue, desktopValue): Returns mobileValue if the device is mobile, otherwise returns desktopValue.
getMobileValue('📱 Mobile', '🖥️ Desktop'); // '📱 Mobile' or '🖥️ Desktop'

🖌️ Directives

  • x-mobileattributes: Applies or removes attributes conditionally.
<div x-mobileattributes="{ 'attribute': [mobileValue, desktopValue] }"></div>

🤝 Contributing

We 💖 contributions! If you have an idea, found a bug, or just want to improve the plugin, feel free to jump in!

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

🙏 Acknowledgments

A huge shoutout to Alpine.js for making JavaScript fun and simple!

🚀 Ready to Go Responsive?

With this plugin, handling responsiveness in your Alpine.js apps has never been easier. Install it today and start building smarter, more dynamic interfaces! 🎉