From 1e836a0def50692e690c8f5888bc9cb4e5a6a171 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 16:15:04 -0500 Subject: [PATCH 1/6] Simplify example_cards.R by using bslib --- vignettes/articles/.gitignore | 1 + vignettes/articles/example_cards.R | 53 +++++++----------------------- 2 files changed, 13 insertions(+), 41 deletions(-) create mode 100644 vignettes/articles/.gitignore diff --git a/vignettes/articles/.gitignore b/vignettes/articles/.gitignore new file mode 100644 index 000000000..075b2542a --- /dev/null +++ b/vignettes/articles/.gitignore @@ -0,0 +1 @@ +/.quarto/ diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index a8710ae03..04a8d99af 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -1,42 +1,16 @@ -card <- function( - ..., - class_card = NULL, - class_card_body = NULL, - class_card_title = NULL, - class_card_footer = "text-end" -) { - card_data <- list(...) - htmltools::withTags( - div( - class = "col", - div( - class = c("card h-100 shadow-sm", class_card), - a( - href = card_data$link, - img( - src = card_data$image, - class = "card-img-top", - alt = paste0("Preview image of ", card_data$title) - ) - ), - div( - class = c("card-body", class_card_body), - h5(class = c("card-title", class_card_title), a(href = card_data$link, card_data$title)), - if (!is.null(card_data$text)) div( - class = "card-text text-muted fs-6", - htmltools::HTML(commonmark::markdown_html(card_data$text)) - ), - ), - if (!is.null(card_data$footer)) div( - class = c("card-footer", class_card_footer), - htmltools::HTML(card_data$footer) - ) - ) - ) +card <- function(title, link, image, alt = NULL, text = NULL, footer = NULL, ...) { + alt <- alt %||% paste0("Preview image of ", title) + + bslib::card( + bslib::card_image(file = image, href = link, alt = alt), + bslib::card_title(htmltools::a(href = link, title)), + if (!is.null(text)) htmltools::HTML(commonmark::markdown_html(text)), + if (!is.null(footer)) + bslib::card_footer(htmltools::HTML(footer)), ) } -example_cards <- function(yml, group = NULL, class_row = "row-cols-1 row-cols-md-2 row-cols-lg-3") { +example_cards <- function(yml, group) { examples <- if (is.list(yml)) { yml } else { @@ -44,10 +18,7 @@ example_cards <- function(yml, group = NULL, class_row = "row-cols-1 row-cols-md } examples <- purrr::keep(examples, function(x) x[["group"]] %in% group) - examples <- purrr::transpose(examples) + cards <- purrr::map(examples, function(x) purrr::exec(card, !!!x)) - htmltools::tags$div( - class = paste("row g-4", class_row), - purrr::pmap(examples, card) - ) + bslib::layout_column_wrap(!!!cards) } From 62121133573859e042716f1847ceb5844061a276 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 16:31:44 -0500 Subject: [PATCH 2/6] Don't embed images --- vignettes/articles/example_cards.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index 04a8d99af..556dee578 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -2,7 +2,7 @@ card <- function(title, link, image, alt = NULL, text = NULL, footer = NULL, ... alt <- alt %||% paste0("Preview image of ", title) bslib::card( - bslib::card_image(file = image, href = link, alt = alt), + bslib::card_image(file = NULL, src = image, href = link, alt = alt), bslib::card_title(htmltools::a(href = link, title)), if (!is.null(text)) htmltools::HTML(commonmark::markdown_html(text)), if (!is.null(footer)) From 95496946f4de298dfde1f52a97f35fc29b45e496 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 16:36:48 -0500 Subject: [PATCH 3/6] Fix width --- vignettes/articles/example_cards.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index 556dee578..fe0f5c55c 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -20,5 +20,5 @@ example_cards <- function(yml, group) { examples <- purrr::keep(examples, function(x) x[["group"]] %in% group) cards <- purrr::map(examples, function(x) purrr::exec(card, !!!x)) - bslib::layout_column_wrap(!!!cards) + bslib::layout_column_wrap(!!!cards, width = 1/3) } From 800a7218eaa1875941eaeef9d3034fa2eba9ebd8 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 17:01:21 -0500 Subject: [PATCH 4/6] More tweaking --- vignettes/articles/example_cards.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index fe0f5c55c..03e73eb1d 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -2,9 +2,12 @@ card <- function(title, link, image, alt = NULL, text = NULL, footer = NULL, ... alt <- alt %||% paste0("Preview image of ", title) bslib::card( - bslib::card_image(file = NULL, src = image, href = link, alt = alt), - bslib::card_title(htmltools::a(href = link, title)), - if (!is.null(text)) htmltools::HTML(commonmark::markdown_html(text)), + bslib::card_header(htmltools::a(href = link, title)), + bslib::card_body( + bslib::card_image(file = NULL, src = image, href = link, alt = alt), + if (!is.null(text)) htmltools::HTML(commonmark::markdown_html(text)), + fillable = FALSE + ), if (!is.null(footer)) bslib::card_footer(htmltools::HTML(footer)), ) From 62014efd4a2ecfb3a0257c63bca9575a32986f57 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 17:02:52 -0500 Subject: [PATCH 5/6] Restore shadow --- vignettes/articles/example_cards.R | 1 + 1 file changed, 1 insertion(+) diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index 03e73eb1d..c02066730 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -2,6 +2,7 @@ card <- function(title, link, image, alt = NULL, text = NULL, footer = NULL, ... alt <- alt %||% paste0("Preview image of ", title) bslib::card( + class = "shadow-sm", bslib::card_header(htmltools::a(href = link, title)), bslib::card_body( bslib::card_image(file = NULL, src = image, href = link, alt = alt), From 46cf7df6e457e4f34cdd1f4d4bcd0ea74f413e3d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 4 Jun 2024 17:07:21 -0500 Subject: [PATCH 6/6] Improve width --- vignettes/articles/example_cards.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/example_cards.R b/vignettes/articles/example_cards.R index c02066730..f37062866 100644 --- a/vignettes/articles/example_cards.R +++ b/vignettes/articles/example_cards.R @@ -24,5 +24,5 @@ example_cards <- function(yml, group) { examples <- purrr::keep(examples, function(x) x[["group"]] %in% group) cards <- purrr::map(examples, function(x) purrr::exec(card, !!!x)) - bslib::layout_column_wrap(!!!cards, width = 1/3) + bslib::layout_column_wrap(!!!cards, width = "300px") }