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