@zeix/ui-element
Version:
UIElement - minimal reactive framework based on Web Components
385 lines (334 loc) β’ 18.8 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Getting Started β UIElement Docs</title>
<meta name="description" content="Installation, setup, and first steps" />
<base href="./getting-started.html" />
<link rel="stylesheet" href="assets/main.css" />
<script type="module" src="assets/main.js"></script>
</head>
<body>
<header class="content-grid">
<h1 class="content">
UIElement Docs <small>Version 0.12.2</small>
</h1>
<nav class="breakout">
<ol>
<li>
<a href="index.html">
<span class="icon">π</span>
<strong>Introduction</strong>
<small>Overview and key benefits of UIElement</small>
</a>
</li>
<li>
<a href="getting-started.html" class="active">
<span class="icon">π</span>
<strong>Getting Started</strong>
<small>Installation, setup, and first steps</small>
</a>
</li>
<li>
<a href="building-components.html">
<span class="icon">ποΈ</span>
<strong>Building Components</strong>
<small>Anatomy, lifecycle, signals, effects</small>
</a>
</li>
<li>
<a href="styling-components.html">
<span class="icon">π¨</span>
<strong>Styling Components</strong>
<small>Scoped styles, CSS custom properties</small>
</a>
</li>
<li>
<a href="data-flow.html">
<span class="icon">π</span>
<strong>Data Flow</strong>
<small>Passing state, events, context</small>
</a>
</li>
<li>
<a href="patterns-techniques.html">
<span class="icon">π‘</span>
<strong>Patterns & Techniques</strong>
<small>Composition, scheduling, best practices</small>
</a>
</li>
<li>
<a href="examples-recipes.html">
<span class="icon">π½οΈ</span>
<strong>Examples & Recipes</strong>
<small>Common use cases and demos</small>
</a>
</li>
<li>
<a href="api-reference.html">
<span class="icon">π</span>
<strong>API Reference</strong>
<small>Detailed documentation of classes and functions</small>
</a>
</li>
<li>
<a href="about-community.html">
<span class="icon">π€</span>
<strong>About & Community</strong>
<small>License, versioning, getting involved</small>
</a>
</li>
</ol>
</nav>
</header>
<main><section class="hero">
<h1 id="getting-started">
<a name="getting-started" class="anchor" href="#getting-started">
<span class="permalink">π</span>
</a>
π Getting Started
</h1><p class="lead"><strong>Set up UIElement in minutes β no build tools required</strong>. 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.</p>
</section>
<section>
<h2 id="how-to-install-uielement">
<a name="how-to-install-uielement" class="anchor" href="#how-to-install-uielement">
<span class="permalink">π</span>
</a>
How to Install UIElement
</h2><p>UIElement works <strong>without build tools</strong> but also supports <strong>NPM and module bundlers</strong> for larger projects. Choose the option that best fits your needs.</p>
<h3 id="using-a-cdn">
<a name="using-a-cdn" class="anchor" href="#using-a-cdn">
<span class="permalink">π</span>
</a>
Using a CDN
</h3><p>For the easiest setup, include <strong>UIElement</strong> via a CDN. This is ideal for <strong>testing or quick projects</strong> where you want lightweight interactivity without additional tooling.</p>
<code-block language="html" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">html</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#F8F8F2"><</span><span style="color:#F92672">script</span><span style="color:#A6E22E"> src</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"https://cdn.jsdelivr.net/npm/@zeix/ui-element@latest/index.js"</span><span style="color:#F8F8F2">></</span><span style="color:#F92672">script</span><span style="color:#F8F8F2">></span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
</section>
<section>
<h3 id="self-hosting-uielement">
<a name="self-hosting-uielement" class="anchor" href="#self-hosting-uielement">
<span class="permalink">π</span>
</a>
Self-Hosting UIElement
</h3><p>For production use, you may want to <strong>self-host UIElement</strong> to avoid relying on a CDN. You can download the latest version from:</p>
<p><a href="https://github.com/zeixcom/ui-element/blob/main/index.js" target="_blank">Github Repository</a></p>
<p>Simply host the file on your server and include it like this:</p>
<code-block language="html" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">html</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#F8F8F2"><</span><span style="color:#F92672">script</span><span style="color:#A6E22E"> src</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"/path/to/your/hosted/ui-element.js"</span><span style="color:#F8F8F2">></</span><span style="color:#F92672">script</span><span style="color:#F8F8F2">></span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
<p><strong>Why self-host?</strong></p>
<ul>
<li>You <strong>control updates</strong> and avoid breaking changes from external CDNs.</li>
<li>Works for <strong>projects with stricter Content Security Policy rules</strong>.</li>
</ul>
<p>Remember to keep the hosted file updated to use the latest features and bug fixes.</p>
</section>
<section>
<h3 id="installing-via-package-managers">
<a name="installing-via-package-managers" class="anchor" href="#installing-via-package-managers">
<span class="permalink">π</span>
</a>
Installing via Package Managers
</h3><p>If youβre using a <strong>bundler</strong> like <strong>Vite, Webpack, or Rollup</strong>, install UIElement via NPM or Bun:</p>
<tab-group>
<div role="tablist">
<button role="tab" id="trigger_installation-npm" aria-controls="panel_installation-npm" aria-selected="true" tabindex="0">NPM</button>
<button role="tab" id="trigger_installation-bun" aria-controls="panel_installation-bun" aria-selected="false" tabindex="-1">Bun</button>
</div>
<div role="tabpanel" id="panel_installation-npm" aria-labelledby="trigger_installation-npm">
<code-block language="bash" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">bash</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#A6E22E">npm</span><span style="color:#E6DB74"> install</span><span style="color:#E6DB74"> @zeix/ui-element</span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
</div>
<div role="tabpanel" id="panel_installation-bun" aria-labelledby="trigger_installation-bun">
<code-block language="bash" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">bash</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#A6E22E">bun</span><span style="color:#E6DB74"> add</span><span style="color:#E6DB74"> @zeix/ui-element</span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
</div>
</tab-group>
<p>Then import the needed functions in your JavaScript:</p>
<code-block language="js" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">js</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#F92672">import</span><span style="color:#F8F8F2"> { asString, component, first, on, RESET, setText } </span><span style="color:#F92672">from</span><span style="color:#E6DB74"> '@zeix/ui-element'</span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
</section>
<section>
<h2 id="creating-your-first-component">
<a name="creating-your-first-component" class="anchor" href="#creating-your-first-component">
<span class="permalink">π</span>
</a>
Creating Your First Component
</h2><p>Now, let's create an interactive Web Component to verify your setup.</p>
<p><strong>What This Component Does</strong></p>
<ul>
<li>Displays <strong>βHello, World!β</strong> by default.</li>
<li>Updates dynamically when you <strong>type into the input field</strong>.</li>
</ul>
<h3 id="markup">
<a name="markup" class="anchor" href="#markup">
<span class="permalink">π</span>
</a>
Markup
</h3><p>Include the following in your server-rendered HTML:</p>
<code-block language="html" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">html</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#F8F8F2"><</span><span style="color:#F92672">hello-world</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F8F8F2"> <</span><span style="color:#F92672">label</span><span style="color:#F8F8F2">>Your name<</span><span style="color:#F92672">br</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F8F8F2"> <</span><span style="color:#F92672">input</span><span style="color:#A6E22E"> type</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"text"</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F8F8F2"> </</span><span style="color:#F92672">label</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F8F8F2"> <</span><span style="color:#F92672">p</span><span style="color:#F8F8F2">>Hello, <</span><span style="color:#F92672">span</span><span style="color:#F8F8F2">>World</</span><span style="color:#F92672">span</span><span style="color:#F8F8F2">>!</</span><span style="color:#F92672">p</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F8F8F2"></</span><span style="color:#F92672">hello-world</span><span style="color:#F8F8F2">></span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
</code-block>
<h3 id="component-definition">
<a name="component-definition" class="anchor" href="#component-definition">
<span class="permalink">π</span>
</a>
Component Definition
</h3><p>Save the following inside a <code><script type="module"></code> tag or an external JavaScript file.</p>
<code-block collapsed language="html" copy-success="Copied!" copy-error="Error trying to copy to clipboard!">
<p class="meta">
<span class="language">html</span>
</p>
<pre class="shiki monokai" style="background-color:#272822;color:#F8F8F2" tabindex="0"><code><span class="line"><span style="color:#F8F8F2"><</span><span style="color:#F92672">script</span><span style="color:#A6E22E"> type</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"module"</span><span style="color:#F8F8F2">></span></span>
<span class="line"><span style="color:#F92672"> import</span><span style="color:#F8F8F2"> { asString, component, first, on, RESET, setText } </span><span style="color:#F92672">from</span><span style="color:#E6DB74"> "https://cdn.jsdelivr.net/npm/@zeix/ui-element@latest/index.js"</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6E22E"> component</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"hello-world"</span><span style="color:#F8F8F2">, {</span></span>
<span class="line"><span style="color:#88846F"> // Parse "name" attribute, falling back to server-rendered content</span></span>
<span class="line"><span style="color:#F8F8F2"> name: </span><span style="color:#A6E22E">asString</span><span style="color:#F8F8F2">(RESET)</span></span>
<span class="line"><span style="color:#F8F8F2"> }, </span><span style="color:#FD971F;font-style:italic">el</span><span style="color:#66D9EF;font-style:italic"> =></span><span style="color:#F8F8F2"> [</span></span>
<span class="line"></span>
<span class="line"><span style="color:#88846F"> // Update content dynamically based on the "name" signal</span></span>
<span class="line"><span style="color:#A6E22E"> first</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"span"</span><span style="color:#F8F8F2">, </span><span style="color:#A6E22E">setText</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"name"</span><span style="color:#F8F8F2">)),</span></span>
<span class="line"></span>
<span class="line"><span style="color:#88846F"> // Handle user input to change the "name"</span></span>
<span class="line"><span style="color:#A6E22E"> first</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"input"</span><span style="color:#F8F8F2">, </span><span style="color:#A6E22E">on</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"input"</span><span style="color:#F8F8F2">, </span><span style="color:#FD971F;font-style:italic">e</span><span style="color:#66D9EF;font-style:italic"> =></span><span style="color:#F8F8F2"> {</span></span>
<span class="line"><span style="color:#F8F8F2"> el.name </span><span style="color:#F92672">=</span><span style="color:#F8F8F2"> e.target.value </span><span style="color:#F92672">||</span><span style="color:#F8F8F2"> RESET</span></span>
<span class="line"><span style="color:#F8F8F2"> }))</span></span>
<span class="line"><span style="color:#F8F8F2"> ])</span></span>
<span class="line"><span style="color:#F8F8F2"></</span><span style="color:#F92672">script</span><span style="color:#F8F8F2">></span></span>
<span class="line"></span></code></pre>
<input-button class="copy">
<button type="button" class="secondary small">
<span class="label">Copy</span>
</button>
</input-button>
<button type="button" class="overlay">Expand</button>
</code-block>
<p><strong>What Happens Here?</strong></p>
<ul>
<li>The <code>asString(RESET)</code> signal <strong>parses the "name" attribute</strong>, falling back to server-rendered value (constant <code>RESET</code>).</li>
<li>The <code>setText('name')</code> effect <strong>syncs the state</strong> with the <code><span></code>.</li>
<li>The <code>on('input')</code> event <strong>updates the state</strong> whenever you type in the first <code><input></code> field, falling back to server-rendered value if empty.</li>
<li>The Web Component <strong>hydrates automatically</strong> when inserted into the page.</li>
</ul>
</section>
<section>
<h2 id="verifying-your-installation">
<a name="verifying-your-installation" class="anchor" href="#verifying-your-installation">
<span class="permalink">π</span>
</a>
Verifying Your Installation
</h2><p>If everything is set up correctly, you should see:</p>
<ul>
<li>A text input field</li>
<li>A greeting (Hello, World!)</li>
<li>The greeting updates as you type</li>
</ul>
<component-demo>
<div class="preview">
<hello-world>
<template shadowrootmode="open">
<label>Your name<br>
<input type="text">
</label>
<p>Hello, <span>World</span>!</p>
</template>
</hello-world>
</div>
</component-demo>
<p>If it's not working:</p>
<ul>
<li>Check the browser console for errors (missing imports, typos).</li>
<li>Ensure your <code><script></code> tag is set to <code>type="module"</code> when using ES modules.</li>
<li>If using NPM, confirm UIElement is installed inside <code>node_modules/@zeix/ui-element</code>.</li>
</ul>
</section>
<section>
<h2 id="next-steps">
<a name="next-steps" class="anchor" href="#next-steps">
<span class="permalink">π</span>
</a>
Next Steps
</h2><p>Now that UIElement is installed, explore the core concepts for <a href="building-components.html">Building Components</a>:</p>
<ul>
<li>β
<strong>Component anatomy and lifecycle</strong> (using Web Components)</li>
<li>β
<strong>Accessing sub-elements</strong> (select children)</li>
<li>β
<strong>Signals & effects</strong> (state-driven DOM updates)</li>
<li>β
<strong>Event listeners</strong> (react to user interaction)</li>
</ul>
<p>Or jump straight to <a href="styling-components.html">Styling Components</a> for CSS best practices.</p>
</section>
</main>
<footer class="content-grid">
<div class="content">
<h2 class="visually-hidden">Footer</h2>
<p>Β© 2024 β 2025 Zeix AG</p>
</div>
</footer>
</body>
</html>