Skip to content

Commit

Permalink
fix(flex): arguments default to NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
nteetor committed Nov 26, 2020
1 parent e6d6724 commit 83137f0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
30 changes: 16 additions & 14 deletions R/flex.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ flex_wrap <- function(wrap) {
#' @param direction A [responsive] argument.
#'
#' One of `r rd_list(names(flex_direction_))` specifying the main axis of
#' flex items, defaults to `"row"`.
#' flex items, defaults to `NULL`, in which case the argument is ignored.
#'
#' If `"row"`, the main axis is horizontal and items are arranged from left to
#' right. The cross axis is the vertical.
Expand All @@ -64,21 +64,24 @@ flex_wrap <- function(wrap) {
#'
#' @param justify A [responsive] argument.
#'
#' One of `r rd_list(names(flex_justify_))` specifying how items are
#' arranged on the main axis, defaults to `"start"`.
#' One of `r rd_list(names(flex_justify_))` specifying how items are arranged
#' on the main axis, defaults to `NULL`, in which case the argument is
#' ignored.
#'
#' If `"between"` or `"around"`, items are arranged by evenly sharing the
#' space between or around the items.
#' If `"between"`, `"around"`, or `"evenly"` then items are arranged by
#' distributing the space available on the main axis in-between the element's
#' flex items.
#'
#' @param align A [responsive] argument.
#'
#' One of `r rd_list(names(flex_align_))` specifying how items are
#' arranged on the cross axis, defaults to `"stretch"`.
#' One of `r rd_list(names(flex_align_))` specifying how items are arranged on
#' the cross axis, defaults to `NULL`, in which case the argument is ignored.
#'
#' @param wrap A [responsive] argument.
#'
#' One of `TRUE` or `FALSE` specifying if items are forced onto one line
#' or allowed to wrap onto multiple lines, defaults to `FALSE`.
#' One of `TRUE` or `FALSE` specifying if items are forced onto one line or
#' allowed to wrap onto multiple lines, defaults to `NULL`, in which case the
#' argument is ignored.
#'
#' @includeRmd man/roxygen/flex.Rmd
#'
Expand All @@ -95,8 +98,8 @@ flex_wrap <- function(wrap) {
#' div("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.")
#' )
#'
flex <- function(x, direction = "row", justify = "start", align = "stretch",
wrap = FALSE) {
flex <- function(x, direction = NULL, justify = NULL, align = NULL,
wrap = NULL) {
assert_subject(x)

classes <- prefix(
Expand Down Expand Up @@ -141,10 +144,9 @@ item_fill <- function(fill) {
abortf("invalid value, expecting %s or %s", "NULL", "TRUE")
}

## fill[fill] <- "fill"
fill[fill] <- "fill"

## responsive(fill)
responsive(set_names(rep_along(fill, "fill"), names(fill)))
responsive(fill)
}

item_grow <- function(grow) {
Expand Down
2 changes: 1 addition & 1 deletion man/background.Rd

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

41 changes: 22 additions & 19 deletions man/flex.Rd

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

22 changes: 18 additions & 4 deletions tests/testthat/test-flex.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
context("flex()")

test_that("no classes by default", {
flex(div()) %>%
expect_s3_class("shiny.tag") %>%
expect_html_class("")
})

test_that("adds classes", {
div() %>%
flex() %>%
flex(div(), direction = "row") %>%
expect_s3_class("shiny.tag") %>%
expect_html_class("cas-flex-row")

div(.style %>% flex()) %>%
div(.style %>% flex(wrap = TRUE)) %>%
expect_s3_class("shiny.tag") %>%
expect_html_class("cas-flex-row")
expect_html_class("cas-flex-wrap")
})

test_that("arguments are responsive", {
div() %>%
flex(
direction = c(default = "column", md = "row")
) %>%
expect_html_class("cas-flex-md-row") %>%
expect_html_class("cas-flex-column")
})

0 comments on commit 83137f0

Please sign in to comment.