R/wa_rating.R

Defines functions wa_rating

Documented in wa_rating

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

#' Create a `wa-rating` component
#'
#' Generated wrapper for the Web Awesome `wa-rating` component. When used
#' as a Shiny input, `input$<input_id>` reflects the component's current
#' `value` value. The Shiny value is returned as a numeric 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 Number. Default: `0`. The current rating.
#' @param disabled Boolean. Default: `FALSE`. Disables the rating.
#' @param label String. Default: `""`. A label that describes the rating
#' to assistive devices.
#' @param name String. Default: `null`. The name of the rating, submitted
#' as a name/value pair with form data.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param default_value Number. Default: `0`. The default value of the
#' form control. Used to reset the rating to its initial value.
#' @param dir String. Optional Web Awesome attribute.
#' @param get_symbol A function that customizes the symbol to be rendered.
#' The first and only argument is the rating's current value. The function
#' should return a string containing trusted HTML of the symbol to render
#' at the specified value. Works well with `<wa-icon>` elements.
#' @param lang String. Optional Web Awesome attribute.
#' @param max Number. Default: `5`. The highest rating to show.
#' @param precision Number. Default: `1`. The precision at which the
#' rating will increase and decrease. For example, to allow half-star
#' ratings, set this attribute to `0.5`.
#' @param readonly Boolean. Default: `FALSE`. Makes the rating readonly.
#' @param required Boolean. Default: `FALSE`. Makes the rating a required
#' field.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The component's size.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` reflects the component's current `value` value. The
#' Shiny value is returned as a numeric value.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_rating <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  label = NULL,
  name = NULL,
  custom_error = NULL,
  default_value = NULL,
  dir = NULL,
  get_symbol = NULL,
  lang = NULL,
  max = NULL,
  precision = NULL,
  readonly = NULL,
  required = NULL,
  size = NULL
) {
  children <- list(...)

  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,
      "name" = name,
      "custom-error" = custom_error,
      "default-value" = default_value,
      "dir" = dir,
      "getSymbol" = get_symbol,
      "lang" = lang,
      "max" = max,
      "precision" = precision,
      "readonly" = readonly,
      "required" = required,
      "size" = size
    ),
    boolean_names = c(
      "disabled",
      "readonly",
      "required"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "readonly" = "readonly",
      "required" = "required"
    )
  )

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