Skip to contents

A shadcn two-state toggle button. input$<inputId> is a logical.

Usage

shad_toggle(
  inputId,
  label = NULL,
  value = FALSE,
  variant = c("default", "outline"),
  size = c("default", "sm", "lg"),
  icon = NULL,
  disabled = FALSE,
  class = NULL,
  ...
)

Arguments

inputId

Input id.

label

Optional text content.

value

Initial pressed state (logical).

variant

"default" or "outline".

size

"default", "sm", or "lg".

icon

Optional icon: a shad_icon() name or a tag.

disabled

If TRUE, disables the control.

class

Extra CSS classes.

...

Extra attributes.

Value

A toggle button tag.

Examples

shad_toggle("bold", icon = "plus", value = TRUE)
#> <button type="button" class="shad-toggle" data-shad="toggle" data-state="on" id="bold">
#>   <svg class="shad-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
#> </button>
shad_toggle("mode", "Outline", variant = "outline")
#> <button type="button" class="shad-toggle shad-toggle--outline" data-shad="toggle" data-state="off" id="mode">Outline</button>