Skip to content

Commit

Permalink
Merge pull request #270 from ThomasChln/master
Browse files Browse the repository at this point in the history
Responsive f7Grid
  • Loading branch information
DivadNojnarg authored Dec 4, 2024
2 parents 42650f8 + 1846ca9 commit 578dcb0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
21 changes: 20 additions & 1 deletion R/f7Grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@
#' @param ... Row content.
#' @param cols Columns number. Numeric between 1 and 20.
#' @param gap Whether to display gap between columns. TRUE by default.
#' @param responsiveCl Class for responsive behavior.
#' The format must be `<SIZE-NCOLS>` such as `<medium-4>`, `<large-3>`.
#' SIZE must be one of \code{c("xsmall", "small", "medium", "large", "xlarge")}.
#' NCOLS has to be between 1 and 20.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#' @export
f7Grid <- function(..., cols, gap = TRUE) {
f7Grid <- function(..., cols, gap = TRUE, responsiveCl = NULL) {

cl <- sprintf("grid grid-cols-%s", cols)

if (!is.null(responsiveCl)) {
# Format must be: <SIZE-NCOLS> like, <medium-4>, <large-3>
tmp <- strsplit(responsiveCl, "-")[[1]]
breakpoint <- tmp[1]
ncols <- as.numeric(tmp[2])
stopifnot(
ncols >= 1 && ncols <= 20,
breakpoint %in% c("xsmall", "small", "medium", "large", "xlarge")
)
cl <- paste(cl, sprintf("%s-grid-cols-%s", breakpoint, ncols))
}

if (gap) cl <- paste(cl, "grid-gap")

shiny::tags$div(class = cl, ...)
}
7 changes: 6 additions & 1 deletion man/f7Grid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/testthat/test-f7Grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@ test_that("grid works", {

grid <- f7Grid(cols = 2, gap = FALSE)
expect_identical(grid$attribs$class, "grid grid-cols-2")


# responsiveCl
grid <- f7Grid(cols = 2, responsiveCl = 'xsmall-1')
expect_identical(grid$attribs$class, "grid grid-cols-2 xsmall-grid-cols-1 grid-gap")

grid <- f7Grid(cols = 2, responsiveCl = 'small-2')
expect_identical(grid$attribs$class, "grid grid-cols-2 small-grid-cols-2 grid-gap")

grid <- f7Grid(cols = 2, responsiveCl = 'medium-4')
expect_identical(grid$attribs$class, "grid grid-cols-2 medium-grid-cols-4 grid-gap")

grid <- f7Grid(cols = 2, responsiveCl = 'large-6')
expect_identical(grid$attribs$class, "grid grid-cols-2 large-grid-cols-6 grid-gap")

grid <- f7Grid(cols = 2, responsiveCl = 'xlarge-8')
expect_identical(grid$attribs$class, "grid grid-cols-2 xlarge-grid-cols-8 grid-gap")
})

0 comments on commit 578dcb0

Please sign in to comment.