R/wa_button.R

Defines functions wa_button

Documented in wa_button

# Generated by tools/generate_components.R. Do not edit by hand.
# nolint start: object_usage_linter.

#' Create a `wa-button` component
#'
#' Generated wrapper for the Web Awesome `wa-button` component. When used
#' as a Shiny input, the component exposes action semantics through
#' `input$<input_id>`. The Shiny input invalidates on each committed
#' action rather than publishing a durable value payload. Each committed
#' action publishes a numeric action value.
#' Generated from Web Awesome metadata.
#'
#' @param ... Child content for the component's default slot.
#' @param input_id Shiny input id for the component. This is also used as
#' the rendered DOM `id` attribute.
#' @param class Optional CSS class string.
#' @param style Optional inline CSS style string.
#' @param value String. The value of the button, submitted as a pair with
#' the button's name as part of the form data, but only when this button
#' is the submitter. This attribute is ignored when `href` is present.
#' @param disabled Boolean. Default: `FALSE`. Disables the button.
#' @param name String. Default: `null`. The name of the button, submitted
#' as a name/value pair with form data, but only when this button is the
#' submitter. This attribute is ignored when `href` is present.
#' @param appearance Enumerated string. Allowed values: `accent`,
#' `filled`, `filled-outlined`, `outlined`, `plain`. Default: `accent`.
#' The button's visual appearance.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param dir String. Optional Web Awesome attribute.
#' @param download String. Tells the browser to download the linked file
#' as this filename. Only used when `href` is present.
#' @param formaction String. Used to override the form owner's `action`
#' attribute. This wrapper argument sets the HTML `formaction` attribute,
#' which maps to the component's `formAction` field/property.
#' @param formenctype Enumerated string. Allowed values:
#' `application/x-www-form-urlencoded`, `multipart/form-data`,
#' `text/plain`. Used to override the form owner's `enctype` attribute.
#' This wrapper argument sets the HTML `formenctype` attribute, which maps
#' to the component's `formEnctype` field/property.
#' @param formmethod Enumerated string. Allowed values: `get`, `post`.
#' Used to override the form owner's `method` attribute. This wrapper
#' argument sets the HTML `formmethod` attribute, which maps to the
#' component's `formMethod` field/property.
#' @param formnovalidate Boolean. Default: `FALSE`. Used to override the
#' form owner's `novalidate` attribute. This wrapper argument sets the
#' HTML `formnovalidate` attribute, which maps to the component's
#' `formNoValidate` field/property.
#' @param formtarget Used to override the form owner's `target` attribute.
#' This wrapper argument sets the HTML `formtarget` attribute, which maps
#' to the component's `formTarget` field/property.
#' @param href String. When set, the underlying button will be rendered as
#' an `<a>` with this `href` instead of a `<button>`.
#' @param lang String. Optional Web Awesome attribute.
#' @param loading Boolean. Default: `FALSE`. Draws the button in a loading
#' state.
#' @param pill Boolean. Default: `FALSE`. Draws a pill-style button with
#' rounded edges.
#' @param rel String. When using `href`, this attribute will map to the
#' underlying link's `rel` attribute.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The button's size.
#' @param target Enumerated string. Allowed values: `_blank`, `_parent`,
#' `_self`, `_top`. Tells the browser where to open the link. Only used
#' when `href` is present.
#' @param title String. Default: `""`. Optional Web Awesome attribute.
#' @param type Enumerated string. Allowed values: `button`, `reset`,
#' `submit`. Default: `button`. The type of button. Note that the default
#' value is `button` instead of `submit`, which is opposite of how native
#' `<button>` elements behave. When the type is `submit`, the button will
#' submit the surrounding form.
#' @param variant Enumerated string. Allowed values: `brand`, `danger`,
#' `neutral`, `success`, `warning`. Default: `neutral`. The button's theme
#' variant. Defaults to `neutral` if not within another element with a
#' variant.
#' @param with_caret Boolean. Default: `FALSE`. Draws the button with a
#' caret. Used to indicate that the button triggers a dropdown menu or
#' similar behavior.
#' @param with_end Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in an `end` element so the server-rendered
#' markup includes the end slot before the component hydrates on the
#' client.
#' @param with_start Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in a `start` element so the
#' server-rendered markup includes the start slot before the component
#' hydrates on the client.
#' @param end An element, such as `<wa-icon>`, placed after the label.
#' @param start An element, such as `<wa-icon>`, placed before the label.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` uses action semantics and invalidates on each
#' committed action rather than publishing a durable value payload. The
#' Shiny action value is returned as a numeric action value.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_button <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  name = NULL,
  appearance = NULL,
  custom_error = NULL,
  dir = NULL,
  download = NULL,
  formaction = NULL,
  formenctype = NULL,
  formmethod = NULL,
  formnovalidate = NULL,
  formtarget = NULL,
  href = NULL,
  lang = NULL,
  loading = NULL,
  pill = NULL,
  rel = NULL,
  size = NULL,
  target = NULL,
  title = NULL,
  type = NULL,
  variant = NULL,
  with_caret = NULL,
  with_end = NULL,
  with_start = NULL,
  end = NULL,
  start = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(end, "end")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(start, "start")
    )
  )

  if (!is.null(appearance)) {
    appearance <- .wa_match_arg(
      appearance,
      "appearance",
      c(
        "accent",
        "filled",
        "filled-outlined",
        "outlined",
        "plain"
      )
    )
  }

  if (!is.null(formenctype)) {
    formenctype <- .wa_match_arg(
      formenctype,
      "formenctype",
      c(
        "application/x-www-form-urlencoded",
        "multipart/form-data",
        "text/plain"
      )
    )
  }

  if (!is.null(formmethod)) {
    formmethod <- .wa_match_arg(
      formmethod,
      "formmethod",
      c(
        "get",
        "post"
      )
    )
  }

  if (!is.null(size)) {
    size <- .wa_match_arg(
      size,
      "size",
      c(
        "large",
        "medium",
        "small"
      )
    )
  }

  if (!is.null(target)) {
    target <- .wa_match_arg(
      target,
      "target",
      c(
        "_blank",
        "_parent",
        "_self",
        "_top"
      )
    )
  }

  if (!is.null(type)) {
    type <- .wa_match_arg(
      type,
      "type",
      c(
        "button",
        "reset",
        "submit"
      )
    )
  }

  if (!is.null(variant)) {
    variant <- .wa_match_arg(
      variant,
      "variant",
      c(
        "brand",
        "danger",
        "neutral",
        "success",
        "warning"
      )
    )
  }

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "value" = value,
      "disabled" = disabled,
      "name" = name,
      "appearance" = appearance,
      "custom-error" = custom_error,
      "dir" = dir,
      "download" = download,
      "formaction" = formaction,
      "formenctype" = formenctype,
      "formmethod" = formmethod,
      "formnovalidate" = formnovalidate,
      "formtarget" = formtarget,
      "href" = href,
      "lang" = lang,
      "loading" = loading,
      "pill" = pill,
      "rel" = rel,
      "size" = size,
      "target" = target,
      "title" = title,
      "type" = type,
      "variant" = variant,
      "with-caret" = with_caret,
      "with-end" = with_end,
      "with-start" = with_start
    ),
    boolean_names = c(
      "disabled",
      "formnovalidate",
      "loading",
      "pill",
      "with-caret",
      "with-end",
      "with-start"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "formnovalidate" = "formnovalidate",
      "loading" = "loading",
      "pill" = "pill",
      "with-caret" = "with_caret",
      "with-end" = "with_end",
      "with-start" = "with_start"
    )
  )

  do.call(
    .wa_component,
    c(
      list("wa-button", .attrs = attrs),
      children
    )
  )
}
# nolint end

Try the shiny.webawesome package in your browser

Any scripts or data that you put into this service are public.

shiny.webawesome documentation built on April 22, 2026, 1:09 a.m.