blob: 94aa826cb6be1aca76dc5fe78814029ecbb37f4c [file] [log] [blame]
Hao Zhuad4ea392020-08-10 01:24:50 -04001#' 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 Zhu9bf19982020-08-11 00:50:33 -04006#' namely `lightable-minimal`, `lightable-classic`, `lightable-material` and
7#' `lightable-material-dark` with `hover` and `striped` options.
Hao Zhuad4ea392020-08-10 01:24:50 -04008#'
9#' @param kable_input A HTML kable object.
Hao Zhud7762a42020-08-10 09:05:47 -040010#' @param lightable_options Options to customize lightable. Similar with
11#' `bootstrap_options` in `kable_styling`. Choices include `basic`, `striped`
12#' and `hover`.
Hao Zhuad4ea392020-08-10 01:24:50 -040013#' @param ... Everything else you need to specify in `kable_styling`.
14#'
15#' @export
Hao Zhud7762a42020-08-10 09:05:47 -040016kable_classic <- function(kable_input, lightable_options = "basic", ...) {
Hao Zhu81c335c2020-08-10 09:20:41 -040017 kable_light(kable_input, "lightable-classic", lightable_options, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040018}
19
20#' @rdname kable_classic
21#' @export
Hao Zhud8a2e332020-08-11 01:26:32 -040022kable_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 Zhud7762a42020-08-10 09:05:47 -040028kable_minimal <- function(kable_input, lightable_options = "basic", ...) {
Hao Zhu81c335c2020-08-10 09:20:41 -040029 kable_light(kable_input, "lightable-minimal", lightable_options, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040030}
31
32#' @rdname kable_classic
33#' @export
Hao Zhud7762a42020-08-10 09:05:47 -040034kable_material <- function(kable_input, lightable_options = "basic", ...) {
Hao Zhu81c335c2020-08-10 09:20:41 -040035 kable_light(kable_input, "lightable-material", lightable_options, ...)
36}
37
Hao Zhu9bf19982020-08-11 00:50:33 -040038#' @rdname kable_classic
39#' @export
40kable_material_dark <- function(kable_input, lightable_options = "basic", ...) {
41 kable_light(kable_input, "lightable-material-dark", lightable_options, ...)
42}
43
Hao Zhu81c335c2020-08-10 09:20:41 -040044kable_light <- function(kable_input, light_class, lightable_options, ...) {
Hao Zhud7762a42020-08-10 09:05:47 -040045 lightable_options <- match.arg(lightable_options,
46 choices = c("basic", "striped", "hover"),
47 several.ok = TRUE)
48 if ("striped" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040049 light_class <- paste(light_class, "lightable-striped")
50 }
Hao Zhud7762a42020-08-10 09:05:47 -040051 if ("hover" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040052 light_class <- paste(light_class, "lightable-hover")
53 }
Hao Zhu3676fe22020-08-11 19:42:42 -040054 out <- kable_styling(kable_input, "none", htmltable_class = light_class, ...)
Hao Zhu81c335c2020-08-10 09:20:41 -040055 attr(out, "lightable") <- TRUE
56 attr(out, "lightable_class") <- light_class
57 return(out)
Hao Zhuad4ea392020-08-10 01:24:50 -040058}