-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(visible): small utility function for visibility
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,6 @@ Collate: | |
'shadow.R' | ||
'text.R' | ||
'utils-docs.R' | ||
'visible.R' | ||
'width.R' | ||
'zzz.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
visible_value <- function(value) { | ||
if (is_true(value)) { | ||
"visible" | ||
} else if (is_false(value)) { | ||
"invisible" | ||
} | ||
} | ||
|
||
#' Element visibility | ||
#' | ||
#' The `visible()` function changes the visibility of a tag element. An | ||
#' invisible element is both visually hidden and is also hidden from screen | ||
#' readers. | ||
#' | ||
#' @inheritParams background | ||
#' | ||
#' @param value One of `TRUE` or `FALSE` specifying if the element is visible, | ||
#' defaults to `TRUE`. | ||
#' | ||
#' @export | ||
#' @examples | ||
#' | ||
#' library(htmltools) | ||
#' | ||
#' div("I am hidden") %>% | ||
#' visible(FALSE) | ||
#' | ||
visible <- function(x, value) { | ||
assert_subject(x) | ||
|
||
class <- visible_value(value) | ||
|
||
add_class(x, class) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
context("visible()") | ||
|
||
test_that("adds classes", { | ||
div() %>% | ||
visible(FALSE) %>% | ||
expect_html_class("invisible") | ||
|
||
div() %>% | ||
visible(TRUE) %>% | ||
expect_html_class("visible") | ||
}) |