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-component-x

v1.1.1

Published

The package simplifies component inclusion for Alpine.js, enabling seamless integration of dynamic and interactive elements into web projects.

Downloads

53

Readme

AlpineJS ComponentX

The Alpine Components Package simplifies component inclusion for Alpine.js, enabling seamless integration of dynamic and interactive elements into web projects.

Install

With a CDN

<script defer src="https://unpkg.com/alpinejs-component-x@latest/dist/component.min.js"></script>
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

With a Package Manager

npm i alpinejs-component-x
// main.js
import Alpine from 'alpinejs'
import component from 'alpinejs-component-x'

Alpine.plugin(component)

Alpine.start()

Usage

The Alpine Components Package simplifies the process of including custom components in your project using either custom elements or directives.

Step 1: Setting up the Components Directory

First, create a directory called "components" (or any other preferred name) in your project's root directory. Inside this directory, create a file named "counter.html".

<!-- /components/counter.html -->
<div x-data="{ count: 0 }">
  <button x-on:click="count++">Increment</button>
  <span x-text="count"></span>
</div>

Step 3: Including the Counter Component

Now, in your initial HTML file (e.g., "index.html" or any other entry point), you can include the counter component using custom elements:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
</head>
<body>
  <!-- Include the Counter Component using the custom element <a-components-counter.html> -->
  <a-components-counter.html></a-components-counter.html>

  <!-- Notice: Use <a-components-counter.html> if you will include this component only once on the page. -->

  <!-- Other way to include if you need multiple components on the page, use <a-include url=""> syntax -->
  <a-include url="components/counter.html"></a-include>

  <!-- You can include other components here using the same syntax -->
  
  <script type="module" src="/main.js"></script>
</body>
</html>

Passing Data to a Component

With the Alpine ComponentX Package, you can easily pass data to your custom components. Let's explore how to do this using the custom element.

Step 1: Update the Counter Component (counter.html)

In "counter.html", modify the component to use the startvalue data as the initial count:

<!-- /components/counter.html -->
<div x-data="{ count: startvalue }">
  <button x-on:click="count++">Increment</button>
  <span x-text="count"></span>
</div>

Step 2: Including the Counter Component with Data

Now, you can include the "counter.html" component using the custom element and pass the startvalue data to it:

<!-- index.html -->

<!-- Include the Counter Component with the initial count value -->
<a-components-counter x-data="{ startvalue: 5 }"></a-components-counter>

<!-- Notice: Use <a-components-counter> if you will include this component only once on the page. -->

<!-- Other way to include if you need multiple components on the page, use <a-include url=""> syntax -->
<a-include url="components/counter.html" x-data="{ startvalue: 10 }"></a-include>

Notice:

  • Use <a-[component-path]> way if you plan to include this component only once on the page. This custom element will directly fetch and render the "counter.html" component.

  • If you need to include the same component multiple times or dynamically load components, use the syntax. This directive will fetch the specified component and include it in the designated area.

Contributing

I am welcome contributions to the Alpine ComponentX Package! Feel free to open issues or submit pull requests in our GitHub repository. Your support helps us enhance the package further.

Support

If you encounter any issues or have questions about using the Alpine ComponentX Package, please don't hesitate to contact us at [email protected].

License

This package is licensed under the MIT License. © 2023 Rakhat Bakytzhanov. All rights reserved.