1#' @export
2#' @rdname navs
3navs_tab_card <- function(..., id = NULL, selected = NULL,
4                          header = NULL, footer = NULL) {
5  tabs <- tagQuery(
6    navs_tab(..., id = id, selected = selected, header = header, footer = footer)
7  )
8
9  # https://getbootstrap.com/docs/5.0/components/card/#navigation
10  nav <- tabs$
11    find(".nav")$
12    addClass("card-header-tabs")$
13    selectedTags()
14
15  content <- tabs$find(".tab-content")$selectedTags()
16
17  card(header = nav, content, caller = "navs_tab_card()")
18}
19
20#' @export
21#' @param placement placement of the nav items relative to the content.
22#' @rdname navs
23navs_pill_card <- function(..., id = NULL, selected = NULL,
24                           header = NULL, footer = NULL,
25                           placement = c("above", "below")) {
26
27  pills <- tagQuery(
28    navs_pill(..., id = id, selected = selected, header = header, footer = footer)
29  )
30
31  above <- match.arg(placement) == "above"
32
33  nav <- pills$
34    find(".nav")$
35    addClass(if (above) "card-header-pills")$
36    selectedTags()
37
38  content <- pills$find(".tab-content")$selectedTags()
39
40  args <- list(nav, content, caller = "navs_pill_card()")
41
42  names(args)[1] <- if (above) "header" else "footer"
43
44  do.call(card, args)
45}
46
47card <- function(..., header = NULL, footer = NULL, caller) {
48  tag <- div(
49    class = "card",
50    if (!is.null(header)) div(class = "card-header", header),
51    div(class = "card-body", ...),
52    if (!is.null(footer)) div(class = "card-footer", footer)
53  )
54  as_fragment(
55    tag_require(tag, version = 4, caller = caller)
56  )
57}
58