blob: e4ed2a3236c948586287b464446fbec6aee316ad [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 Zhu8f46db82020-08-18 21:48:23 -040013#' @param html_font A string for HTML css font. For example,
14#' `html_font = '"Arial Narrow", arial, helvetica, sans-serif'`.
Hao Zhuad4ea392020-08-10 01:24:50 -040015#' @param ... Everything else you need to specify in `kable_styling`.
16#'
17#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040018kable_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 Zhuad4ea392020-08-10 01:24:50 -040023}
24
25#' @rdname kable_classic
26#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040027kable_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 Zhud8a2e332020-08-11 01:26:32 -040032}
33
34#' @rdname kable_classic
35#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040036kable_minimal <- function(
37 kable_input, lightable_options = "basic",
Hao Zhu8b16a6c2020-08-18 16:59:20 -040038 html_font = '"Trebuchet MS", verdana, calibri, sans-serif', ...) {
Hao Zhu33b865f2020-08-18 02:10:43 -040039 kable_light(kable_input, "lightable-minimal",
40 lightable_options, html_font, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040041}
42
43#' @rdname kable_classic
44#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040045kable_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 Zhu81c335c2020-08-10 09:20:41 -040050}
51
Hao Zhu9bf19982020-08-11 00:50:33 -040052#' @rdname kable_classic
53#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040054kable_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 Zhu9bf19982020-08-11 00:50:33 -040059}
60
Hao Zhu33b865f2020-08-18 02:10:43 -040061#' @rdname kable_classic
62#' @export
63kable_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
70kable_light <- function(kable_input, light_class, lightable_options,
71 html_font = NULL, ...) {
Hao Zhud7762a42020-08-10 09:05:47 -040072 lightable_options <- match.arg(lightable_options,
73 choices = c("basic", "striped", "hover"),
74 several.ok = TRUE)
75 if ("striped" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040076 light_class <- paste(light_class, "lightable-striped")
77 }
Hao Zhud7762a42020-08-10 09:05:47 -040078 if ("hover" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040079 light_class <- paste(light_class, "lightable-hover")
80 }
Hao Zhu33b865f2020-08-18 02:10:43 -040081 out <- kable_styling(kable_input, "none", htmltable_class = light_class,
82 html_font = html_font, ...)
Hao Zhu81c335c2020-08-10 09:20:41 -040083 attr(out, "lightable") <- TRUE
84 attr(out, "lightable_class") <- light_class
85 return(out)
Hao Zhuad4ea392020-08-10 01:24:50 -040086}