{"slug":"getting-started","title":"Getting started","headings":["Install","Your first component","Props","JSX"],"contentHtml":"<h1 id=\"getting-started\">Getting started</h1><h2 id=\"install\">Install</h2><pre class=\"shiki github-dark\" style=\"background-color:#17171d;color:#e1e4e8\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#B392F0\">pnpm</span><span style=\"color:#9ECBFF\"> add</span><span style=\"color:#9ECBFF\"> ruri</span></span></code></pre><h2 id=\"your-first-component\">Your first component</h2><p>This sample is live - the button really works:</p><div class=\"playground\"><pre class=\"pg-code shiki github-dark\" style=\"background-color:#17171d;color:#e1e4e8\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#F97583\">import</span><span style=\"color:#E1E4E8\"> { tags, Signal } </span><span style=\"color:#F97583\">from</span><span style=\"color:#9ECBFF\"> \"ruri\"</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:#F97583\">const</span><span style=\"color:#E1E4E8\"> { </span><span style=\"color:#79B8FF\">div</span><span style=\"color:#E1E4E8\">, </span><span style=\"color:#79B8FF\">button</span><span style=\"color:#E1E4E8\">, </span><span style=\"color:#79B8FF\">ul</span><span style=\"color:#E1E4E8\">, </span><span style=\"color:#79B8FF\">li</span><span style=\"color:#E1E4E8\"> } </span><span style=\"color:#F97583\">=</span><span style=\"color:#E1E4E8\"> tags</span></span>\n<span class=\"line\"><span style=\"color:#F97583\">const</span><span style=\"color:#79B8FF\"> count</span><span style=\"color:#F97583\"> =</span><span style=\"color:#F97583\"> new</span><span style=\"color:#B392F0\"> Signal</span><span style=\"color:#E1E4E8\">(</span><span style=\"color:#79B8FF\">0</span><span style=\"color:#E1E4E8\">)</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:#F97583\">const</span><span style=\"color:#79B8FF\"> app</span><span style=\"color:#F97583\"> =</span><span style=\"color:#B392F0\"> div</span><span style=\"color:#E1E4E8\">({},</span></span>\n<span class=\"line\"><span style=\"color:#B392F0\">    ul</span><span style=\"color:#E1E4E8\">({}, </span><span style=\"color:#B392F0\">li</span><span style=\"color:#E1E4E8\">({}, </span><span style=\"color:#9ECBFF\">\"count: \"</span><span style=\"color:#E1E4E8\">, count)),</span></span>\n<span class=\"line\"><span style=\"color:#B392F0\">    button</span><span style=\"color:#E1E4E8\">({ </span><span style=\"color:#B392F0\">onclick</span><span style=\"color:#E1E4E8\">: () </span><span style=\"color:#F97583\">=></span><span style=\"color:#E1E4E8\"> count.value</span><span style=\"color:#F97583\">++</span><span style=\"color:#E1E4E8\"> }, </span><span style=\"color:#9ECBFF\">\"+1\"</span><span style=\"color:#E1E4E8\">),</span></span>\n<span class=\"line\"><span style=\"color:#E1E4E8\">)</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:#E1E4E8\">output.</span><span style=\"color:#B392F0\">append</span><span style=\"color:#E1E4E8\">(app)</span></span></code></pre><div class=\"pg-view\" id=\"pg-view-1\"><span class=\"pg-hint\">running...</span></div></div><p>Playground blocks are fenced with ``<code>ruri</code>: the docs client rewrites the import to the bundled framework and runs the code against an <code>output</code> element rendered below the listing.</p><ul><li><code>tags</code> is a typed proxy for every HTML, SVG and MathML element</li><li>props are plain objects; <code>onclick</code> becomes an event listener</li><li>signals passed as children become self-updating text nodes</li></ul><h2 id=\"props\">Props</h2><table><thead><tr><th>prop</th><th>behaviour</th></tr></thead><tbody><tr><td><code>class: [&quot;a&quot;, &quot;b&quot;]</code></td><td>arrays are joined</td></tr><tr><td><code>checked: false</code></td><td>boolean attributes follow the HTML syntax</td></tr><tr><td><code>style: { color: &quot;red&quot; }</code></td><td>objects are assigned to the style declaration</td></tr><tr><td><code>value: someSignal</code></td><td>reactive attributes update on change</td></tr><tr><td><code>id: null</code></td><td>removes the attribute</td></tr></tbody></table><h2 id=\"jsx\">JSX</h2><pre class=\"shiki github-dark\" style=\"background-color:#17171d;color:#e1e4e8\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#E1E4E8\">{ </span><span style=\"color:#79B8FF\">\"compilerOptions\"</span><span style=\"color:#E1E4E8\">: { </span><span style=\"color:#79B8FF\">\"jsx\"</span><span style=\"color:#E1E4E8\">: </span><span style=\"color:#9ECBFF\">\"react-jsx\"</span><span style=\"color:#E1E4E8\">, </span><span style=\"color:#79B8FF\">\"jsxImportSource\"</span><span style=\"color:#E1E4E8\">: </span><span style=\"color:#9ECBFF\">\"ruri\"</span><span style=\"color:#E1E4E8\"> } }</span></span></code></pre><pre class=\"language-jsx\">import { render, Signal } from &quot;ruri&quot;\n\nconst count = new Signal(0)\nrender(document.body, &lt;button onclick={() =&gt; count.value++}&gt;{count}&lt;/button&gt;)</pre>"}