Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame^] | 1 | #' HTML table attributes |
| 2 | #' |
| 3 | #' @description This function provides a set of shortcuts to common HTML table |
| 4 | #' formats |
| 5 | #' |
| 6 | #' @param bootstrap_options Common HTML table formats |
| 7 | #' @param font_size |
| 8 | #' |
| 9 | #' @export |
| 10 | htmlTable_styling <- function(bootstrap_options = "bs-table", |
| 11 | font_size = NULL, full_width = T) { |
| 12 | bootstrap_options <- match.arg( |
| 13 | bootstrap_options, |
| 14 | c("bs-table", "striped", "bordered", "hover", "condensed", "responsive"), |
| 15 | several.ok = T |
| 16 | ) |
| 17 | |
| 18 | table_attr_class <- character() |
| 19 | if (length(bootstrap_options) == 1 && bootstrap_options == "bs-table") { |
| 20 | table_attr_class <- "class='table'" |
| 21 | } else { |
| 22 | bootstrap_options <- bootstrap_options[bootstrap_options != "bs-table"] |
| 23 | bootstrap_options <- paste0("table-", bootstrap_options) |
| 24 | table_attr_class <- paste0("class='table ", |
| 25 | paste0(bootstrap_options, collapse = " "), "'") |
| 26 | } |
| 27 | |
| 28 | table_attr_style <- c() |
| 29 | if (!is.null(font_size)) { |
| 30 | table_attr_style <- c(table_attr_style, |
| 31 | paste0("font-size: ", font_size, "px;")) |
| 32 | } |
| 33 | if (!full_width) { |
| 34 | table_attr_style <- c(table_attr_style, "width: auto !important;") |
| 35 | } |
| 36 | if (length(table_attr_style) != 0) { |
| 37 | table_attr_style <- paste0("style = '", |
| 38 | paste0(table_attr_style, collapse = " "), "'") |
| 39 | } |
| 40 | return(paste(table_attr_class, table_attr_style)) |
| 41 | } |