R/wa_slider.R

Defines functions update_wa_slider wa_slider

Documented in update_wa_slider wa_slider

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

#' Create a `wa-slider` component
#'
#' Generated wrapper for the Web Awesome `wa-slider` 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. 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 slider.
#' @param label String. Default: `""`. The slider's label. If you need to
#' provide HTML in the label, use the `label` slot instead.
#' @param hint String. Default: `""`. The slider hint. If you need to
#' display HTML, use the hint slot instead.
#' @param name String. Default: `null`. The name of the slider. This will
#' be submitted with the form as a name/value pair.
#' @param autofocus Boolean. Default: `FALSE`. Tells the browser to focus
#' the slider when the page loads or a dialog is shown.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param dir String. Optional Web Awesome attribute.
#' @param indicator_offset Number. The starting value from which to draw
#' the slider's fill, which is based on its current value.
#' @param lang String. Optional Web Awesome attribute.
#' @param max Number. Default: `100`. The maximum value allowed.
#' @param max_value Number. Default: `50`. The maximum value of a range
#' selection. Used only when range attribute is set.
#' @param min Number. Default: `0`. The minimum value allowed.
#' @param min_value Number. Default: `0`. The minimum value of a range
#' selection. Used only when range attribute is set.
#' @param orientation Enumerated string. Allowed values: `horizontal`,
#' `vertical`. Default: `horizontal`. The orientation of the slider.
#' @param range Boolean. Default: `FALSE`. Converts the slider to a range
#' slider with two thumbs.
#' @param readonly Boolean. Default: `FALSE`. Makes the slider a read-only
#' field.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The slider's size.
#' @param step Number. Default: `1`. The granularity the value must adhere
#' to when incrementing and decrementing.
#' @param tooltip_distance Number. Default: `8`. The distance of the
#' tooltip from the slider's thumb.
#' @param tooltip_placement Enumerated string. Allowed values: `bottom`,
#' `left`, `right`, `top`. Default: `top`. The placement of the tooltip in
#' reference to the slider's thumb.
#' @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 with_markers Boolean. Default: `FALSE`. Draws markers at each
#' step along the slider.
#' @param with_tooltip Boolean. Default: `FALSE`. Draws a tooltip above
#' the thumb when the control has focus or is dragged.
#' @param hint_slot Text that describes how to use the input.
#' Alternatively, you can use the `hint` attribute. instead.
#' @param label_slot The slider label. Alternatively, you can use the
#' `label` attribute.
#' @param reference One or more reference labels to show visually below
#' the slider.
#'
#' @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_slider <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  label = NULL,
  hint = NULL,
  name = NULL,
  autofocus = NULL,
  custom_error = NULL,
  dir = NULL,
  indicator_offset = NULL,
  lang = NULL,
  max = NULL,
  max_value = NULL,
  min = NULL,
  min_value = NULL,
  orientation = NULL,
  range = NULL,
  readonly = NULL,
  size = NULL,
  step = NULL,
  tooltip_distance = NULL,
  tooltip_placement = NULL,
  with_hint = NULL,
  with_label = NULL,
  with_markers = NULL,
  with_tooltip = NULL,
  hint_slot = NULL,
  label_slot = NULL,
  reference = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(hint_slot, "hint")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(label_slot, "label")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(reference, "reference")
    )
  )

  if (!is.null(orientation)) {
    orientation <- .wa_match_arg(
      orientation,
      "orientation",
      c(
        "horizontal",
        "vertical"
      )
    )
  }

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

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

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "value" = value,
      "disabled" = disabled,
      "label" = label,
      "hint" = hint,
      "name" = name,
      "autofocus" = autofocus,
      "custom-error" = custom_error,
      "dir" = dir,
      "indicator-offset" = indicator_offset,
      "lang" = lang,
      "max" = max,
      "max-value" = max_value,
      "min" = min,
      "min-value" = min_value,
      "orientation" = orientation,
      "range" = range,
      "readonly" = readonly,
      "size" = size,
      "step" = step,
      "tooltip-distance" = tooltip_distance,
      "tooltip-placement" = tooltip_placement,
      "with-hint" = with_hint,
      "with-label" = with_label,
      "with-markers" = with_markers,
      "with-tooltip" = with_tooltip
    ),
    boolean_names = c(
      "disabled",
      "autofocus",
      "range",
      "readonly",
      "with-hint",
      "with-label",
      "with-markers",
      "with-tooltip"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "autofocus" = "autofocus",
      "range" = "range",
      "readonly" = "readonly",
      "with-hint" = "with_hint",
      "with-label" = "with_label",
      "with-markers" = "with_markers",
      "with-tooltip" = "with_tooltip"
    )
  )

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

# Generated by tools/generate_components.R. Do not edit by hand.

#' Update a `wa-slider` component
#'
#' Generated update helper for the Web Awesome `wa-slider` component.
#'
#' @param session Shiny session object.
#' @param input_id Input id of the component to update.
#' @param value Optional value to send to the component.
#' @param label Optional label text to send to the component.
#' @param hint Optional hint text to send to the component.
#' @param disabled Optional logical disabled state to send to the component.
#'
#' @return Invisibly returns `NULL`.
#'
#' @rdname wa_slider
#' @export
update_wa_slider <- function(
  session,
  input_id,
  value = NULL,
  label = NULL,
  hint = NULL,
  disabled = NULL
) {
  message <- Filter(
    Negate(is.null),
    list(
      value = value,
      label = label,
      hint = hint,
      disabled = disabled
    )
  )

  if (length(message) == 0L) {
    return(invisible(NULL))
  }

  session$sendInputMessage(input_id, message)
  invisible(NULL)
}

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.