# Button A styled clickable button. Use it for form submissions, navigation actions, or triggering HTMX requests. --- ## Quick example ```csharp new Button("Save changes", type: "submit") new Button("Cancel", variant: "outline") new Button("Delete", variant: "destructive") ``` --- ## All the options ```csharp public Button( string label, string variant = "default", string size = "default", string type = "button", string hxAttrs = "") ``` | Parameter | What it does | |---|---| | `label` | The button text. Can include raw HTML — useful for icons. | | `variant` | Visual style. See table below. | | `size` | How big the button is. See table below. | | `type` | HTML button type. Use `"submit"` for form submit buttons. Defaults to `"button"`. | | `hxAttrs` | Extra HTML attributes added verbatim — use this for HTMX, `disabled`, `data-*`, etc. | **Variants:** | Variant | Looks like | |---|---| | `default` | Filled with the primary colour — use for the main action on a page | | `destructive` | Red — use for irreversible actions like delete | | `outline` | Transparent with a border — use for secondary actions | | `secondary` | Muted fill — use for tertiary actions | | `ghost` | Invisible until hovered — use for toolbar buttons and icon actions | | `link` | Looks like a hyperlink with an underline on hover | **Sizes:** | Size | Dimensions | |---|---| | `sm` | Compact (36px tall) — good for dense UI | | `default` | Standard (40px tall) | | `lg` | Large (44px tall) — good for prominent CTAs | | `icon` | Square (40×40) — for icon-only buttons | --- ## Real-world examples ### Form submit button ```csharp new Button("Sign in", type: "submit") ``` ### Confirm and cancel in a dialog footer ```csharp var footer = """ {cancelButton} {deleteButton} """; // Pre-render each to HTML string and embed: string Render(IHtmxComponent c) { var w = new System.Buffers.ArrayBufferWriter(); c.Render(new HtmxRenderContext(w)); return System.Text.Encoding.UTF8.GetString(w.WrittenSpan); } new Card( content: "

Are you sure you want to delete this item?

", footer: Render(new Button("Cancel", variant: "outline")) + Render(new Button("Delete", variant: "destructive", type: "submit"))) ``` ### HTMX load more button ```csharp new Button( "Load more", variant: "outline", hxAttrs: """hx-get="/items?page=2" hx-target="#item-list" hx-swap="beforeend"""") ``` ### Icon-only ghost button (e.g. a refresh icon in a toolbar) ```csharp new Button( label: "", variant: "ghost", size: "icon") ``` ### Disabled state Button does not have a `disabled` parameter. Pass it through `hxAttrs`: ```csharp new Button("Processing...", hxAttrs: "disabled aria-disabled='true'") ``` --- ## How it works Button is a `