R/tab-utils.R

Defines functions .gt_tab_theme_css .gt_tab_pane .gt_tab_link

#' @noRd
.gt_tab_link <- function(panel, is_active, data_ns, preserve_inactive_space = FALSE) {
  class <- if (is_active) {
    "gt-tab-link active"
  } else if (preserve_inactive_space) {
    "gt-tab-link "
  } else {
    "gt-tab-link"
  }
  label_content <- if (!is.null(panel$icon)) {
    list(
      shiny::tags$span(class = "gt-tab-icon", panel$icon),
      shiny::tags$span(class = "gt-tab-label", panel$label)
    )
  } else {
    list(shiny::tags$span(class = "gt-tab-label", panel$label))
  }

  do.call(
    shiny::tags$div,
    c(
      list(
        class = class,
        id = paste0(data_ns, "-tab-", panel$value),
        `data-value` = panel$value,
        `data-ns` = data_ns,
        role = "tab",
        tabindex = if (is_active) "0" else "-1",
        `aria-selected` = if (is_active) "true" else "false",
        `aria-controls` = paste0(data_ns, "-pane-", panel$value)
      ),
      label_content
    )
  )
}

#' @noRd
.gt_tab_pane <- function(panel, is_active, id, tab_id = NULL,
                         preserve_inactive_space = FALSE) {
  class <- if (is_active) {
    "gt-tab-pane active"
  } else if (preserve_inactive_space) {
    "gt-tab-pane "
  } else {
    "gt-tab-pane"
  }

  shiny::div(
    class = class,
    id = id,
    role = "tabpanel",
    `aria-labelledby` = tab_id,
    `aria-hidden` = if (is_active) "false" else "true",
    inert = if (is_active) NULL else "",
    tabindex = if (is_active) "0" else "-1",
    do.call(shiny::div, c(list(class = "gt-card"), panel$content))
  )
}

#' @noRd
.gt_tab_theme_css <- function(theme, scope_id, selector = NULL) {
  scope <- if (is.null(selector)) paste0("#", scope_id) else paste0(selector, " #", scope_id)
  sprintf(
    "%s{--gt-tab-text:%s;--gt-tab-active-text:%s;--gt-halo-bg:%s;--gt-halo-border:%s;--gt-focus-ring:%s;--gt-halo-shadow:%s;--gt-content-bg:%s;--gt-content-border:%s;--gt-card-bg:%s;--gt-card-text:%s;}",
    scope,
    theme$tab_text,
    theme$tab_active_text,
    theme$halo_bg,
    theme$halo_border,
    theme$focus_ring,
    theme$halo_shadow,
    theme$content_bg,
    theme$content_border,
    theme$card_bg,
    theme$card_text
  )
}

Try the glasstabs package in your browser

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

glasstabs documentation built on Sept. 11, 2026, 5:08 p.m.