blob: 63e578ddd0743a8bfd8ef404e67b33c20a042f39 [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,
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 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 Zhud7762a42020-08-10 09:05:47 -040022kable_minimal <- function(kable_input, lightable_options = "basic", ...) {
Hao Zhu81c335c2020-08-10 09:20:41 -040023 kable_light(kable_input, "lightable-minimal", lightable_options, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040024}
25
26#' @rdname kable_classic
27#' @export
Hao Zhud7762a42020-08-10 09:05:47 -040028kable_material <- function(kable_input, lightable_options = "basic", ...) {
Hao Zhu81c335c2020-08-10 09:20:41 -040029 kable_light(kable_input, "lightable-material", lightable_options, ...)
30}
31
32kable_light <- function(kable_input, light_class, lightable_options, ...) {
Hao Zhud7762a42020-08-10 09:05:47 -040033 lightable_options <- match.arg(lightable_options,
34 choices = c("basic", "striped", "hover"),
35 several.ok = TRUE)
36 if ("striped" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040037 light_class <- paste(light_class, "lightable-striped")
38 }
Hao Zhud7762a42020-08-10 09:05:47 -040039 if ("hover" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040040 light_class <- paste(light_class, "lightable-hover")
41 }
Hao Zhu81c335c2020-08-10 09:20:41 -040042 out <- kable_styling(kable_input, "none", lightable_class = light_class, ...)
43 attr(out, "lightable") <- TRUE
44 attr(out, "lightable_class") <- light_class
45 return(out)
Hao Zhuad4ea392020-08-10 01:24:50 -040046}