Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 1 | #' Alternative HTML themes |
| 2 | #' |
| 3 | #' @description kableExtra uses the built-in bootstrap themes by default in |
| 4 | #' `kable_styling()`. Alternatively, you can use a customized table themes for |
| 5 | #' your table. This `lightable` table style sheet comes with three formats, |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 6 | #' namely `lightable-minimal`, `lightable-classic`, `lightable-material` and |
| 7 | #' `lightable-material-dark` with `hover` and `striped` options. |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 8 | #' |
| 9 | #' @param kable_input A HTML kable object. |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 10 | #' @param lightable_options Options to customize lightable. Similar with |
| 11 | #' `bootstrap_options` in `kable_styling`. Choices include `basic`, `striped` |
| 12 | #' and `hover`. |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 13 | #' @param ... Everything else you need to specify in `kable_styling`. |
| 14 | #' |
| 15 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 16 | kable_classic <- function( |
| 17 | kable_input, lightable_options = "basic", |
| 18 | html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) { |
| 19 | kable_light(kable_input, "lightable-classic", |
| 20 | lightable_options, html_font, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | #' @rdname kable_classic |
| 24 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 25 | kable_classic_2 <- function( |
| 26 | kable_input, lightable_options = "basic", |
| 27 | html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) { |
| 28 | kable_light(kable_input, "lightable-classic-2", |
| 29 | lightable_options, html_font, ...) |
Hao Zhu | d8a2e33 | 2020-08-11 01:26:32 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | #' @rdname kable_classic |
| 33 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 34 | kable_minimal <- function( |
| 35 | kable_input, lightable_options = "basic", |
| 36 | html_font = 'calibri, cambria, "Source Sans Pro", sans-serif', ...) { |
| 37 | kable_light(kable_input, "lightable-minimal", |
| 38 | lightable_options, html_font, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | #' @rdname kable_classic |
| 42 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 43 | kable_material <- function( |
| 44 | kable_input, lightable_options = "basic", |
| 45 | html_font = '"Source Sans Pro", helvetica, sans-serif', ...) { |
| 46 | kable_light(kable_input, "lightable-material", |
| 47 | lightable_options, html_font, ...) |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 50 | #' @rdname kable_classic |
| 51 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 52 | kable_material_dark <- function( |
| 53 | kable_input, lightable_options = "basic", |
| 54 | html_font = '"Source Sans Pro", helvetica, sans-serif', ...) { |
| 55 | kable_light(kable_input, "lightable-material-dark", |
| 56 | lightable_options, html_font, ...) |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 59 | #' @rdname kable_classic |
| 60 | #' @export |
| 61 | kable_paper <- function( |
| 62 | kable_input, lightable_options = "basic", |
| 63 | html_font = '"Arial Narrow", arial, helvetica, sans-serif', ...) { |
| 64 | kable_light(kable_input, "lightable-paper", lightable_options, |
| 65 | html_font, ...) |
| 66 | } |
| 67 | |
| 68 | kable_light <- function(kable_input, light_class, lightable_options, |
| 69 | html_font = NULL, ...) { |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 70 | lightable_options <- match.arg(lightable_options, |
| 71 | choices = c("basic", "striped", "hover"), |
| 72 | several.ok = TRUE) |
| 73 | if ("striped" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 74 | light_class <- paste(light_class, "lightable-striped") |
| 75 | } |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 76 | if ("hover" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 77 | light_class <- paste(light_class, "lightable-hover") |
| 78 | } |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 79 | out <- kable_styling(kable_input, "none", htmltable_class = light_class, |
| 80 | html_font = html_font, ...) |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 81 | attr(out, "lightable") <- TRUE |
| 82 | attr(out, "lightable_class") <- light_class |
| 83 | return(out) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 84 | } |