Button
Trigger actions and submit forms with explicit text, icon, color, variant, size, and pending content.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let basicButton =
fveButton {
_dataIndicator "_basic_sync_pending"
_dataOn ("click", "@get('/components/button/settled', {filterSignals: {exclude: /.*/}, retry: 'never'})")
"Sync"
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add button --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/button.js';The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let basicButton =
fveButton {
_dataIndicator "_basic_sync_pending"
_dataOn ("click", "@get('/components/button/settled', {filterSignals: {exclude: /.*/}, retry: 'never'})")
"Sync"
}Sizes
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let buttonSizeExamples =
div {
_class "flex min-w-0 flex-wrap items-end justify-center gap-6"
for size, label in
[ Size.ExtraSmall, "Extra small"
Size.Small, "Small"
Size.Medium, "Medium"
Size.Large, "Large"
Size.ExtraLarge, "Extra large" ] do
div {
_class "flex flex-col items-center gap-3"
fveButton {
_size size; _color Color.Primary; _variant ButtonVariant.Solid
label
}
fveButton {
_size size; _variant ButtonVariant.Outline
_ariaLabel (label + " refresh")
refreshIcon
}
}
}This example also uses Icon. See their Installation sections for any additional setup.
Extra small, Small, Medium, Large and Extra large are 24, 28, 32, 36 and 40px at the default root size. Horizontal and vertical padding follow the shared size tokens independently, with borders included in the insets. Content determines width; icon-only controls do not need to be square. Supply an accessible name for icon-only controls. Medium is the 32px application default.
Colors
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let buttonColorExamples =
div {
_class "flex flex-wrap items-center justify-center gap-3"
for label, palette in
[ "Primary", Color.Primary
"Secondary", Color.Secondary
"Success", Color.Success
"Warning", Color.Warning
"Error", Color.Error
"Info", Color.Info
"Neutral", Color.Neutral ] do
fveButton {
_color palette
_variant ButtonVariant.Solid
label
}
}Variants
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let buttonVariantExamples =
div {
_class "flex flex-wrap items-center justify-center gap-3"
for label, treatment in
[ "Solid", ButtonVariant.Solid
"Soft", ButtonVariant.Soft
"Outline", ButtonVariant.Outline
"Ghost", ButtonVariant.Ghost ] do
fveButton {
_color Color.Primary
_variant treatment
label
}
}Ghost buttons stay flat, without a decorative shadow at rest, on hover or while pressed. Subtle state backgrounds and the keyboard focus ring remain visible, including native submit/reset controls.
Uniform padding
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let uniformPaddingButtons =
form {
_method "get"
_action "/components/button"
_class "flex flex-wrap items-center justify-center gap-4"
for size, label in [ Size.ExtraSmall, "Extra small"; Size.Small, "Small"; Size.Medium, "Medium"; Size.Large, "Large"; Size.ExtraLarge, "Extra large" ] do
for kind in [ "button"; "submit"; "reset" ] do
fveButton {
_type kind
_size size
_padding Padding.Uniform
_ariaLabel (label + " " + kind)
refreshIcon
}
}This example also uses Icon. See their Installation sections for any additional setup.
Padding.Uniform uses the size’s vertical inset on every side. A square child produces a square control, including native submit/reset controls. Omit padding or use Padding.Default for ordinary text padding. Minimum dimensions and border compensation still apply.
All color variants
Solid
Soft
Outline
Ghost
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let actionColors =
[ Color.Primary, "Primary"; Color.Secondary, "Secondary"; Color.Success, "Success"
Color.Warning, "Warning"; Color.Error, "Error"; Color.Info, "Info"; Color.Neutral, "Neutral" ]
let actionPaletteGrid (rows: (string * HtmlElement list) list) =
div {
_class "grid min-w-0 w-full gap-6"
for label, controls in rows do
div {
_data("action-variant", label.ToLowerInvariant())
_class "grid min-w-0 gap-3"
h3 { _class "text-sm font-semibold"; label }
div { _class "flex min-w-0 flex-wrap items-center gap-3"; yield! controls }
}
}
let buttonPaletteExamples =
[ for variant, treatment in [ "Solid", ButtonVariant.Solid; "Soft", ButtonVariant.Soft; "Outline", ButtonVariant.Outline; "Ghost", ButtonVariant.Ghost ] do
variant,
[ for color, label in actionColors do
fveButton {
_variant treatment; _color color
_ariaLabel (variant + " " + label)
_data("action-color", label.ToLowerInvariant())
label
} ] ]
|> actionPaletteGridCompare each variant’s idle, hover and pressed state. Built-in Soft actions use a visible resting tint in light mode. Custom palettes and soft-color token overrides retain their authored values. Solid and tinted fills retain their color identity; text/icons stay opaque. Focus, selected and unavailable states remain independent.
Pending
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let pendingSyncButton =
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_dataIndicator "_sync_pending"
_dataOn ("click", "@get('/components/button/settled', {filterSignals: {exclude: /.*/}, retry: 'never'})")
"Sync"
}Click Sync to see its loading state.
Children
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let plusIcon = fveIcon { _name IconName.Plus; _variant IconVariant.Micro }
let buttonContentExamples =
let continueIcon = fveIcon { _name IconName.ChevronRight; _variant IconVariant.Micro }
div {
_class "flex flex-wrap items-center justify-center gap-3"
fveButton { "Text" }
fveButton {
_ariaLabel "Refresh"
refreshIcon
}
fveButton {
plusIcon
"New branch"
}
fveButton {
"Continue"
continueIcon
}
fveButton {
strong { "Custom" }
span { " content" }
}
}This example also uses Icon. See their Installation sections for any additional setup.
SVG icons follow the control size: 12px for Extra small, 16px for Small and Medium, and 20px for Large and Extra large at the default root size.
Icon-only variants
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let iconOnlyButtonVariantExamples =
div {
_class "flex flex-wrap items-center justify-center gap-3"
for label, treatment in
[ "Solid", ButtonVariant.Solid
"Soft", ButtonVariant.Soft
"Outline", ButtonVariant.Outline
"Ghost", ButtonVariant.Ghost ] do
fveButton {
_color Color.Secondary
_variant treatment
_ariaLabel (label + " refresh")
refreshIcon
}
}This example also uses Icon. See their Installation sections for any additional setup.
Custom palette
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let customButtonPalette: ColorPalette =
{ light =
{ solid = "#9a3412"
solidHover = "#7c2d12"
solidActive = "#431407"
onSolid = "#ffffff"
soft = "#fff7ed"
softHover = "#ffedd5"
softActive = "#fed7aa"
text = "#9a3412"
border = "#9a3412"
focus = "#9a3412" }
dark =
{ solid = "#fdba74"
solidHover = "#fed7aa"
solidActive = "#ffedd5"
onSolid = "#431407"
soft = "#431407"
softHover = "#5c2209"
softActive = "#7c2d12"
text = "#ffedd5"
border = "#fdba74"
focus = "#fdba74" } }
let customPaletteButtons =
div {
_class "flex flex-wrap items-center justify-center gap-3"
for label, treatment in
[ "Solid", ButtonVariant.Solid
"Soft", ButtonVariant.Soft
"Outline", ButtonVariant.Outline
"Ghost", ButtonVariant.Ghost ] do
fveButton {
_color Color.Custom
_palette customButtonPalette
_variant treatment
label
}
}Primary buttons
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let primaryButtons =
div {
_class "flex flex-wrap items-center justify-center gap-4"
for size in [ Size.Small; Size.Medium; Size.Large ] do
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_size size
"Create"
}
}Secondary buttons
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let secondaryButtons =
div {
_class "flex flex-wrap items-center justify-center gap-4"
for size in [ Size.Small; Size.Medium; Size.Large ] do
fveButton {
_color Color.Secondary
_variant ButtonVariant.Soft
_size size
"View reports"
}
}Ghost buttons
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let ghostButtons =
div {
_class "flex flex-wrap items-center justify-center gap-4"
for size in [ Size.Small; Size.Medium; Size.Large ] do
fveButton {
_variant ButtonVariant.Ghost
_size size
"Cancel"
}
}Native Ghost reset
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let nativeGhostReset =
form {
_class "flex flex-wrap items-end justify-center gap-3"
div {
_class "grid gap-2"
label { _for "ghost-reset-name"; _class "text-sm font-medium"; "Example name" }
fveInput { _id "ghost-reset-name"; _name "name"; _value "Example" }
}
fveButton {
_type "reset"
_variant ButtonVariant.Ghost
_size Size.Medium
"Reset"
}
}Change the name, then Reset to restore its initial value. The flat native reset button retains its control sizing and works before enhancement or without JavaScript.
Destructive buttons
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let destructiveButtons =
div {
_class "flex flex-wrap items-center justify-center gap-4"
for size in [ Size.Small; Size.Medium; Size.Large ] do
fveButton {
_color Color.Error
_variant ButtonVariant.Solid
_size size
"Delete"
}
}Destructive pending
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let pendingErrorButton =
fveButton {
_color Color.Error
_variant ButtonVariant.Solid
_dataIndicator "_delete_pending"
_dataOn ("click", "@get('/components/button/settled', {filterSignals: {exclude: /.*/}, retry: 'never'})")
"Delete"
}Click Delete to see its loading state.
Disabled buttons
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let disabledDeleteButton =
fveButton {
_color Color.Error
_variant ButtonVariant.Solid
_disabled true
"Delete"
}Primary icon-only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let plusIcon = fveIcon { _name IconName.Plus; _variant IconVariant.Micro }
let createIconOnlyButton =
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_ariaLabel "Create"
plusIcon
}This example also uses Icon. See their Installation sections for any additional setup.
Pending icon-only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let refreshingIconOnlyButton =
fveButton {
_variant ButtonVariant.Ghost
_ariaLabel "Refresh"
_dataIndicator "_refresh_pending"
_dataOn ("click", "@get('/components/button/settled', {filterSignals: {exclude: /.*/}, retry: 'never'})")
refreshIcon
}This example also uses Icon. See their Installation sections for any additional setup.
Click the button to see its loading state.
Disabled icon-only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let removeIcon = fveIcon { _name IconName.Trash; _variant IconVariant.Micro }
let disabledRemoveIconOnlyButton =
fveButton {
_color Color.Error
_variant ButtonVariant.Solid
_ariaLabel "Remove"
_disabled true
removeIcon
}This example also uses Icon. See their Installation sections for any additional setup.
Datastar visibility
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let buttonVisibilityExample =
div {
_class "flex flex-wrap items-center justify-center gap-4"
_dataSignals "{actionVisible: false}"
fveButton { _dataOn("click", "$actionVisible = !$actionVisible"); "Toggle action visibility" }
fveButton {
_dataShow "$actionVisible"
_ariaLabel "Refresh visible action"
_dataOn("click", "$actionVisible = false")
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Mini }
}
}This example also uses Icon. See their Installation sections for any additional setup.
The caller owns data-show. Toggle visibility without changing Button presentation or its native control.
Row actions
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let moreActionsIcon = fveIcon { _name IconName.EllipsisHorizontal; _variant IconVariant.Micro }
type RowActionAccount = { id: int; name: string; canDelete: bool }
let rowActionAccounts =
[ { id = 101; name = "Operating checking"; canDelete = false }
{ id = 104; name = "Savings"; canDelete = false }
{ id = 105; name = "Unassigned expense"; canDelete = true } ]
let rowActionMenu prefix (account: RowActionAccount) =
let href = $"/examples/application/accounts/{account.id}"
fveDropdownMenu {
_id ($"{prefix}-{account.id}")
_class "ms-auto shrink-0"
_ariaLabel ("Actions for " + account.name)
fveDropdownMenuTrigger {
fveButton {
_variant ButtonVariant.Ghost
_size Size.Small
_class "aria-expanded:bg-[var(--fve-surface-active)]"
moreActionsIcon
}
}
fveDropdownMenuItem { _href href; "Open account" }
fveDropdownMenuItem { _href (href + "/edit"); "Edit account" }
fveDropdownMenuSeparator { () }
fveDropdownMenuItem {
_href (href + "/delete")
_color Color.Error
_disabled (not account.canDelete)
if not account.canDelete then _description "Has a balance or recorded transactions"
"Delete account"
}
}
let rowActionButtons =
div {
_class "mx-auto grid w-full max-w-lg gap-1"
for index, account in rowActionAccounts |> List.indexed do
div {
_class ("flex min-w-0 flex-wrap items-center justify-between gap-3 rounded px-3 py-2 " +
(if index = 1 then "bg-[var(--fve-brand-subtle)]" else "[&:not([readonly])]:not-disabled:not-aria-disabled:not-aria-busy:hover:bg-[linear-gradient(var(--fve-hover-wash),var(--fve-hover-wash))] [&:not([readonly])]:not-disabled:not-aria-disabled:not-aria-busy:active:bg-[linear-gradient(var(--fve-pressed-wash),var(--fve-pressed-wash))]"))
span { _class "min-w-0 flex-[1_0_min(10rem,100%)] break-words text-sm"; account.name }
rowActionMenu "button-row-actions" account
}
div {
_class "flex min-w-0 flex-wrap items-center justify-between gap-3 px-3 py-2 text-sm text-[var(--fve-muted-text)]"
span { _class "min-w-0 flex-[1_0_min(10rem,100%)] break-words"; "Actions unavailable" }
fveButton {
_variant ButtonVariant.Ghost; _size Size.Small; _class "ms-auto"
_ariaLabel "Actions unavailable"; _disabled true; moreActionsIcon
}
}
}This example also uses DropdownMenu, Icon. See their Installation sections for any additional setup.
Use a 28px-high Small ghost button with a horizontal-ellipsis icon child and the default control padding. Name it for its record; preserve hover contrast on hovered and selected backgrounds. Open, Edit and Delete navigate to the working Application example.
Labels and focus
Text content names the button. For icon-only actions, provide _ariaLabel; see the icon-only examples above.
API reference
type ButtonVariant =
| Solid
| Soft
| Outline
| Ghost
type ButtonBuilder
module ButtonDsl =
val fveButton : ButtonBuilder