diff --git a/NAMESPACE b/NAMESPACE index 0d01b4dd..2fa76587 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -114,8 +114,6 @@ export(f7Tooltip) export(f7ValidateInput) export(f7VirtualList) export(f7VirtualListItem) -export(f7checkBox) -export(f7checkBoxGroup) export(getF7Colors) export(hideF7Preloader) export(insertF7Tab) @@ -129,7 +127,6 @@ export(updateF7App) export(updateF7AutoComplete) export(updateF7Button) export(updateF7Card) -export(updateF7Checkbox) export(updateF7DatePicker) export(updateF7Entity) export(updateF7Fab) diff --git a/NEWS.md b/NEWS.md index 1ee09d2a..6ef71cb7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ - `f7AddMessages()` is definitely removed. Deprecated from previous releases. - `f7Appbar()` has been removed in Framework7. We have no alternative to replace it. - `f7ShowNavbar()` and `f7HideNavbar()` are removed, as long time deprecated. +- `f7checkBox()` and `f7checkBoxGroup()` are removed, as long time deprecated. ## Deprecation - `f7Accordion()`: @@ -27,6 +28,8 @@ We now return an object of objects which becomes a list of lists. - `f7Block()` gains an `outline` parameter (add grey border). - `f7Button()` get a new `tonal` style. - `f7Card()` get a new `raised` and `divider` parameters. +- `f7CheckboxGroup()` has a new `position` parameter to control +the check icon position. Default to left. - Fix various issues in documentation. # shinyMobile 1.0.1 diff --git a/R/f7-inputs.R b/R/f7-inputs.R index 2e4b1225..41c48276 100644 --- a/R/f7-inputs.R +++ b/R/f7-inputs.R @@ -905,34 +905,7 @@ updateF7DatePicker <- function(inputId, value = NULL, ..., #' @param value Initial value (TRUE or FALSE). #' #' @rdname checkbox -#' @examples -#' if (interactive()) { -#' library(shiny) -#' library(shinyMobile) -#' -#' shinyApp( -#' ui = f7Page( -#' title = "My app", -#' f7SingleLayout( -#' navbar = f7Navbar(title = "f7Checkbox"), -#' f7Card( -#' f7Checkbox( -#' inputId = "check", -#' label = "Checkbox", -#' value = FALSE -#' ), -#' verbatimTextOutput("test") -#' ) -#' ) -#' ), -#' server = function(input, output) { -#' output$test <- renderPrint({ -#' input$check -#' }) -#' } -#' ) -#' } -#' # +#' @example inst/examples/checkbox/app.R #' @export f7Checkbox <- function(inputId, label, value = FALSE) { value <- shiny::restoreInput(id = inputId, default = value) @@ -950,95 +923,21 @@ f7Checkbox <- function(inputId, label, value = FALSE) { ) } - - -#' Deprecated functions -#' -#' \code{f7checkBox} creates a checkbox input. Use \link{f7Checkbox} instead. -#' -#' @rdname f7-deprecated -#' @inheritParams f7checkBoxGroup -#' @keywords internal -#' @export -f7checkBox <- function(inputId, label, value = FALSE) { - .Deprecated( - "f7Checkbox", - package = "shinyMobile", - "f7checkBox will be removed in future release. Please use - f7Checkbox instead.", - old = as.character(sys.call(sys.parent()))[1L] - ) - f7Checkbox(inputId, label, value) -} - - #' Update Framework7 checkbox #' #' \code{updateF7Checkbox} changes the value of a checkbox input on the client. #' #' @rdname checkbox #' @param inputId The id of the input object. -#' @param label The label to set for the input object. +#' @param label The label to set for the input object. Does not work. #' @param value The value to set for the input object. #' @param session The Shiny session object. -#' -#' @export -#' -#' @examples -#' if (interactive()) { -#' library(shiny) -#' library(shinyMobile) -#' -#' ui <- f7Page( -#' f7SingleLayout( -#' navbar = f7Navbar(title = "updateF7CheckBox"), -#' f7Slider( -#' inputId = "controller", -#' label = "Number of observations", -#' max = 10, -#' min = 0, -#' value = 1, -#' step = 1, -#' scale = TRUE -#' ), -#' f7checkBox( -#' inputId = "check", -#' label = "Checkbox" -#' ) -#' ) -#' ) -#' -#' server <- function(input, output, session) { -#' observe({ -#' # TRUE if input$controller is odd, FALSE if even. -#' x_even <- input$controller %% 2 == 1 -#' -#' if (x_even) { -#' showNotification( -#' id = "notif", -#' paste("The slider is ", input$controller, "and the checkbox is", input$check), -#' duration = NULL, -#' type = "warning" -#' ) -#' } else { -#' removeNotification("notif") -#' } -#' -#' updateF7Checkbox("check", value = x_even) -#' }) -#' } -#' -#' shinyApp(ui, server) -#' } updateF7Checkbox <- function(inputId, label = NULL, value = NULL, session = shiny::getDefaultReactiveDomain()) { message <- dropNulls(list(label = label, value = value)) session$sendInputMessage(inputId, message) } - - - #' Framework7 checkbox group #' #' \code{f7CheckboxGroup} creates a checkbox group input @@ -1047,50 +946,33 @@ updateF7Checkbox <- function(inputId, label = NULL, value = NULL, #' @param label Checkbox group label. #' @param choices Checkbox group choices. #' @param selected Checkbox group selected value. +#' @param position Check mark position. +#' \code{"left"} or \code{"right"}. #' #' @export #' @rdname checkboxgroup #' -#' @examples -#' if (interactive()) { -#' library(shiny) -#' library(shinyMobile) -#' -#' shiny::shinyApp( -#' ui = f7Page( -#' title = "My app", -#' f7SingleLayout( -#' navbar = f7Navbar(title = "f7CheckboxGroup"), -#' f7CheckboxGroup( -#' inputId = "variable", -#' label = "Choose a variable:", -#' choices = colnames(mtcars)[-1], -#' selected = NULL -#' ), -#' tableOutput("data") -#' ) -#' ), -#' server = function(input, output) { -#' output$data <- renderTable( -#' { -#' mtcars[, c("mpg", input$variable), drop = FALSE] -#' }, -#' rownames = TRUE -#' ) -#' } -#' ) -#' } -f7CheckboxGroup <- function(inputId, label, choices = NULL, selected = NULL) { +#' @example inst/examples/checkboxgroup/app.R +f7CheckboxGroup <- function( + inputId, label, choices = NULL, selected = NULL, + position = c("left", "right")) { + position <- match.arg(position) + position <- switch(position, + "left" = "start", + "right" = "end" + ) selectedPosition <- if (!is.null(selected)) match(selected, choices) else NULL - choicesTag <- lapply(X = seq_along(choices), function(i) { shiny::tags$li( shiny::tags$label( - class = "item-checkbox item-content", + class = sprintf("item-checkbox item-checkbox-icon-%s item-content", position), shiny::tags$input( type = "checkbox", name = inputId, - value = choices[[i]] + value = choices[[i]], + checked = if (!is.null(selectedPosition)) { + if (i == selectedPosition) NA + } ), shiny::tags$i(class = "icon icon-checkbox"), shiny::tags$div( @@ -1101,15 +983,13 @@ f7CheckboxGroup <- function(inputId, label, choices = NULL, selected = NULL) { ) }) - if (!is.null(selected)) choicesTag[[selectedPosition]]$children[[1]]$children[[1]]$attribs[["checked"]] <- NA - shiny::tagList( shiny::tags$div( class = "block-title", label ), shiny::tags$div( - class = "list shiny-input-checkboxgroup", + class = "list list-strong-ios list-outline-ios list-dividers-ios shiny-input-checkboxgroup", id = inputId, shiny::tags$ul( choicesTag @@ -1118,32 +998,6 @@ f7CheckboxGroup <- function(inputId, label, choices = NULL, selected = NULL) { ) } - - -#' Deprecated functions -#' -#' \code{f7checkBoxGroup} creates a checkbox group input. -#' Use \link{f7CheckboxGroup} instead -#' -#' @rdname f7-deprecated -#' @inheritParams f7checkBoxGroup -#' @keywords internal -#' @export -f7checkBoxGroup <- function(inputId, label, choices = NULL, selected = NULL) { - .Deprecated( - "f7CheckboxGroup", - package = "shinyMobile", - "f7checkBoxGroup will be removed in future release. Please use - f7CheckboxGroup instead.", - old = as.character(sys.call(sys.parent()))[1L] - ) - - f7CheckboxGroup(inputId, label, choices, selected) -} - - - - #' Create option html tag based on choice input #' #' Used by \link{f7SmartSelect} and \link{f7Select} diff --git a/_pkgdown.yml b/_pkgdown.yml index 9de0d110..36e4d476 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -68,9 +68,7 @@ reference: desc: slider, radio, checkboxes, ... contents: - '`f7AutoComplete`' - - '`f7checkBox`' - '`f7Checkbox`' - - '`f7checkBoxGroup`' - '`f7CheckboxGroup`' - '`f7ColorPicker`' - '`f7DatePicker`' diff --git a/inst/examples/checkbox/app.R b/inst/examples/checkbox/app.R new file mode 100644 index 00000000..4ce9d067 --- /dev/null +++ b/inst/examples/checkbox/app.R @@ -0,0 +1,22 @@ +library(shiny) +library(shinyMobile) + +app <- shinyApp( + ui = f7Page( + f7SingleLayout( + navbar = f7Navbar(title = "updateF7Checkbox"), + f7Block(f7Button("update", "Toggle checkbox")), + f7Checkbox( + inputId = "checkbox", + label = "Checkbox", + value = FALSE + ) + ) + ), server = function(input, output, session) { + observeEvent(input$update, { + updateF7Checkbox("checkbox", value = !input$checkbox) + }) + } +) + +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app diff --git a/inst/examples/checkboxgroup/app.R b/inst/examples/checkboxgroup/app.R new file mode 100644 index 00000000..63c2d8ce --- /dev/null +++ b/inst/examples/checkboxgroup/app.R @@ -0,0 +1,29 @@ +library(shiny) +library(shinyMobile) + +app <- shinyApp( + ui = f7Page( + title = "My app", + f7SingleLayout( + navbar = f7Navbar(title = "f7CheckboxGroup"), + f7CheckboxGroup( + inputId = "checkboxgroup", + label = "Choose a variable:", + choices = colnames(mtcars)[-1], + selected = "disp", + position = "right" + ), + tableOutput("data") + ) + ), + server = function(input, output) { + output$data <- renderTable( + { + mtcars[, c("mpg", input$checkboxgroup), drop = FALSE] + }, + rownames = TRUE + ) + } +) + +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app diff --git a/man/checkbox.Rd b/man/checkbox.Rd index 97e630c4..4219025a 100644 --- a/man/checkbox.Rd +++ b/man/checkbox.Rd @@ -17,7 +17,7 @@ updateF7Checkbox( \arguments{ \item{inputId}{The id of the input object.} -\item{label}{The label to set for the input object.} +\item{label}{The label to set for the input object. Does not work.} \item{value}{The value to set for the input object.} @@ -29,76 +29,26 @@ updateF7Checkbox( \code{updateF7Checkbox} changes the value of a checkbox input on the client. } \examples{ -if (interactive()) { - library(shiny) - library(shinyMobile) +library(shiny) +library(shinyMobile) - shinyApp( - ui = f7Page( - title = "My app", - f7SingleLayout( - navbar = f7Navbar(title = "f7Checkbox"), - f7Card( - f7Checkbox( - inputId = "check", - label = "Checkbox", - value = FALSE - ), - verbatimTextOutput("test") - ) - ) - ), - server = function(input, output) { - output$test <- renderPrint({ - input$check - }) - } - ) -} -# -if (interactive()) { - library(shiny) - library(shinyMobile) - - ui <- f7Page( +app <- shinyApp( + ui = f7Page( f7SingleLayout( - navbar = f7Navbar(title = "updateF7CheckBox"), - f7Slider( - inputId = "controller", - label = "Number of observations", - max = 10, - min = 0, - value = 1, - step = 1, - scale = TRUE - ), - f7checkBox( - inputId = "check", - label = "Checkbox" + navbar = f7Navbar(title = "updateF7Checkbox"), + f7Block(f7Button("update", "Toggle checkbox")), + f7Checkbox( + inputId = "checkbox", + label = "Checkbox", + value = FALSE ) ) - ) - - server <- function(input, output, session) { - observe({ - # TRUE if input$controller is odd, FALSE if even. - x_even <- input$controller \%\% 2 == 1 - - if (x_even) { - showNotification( - id = "notif", - paste("The slider is ", input$controller, "and the checkbox is", input$check), - duration = NULL, - type = "warning" - ) - } else { - removeNotification("notif") - } - - updateF7Checkbox("check", value = x_even) + ), server = function(input, output, session) { + observeEvent(input$update, { + updateF7Checkbox("checkbox", value = !input$checkbox) }) } +) - shinyApp(ui, server) -} +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app } diff --git a/man/checkboxgroup.Rd b/man/checkboxgroup.Rd index 608bbc14..26327f42 100644 --- a/man/checkboxgroup.Rd +++ b/man/checkboxgroup.Rd @@ -4,7 +4,13 @@ \alias{f7CheckboxGroup} \title{Framework7 checkbox group} \usage{ -f7CheckboxGroup(inputId, label, choices = NULL, selected = NULL) +f7CheckboxGroup( + inputId, + label, + choices = NULL, + selected = NULL, + position = c("left", "right") +) } \arguments{ \item{inputId}{Checkbox group input.} @@ -14,37 +20,41 @@ f7CheckboxGroup(inputId, label, choices = NULL, selected = NULL) \item{choices}{Checkbox group choices.} \item{selected}{Checkbox group selected value.} + +\item{position}{Check mark position. +\code{"left"} or \code{"right"}.} } \description{ \code{f7CheckboxGroup} creates a checkbox group input } \examples{ -if (interactive()) { - library(shiny) - library(shinyMobile) +library(shiny) +library(shinyMobile) - shiny::shinyApp( - ui = f7Page( - title = "My app", - f7SingleLayout( - navbar = f7Navbar(title = "f7CheckboxGroup"), - f7CheckboxGroup( - inputId = "variable", - label = "Choose a variable:", - choices = colnames(mtcars)[-1], - selected = NULL - ), - tableOutput("data") - ) - ), - server = function(input, output) { - output$data <- renderTable( - { - mtcars[, c("mpg", input$variable), drop = FALSE] - }, - rownames = TRUE - ) - } - ) -} +app <- shinyApp( + ui = f7Page( + title = "My app", + f7SingleLayout( + navbar = f7Navbar(title = "f7CheckboxGroup"), + f7CheckboxGroup( + inputId = "checkboxgroup", + label = "Choose a variable:", + choices = colnames(mtcars)[-1], + selected = "disp", + position = "right" + ), + tableOutput("data") + ) + ), + server = function(input, output) { + output$data <- renderTable( + { + mtcars[, c("mpg", input$checkboxgroup), drop = FALSE] + }, + rownames = TRUE + ) + } +) + +if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app } diff --git a/man/f7-deprecated.Rd b/man/f7-deprecated.Rd index bb0222b2..b8159e71 100644 --- a/man/f7-deprecated.Rd +++ b/man/f7-deprecated.Rd @@ -1,9 +1,7 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/f7-inputs.R, R/f7-tabs.R, -% R/f7-validate-inputs.R, R/f7Popover.R, R/f7Preloader.R, R/manifest.R -\name{f7checkBox} -\alias{f7checkBox} -\alias{f7checkBoxGroup} +% Please edit documentation in R/f7-tabs.R, R/f7-validate-inputs.R, +% R/f7Popover.R, R/f7Preloader.R, R/manifest.R +\name{f7InsertTab} \alias{f7InsertTab} \alias{f7RemoveTab} \alias{f7ValidateInput} @@ -12,12 +10,8 @@ \alias{f7ShowPreloader} \alias{hideF7Preloader} \alias{create_manifest} -\title{Deprecated functions} +\title{Framework7 tab insertion} \usage{ -f7checkBox(inputId, label, value = FALSE) - -f7checkBoxGroup(inputId, label, choices = NULL, selected = NULL) - f7InsertTab( id, tab, @@ -63,8 +57,6 @@ create_manifest( ) } \arguments{ -\item{inputId}{Input to validate.} - \item{id}{\link{f7Tabs} id.} \item{tab}{\link{f7Tab} to insert.} @@ -77,6 +69,8 @@ create_manifest( \item{session}{shiny session.} +\item{inputId}{Input to validate.} + \item{info}{Additional text to display below the input field.} \item{pattern}{Pattern for validation. Regex.} @@ -118,11 +112,6 @@ This function creates a www folder for your shiny app. Must specify the path. It creates 1 folders to contain icons and the manifest.json file. } \description{ -\code{f7checkBox} creates a checkbox input. Use \link{f7Checkbox} instead. - -\code{f7checkBoxGroup} creates a checkbox group input. -Use \link{f7CheckboxGroup} instead - \code{removeF7Tab} removes an \link{f7Tab} in an \link{f7Tabs}. Use \link{removeF7Tab} instead diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001.json b/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001.json new file mode 100644 index 00000000..5aa10550 --- /dev/null +++ b/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001.json @@ -0,0 +1,5 @@ +{ + "input": { + "checkbox": false + } +} diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001_.png b/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001_.png new file mode 100644 index 00000000..20980f47 Binary files /dev/null and b/tests/testthat/_snaps/mac-4.3/checkbox/checkbox-app-001_.png differ diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001.json b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001.json new file mode 100644 index 00000000..7aa74d69 --- /dev/null +++ b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001.json @@ -0,0 +1,5 @@ +{ + "input": { + "checkboxgroup": "disp" + } +} diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001_.png b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001_.png new file mode 100644 index 00000000..e95e6c27 Binary files /dev/null and b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-001_.png differ diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002.json b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002.json new file mode 100644 index 00000000..fd7f1136 --- /dev/null +++ b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002.json @@ -0,0 +1,5 @@ +{ + "input": { + "checkboxgroup": "wt" + } +} diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.new.png b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.new.png new file mode 100644 index 00000000..7338ffe9 Binary files /dev/null and b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.new.png differ diff --git a/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.png b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.png new file mode 100644 index 00000000..5efd2283 Binary files /dev/null and b/tests/testthat/_snaps/mac-4.3/checkbox/checkboxgroup-app-002_.png differ diff --git a/tests/testthat/_snaps/mac-4.3/f7ActionSheet/actionsheet-app-004_.new.png b/tests/testthat/_snaps/mac-4.3/f7ActionSheet/actionsheet-app-004_.new.png index 244d0546..a1c5218f 100644 Binary files a/tests/testthat/_snaps/mac-4.3/f7ActionSheet/actionsheet-app-004_.new.png and b/tests/testthat/_snaps/mac-4.3/f7ActionSheet/actionsheet-app-004_.new.png differ diff --git a/tests/testthat/test-checkbox.R b/tests/testthat/test-checkbox.R new file mode 100644 index 00000000..398300c4 --- /dev/null +++ b/tests/testthat/test-checkbox.R @@ -0,0 +1,64 @@ +test_that("checkbox tag", { + checkbox <- f7Checkbox("check", "Checkbox") + expect_s3_class(checkbox, "shiny.tag.list") + expect_length(checkbox, 2) + expect_identical(checkbox[[2]]$attribs$class, "checkbox") + expect_identical(checkbox[[2]]$children[[1]]$attribs$id, "check") +}) + +library(shinytest2) +test_that("checkbox works as expected", { + # Don't run these tests on the CRAN build servers + skip_on_cran() + shiny_app_path <- + system.file("examples/checkbox/app.R", package = "shinyMobile") + app <- AppDriver$new( + shiny_app_path, + name = "checkbox-app", + variant = platform_variant() + ) + app$expect_values(input = "checkbox") + app$click(selector = "#update") + app$expect_values(input = "checkbox") +}) + +test_that("checkboxgroup tag", { + checkbox_group <- f7CheckboxGroup( + inputId = "checkboxgroup", + label = "Choose a variable:", + choices = colnames(mtcars)[-1], + selected = "disp", + position = "right" + ) + expect_s3_class(checkbox_group, "shiny.tag.list") + expect_length(checkbox_group, 2) + expect_identical(checkbox_group[[1]]$attribs$class, "block-title") + expect_identical(checkbox_group[[2]]$attribs$id, "checkboxgroup") + expect_identical( + checkbox_group[[2]]$attribs$class, + "list list-strong-ios list-outline-ios list-dividers-ios shiny-input-checkboxgroup" + ) + + # Test if items number match the choices param. + items <- htmltools::tagQuery(checkbox_group[[2]])$ + find("li")$ + selectedTag() + + expect_length(items, length(colnames(mtcars)) - 1) +}) + +library(shinytest2) +test_that("checkboxgroup works as expected", { + # Don't run these tests on the CRAN build servers + skip_on_cran() + shiny_app_path <- + system.file("examples/checkboxgroup/app.R", package = "shinyMobile") + app <- AppDriver$new( + shiny_app_path, + name = "checkboxgroup-app", + variant = platform_variant() + ) + app$expect_values(input = "checkboxgroup") + app$set_inputs("checkboxgroup" = "wt") + app$expect_values(input = "checkboxgroup") +})