UNPKG

@zeix/ui-element

Version:

UIElement - minimal reactive framework based on Web Components

267 lines (237 loc) 14.1 kB
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Introduction – UIElement Docs</title> <meta name="description" content="Overview and key benefits of UIElement" /> <base href="./index.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" class="active"> <span class="icon">📖</span> <strong>Introduction</strong> <small>Overview and key benefits of UIElement</small> </a> </li> <li> <a href="getting-started.html"> <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="introduction"> <a name="introduction" class="anchor" href="#introduction"> <span class="permalink">🔗</span> </a> 📖 Introduction </h1><p class="lead">Web development doesn't need to be complicated. UIElement offers a refreshingly simple approach to create reactive Web Components that enhance your existing HTML.</p> </section> <section> <h2 id="what-is-uielement"> <a name="what-is-uielement" class="anchor" href="#what-is-uielement"> <span class="permalink">🔗</span> </a> What is UIElement? </h2><p>UIElement is a lightweight TypeScript library (approximately 4kB gzipped) that brings signal-based reactivity to Web Components. It serves as a thin layer between standard web technologies and modern reactivity patterns, empowering you to:</p> <ul> <li>Transform ordinary HTML elements into reactive components</li> <li>Bind UI updates directly to state changes with minimal boilerplate</li> <li>Create reusable component patterns without complex abstractions</li> <li>Progressively enhance server-rendered content with client-side interactivity</li> </ul> <code-block collapsed 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"> { asInteger, component, first, on, RESET, setText } </span><span style="color:#F92672">from</span><span style="color:#E6DB74"> "@zeix/ui-element"</span><span style="color:#F8F8F2">;</span></span> <span class="line"></span> <span class="line"><span style="color:#A6E22E">component</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"show-appreciation"</span><span style="color:#F8F8F2">, {</span></span> <span class="line"><span style="color:#F8F8F2"> count: </span><span style="color:#A6E22E">asInteger</span><span style="color:#F8F8F2">(RESET) </span><span style="color:#88846F">// Get initial value from .count element</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 count display when state changes</span></span> <span class="line"><span style="color:#A6E22E"> first</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">".count"</span><span style="color:#F8F8F2">, </span><span style="color:#A6E22E">setText</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"count"</span><span style="color:#F8F8F2">)),</span></span> <span class="line"></span> <span class="line"><span style="color:#88846F"> // Handle click events to change state</span></span> <span class="line"><span style="color:#A6E22E"> first</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"button"</span><span style="color:#F8F8F2">, </span><span style="color:#A6E22E">on</span><span style="color:#F8F8F2">(</span><span style="color:#E6DB74">"click"</span><span style="color:#F8F8F2">, () </span><span style="color:#66D9EF;font-style:italic">=></span><span style="color:#F8F8F2"> { el.count</span><span style="color:#F92672">++</span><span style="color:#F8F8F2"> }))</span></span> <span class="line"><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>UIElement augments what the platform already provides. It leverages the Web Components standard while adding just enough convenience functions to make reactive UI behaviors easy to implement.</p> </section> <section> <h2 id="philosophy-amp-design-goals"> <a name="philosophy-amp-design-goals" class="anchor" href="#philosophy-amp-design-goals"> <span class="permalink">🔗</span> </a> Philosophy &amp; Design Goals </h2> <h3 id="html-first-approach"> <a name="html-first-approach" class="anchor" href="#html-first-approach"> <span class="permalink">🔗</span> </a> HTML-First Approach </h3><p>While many frameworks start with JavaScript and generate HTML, UIElement takes the opposite approach. It assumes you already have HTML (usually server-rendered) and want to enhance it with behavior:</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:#88846F">&#x3C;!-- Start with semantic HTML --></span></span> <span class="line"><span style="color:#F8F8F2">&#x3C;</span><span style="color:#F92672">show-appreciation</span><span style="color:#A6E22E"> aria-label</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"Show appreciation"</span><span style="color:#F8F8F2">></span></span> <span class="line"><span style="color:#F8F8F2"> &#x3C;</span><span style="color:#F92672">button</span><span style="color:#A6E22E"> type</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"button"</span><span style="color:#F8F8F2">></span></span> <span class="line"><span style="color:#F8F8F2"> &#x3C;</span><span style="color:#F92672">span</span><span style="color:#A6E22E"> class</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"emoji"</span><span style="color:#F8F8F2">>💐&#x3C;/</span><span style="color:#F92672">span</span><span style="color:#F8F8F2">></span></span> <span class="line"><span style="color:#F8F8F2"> &#x3C;</span><span style="color:#F92672">span</span><span style="color:#A6E22E"> class</span><span style="color:#F8F8F2">=</span><span style="color:#E6DB74">"count"</span><span style="color:#F8F8F2">>5&#x3C;/</span><span style="color:#F92672">span</span><span style="color:#F8F8F2">></span></span> <span class="line"><span style="color:#F8F8F2"> &#x3C;/</span><span style="color:#F92672">button</span><span style="color:#F8F8F2">></span></span> <span class="line"><span style="color:#F8F8F2">&#x3C;/</span><span style="color:#F92672">show-appreciation</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>This philosophy means:</p> <ul> <li>Better SEO and initial page load performance</li> <li>Progressive enhancement for resilient UIs</li> <li>Less client-side rendering overhead</li> <li>Simpler accessibility implementation</li> </ul> <h3 id="performance-by-design"> <a name="performance-by-design" class="anchor" href="#performance-by-design"> <span class="permalink">🔗</span> </a> Performance By Design </h3><p>UIElement avoids the overhead of virtual DOM diffing, instead using precise, targeted DOM updates through a fine-grained reactivity system:</p> <ul> <li>Efficient signal propagation that updates only what changed</li> <li>Batch processing and scheduling of updates to minimize browser reflows</li> <li>Minimal abstraction layers between your code and the browser</li> </ul> <h3 id="developer-experience-without-compromise"> <a name="developer-experience-without-compromise" class="anchor" href="#developer-experience-without-compromise"> <span class="permalink">🔗</span> </a> Developer Experience Without Compromise </h3><p>UIElement is designed to be intuitive and easy to use. It&#39;s built with type safety in mind, ensuring that your code is correct and that you don&#39;t miss any potential bugs.</p> <ul> <li><strong>Type Safety</strong>: Get early warnings when types don&#39;t match, improving code quality and reducing bugs.</li> <li><strong>Minimal Boilerplate</strong>: Write less code to achieve the same result.</li> <li><strong>Declarative Syntax</strong>: Define component behavior by composing small, reusable functions (attribute parsers and effects).</li> <li><strong>Customizable</strong>: UIElement is designed to be easily customizable and extensible. You can create your own custom attribute parsers and effects to suit your specific needs.</li> </ul> </section> <section> <h2 id="why-uielement"> <a name="why-uielement" class="anchor" href="#why-uielement"> <span class="permalink">🔗</span> </a> Why UIElement? </h2><p>While there are many excellent JavaScript frameworks out there, UIElement embraces web standards without proprietary extensions. It deliberately eschews abstractions like HTML-in-JS (client-side rendering) or JS-in-HTML (logic in framework-specific attributes) in favor of directness. While it does state management and view updates the hard way internally, it provides the benefits of declarative reactivity with only a few functions to compose complex behavior for developers.</p> <p>UIElement differentiates itself through:</p> <ul> <li><strong>Simplicity</strong>: Few, clear concepts (components, signals, element selectors, effects) allow developers to quickly build interactive components.</li> <li><strong>Performance</strong>: Fine-grained, direct DOM manipulation outperforms virtual DOM approaches with re-rendering.</li> <li><strong>Minimalism</strong>: As a thin layer over native web standards, it has no dependencies and minimal footprint with tree-shakable functions.</li> </ul> <p>UIElement shines when:</p> <ul> <li>You&#39;re working with server-rendered content that needs client-side enhancements</li> <li>Performance is critical, especially on lower-powered devices</li> <li>You want component reusability without framework lock-in</li> <li>You prefer working with future-proof standard web technologies</li> <li>You need to integrate with diverse tech stacks and existing codebases</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 you understand what UIElement is and its core philosophy, you&#39;re ready to:</p> <ul> <li>Move on to <a href="getting-started.html">Getting Started</a> to install the library and build your first component</li> <li>Learn more about <a href="building-components.html">Building Components</a> to create reusable UI patterns</li> <li>Explore <a href="data-flow.html">Data Flow</a> to understand how to manage component communication</li> </ul> </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>