oneuiCookbook
oneui cookbook
HTML components
Build a reactive HTML component with C# stateBuild a reactive HTML component with C# state in OneUI. Compile a counter template, click its button in memory, and see the rendered text update.Pass parameters to a child HTML component in C#Pass a typed parameter from a parent template to a child HTML component with OneUI. See the child update when its parent’s C# state changes.Conditionally render HTML in a C# component templateConditionally render HTML in a C# component template with OneUI. Use if and else branches to switch between saved and unsaved messages.Render a list in a C# HTML component templateRender a C# collection as repeated HTML in a OneUI component. Use a keyed template to render list items and keep their identity when reordered.Two-way bind an HTML input to C# stateTwo-way bind an HTML input to C# state with OneUI’s bind:value. See user edits update the property and a C# assignment update the field.
Recipes
Scope CSS to an HTML component in C#Put a CSS file next to a OneUI HTML template to keep selectors local. Run a C# example that checks the rule against two elements with the same class.Focus an input after a C# component updatesSet keyboard focus when a OneUI update adds a search input. Bind an ElementRef in HTML and call Focus from the C# component’s OnMounted callback.Render inline SVG in a C# UI componentPut an SVG shape in a OneUI HTML template, bind its fill to C# state, and run a console example that checks the SVG namespace and updated fill.Build a C# UI component without HTMLBuild a OneUI button and update its label in pure C#. The example uses Component, Scope and SetState without an HTML template or generated bindings.Pass HTML into named component slots in C#Define a named slot with fallback HTML in OneUI. Fill it from a parent template, leave it empty in another instance, and update the parent’s bound title.