fix(logo): take style_flextable_civilytics() defaults from civilytics_colors (#21)

Header, zebra, borders, and footer text now use navy_700, paper_2,
rule_strong, rule, and ink_3 instead of Bootstrap hex values. Tables built
with the defaults change appearance.

Closes #21

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Sonnet 5.5 committed 2026-10-15 15:27:54 -04:00
1 parent 4f697e2d52
commit d6e3ba2fb4
3 files changed
+42 -20

No files matched your search

+12 -10
View File
@@ -15,7 +15,8 @@
#' `flextable` is unavailable.
#'
#' @param ft A [flextable::flextable()] object.
#' @param header_bg Character. Header background fill. Default `"#2c3e50"`.
#' @param header_bg Character. Header background fill. Default
#' `civilytics_colors[["navy_700"]]`.
#' @param header_color Character. Header text color. Default `"white"`.
#' @param title_fontsize Numeric. Font size for the first header line (the
#' title row, `i = 1`). Default `14`.
@@ -25,17 +26,18 @@
#' @param zebra Logical. Apply alternating-row striping to even body rows.
#' Default `TRUE`. Safely skipped for tables with fewer than two body rows.
#' @param zebra_bg Character. Fill color for striped (even) body rows.
#' Default `"#f0f0eb"`.
#' Default `civilytics_colors[["paper_2"]]`.
#' @param outer_border_color Character. Outer border color. Default
#' `"#888888"`.
#' `civilytics_colors[["rule_strong"]]`.
#' @param outer_border_width Numeric. Outer border width. Default `1`.
#' @param inner_border_color Character. Inner horizontal border color (body).
#' Default `"#cccccc"`.
#' Default `civilytics_colors[["rule"]]`.
#' @param inner_border_width Numeric. Inner horizontal border width. Default
#' `0.5`.
#' @param footer_fontsize Numeric. Footer font size (applied only if a footer
#' part exists). Default `9`.
#' @param footer_color Character. Footer text color. Default `"#555555"`.
#' @param footer_color Character. Footer text color. Default
#' `civilytics_colors[["ink_3"]]`.
#'
#' @return The styled [flextable::flextable()] object.
#' @export
@@ -50,19 +52,19 @@
#' style_flextable_civilytics()
#' }
style_flextable_civilytics <- function(ft,
header_bg = "#2c3e50",
header_bg = civilytics_colors[["navy_700"]],
header_color = "white",
title_fontsize = 14,
body_fontsize = 11,
font_name = "Arial",
zebra = TRUE,
zebra_bg = "#f0f0eb",
outer_border_color = "#888888",
zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1,
inner_border_color = "#cccccc",
inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5,
footer_fontsize = 9,
footer_color = "#555555") {
footer_color = civilytics_colors[["ink_3"]]) {
if (!requireNamespace("flextable", quietly = TRUE)) {
stop("Install 'flextable' to use this function.", call. = FALSE)
}
+12 -10
View File
@@ -6,25 +6,26 @@
\usage{
style_flextable_civilytics(
ft,
header_bg = "#2c3e50",
header_bg = civilytics_colors[["navy_700"]],
header_color = "white",
title_fontsize = 14,
body_fontsize = 11,
font_name = "Arial",
zebra = TRUE,
zebra_bg = "#f0f0eb",
outer_border_color = "#888888",
zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1,
inner_border_color = "#cccccc",
inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5,
footer_fontsize = 9,
footer_color = "#555555"
footer_color = civilytics_colors[["ink_3"]]
)
}
\arguments{
\item{ft}{A [flextable::flextable()] object.}
\item{header_bg}{Character. Header background fill. Default `"#2c3e50"`.}
\item{header_bg}{Character. Header background fill. Default
`civilytics_colors[["navy_700"]]`.}
\item{header_color}{Character. Header text color. Default `"white"`.}
@@ -40,15 +41,15 @@ title row, `i = 1`). Default `14`.}
Default `TRUE`. Safely skipped for tables with fewer than two body rows.}
\item{zebra_bg}{Character. Fill color for striped (even) body rows.
Default `"#f0f0eb"`.}
Default `civilytics_colors[["paper_2"]]`.}
\item{outer_border_color}{Character. Outer border color. Default
`"#888888"`.}
`civilytics_colors[["rule_strong"]]`.}
\item{outer_border_width}{Numeric. Outer border width. Default `1`.}
\item{inner_border_color}{Character. Inner horizontal border color (body).
Default `"#cccccc"`.}
Default `civilytics_colors[["rule"]]`.}
\item{inner_border_width}{Numeric. Inner horizontal border width. Default
`0.5`.}
@@ -56,7 +57,8 @@ Default `"#cccccc"`.}
\item{footer_fontsize}{Numeric. Footer font size (applied only if a footer
part exists). Default `9`.}
\item{footer_color}{Character. Footer text color. Default `"#555555"`.}
\item{footer_color}{Character. Footer text color. Default
`civilytics_colors[["ink_3"]]`.}
}
\value{
The styled [flextable::flextable()] object.
+18
View File
@@ -87,3 +87,21 @@ test_that("extra_height increases the exported PNG height", {
expect_gt(dim(png::readPNG(path_big))[1], dim(png::readPNG(path_small))[1])
})
test_that("style_flextable_civilytics defaults come from civilytics_colors (#21)", {
defaults <- formals(style_flextable_civilytics)
expect_identical(eval(defaults$header_bg), civilytics_colors[["navy_700"]])
expect_identical(eval(defaults$zebra_bg), civilytics_colors[["paper_2"]])
expect_identical(eval(defaults$outer_border_color), civilytics_colors[["rule_strong"]])
expect_identical(eval(defaults$inner_border_color), civilytics_colors[["rule"]])
expect_identical(eval(defaults$footer_color), civilytics_colors[["ink_3"]])
})
test_that("style_flextable_civilytics paints the header with brand navy", {
skip_if_not_installed("flextable")
skip_if_not_installed("officer")
styled <- style_flextable_civilytics(flextable::flextable(head(mtcars, 3)))
header_fill <- unique(as.vector(styled$header$styles$cells$background.color$data))
expect_identical(toupper(header_fill), toupper(civilytics_colors[["navy_700"]]))
})