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 | 8f46db8 | 2020-08-18 21:48:23 -0400 | [diff] [blame^] | 13 | #' @param html_font A string for HTML css font. For example, |
| 14 | #' `html_font = '"Arial Narrow", arial, helvetica, sans-serif'`. |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 15 | #' @param ... Everything else you need to specify in `kable_styling`. |
| 16 | #' |
| 17 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 18 | kable_classic <- function( |
| 19 | kable_input, lightable_options = "basic", |
| 20 | html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) { |
| 21 | kable_light(kable_input, "lightable-classic", |
| 22 | lightable_options, html_font, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | #' @rdname kable_classic |
| 26 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 27 | kable_classic_2 <- function( |
| 28 | kable_input, lightable_options = "basic", |
| 29 | html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) { |
| 30 | kable_light(kable_input, "lightable-classic-2", |
| 31 | lightable_options, html_font, ...) |
Hao Zhu | d8a2e33 | 2020-08-11 01:26:32 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | #' @rdname kable_classic |
| 35 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 36 | kable_minimal <- function( |
| 37 | kable_input, lightable_options = "basic", |
Hao Zhu | 8b16a6c | 2020-08-18 16:59:20 -0400 | [diff] [blame] | 38 | html_font = '"Trebuchet MS", verdana, calibri, sans-serif', ...) { |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 39 | kable_light(kable_input, "lightable-minimal", |
| 40 | lightable_options, html_font, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | #' @rdname kable_classic |
| 44 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 45 | kable_material <- function( |
| 46 | kable_input, lightable_options = "basic", |
| 47 | html_font = '"Source Sans Pro", helvetica, sans-serif', ...) { |
| 48 | kable_light(kable_input, "lightable-material", |
| 49 | lightable_options, html_font, ...) |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 52 | #' @rdname kable_classic |
| 53 | #' @export |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 54 | kable_material_dark <- function( |
| 55 | kable_input, lightable_options = "basic", |
| 56 | html_font = '"Source Sans Pro", helvetica, sans-serif', ...) { |
| 57 | kable_light(kable_input, "lightable-material-dark", |
| 58 | lightable_options, html_font, ...) |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 61 | #' @rdname kable_classic |
| 62 | #' @export |
| 63 | kable_paper <- function( |
| 64 | kable_input, lightable_options = "basic", |
| 65 | html_font = '"Arial Narrow", arial, helvetica, sans-serif', ...) { |
| 66 | kable_light(kable_input, "lightable-paper", lightable_options, |
| 67 | html_font, ...) |
| 68 | } |
| 69 | |
| 70 | kable_light <- function(kable_input, light_class, lightable_options, |
| 71 | html_font = NULL, ...) { |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 72 | lightable_options <- match.arg(lightable_options, |
| 73 | choices = c("basic", "striped", "hover"), |
| 74 | several.ok = TRUE) |
| 75 | if ("striped" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 76 | light_class <- paste(light_class, "lightable-striped") |
| 77 | } |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 78 | if ("hover" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 79 | light_class <- paste(light_class, "lightable-hover") |
| 80 | } |
Hao Zhu | 33b865f | 2020-08-18 02:10:43 -0400 | [diff] [blame] | 81 | out <- kable_styling(kable_input, "none", htmltable_class = light_class, |
| 82 | html_font = html_font, ...) |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 83 | attr(out, "lightable") <- TRUE |
| 84 | attr(out, "lightable_class") <- light_class |
| 85 | return(out) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 86 | } |