blob: 4200dac41c416538fccfaeca46108141724fe2f2 [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 Zhu33b865f2020-08-18 02:10:43 -040016kable_classic <- function(
17 kable_input, lightable_options = "basic",
18 html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) {
19 kable_light(kable_input, "lightable-classic",
20 lightable_options, html_font, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040021}
22
23#' @rdname kable_classic
24#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040025kable_classic_2 <- function(
26 kable_input, lightable_options = "basic",
27 html_font = '"Arial Narrow", "Source Sans Pro", sans-serif', ...) {
28 kable_light(kable_input, "lightable-classic-2",
29 lightable_options, html_font, ...)
Hao Zhud8a2e332020-08-11 01:26:32 -040030}
31
32#' @rdname kable_classic
33#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040034kable_minimal <- function(
35 kable_input, lightable_options = "basic",
36 html_font = 'calibri, cambria, "Source Sans Pro", sans-serif', ...) {
37 kable_light(kable_input, "lightable-minimal",
38 lightable_options, html_font, ...)
Hao Zhuad4ea392020-08-10 01:24:50 -040039}
40
41#' @rdname kable_classic
42#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040043kable_material <- function(
44 kable_input, lightable_options = "basic",
45 html_font = '"Source Sans Pro", helvetica, sans-serif', ...) {
46 kable_light(kable_input, "lightable-material",
47 lightable_options, html_font, ...)
Hao Zhu81c335c2020-08-10 09:20:41 -040048}
49
Hao Zhu9bf19982020-08-11 00:50:33 -040050#' @rdname kable_classic
51#' @export
Hao Zhu33b865f2020-08-18 02:10:43 -040052kable_material_dark <- function(
53 kable_input, lightable_options = "basic",
54 html_font = '"Source Sans Pro", helvetica, sans-serif', ...) {
55 kable_light(kable_input, "lightable-material-dark",
56 lightable_options, html_font, ...)
Hao Zhu9bf19982020-08-11 00:50:33 -040057}
58
Hao Zhu33b865f2020-08-18 02:10:43 -040059#' @rdname kable_classic
60#' @export
61kable_paper <- function(
62 kable_input, lightable_options = "basic",
63 html_font = '"Arial Narrow", arial, helvetica, sans-serif', ...) {
64 kable_light(kable_input, "lightable-paper", lightable_options,
65 html_font, ...)
66}
67
68kable_light <- function(kable_input, light_class, lightable_options,
69 html_font = NULL, ...) {
Hao Zhud7762a42020-08-10 09:05:47 -040070 lightable_options <- match.arg(lightable_options,
71 choices = c("basic", "striped", "hover"),
72 several.ok = TRUE)
73 if ("striped" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040074 light_class <- paste(light_class, "lightable-striped")
75 }
Hao Zhud7762a42020-08-10 09:05:47 -040076 if ("hover" %in% lightable_options) {
Hao Zhuad4ea392020-08-10 01:24:50 -040077 light_class <- paste(light_class, "lightable-hover")
78 }
Hao Zhu33b865f2020-08-18 02:10:43 -040079 out <- kable_styling(kable_input, "none", htmltable_class = light_class,
80 html_font = html_font, ...)
Hao Zhu81c335c2020-08-10 09:20:41 -040081 attr(out, "lightable") <- TRUE
82 attr(out, "lightable_class") <- light_class
83 return(out)
Hao Zhuad4ea392020-08-10 01:24:50 -040084}