UIElement Docs Version 0.9.4

πŸš€ Getting Started

Set up UIElement in minutes – no build tools required. Whether you’re enhancing server-rendered HTML with lightweight interactivity or integrating Web Components into a modern JavaScript project, UIElement makes it simple to get started.

How to Install UIElement

UIElement works without build tools but also supports NPM and module bundlers for larger projects. Choose the option that best fits your needs.

Using a CDN

For the easiest setup, include UIElement via a CDN. This is ideal for testing or quick projects where you want lightweight interactivity without additional tooling.

html

<script src="https://cdn.jsdelivr.net/npm/@zeix/ui-element@latest/index.js"></script>

Or use <script type="module"> to import UIElement in your HTML:

html

<script type="module">
import { UIElement } from 'https://cdn.jsdelivr.net/npm/@zeix/ui-element@latest/index.js'

// Your code here
</script>

Self-Hosting UIElement

For production use, you may want to self-host UIElement to avoid relying on a CDN. You can download the latest version from:

Github Repository

Simply host the file on your server and include it like this:

html

<script src="/path/to/your/hosted/ui-element.js"></script>

Why self-host?

Remember to keep the hosted file updated to use the latest features and bug fixes.

Installing via NPM

If you’re using a bundler like Vite, Webpack, or Rollup, install UIElement via NPM:

bash

npm install @zeix/ui-element

Then import UIElement in your JavaScript:

js

import { UIElement } from '@zeix/ui-element'

Creating Your First Component

Now, let’s create an interactive Web Component to verify your setup.

What This Component Does

Markup

Include the following in your server-rendered HTML:

html

<hello-world>
	<label>Your name<br>
		<input type="text">
	</label>
	<p>Hello, <span>World</span>!</p>
</hello-world>

Component Definition

Save the following inside a <script type="module"> tag or an external JavaScript file.

html

<script type="module">
	import { UIElement, setText } from 'https://cdn.jsdelivr.net/npm/@zeix/ui-element@latest/index.js'

	class HelloWorld extends UIElement {
		connectedCallback() {

			// Update content dynamically based on the 'name' signal
			this.first('span').sync(setText('name'))

			// Handle user input to change the 'name'
			this.first('input').on('input', e => this.set('name', e.target.value || undefined))
		}
	}
	HelloWorld.define('hello-world');
</script>

What Happens Here?

Verifying Your Installation

If everything is set up correctly, you should see:

If it’s not working:

Next Steps

Now that UIElement is installed, explore the Core Concepts to learn about:

Or jump straight into the Detailed Walkthrough to get hands-on.