Skip to main content

Component | Button

Render a button.

ui.button("button-id", { 
label: "Click me",
onClick: () => console.log("clicked")
})

Appearance

Use the appearance property to easily style the button from a predefined set of options.

ui.button("1", { label: "Primary", appearance: "primary" })
ui.button("2", { label: "Outline", appearance: "outline" })
ui.button("3", { label: "Warning", appearance: "warning" })
ui.button("4", { label: "Danger", appearance: "danger" })

Or, use the style property to apply custom styles to the button.

ui.button("custom", { 
label: "Custom button",
style: {
backgroundColor: "black",
color: "white",
padding: "10px 20px",
borderRadius: "999px"
}
})

API reference

Function signature

ui.button(
id: string,
properties?: Partial<{
label: string,
appearance: "primary" | "outline" | "warning" | "danger",
onClick: () => void,
style: Style
}>
)

Parameters

id

required string
A unique identifier for the component. This is necessary so that Compose can properly pass user actions back to the component.

properties.label

optional string

The label to display inside the button. If not provided, the label will be inferred from the id.


properties.appearance

optional string literal

The appearance of the button. Defaults to primary.

Options include:

  • "primary"
  • "outline"
  • "warning"
  • "danger"

properties.onClick

optional () => void

A callback function that is called when the button is clicked.


properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.