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 | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 16 | kable_classic <- function(kable_input, lightable_options = "basic", ...) { |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 17 | kable_light(kable_input, "lightable-classic", lightable_options, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | #' @rdname kable_classic |
| 21 | #' @export |
Hao Zhu | d8a2e33 | 2020-08-11 01:26:32 -0400 | [diff] [blame] | 22 | kable_classic_2 <- function(kable_input, lightable_options = "basic", ...) { |
| 23 | kable_light(kable_input, "lightable-classic-2", lightable_options, ...) |
| 24 | } |
| 25 | |
| 26 | #' @rdname kable_classic |
| 27 | #' @export |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 28 | kable_minimal <- function(kable_input, lightable_options = "basic", ...) { |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 29 | kable_light(kable_input, "lightable-minimal", lightable_options, ...) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | #' @rdname kable_classic |
| 33 | #' @export |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 34 | kable_material <- function(kable_input, lightable_options = "basic", ...) { |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 35 | kable_light(kable_input, "lightable-material", lightable_options, ...) |
| 36 | } |
| 37 | |
Hao Zhu | 9bf1998 | 2020-08-11 00:50:33 -0400 | [diff] [blame] | 38 | #' @rdname kable_classic |
| 39 | #' @export |
| 40 | kable_material_dark <- function(kable_input, lightable_options = "basic", ...) { |
| 41 | kable_light(kable_input, "lightable-material-dark", lightable_options, ...) |
| 42 | } |
| 43 | |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 44 | kable_light <- function(kable_input, light_class, lightable_options, ...) { |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 45 | lightable_options <- match.arg(lightable_options, |
| 46 | choices = c("basic", "striped", "hover"), |
| 47 | several.ok = TRUE) |
| 48 | if ("striped" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 49 | light_class <- paste(light_class, "lightable-striped") |
| 50 | } |
Hao Zhu | d7762a4 | 2020-08-10 09:05:47 -0400 | [diff] [blame] | 51 | if ("hover" %in% lightable_options) { |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 52 | light_class <- paste(light_class, "lightable-hover") |
| 53 | } |
Hao Zhu | 3676fe2 | 2020-08-11 19:42:42 -0400 | [diff] [blame^] | 54 | out <- kable_styling(kable_input, "none", htmltable_class = light_class, ...) |
Hao Zhu | 81c335c | 2020-08-10 09:20:41 -0400 | [diff] [blame] | 55 | attr(out, "lightable") <- TRUE |
| 56 | attr(out, "lightable_class") <- light_class |
| 57 | return(out) |
Hao Zhu | ad4ea39 | 2020-08-10 01:24:50 -0400 | [diff] [blame] | 58 | } |