R/wa_color_picker.R

Defines functions wa_color_picker

Documented in wa_color_picker

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

#' Create a `wa-color-picker` component
#'
#' Generated wrapper for the Web Awesome `wa-color-picker` component. When
#' used as a Shiny input, `input$<input_id>` reflects the component's
#' current `value` 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 default value of the form control. Primarily
#' used for resetting the form control. This wrapper argument sets the
#' HTML `value` attribute, which maps to the component's `defaultValue`
#' field/property rather than its live `value` property.
#' @param disabled Boolean. Default: `FALSE`. Disables the color picker.
#' @param label String. Default: `""`. The color picker's label. This will
#' not be displayed, but it will be announced by assistive devices. If you
#' need to display HTML, you can use the `label` slot` instead.
#' @param hint String. Default: `""`. The color picker's hint. If you need
#' to display HTML, use the `hint` slot instead.
#' @param name String. Default: `null`. The name of the form control,
#' submitted as a name/value pair with form data.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param dir String. Optional Web Awesome attribute.
#' @param format Enumerated string. Allowed values: `hex`, `hsl`, `hsv`,
#' `rgb`. Default: `hex`. The format to use. If opacity is enabled, these
#' will translate to HEXA, RGBA, HSLA, and HSVA respectively. The color
#' picker will accept user input in any format (including CSS color names)
#' and convert it to the desired format.
#' @param lang String. Optional Web Awesome attribute.
#' @param opacity Boolean. Default: `FALSE`. Shows the opacity slider.
#' Enabling this will cause the formatted value to be HEXA, RGBA, or HSLA.
#' @param open Boolean. Default: `FALSE`. Indicates whether or not the
#' popup is open. You can toggle this attribute to show and hide the
#' popup, or you can use the `show()` and `hide()` methods and this
#' attribute will reflect the popup's open state.
#' @param placement Enumerated string. Allowed values: `bottom`,
#' `bottom-end`, `bottom-start`, `left`, `left-end`, `left-start`,
#' `right`, `right-end`, `right-start`, `top`, `top-end`, `top-start`.
#' Default: `bottom-start`. The preferred placement of the color picker's
#' popup. Note that the actual placement will vary as configured to keep
#' the panel inside of the viewport.
#' @param required Boolean. Default: `FALSE`. Makes the color picker a
#' required field.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. Determines the size of the color picker's
#' trigger
#' @param swatches Default: `""`. One or more predefined color swatches to
#' display as presets in the color picker. Can include any format the
#' color picker can parse, including HEX(A), RGB(A), HSL(A), HSV(A), and
#' CSS color names. Each color must be separated by a semicolon (`;`).
#' Alternatively, you can pass an array of color values or an array of `{
#' color, label }` objects to this property using JavaScript. When using
#' objects with labels, the label will be used for the swatch's accessible
#' name instead of the raw color value.
#' @param uppercase Boolean. Default: `FALSE`. By default, values are
#' lowercase. With this attribute, values will be uppercase instead.
#' @param with_hint Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in a `hint` element so the server-rendered
#' markup includes the hint before the component hydrates on the client.
#' @param with_label Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in a `label` element so the
#' server-rendered markup includes the label before the component hydrates
#' on the client.
#' @param without_format_toggle Boolean. Default: `FALSE`. Removes the
#' button that lets users toggle between format.
#' @param hint_slot The color picker's form hint. Alternatively, you can
#' use the `hint` attribute.
#' @param label_slot The color picker's form label. Alternatively, you can
#' use the `label` attribute.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` reflects the component's current `value` value.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_color_picker <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  label = NULL,
  hint = NULL,
  name = NULL,
  custom_error = NULL,
  dir = NULL,
  format = NULL,
  lang = NULL,
  opacity = NULL,
  open = NULL,
  placement = NULL,
  required = NULL,
  size = NULL,
  swatches = NULL,
  uppercase = NULL,
  with_hint = NULL,
  with_label = NULL,
  without_format_toggle = NULL,
  hint_slot = NULL,
  label_slot = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(hint_slot, "hint")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(label_slot, "label")
    )
  )

  if (!is.null(format)) {
    format <- .wa_match_arg(
      format,
      "format",
      c(
        "hex",
        "hsl",
        "hsv",
        "rgb"
      )
    )
  }

  if (!is.null(placement)) {
    placement <- .wa_match_arg(
      placement,
      "placement",
      c(
        "bottom",
        "bottom-end",
        "bottom-start",
        "left",
        "left-end",
        "left-start",
        "right",
        "right-end",
        "right-start",
        "top",
        "top-end",
        "top-start"
      )
    )
  }

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

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "value" = value,
      "disabled" = disabled,
      "label" = label,
      "hint" = hint,
      "name" = name,
      "custom-error" = custom_error,
      "dir" = dir,
      "format" = format,
      "lang" = lang,
      "opacity" = opacity,
      "open" = open,
      "placement" = placement,
      "required" = required,
      "size" = size,
      "swatches" = swatches,
      "uppercase" = uppercase,
      "with-hint" = with_hint,
      "with-label" = with_label,
      "without-format-toggle" = without_format_toggle
    ),
    boolean_names = c(
      "disabled",
      "opacity",
      "open",
      "required",
      "uppercase",
      "with-hint",
      "with-label",
      "without-format-toggle"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "opacity" = "opacity",
      "open" = "open",
      "required" = "required",
      "uppercase" = "uppercase",
      "with-hint" = "with_hint",
      "with-label" = "with_label",
      "without-format-toggle" = "without_format_toggle"
    )
  )

  do.call(
    .wa_component,
    c(
      list("wa-color-picker", .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.