Skip to content

Commit

Permalink
bugfix style_bootstrap lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 16, 2024
1 parent 540286d commit 85c8f51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ style_tt_lazy <- function (x,
tabularray_inner = tabularray_inner, tabularray_outer = tabularray_outer)

for (k in seq_len(nrow(settings))) {
out <- style_bootstrap(out, i = settings$i[k], j = settings$j[k], css = bootstrap_css)
out <- style_bootstrap(out, i = settings$i[k], j = settings$j[k], css = settings$bootstrap[k])
out <- style_bootstrap(x = out, i = settings$i[k], j = settings$j[k], css = bootstrap_css)
out <- style_bootstrap(x = out, i = settings$i[k], j = settings$j[k], css = settings$bootstrap[k])
}

if (!is.null(bootstrap_css) || !is.null(bootstrap_css_rule)) {
out <- style_bootstrap(
i = ival, j = jval,
x = out, i = ival, j = jval,
css = bootstrap_css, css_rule = bootstrap_css_rule)
}

Expand Down
12 changes: 8 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ meta <- function(x, get, set) {
# style_tt() stores style calls and we only want to evaluate them at the end because
# some rows may be added, which changes how the style is applied
eval_style <- function(x) {
lazy_style <- meta(x)$lazy_style
out <- x

ls <- meta(out)$lazy_style
# drop lazy styles from output to avoid weirdness
m <- meta(x)
m$lazy_style <- NULL
attr(out, "tinytable_meta") <- m

for (lazy_style in meta(out)$lazy_style) {
lazy_style[["x"]] <- out
out <- eval(lazy_style)
for (l in lazy_style) {
l[["x"]] <- out
out <- eval(l)
}

return(out)
Expand Down
1 change: 1 addition & 0 deletions vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ tt(x, theme = "table table-striped table-warning table-hover")
The `style_tt()` function allows us to declare CSS properties and values for individual cells, columns, or rows of a table. For example, if we want to make the first column bold, we could do:

```{r}
x <- mtcars[1:4, 1:5]
tt(x) |>
style_tt(j = 1, bootstrap_css = "font-weight: bold; color: red;")
```
Expand Down

0 comments on commit 85c8f51

Please sign in to comment.